R/power.t.test.R
power_t_test.Rd
Compute power of test, or determine parameters to obtain target power for equal and unequal sample sizes.
Number of observations (in the smallest group if two groups)
True difference in means
Standard deviation
Significance level (Type I error probability)
Power of test (1 minus Type II error probability)
The ratio n2/n1 between the larger group and the smaller group. Should be a value equal to or greater than 1 since n2 is the larger group. Defaults to 1 (equal group sizes). If ratio is set to NULL (i.e., find the ratio) then the ratio might be smaller than 1 depending on the desired power and ratio of the sd's.
The ratio sd2/sd1 between the standard deviations in the larger group and the smaller group. Defaults to 1 (equal standard deviations in the two groups)
Type of t test
One- or two-sided test
Method for calculating the degrees of default. Possibilities are welch (the default) or classical.
Use strict interpretation in two-sided case. Defaults to TRUE unlike the standard power.t.test function.
Object of class power.htest
, a list of the arguments (including the computed one)
augmented with method
and note
elements.
Exactly one of the parameters n
, delta
, power
, sd
, sig.level
, ratio
sd.ratio
must be passed as NULL,
and that parameter is determined from the others. Notice that the last two have non-NULL defaults
so NULL must be explicitly passed if you want to compute them.
The default strict = TRUE
ensures that the power will include the probability
of rejection in the opposite direction of the true effect, in the
two-sided case. Without this the power will be half the
significance level if the true difference is zero.
uniroot
is used to solve power equation for unknowns, so you may
see errors from it, notably about inability to bracket the root
when invalid arguments are given.
# Sampling with a ratio of 1:4
power_t_test(delta=300, sd=450, power=.8, ratio=4)
#>
#> Two-sample t test power calculation with unequal sample sizes
#>
#> n = 23.37341, 93.49363
#> delta = 300
#> sd = 450, 450
#> sig.level = 0.05
#> power = 0.8
#> alternative = two.sided
#>
#> NOTE: n is vector of number in each group
#>
# Equal group sizes but different sd's
# The sd in the second group is twice the sd in the second group
power_t_test(delta=300, sd=450, power=.8, sd.ratio=2)
#>
#> Two-sample t test power calculation with unequal variances
#>
#> n = 89.61929, 89.61929
#> delta = 300
#> sd = 450, 900
#> sig.level = 0.05
#> power = 0.8
#> alternative = two.sided
#>
#> NOTE: n is number in *each* group
#>
# Fixed group one size to 50 individuals, but looking for the number of individuals in the
# second group. Different sd's with twice the sd in the larger group
power_t_test(n=50, delta=300, sd=450, power=.8, ratio=NULL, sd.ratio=2)
#>
#> Two-sample t test power calculation with unequal sample sizes and unequal variances
#>
#> n = 50.0000, 111.3118
#> delta = 300
#> sd = 450, 900
#> sig.level = 0.05
#> power = 0.8
#> alternative = two.sided
#>
#> NOTE: n is vector of number in each group
#>