Skip to content

Commit

Permalink
Style code (GHA)
Browse files Browse the repository at this point in the history
  • Loading branch information
guangguangzai committed Aug 21, 2024
1 parent 6235ec0 commit a16939a
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions vignettes/wpgsd_corr_example.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ library(gt)
```{r}
event_tb <- tribble(
~Population, ~"Number of Event in IA", ~"Number of Event in FA",
"Population 1", 100,200,
"Population 2", 110,220,
"Population 1", 100, 200,
"Population 2", 110, 220,
"Overlap of Population 1 and 2", 80, 160,
"Overall Population", 225, 450
)
Expand All @@ -60,7 +60,7 @@ The number of events are listed as
event_tbl <- tribble(
~Population, ~"Number of Event in IA",
"Population 1", 100,
"Population 2", 110,
"Population 2", 110,
"Overlap in population 1 and 2", 80
)
event_tbl %>%
Expand All @@ -70,8 +70,8 @@ event_tbl %>%
The the corrleation could be simply calculated as
$$Corr(Z_{11},Z_{21})=\frac{80}{\sqrt{100*110}}=0.76$$
```{r}
Corr1=80/sqrt(100*110)
round(Corr1,2)
Corr1 <- 80 / sqrt(100 * 110)
round(Corr1, 2)
```

### Example 2 - Correlation of different analyses within the same population
Expand All @@ -82,7 +82,7 @@ The number of events are listed as
```{r}
event_tb2 <- tribble(
~Population, ~"Number of Event in IA", ~"Number of Event in FA",
"Population 1", 100,200
"Population 1", 100, 200
)
event_tb2 %>%
gt() %>%
Expand All @@ -92,8 +92,8 @@ The the corrleation could be simply calculated as
$$Corr(Z_{11},Z_{12})=\frac{100}{\sqrt{100*200}}=0.71$$
The 100 in the numerator is the overlap number of events of interim analysis and final analysis in population 1.
```{r}
Corr1=100/sqrt(100*200)
round(Corr1,2)
Corr1 <- 100 / sqrt(100 * 200)
round(Corr1, 2)
```
### Example 3 - Correlation of different analyses and different population
Let's consider the situation that we want to compare population 1 in interim analyses and population 2 in final analyses. Then for different population, $i=1$ and $i=2$, and to compare IA and FA, the $k$ will be $k=1$ and $k=2$.
Expand All @@ -103,10 +103,9 @@ The number of events are listed as
```{r}
event_tb3 <- tribble(
~Population, ~"Number of Event in IA", ~"Number of Event in FA",
"Population 1", 100,200,
"Population 1", 100, 200,
"Population 2", 110, 220,
"Overlap in population 1 and 2", 80,160
"Overlap in population 1 and 2", 80, 160
)
event_tb3 %>%
gt() %>%
Expand All @@ -116,31 +115,31 @@ The correlation could be simply calculated as
$$Corr(Z_{11},Z_{22})=\frac{80}{\sqrt{100*220}}=0.54$$
The 80 in the numerator is the overlap number of events of population 1 in interim analysis and population 2 in final analysis.
```{r}
Corr1=80/sqrt(100*220)
round(Corr1,2)
Corr1 <- 80 / sqrt(100 * 220)
round(Corr1, 2)
```
Now we know how to calculate the correlation values under different situations, and the generate_corr() function was built based on this logic. We can directly calculate the results for each cross situation via the function.

First, we need a event table including the information of the study.

```{r}
library(wpgsd)
#The event table
# The event table
event <- tibble::tribble(
~ H1, ~H2, ~Analysis, ~Event,
1, 1, 1, 100,
2, 2, 1, 110,
3, 3, 1, 225,
1, 2, 1, 80,
1, 3, 1, 100,
2, 3, 1, 110,
1, 1, 2, 200,
2, 2, 2, 220,
3, 3, 2, 450,
1, 2, 2, 160,
1, 3, 2, 200,
2, 3, 2, 220
)
~H1, ~H2, ~Analysis, ~Event,
1, 1, 1, 100,
2, 2, 1, 110,
3, 3, 1, 225,
1, 2, 1, 80,
1, 3, 1, 100,
2, 3, 1, 110,
1, 1, 2, 200,
2, 2, 2, 220,
3, 3, 2, 450,
1, 2, 2, 160,
1, 3, 2, 200,
2, 3, 2, 220
)
event %>%
gt() %>%
tab_header(title = "Number of events at each population & analyses")
Expand All @@ -155,4 +154,4 @@ For example: H1=1, H2=1, Analysis=1, Event=100 indicates that in the first popul

Another example: H1=1, H2=2, Analysis=2, Event=160 indicates that the number of overlapping cases where the experimental treatment is superior to the control in population 1 and 2 in the final analysis is 160.

*To be noticed, the column names in this function are fixed to be 'H1, H2, Analysis, Event'.
*To be noticed, the column names in this function are fixed to be 'H1, H2, Analysis, Event'.

0 comments on commit a16939a

Please sign in to comment.