Learn R Programming

powerSurvEpi (version 0.1.5)

ssizeWelchT: Sample Size Calculation For Two-Sided Two Sample T Test With Unequal Variances And Unequal Sample Sizes

Description

Sample size calculation for two-sided two sample t test with unequal variances and unequal sample sizes

Usage

ssizeWelchT(
  ratioN2toN1, 
  meanDiff, 
  sd1, 
  sd2, 
  power = 0.8, 
  alpha = 0.05, 
  minN1 = 3)

Value

A list with 2 elements

n1

sample size for group 1

n2

sample size for group 2

Arguments

ratioN2toN1

numeric. The ratio of sample size for group 2 to sample size for group 1

meanDiff

mean difference between 2 groups

sd1

standard deviation of group 1

sd2

standard deviation of group 2

power

power

alpha

Type I error rate

minN1

minimum sample size for group 1

Details

The power formula is $$ power = Pr\left(|T| > t_{1-\alpha/2, \nu} | T \sim t_{\nu, \lambda}\right), $$ where \(\lambda\) is the noncentrality parameter of the t distribution with degree of freedom \(\nu\). \(t_{1-\alpha/2, \nu}\) is the upper \(100\alpha/2\) percentile of the t distribution with degree of freedom \(\nu\). \(\alpha\) is the significance level. The noncentrality parameter \(\lambda\) is defined as $$ \lambda = \frac{|\mu_1 - \mu_2|}{\sqrt{\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}}}. $$

The degree \(\nu\) of freedom is the Satterthwaite approximation and is defined as $$ \nu = \frac{\left(\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}\right)^2}{ \frac{\left(\frac{\sigma_1^2}{n_1}\right)^2}{n_1-1} + \frac{\left(\frac{\sigma_2^2}{n_2}\right)^2}{n_2-1} } $$

Examples

Run this code
ssizeWelchT(
    ratioN2toN1=30/64, # ratio of sample size for group 2 to sample size for group 1
    meanDiff = 1, # mean difference between 2 groups
    sd1 = 2, # SD of group 1
    sd2 = 1, # SD of group 2
    power = 0.8918191, # power
    alpha = 0.05, # type I error rate
    minN1 = 3 # minimu possible sample size for group 1
)
# n1 = 64 and n2 = 30

Run the code above in your browser using DataLab