Skip to content

Commit 5def267

Browse files
author
NightlordTW
committed
Expand vignette
1 parent 6d10800 commit 5def267

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

vignettes/sampleSize_parallel_2A1E.Rmd

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ To estimate the power for different sample sizes, we use the [sampleSize()](../
6666
Below is an example of how the function can be implemented in R:
6767

6868
```{r}
69+
library(SimTOST)
70+
6971
(N_ss <- sampleSize(
7072
power = 0.90, # Target power
7173
alpha = 0.025, # Type-I error rate
@@ -78,7 +80,6 @@ Below is an example of how the function can be implemented in R:
7880
ctype = "DOM", # Comparison type
7981
lognorm = FALSE, # Assumes normal distribution
8082
optimization_method = "step-by-step", # Optimization method
81-
adjust = "no", # No adjustments
8283
ncores = 1, # Single-core processing
8384
nsim = 1000, # Number of simulations
8485
seed = 1234 # Random seed for reproducibility
@@ -94,10 +95,11 @@ We can visualize the power curve for different sample sizes using the following
9495
plot(N_ss)
9596
```
9697

97-
Consider now we want to adjust the sample size for an anticipated drop-out rate of 20% in each group. We can modify the code as follows:
98+
To account for an anticipated dropout rate of 20% in each group, we need to adjust the sample size. The following code demonstrates how to incorporate this adjustment using a custom optimization routine. This routine is designed to find the smallest integer sample size that meets or exceeds the target power. It employs a stepwise search strategy, starting with larger step sizes and progressively refining them as it approaches the solution.
9899

99100
```{r}
100-
(N_ss <- sampleSize(
101+
# Adjusted sample size calculation with 20% dropout rate
102+
(N_ss_dropout <- sampleSize(
101103
power = 0.90, # Target power
102104
alpha = 0.025, # Type-I error rate
103105
mu_list = list("R" = mu_r, "T" = mu_t), # Means for reference and treatment groups
@@ -109,13 +111,13 @@ Consider now we want to adjust the sample size for an anticipated drop-out rate
109111
dtype = "parallel", # Study design
110112
ctype = "DOM", # Comparison type
111113
lognorm = FALSE, # Assumes normal distribution
112-
optimization_method = "step-by-step", # Optimization method
113-
adjust = "no", # No adjustments
114+
optimization_method = "fast", # Fast optimization method
114115
ncores = 1, # Single-core processing
115116
nsim = 1000, # Number of simulations
116117
seed = 1234 # Random seed for reproducibility
117118
))
118119
```
119-
120+
121+
Previously, finding the required sample size took `r nrow(N_ss$table.iter)` iterations. With the fast optimizer, the number of iterations is reduced to `r nrow(N_ss_dropout$table.iter)`, significantly improving efficiency.
120122

121123

0 commit comments

Comments
 (0)