Compute the power of a one- or two-sample t-test, given the sample size, scaled difference, and significance level.
Extended methods and derivations are available in
Statistical power and study design: tTestPower.
Open the vignette locally with
vignette("power-and-study-design", package = "EnvStats").
numeric vector of sample sizes. When sample.type="one.sample",
n.or.n1 denotes \(n\), the number of observations in the single sample. When sample.type="two.sample", n.or.n1 denotes \(n_1\), the number
of observations from group 1.
Missing (NA), undefined (NaN), and infinite (Inf, -Inf)
values are not allowed.
numeric vector of sample sizes for group 2. The default value is the value of
n.or.n1. This argument is ignored when sample.type="one.sample".
Missing (NA), undefined (NaN), and infinite (Inf, -Inf)
values are not allowed.
numeric vector specifying the ratio of the true difference \(\delta\) (\(\delta = \mu - \mu_0\) for the one-sample case and \(\delta = \mu_1 - \mu_2\) for the two-sample case) to the population standard deviation (\(\sigma\)). This is also called the “scaled difference”.
The default value is delta.over.sigma=0.
numeric vector of numbers between 0 and 1 indicating the Type I error level
associated with the hypothesis test. The default value is alpha=0.05.
character string indicating whether to compute power based on a one-sample or
two-sample hypothesis test. When sample.type="one.sample", the computed
power is based on a hypothesis test for a single mean. When sample.type="two.sample", the computed power is based on a hypothesis test
for the difference between two means. The default value is
sample.type="one.sample" unless the argument n2 is supplied.
character string indicating the kind of alternative hypothesis. The possible values are:
"two.sided" (the default). \(H_a: \mu \ne \mu_0\) for the one-sample case and
\(H_a: \mu_1 \ne \mu_2\) for the two-sample case.
"greater". \(H_a: \mu > \mu_0\) for the one-sample case and
\(H_a: \mu_1 > \mu_2\) for the two-sample case.
"less". \(H_a: \mu < \mu_0\) for the one-sample case and
\(H_a: \mu_1 < \mu_2\) for the two-sample case.
logical scalar indicating whether to compute the power based on an approximation to
the non-central t-distribution. The default value is FALSE.
a numeric vector powers.
Berthouex, P.M., and L.C. Brown. (2002). Statistics for Environmental Engineers. Second Edition. Lewis Publishers, Boca Raton, FL.
Helsel, D.R., and R.M. Hirsch. (1992). Statistical Methods in Water Resources Research. Elsevier, New York, NY, Chapter 7.
Johnson, N. L., S. Kotz, and N. Balakrishnan. (1995). Continuous Univariate Distributions, Volume 2. Second Edition. John Wiley and Sons, New York, Chapters 28, 31
Millard, S.P., and N.K. Neerchal. (2001). Environmental Statistics with S-PLUS. CRC Press, Boca Raton, FL.
USEPA. (1989b). Statistical Analysis of Ground-Water Monitoring Data at RCRA Facilities, Interim Final Guidance. EPA/530-SW-89-026. Office of Solid Waste, U.S. Environmental Protection Agency, Washington, D.C.
USEPA. (2009). Statistical Analysis of Groundwater Monitoring Data at RCRA Facilities, Unified Guidance. EPA 530/R-09-007, March 2009. Office of Resource Conservation and Recovery Program Implementation and Information Division. U.S. Environmental Protection Agency, Washington, D.C.
Zar, J.H. (2010). Biostatistical Analysis. Fifth Edition. Prentice-Hall, Upper Saddle River, NJ.
The normal distribution and lognormal distribution are probably the two most frequently used distributions to model environmental data. Often, you need to determine whether a population mean is significantly different from a specified standard (e.g., an MCL or ACL, USEPA, 1989b, Section 6), or whether two different means are significantly different from each other (e.g., USEPA 2009, Chapter 16). In this case, assuming normally distributed data, you can perform the Student's t-test.
In the course of designing a sampling program, an environmental scientist may wish
to determine the relationship between sample size, significance level, power, and
scaled difference if one of the objectives of the sampling program is to determine
whether a mean differs from a specified level or two means differ from each other.
The functions tTestPower, tTestN,
tTestScaledMdd, and plotTTestDesign can be used to
investigate these relationships for the case of normally-distributed observations.
# Look at how the power of the one-sample t-test increases with
# increasing sample size:
seq(5, 30, by = 5)
#> [1] 5 10 15 20 25 30
#[1] 5 10 15 20 25 30
power <- tTestPower(n.or.n1 = seq(5, 30, by = 5), delta.over.sigma = 0.5)
round(power, 2)
#> [1] 0.14 0.29 0.44 0.56 0.67 0.75
#[1] 0.14 0.29 0.44 0.56 0.67 0.75
#----------
# Repeat the last example, but use the approximation.
# Note how the approximation underestimates the power
# for the smaller sample sizes.
#----------------------------------------------------
power <- tTestPower(n.or.n1 = seq(5, 30, by = 5), delta.over.sigma = 0.5,
approx = TRUE)
round(power, 2)
#> [1] 0.10 0.26 0.42 0.56 0.67 0.75
#[1] 0.10 0.26 0.42 0.56 0.67 0.75
#----------
# Look at how the power of the two-sample t-test increases with increasing
# scaled difference:
seq(0.5, 2, by = 0.5)
#> [1] 0.5 1.0 1.5 2.0
#[1] 0.5 1.0 1.5 2.0
power <- tTestPower(10, sample.type = "two.sample",
delta.over.sigma = seq(0.5, 2, by = 0.5))
round(power, 2)
#> [1] 0.19 0.56 0.89 0.99
#[1] 0.19 0.56 0.89 0.99
#----------
# Look at how the power of the two-sample t-test increases with increasing values
# of Type I error:
power <- tTestPower(20, sample.type = "two.sample", delta.over.sigma = 0.5,
alpha = c(0.001, 0.01, 0.05, 0.1))
round(power, 2)
#> [1] 0.03 0.14 0.34 0.46
#[1] 0.03 0.14 0.34 0.46
#==========
# Modifying the example on pages 21-4 to 21-5 of USEPA (2009), determine how
# adding another four months of observations to increase the sample size from
# 4 to 8 for any one particular compliance well will affect the power of a
# one-sample t-test that compares the mean for the well with the MCL of
# 7 ppb. Use alpha = 0.01, assume an upper one-sided alternative
# (i.e., compliance well mean larger than 7 ppb), and assume a scaled
# difference of 2. (The data are stored in EPA.09.Ex.21.1.aldicarb.df.)
# Note that the power changes from 49% to 98% by increasing the sample size
# from 4 to 8.
tTestPower(n.or.n1 = c(4, 8), delta.over.sigma = 2, alpha = 0.01,
sample.type = "one.sample", alternative = "greater")
#> [1] 0.4865800 0.9835401
#[1] 0.4865800 0.9835401
#==========
# Clean up
#---------
rm(power)