Last updated: 2024-12-05

Checks: 7 0

Knit directory: demor2/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20241122) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 91cee18. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/power.Rmd) and HTML (docs/power.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 91cee18 Chun-Hui Lin 2024-12-05 Update power page (Fisher’s exact test).
html 2739810 Chun-Hui Lin 2024-12-03 Build site.
Rmd 3cd7a71 Chun-Hui Lin 2024-12-03 Update power page (chi-squared test).
html 8d0c926 Chun-Hui Lin 2024-12-03 Build site.
Rmd 5776387 Chun-Hui Lin 2024-12-03 Add power-related files.

Some notes on power/sample size calculation from the pwr tutorial and prior experience. Before jumping into the calculation, things-to-do are listed in the following:

  • Exposure and outcome type/distribution: determine which test to use.
  • Minimal clinically important difference (MCID): expect the smallest meaningful change.
  • Power and significance level (\(\alpha\)): usually apply 80% and 0.05 as the setup.
  • For power calculation, number of samples collected per group is necessary.
  • For sample size calculation, effect size (\(|\mu_1 - \mu_2|/\sigma\)) or its components are necessary. You can either make assumption of it or obtain estimates from dataset or literature review.

Two-sample t-test

pwr::pwr.t.test

Assuming an effect size of 1, we’ll need at least 17 subjects in each group to detect the difference with at least 80% power using \(\alpha\)=0.05 and two-sided testing.

# assume same sizes per group
pwr.t.test(d = 1, power = 0.8)

     Two-sample t test power calculation 

              n = 16.71472
              d = 1
      sig.level = 0.05
          power = 0.8
    alternative = two.sided

NOTE: n is number in *each* group

pwr::pwr.t2n.test

When the sample sizes in the two groups are 198 and 37 respectively, we are able to detect a mean difference of 9.029, assuming the common standard deviation is 17.92, with at least 80% power using \(\alpha\)=0.05 and two-sided testing.

# assume different sizes per group
pwr.t2n.test(n1 = 198, n2 = 37, power = 0.8)

     t test power calculation 

             n1 = 198
             n2 = 37
              d = 0.5038656
      sig.level = 0.05
          power = 0.8
    alternative = two.sided

Chi-squared test

nQuery::PTT0PU-1

pwr.2p2n.test is not applicable since we assume certain proportion of group 1 based on literature review. Assuming that roughly 35% of group 1 will develop the outcome, with the observed samples sizes, we are able to detect a difference in proportions of 9.3% (35% in group 1 vs. 44.3% in group 2) with 80% power using \(\alpha\)=0.05 and two-sided testing.

Fisher’s exact test

Exact::power.exact.test

With an overall sample size of 30 and 5 per skin type, only a difference between 0% and 100% could be detected with 80% power using \(\alpha\)=0.05 and two-sided testing. Under same assumption, the differences between 0% and 80% or 20% and 100% could be detected with power between 70% and 80%. Those are large differences which may not be observed in the study with small sample size per group.

power.exact.test(0, 1, 5, 5, method = 'fisher')

     Fisher's Exact Test 

         n1, n2 = 5, 5
         p1, p2 = 0, 1
          alpha = 0.05
          power = 1
    alternative = two.sided
          delta = 0
# equivalent: c(0.2, 1, 5, 5)
power.exact.test(0, 0.8, 5, 5, method = 'fisher')

     Fisher's Exact Test 

         n1, n2 = 5, 5
         p1, p2 = 0.0, 0.8
          alpha = 0.05
          power = 0.73728
    alternative = two.sided
          delta = 0

sessionInfo()
R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS 15.1.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Detroit
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Exact_3.3       pwr_1.3-0       workflowr_1.7.1

loaded via a namespace (and not attached):
 [1] jsonlite_1.8.9    compiler_4.4.0    promises_1.3.0    Rcpp_1.0.13      
 [5] stringr_1.5.1     git2r_0.33.0      callr_3.7.6       later_1.3.2      
 [9] jquerylib_0.1.4   yaml_2.3.10       fastmap_1.2.0     R6_2.5.1         
[13] knitr_1.48        tibble_3.2.1      rprojroot_2.0.4   bslib_0.8.0      
[17] pillar_1.9.0      rlang_1.1.4       utf8_1.2.4        cachem_1.1.0     
[21] stringi_1.8.4     httpuv_1.6.15     xfun_0.47         getPass_0.2-4    
[25] fs_1.6.4          sass_0.4.9        cli_3.6.3         magrittr_2.0.3   
[29] ps_1.7.6          digest_0.6.37     processx_3.8.4    rootSolve_1.8.2.4
[33] rstudioapi_0.16.0 ExactData_2.0     lifecycle_1.0.4   vctrs_0.6.5      
[37] evaluate_1.0.0    glue_1.8.0        whisker_0.4.1     fansi_1.0.6      
[41] rmarkdown_2.28    httr_1.4.7        tools_4.4.0       pkgconfig_2.0.3  
[45] htmltools_0.5.8.1