tTestPower {EnvStats}R Documentation

Power of a One- or Two-Sample t-Test

Description

Compute the power of a one- or two-sample t-test, given the sample size, scaled difference, and significance level.

Usage

  tTestPower(n.or.n1, n2 = n.or.n1, delta.over.sigma = 0, alpha = 0.05, 
    sample.type = ifelse(!missing(n2), "two.sample", "one.sample"), 
    alternative = "two.sided", approx = FALSE)

Arguments

n.or.n1

numeric vector of sample sizes. When sample.type="one.sample", n.or.n1 denotes nn, the number of observations in the single sample. When
sample.type="two.sample", n.or.n1 denotes n1n_1, the number of observations from group 1. Missing (NA), undefined (NaN), and infinite (Inf, -Inf) values are not allowed.

n2

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.

delta.over.sigma

numeric vector specifying the ratio of the true difference δ\delta (δ=μμ0\delta = \mu - \mu_0 for the one-sample case and δ=μ1μ2\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.

alpha

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.

sample.type

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.

alternative

character string indicating the kind of alternative hypothesis. The possible values are:

  • "two.sided" (the default). Ha:μμ0H_a: \mu \ne \mu_0 for the one-sample case and Ha:μ1μ2H_a: \mu_1 \ne \mu_2 for the two-sample case.

  • "greater". Ha:μ>μ0H_a: \mu > \mu_0 for the one-sample case and Ha:μ1>μ2H_a: \mu_1 > \mu_2 for the two-sample case.

  • "less". Ha:μ<μ0H_a: \mu < \mu_0 for the one-sample case and Ha:μ1<μ2H_a: \mu_1 < \mu_2 for the two-sample case.

approx

logical scalar indicating whether to compute the power based on an approximation to the non-central t-distribution. The default value is FALSE.

Details

If the arguments n.or.n1, n2, delta.over.sigma, and alpha are not all the same length, they are replicated to be the same length as the length of the longest argument.

One-Sample Case (sample.type="one.sample")
Let x=x1,x2,,xn\underline{x} = x_1, x_2, \ldots, x_n denote a vector of nn observations from a normal distribution with mean μ\mu and standard deviation σ\sigma, and consider the null hypothesis:

H0:μ=μ0            (1)H_0: \mu = \mu_0 \;\;\;\;\;\; (1)

The three possible alternative hypotheses are the upper one-sided alternative (alternative="greater"):

Ha:μ>μ0            (2)H_a: \mu > \mu_0 \;\;\;\;\;\; (2)

the lower one-sided alternative (alternative="less")

Ha:μ<μ0            (3)H_a: \mu < \mu_0 \;\;\;\;\;\; (3)

and the two-sided alternative (alternative="two.sided")

Ha:μμ0            (4)H_a: \mu \ne \mu_0 \;\;\;\;\;\; (4)

The test of the null hypothesis (1) versus any of the three alternatives (2)-(4) is based on the Student t-statistic:

t=xˉμ0s/n            (5)t = \frac{\bar{x} - \mu_0}{s/\sqrt{n}} \;\;\;\;\;\; (5)

where

xˉ=1ni=1nxi            (6)\bar{x} = \frac{1}{n} \sum_{i=1}^n x_i \;\;\;\;\;\; (6)

s2=1n1i=1n(xixˉ)2            (7)s^2 = \frac{1}{n-1} \sum_{i=1}^n (x_i - \bar{x})^2 \;\;\;\;\;\; (7)

Under the null hypothesis (1), the t-statistic in (5) follows a Student's t-distribution with n1n-1 degrees of freedom (Zar, 2010, Chapter 7; Johnson et al., 1995, pp.362-363).

The formula for the power of the test depends on which alternative is being tested. The two subsections below describe exact and approximate formulas for the power of the one-sample t-test. Note that none of the equations for the power of the t-test requires knowledge of the values δ\delta (Equation (12) below) or σ\sigma (the population standard deviation), only the ratio δ/σ\delta/\sigma. The argument delta.over.sigma is this ratio, and it is referred to as the “scaled difference”.

Exact Power Calculations (approx=FALSE)
This subsection describes the exact formulas for the power of the one-sample t-test.

Upper one-sided alternative (alternative="greater")
The standard Student's t-test rejects the null hypothesis (1) in favor of the upper alternative hypothesis (2) at level-α\alpha if

ttν(1α)            (8)t \ge t_{\nu}(1 - \alpha) \;\;\;\;\;\; (8)

where

ν=n1            (9)\nu = n - 1 \;\;\;\;\;\; (9)

and tν(p)t_{\nu}(p) denotes the pp'th quantile of Student's t-distribution with ν\nu degrees of freedom (Zar, 2010; Berthouex and Brown, 2002). The power of this test, denoted by 1β1-\beta, where β\beta denotes the probability of a Type II error, is given by:

1β=Pr[tν,Δtν(1α)]=1G[tν(1α),ν,Δ]            (10)1 - \beta = Pr[t_{\nu, \Delta} \ge t_{\nu}(1 - \alpha)] = 1 - G[t_{\nu}(1 - \alpha), \nu, \Delta] \;\;\;\;\;\; (10)

where

Δ=n(δσ)            (11)\Delta = \sqrt{n} (\frac{\delta}{\sigma}) \;\;\;\;\;\; (11)

δ=μμ0           (12)\delta = \mu - \mu_0 \;\;\;\;\;\ (12)

and tν,Δt_{\nu, \Delta} denotes a non-central Student's t-random variable with ν\nu degrees of freedom and non-centrality parameter Δ\Delta, and G(x,ν,Δ)G(x, \nu, \Delta) denotes the cumulative distribution function of this random variable evaluated at xx (Johnson et al., 1995, pp.508-510).

Lower one-sided alternative (alternative="less")
The standard Student's t-test rejects the null hypothesis (1) in favor of the lower alternative hypothesis (3) at level-α\alpha if

ttν(α)            (13)t \le t_{\nu}(\alpha) \;\;\;\;\;\; (13)

and the power of this test is given by:

1β=Pr[tν,Δtν(α)]=G[tν(α),ν,Δ]            (14)1 - \beta = Pr[t_{\nu, \Delta} \le t_{\nu}(\alpha)] = G[t_{\nu}(\alpha), \nu, \Delta] \;\;\;\;\;\; (14)


Two-sided alternative (alternative="two.sided")
The standard Student's t-test rejects the null hypothesis (1) in favor of the two-sided alternative hypothesis (4) at level-α\alpha if

ttν(1α/2)            (15)|t| \ge t_{\nu}(1 - \alpha/2) \;\;\;\;\;\; (15)

and the power of this test is given by:

1β=Pr[tν,Δtν(α/2)]+Pr[tν,Δtν(1α/2)]1 - \beta = Pr[t_{\nu, \Delta} \le t_{\nu}(\alpha/2)] + Pr[t_{\nu, \Delta} \ge t_{\nu}(1 - \alpha/2)]

=G[tν(α/2),ν,Δ]+1G[tν(1α/2),ν,Δ]            (16)= G[t_{\nu}(\alpha/2), \nu, \Delta] + 1 - G[t_{\nu}(1 - \alpha/2), \nu, \Delta] \;\;\;\;\;\; (16)

The power of the t-test given in Equation (16) can also be expressed in terms of the cumulative distribution function of the non-central F-distribution as follows. Let Fν1,ν2,ΔF_{\nu_1, \nu_2, \Delta} denote a non-central F random variable with ν1\nu_1 and ν2\nu_2 degrees of freedom and non-centrality parameter Δ\Delta, and let H(x,ν1,ν2,Δ)H(x, \nu_1, \nu_2, \Delta) denote the cumulative distribution function of this random variable evaluated at xx. Also, let Fν1,ν2(p)F_{\nu_1, \nu_2}(p) denote the pp'th quantile of the central F-distribution with ν1\nu_1 and ν2\nu_2 degrees of freedom. It can be shown that

(tν,Δ)2F1,ν,Δ2            (17)(t_{\nu, \Delta})^2 \cong F_{1, \nu, \Delta^2} \;\;\;\;\;\; (17)

where \cong denotes “equal in distribution”. Thus, it follows that

[tν(1α/2)]2=F1,ν(1α)            (18)[t_{\nu}(1 - \alpha/2)]^2 = F_{1, \nu}(1 - \alpha) \;\;\;\;\;\; (18)

so the formula for the power of the t-test given in Equation (16) can also be written as:

1β=Pr{(tν,Δ)2[tν(1α/2)]2}1 - \beta = Pr\{(t_{\nu, \Delta})^2 \ge [t_{\nu}(1 - \alpha/2)]^2\}

=Pr[F1,ν,Δ2F1,ν(1α)]=1H[F1,ν(1α),1,ν,Δ2]            (19)= Pr[F_{1, \nu, \Delta^2} \ge F_{1, \nu}(1 - \alpha)] = 1 - H[F_{1, \nu}(1-\alpha), 1, \nu, \Delta^2] \;\;\;\;\;\; (19)


Approximate Power Calculations (approx=TRUE)
Zar (2010, pp.115–118) presents an approximation to the power for the t-test given in Equations (10), (14), and (16) above. His approximation to the power can be derived by using the approximation

n(δs)n(δσ)=Δ            (20)\sqrt{n} (\frac{\delta}{s}) \approx \sqrt{n} (\frac{\delta}{\sigma}) = \Delta \;\;\;\;\;\; (20)

where \approx denotes “approximately equal to”. Zar's approximation can be summarized in terms of the cumulative distribution function of the non-central t-distribution as follows:

G(x,ν,Δ)G(xΔ,ν,0)=G(xΔ,ν)            (21)G(x, \nu, \Delta) \approx G(x - \Delta, \nu, 0) = G(x - \Delta, \nu) \;\;\;\;\;\; (21)

where G(x,ν)G(x, \nu) denotes the cumulative distribution function of the central Student's t-distribution with ν\nu degrees of freedom evaluated at xx.

The following three subsections explicitly derive the approximation to the power of the t-test for each of the three alternative hypotheses.

Upper one-sided alternative (alternative="greater")
The power for the upper one-sided alternative (2) given in Equation (10) can be approximated as:

1β=Pr[ttν(1α)]1 - \beta = Pr[t \ge t_{\nu}(1 - \alpha)]

=Pr[xˉμs/ntν(1α)nδs]= Pr[\frac{\bar{x} - \mu}{s/\sqrt{n}} \ge t_{\nu}(1 - \alpha) - \sqrt{n}\frac{\delta}{s}]

Pr[tνtν(1α)Δ]\approx Pr[t_{\nu} \ge t_{\nu}(1 - \alpha) - \Delta]

=1Pr[tνtν(1α)Δ]= 1 - Pr[t_{\nu} \le t_{\nu}(1 - \alpha) - \Delta]

=1G[tν(1α)Δ,ν]            (22) = 1 - G[t_{\nu}(1-\alpha) - \Delta, \nu] \;\;\;\;\;\; (22)

where tνt_{\nu} denotes a central Student's t-random variable with ν\nu degrees of freedom.

Lower one-sided alternative (alternative="less")
The power for the lower one-sided alternative (3) given in Equation (14) can be approximated as:

1β=Pr[ttν(α)]1 - \beta = Pr[t \le t_{\nu}(\alpha)]

=Pr[xˉμs/ntν(α)nδs]= Pr[\frac{\bar{x} - \mu}{s/\sqrt{n}} \le t_{\nu}(\alpha) - \sqrt{n}\frac{\delta}{s}]

Pr[tνtν(α)Δ]\approx Pr[t_{\nu} \le t_{\nu}(\alpha) - \Delta]

=G[tν(α)Δ,ν]            (23) = G[t_{\nu}(\alpha) - \Delta, \nu] \;\;\;\;\;\; (23)


Two-sided alternative (alternative="two.sided")
The power for the two-sided alternative (4) given in Equation (16) can be approximated as:

1β=Pr[ttν(α/2)]+Pr[ttν(1α/2)]1 - \beta = Pr[t \le t_{\nu}(\alpha/2)] + Pr[t \ge t_{\nu}(1 - \alpha/2)]

=Pr[xˉμs/ntν(α/2)nδs]+Pr[xˉμs/ntν(1α)nδs]= Pr[\frac{\bar{x} - \mu}{s/\sqrt{n}} \le t_{\nu}(\alpha/2) - \sqrt{n}\frac{\delta}{s}] + Pr[\frac{\bar{x} - \mu}{s/\sqrt{n}} \ge t_{\nu}(1 - \alpha) - \sqrt{n}\frac{\delta}{s}]

Pr[tνtν(α/2)Δ]+Pr[tνtν(1α/2)Δ]\approx Pr[t_{\nu} \le t_{\nu}(\alpha/2) - \Delta] + Pr[t_{\nu} \ge t_{\nu}(1 - \alpha/2) - \Delta]

=G[tν(α/2)Δ,ν]+1G[tν(1α/2)Δ,ν]            (24)= G[t_{\nu}(\alpha/2) - \Delta, \nu] + 1 - G[t_{\nu}(1-\alpha/2) - \Delta, \nu] \;\;\;\;\;\; (24)


Two-Sample Case (sample.type="two.sample")
Let x1=x11,x12,,x1n1\underline{x}_1 = x_{11}, x_{12}, \ldots, x_{1n_1} denote a vector of n1n_1 observations from a normal distribution with mean μ1\mu_1 and standard deviation σ\sigma, and let x2=x21,x22,,x2n2\underline{x}_2 = x_{21}, x_{22}, \ldots, x_{2n_2} denote a vector of n2n_2 observations from a normal distribution with mean μ2\mu_2 and standard deviation σ\sigma, and consider the null hypothesis:

H0:μ1=μ2            (25)H_0: \mu_1 = \mu_2 \;\;\;\;\;\; (25)

The three possible alternative hypotheses are the upper one-sided alternative (alternative="greater"):

Ha:μ1>μ2            (26)H_a: \mu_1 > \mu_2 \;\;\;\;\;\; (26)

the lower one-sided alternative (alternative="less")

Ha:μ1<μ2            (27)H_a: \mu_1 < \mu_2 \;\;\;\;\;\; (27)

and the two-sided alternative (alternative="two.sided")

Ha:μ1μ2            (28)H_a: \mu_1 \ne \mu_2 \;\;\;\;\;\; (28)

The test of the null hypothesis (25) versus any of the three alternatives (26)-(28) is based on the Student t-statistic:

t=xˉ1xˉ2sp1n1+1n2            (29)t = \frac{\bar{x}_1 - \bar{x}_2}{s_p\sqrt{\frac{1}{n_1} + \frac{1}{n_2}}} \;\;\;\;\;\; (29)

where

xˉ1=1n1i=1n1x1i            (30)\bar{x}_1 = \frac{1}{n_1} \sum_{i=1}^{n_1} x_{1i} \;\;\;\;\;\; (30)

xˉ2=1n2i=1n2x2i            (31)\bar{x}_2 = \frac{1}{n_2} \sum_{i=1}^{n_2} x_{2i} \;\;\;\;\;\; (31)

sp2=(n11)s12+(n21)s22n1+n22            (32)s_p^2 = \frac{(n_1 - 1) s_1^2 + (n_2 - 1) s_2^2}{n_1 + n_2 - 2} \;\;\;\;\;\; (32)

s12=1n11i=1n1(x1ixˉ1)2            (33)s_1^2 = \frac{1}{n_1 - 1} \sum_{i=1}^{n_1} (x_{1i} - \bar{x}_1)^2 \;\;\;\;\;\; (33)

s22=1n21i=1n2(x2ixˉ2)2            (34)s_2^2 = \frac{1}{n_2 - 1} \sum_{i=1}^{n_2} (x_{2i} - \bar{x}_2)^2 \;\;\;\;\;\; (34)

Under the null hypothesis (25), the t-statistic in (29) follows a Student's t-distribution with n1+n22n_1 + n_2 - 2 degrees of freedom (Zar, 2010, Chapter 8; Johnson et al., 1995, pp.508–510, Helsel and Hirsch, 1992, pp.124–128).

The formulas for the power of the two-sample t-test are precisely the same as those for the one-sample case, with the following modifications:

ν=n1+n22            (35)\nu = n_1 + n_2 - 2 \;\;\;\;\;\; (35)

Δ=n1n2n1+n2(δσ)            (36)\Delta = \sqrt{\frac{n_1 n_2}{n_1 + n_2}} (\frac{\delta}{\sigma}) \;\;\;\;\;\; (36)

δ=μ1μ2            (37)\delta = \mu_1 - \mu_2 \;\;\;\;\;\; (37)

Note that none of the equations for the power of the t-test requires knowledge of the values δ\delta or σ\sigma (the population standard deviation for both populations), only the ratio δ/σ\delta/\sigma. The argument delta.over.sigma is this ratio, and it is referred to as the “scaled difference”.

Value

a numeric vector powers.

Note

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.

Author(s)

Steven P. Millard (EnvStats@ProbStatInfo.com)

References

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.

See Also

tTestN, tTestScaledMdd, tTestAlpha, plotTTestDesign, Normal, t.test, Hypothesis Tests.

Examples

  # 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 

  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

  #----------

  # 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

  #----------

  # 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 

  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

  #----------

  # 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

  #==========

  # 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

  #==========

  # Clean up
  #---------
  rm(power)

[Package EnvStats version 2.8.1 Index]