vignettes/power-and-study-design.Rmd
power-and-study-design.RmdThis vignette surveys the functions available for planning studies, then derives power calculations for t-tests and tests of a linear trend. The overview includes sample-size and precision tools for confidence, prediction, and tolerance intervals.
Related vignettes:
For monitoring-specific power calculations, see normal prediction interval power and nonparametric prediction interval power.
Help topic: FcnsByCatPower.
Confidence Intervals
| Function Name | Description |
ciTableProp
|
Confidence intervals for binomial proportion, or |
| difference between two proportions, following Bacchetti (2010) | |
ciBinomHalfWidth
|
Compute the half-width of a confidence interval for a |
| Binomial proportion or the difference between two proportions. | |
ciBinomN
|
Compute the sample size necessary to achieve a specified |
| half-width of a confidence interval for a Binomial proportion or | |
| the difference between two proportions. | |
plotCiBinomDesign
|
Create plots for a sampling design based on a confidence interval |
| for a Binomial proportion or the difference between two proportions. | |
ciTableMean
|
Confidence intervals for mean of normal distribution, or |
| difference between two means, following Bacchetti (2010) | |
ciNormHalfWidth
|
Compute the half-width of a confidence interval for the mean of a |
| Normal distribution or the difference between two means. | |
ciNormN
|
Compute the sample size necessary to achieve a specified half-width |
| of a confidence interval for the mean of a Normal distribution or | |
| the difference between two means. | |
plotCiNormDesign
|
Create plots for a sampling design based on a confidence interval |
| for the mean of a Normal distribution or the difference between | |
| two means. | |
ciNparConfLevel
|
Compute the confidence level associated with a nonparametric |
| confidence interval for a percentile. | |
ciNparN
|
Compute the sample size necessary to achieve a specified |
| confidence level for a nonparametric confidence interval for | |
| a percentile. | |
plotCiNparDesign
|
Create plots for a sampling design based on a nonparametric |
| confidence interval for a percentile. |
Hypothesis Tests
| Function Name | Description |
aovN
|
Compute the sample sizes necessary to achieve a |
| specified power for a one-way fixed-effects analysis | |
| of variance test. | |
aovPower
|
Compute the power of a one-way fixed-effects analysis of |
| variance test. | |
plotAovDesign
|
Create plots for a sampling design based on a one-way |
| analysis of variance. | |
propTestN
|
Compute the sample size necessary to achieve a specified |
| power for a one- or two-sample proportion test. | |
propTestPower
|
Compute the power of a one- or two-sample proportion test. |
propTestMdd
|
Compute the minimal detectable difference associated with |
| a one- or two-sample proportion test. | |
plotPropTestDesign
|
Create plots involving sample size, power, difference, and |
| significance level for a one- or two-sample proportion test. | |
tTestAlpha
|
Compute the Type I Error associated with specified values for |
| for power, sample size(s), and scaled MDD for a one- or | |
| two-sample t-test. | |
tTestN
|
Compute the sample size necessary to achieve a specified |
| power for a one- or two-sample t-test. | |
tTestPower
|
Compute the power of a one- or two-sample t-test. |
tTestScaledMdd
|
Compute the scaled minimal detectable difference |
| associated with a one- or two-sample t-test. | |
plotTTestDesign
|
Create plots for a sampling design based on a one- or |
| two-sample t-test. | |
tTestLnormAltN
|
Compute the sample size necessary to achieve a specified |
| power for a one- or two-sample t-test, assuming lognormal | |
| data. | |
tTestLnormAltPower
|
Compute the power of a one- or two-sample t-test, assuming |
| lognormal data. | |
tTestLnormAltRatioOfMeans
|
Compute the minimal or maximal detectable ratio of means |
| associated with a one- or two-sample t-test, assuming | |
| lognormal data. | |
plotTTestLnormAltDesign
|
Create plots for a sampling design based on a one- or |
| two-sample t-test, assuming lognormal data. | |
linearTrendTestN
|
Compute the sample size necessary to achieve a specified |
| power for a t-test for linear trend. | |
linearTrendTestPower
|
Compute the power of a t-test for linear trend. |
linearTrendTestScaledMds
|
Compute the scaled minimal detectable slope for a t-test |
| for linear trend. | |
plotLinearTrendTestDesign
|
Create plots for a sampling design based on a t-test for |
| linear trend. |
Prediction Intervals
Normal Distribution Prediction Intervals
| Function Name | Description |
predIntNormHalfWidth
|
Compute the half-width of a prediction |
| interval for a normal distribution. | |
predIntNormK
|
Compute the required value of for |
| a prediction interval for a Normal | |
| distribution. | |
predIntNormN
|
Compute the sample size necessary to |
| achieve a specified half-width for a | |
| prediction interval for a Normal | |
| distribution. | |
plotPredIntNormDesign
|
Create plots for a sampling design |
| based on the width of a prediction | |
| interval for a Normal distribution. | |
predIntNormTestPower
|
Compute the probability that at least |
| one future observation (or mean) | |
| falls outside a prediction interval | |
| for a Normal distribution. | |
plotPredIntNormTestPowerCurve
|
Create plots for a sampling |
| design based on a prediction interval | |
| for a Normal distribution. | |
predIntNormSimultaneousTestPower
|
Compute the probability that at |
| least one set of future observations | |
| (or means) violates the given rule | |
| based on a simultaneous prediction | |
| interval for a Normal distribution. | |
plotPredIntNormSimultaneousTestPowerCurve
|
Create plots for a sampling design |
| based on a simultaneous prediction | |
| interval for a Normal distribution. |
Lognormal Distribution Prediction Intervals
| Function Name | Description |
predIntLnormAltTestPower
|
Compute the probability that at least |
| one future observation (or geometric | |
| mean) falls outside a prediction | |
| interval for a lognormal distribution. | |
plotPredIntLnormAltTestPowerCurve
|
Create plots for a sampling design |
| based on a prediction interval for a | |
| lognormal distribution. | |
predIntLnormAltSimultaneousTestPower
|
Compute the probability that at least |
| one set of future observations (or | |
| geometric means) violates the given | |
| rule based on a simultaneous | |
| prediction interval for a lognormal | |
| distribution. | |
plotPredIntLnormAltSimultaneousTestPowerCurve
|
Create plots for a sampling design |
| based on a simultaneous prediction | |
| interval for a lognormal distribution. |
Nonparametric Prediction Intervals
| Function Name | Description |
predIntNparConfLevel
|
Compute the confidence level associated with |
| a nonparametric prediction interval. | |
predIntNparN
|
Compute the required sample size to achieve |
| a specified confidence level for a | |
| nonparametric prediction interval. | |
plotPredIntNparDesign
|
Create plots for a sampling design based on |
| the confidence level and sample size of a | |
| nonparametric prediction interval. | |
predIntNparSimultaneousConfLevel
|
Compute the confidence level associated with |
| a simultaneous nonparametric prediction | |
| interval. | |
predIntNparSimultaneousN
|
Compute the required sample size for a |
| simultaneous nonparametric prediction | |
| interval. | |
plotPredIntNparSimultaneousDesign
|
Create plots for a sampling design based on |
| a simultaneous nonparametric prediction | |
| interval. | |
predIntNparSimultaneousTestPower
|
Compute the probability that at least one |
| set of future observations violates the | |
| given rule based on a nonparametric | |
| simultaneous prediction interval. | |
plotPredIntNparSimultaneousTestPowerCurve
|
Create plots for a sampling design based on |
| a simultaneous nonparametric prediction | |
| interval. |
Tolerance Intervals
| Function Name | Description |
tolIntNormHalfWidth
|
Compute the half-width of a tolerance |
| interval for a normal distribution. | |
tolIntNormK
|
Compute the required value of for a |
| tolerance interval for a Normal distribution. | |
tolIntNormN
|
Compute the sample size necessary to achieve a |
| specified half-width for a tolerance interval | |
| for a Normal distribution. | |
plotTolIntNormDesign
|
Create plots for a sampling design based on a |
| tolerance interval for a Normal distribution. | |
tolIntNparConfLevel
|
Compute the confidence level associated with a |
| nonparametric tolerance interval for a specified | |
| sample size and coverage. | |
tolIntNparCoverage
|
Compute the coverage associated with a |
| nonparametric tolerance interval for a specified | |
| sample size and confidence level. | |
tolIntNparN
|
Compute the sample size required for a nonparametric |
| tolerance interval with a specified coverage and | |
| confidence level. | |
plotTolIntNparDesign
|
Create plots for a sampling design based on a |
| nonparametric tolerance interval. |
Help topic: tTestPower.
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
denote a vector of
observations from a normal
distribution with mean
and standard deviation
,
and consider the null hypothesis:
The three possible alternative hypotheses are the upper one-sided
alternative (alternative="greater"):
the lower one-sided alternative (alternative="less")
and the two-sided alternative
(alternative="two.sided")
The test of the null hypothesis (1) versus any of the three alternatives (2)-(4) is based on the Student t-statistic:
where
Under the null hypothesis (1), the t-statistic in (5) follows a Student’s t-distribution with 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
(Equation (12) below) or
(the population standard deviation), only the ratio
.
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-
if
where
and denotes the ’th quantile of Student’s t-distribution with degrees of freedom (Zar, 2010; Berthouex and Brown, 2002). The power of this test, denoted by , where denotes the probability of a Type II error, is given by:
where
and denotes a non-central Student’s t-random variable with degrees of freedom and non-centrality parameter , and denotes the cumulative distribution function of this random variable evaluated at (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-
if
and the power of this test is given by:
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-
if
and the power of this test is given by:
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 denote a non-central F random variable with and degrees of freedom and non-centrality parameter , and let denote the cumulative distribution function of this random variable evaluated at . Also, let denote the ’th quantile of the central F-distribution with and degrees of freedom. It can be shown that
where denotes “equal in distribution”. Thus, it follows that
so the formula for the power of the t-test given in Equation (16) can also be written as:
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
where 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:
where denotes the cumulative distribution function of the central Student’s t-distribution with degrees of freedom evaluated at .
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:
where denotes a central Student’s t-random variable with 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:
Two-sided alternative
(alternative="two.sided")
The power for the two-sided alternative (4) given in Equation (16) can
be approximated as:
Two-Sample Case
(sample.type="two.sample")
Let
denote a vector of
observations from a normal
distribution with mean
and standard deviation
,
and let
denote a vector of
observations from a normal distribution with mean
and standard deviation
,
and consider the null hypothesis:
The three possible alternative hypotheses are the upper one-sided
alternative (alternative="greater"):
the lower one-sided alternative (alternative="less")
and the two-sided alternative
(alternative="two.sided")
The test of the null hypothesis (25) versus any of the three alternatives (26)-(28) is based on the Student t-statistic:
where
Under the null hypothesis (25), the t-statistic in (29) follows a Student’s t-distribution with 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:
Note that none of the equations for the power of the t-test requires
knowledge of the values
or
(the population standard deviation for both populations), only the ratio
.
The argument delta.over.sigma is this ratio, and it is
referred to as the “scaled difference”.
Help topic: linearTrendTestPower.
If the argument x is a vector, it is converted into a
list with one component. If the arguments n,
x, slope.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.
Basic Model
Consider the simple linear regression model
where denotes the predictor variable (observed without error), denotes the intercept, denotes the slope, and the error term is assumed to be a random variable from a normal distribution with mean 0 and standard deviation . Let
denote independent observed pairs from the model (1).
Often in environmental data analysis, we are interested in determining whether there is a trend in some indicator variable over time. In this case, the predictor variable is time (e.g., day, month, quarter, year, etc.), and the values of the response variable represent measurements taken over time. The slope then represents the change in the average of the response variable per one unit of time.
When the argument x is a numeric vector, it represents
the
values of the predictor variable. When the argument x is a
list, each component of x is a numeric vector that
represents a set values of the predictor variable (and the number of
elements may vary by component). By default, the argument x
is a list for which the i’th component is simply the integers from 1 to
the value of the i’th element of the argument n,
representing, for example, Day 1, Day2, …, Day n[i].
In the discussion that follows, be sure not to confuse the intercept and slope coefficients and with the Type II error of the hypothesis test, which is denoted by .
Estimation of Coefficients and Confidence Interval for
Slope
The standard least-squares estimators of the slope and intercept are
given by:
where
(Draper and Smith, 1998, p.25; Zar, 2010, p.332-334; Berthoux and Brown, 2002, p.297; Helsel and Hirsch, p.226). The estimator of slope in Equation (3) has a normal distribution with mean equal to the true slope, and variance given by:
(Draper and Smith, 1998, p.35; Zar, 2010, p.341; Berthoux and Brown, 2002, p.299; Helsel and Hirsch, 1992, p.227). Thus, a two-sided confidence interval for the slope is given by:
where
and denotes the ’th quantile of Student’s t-distribution with degrees of freedom (Draper and Smith, 1998, p.36; Zar, 2010, p.343; Berthoux and Brown, 2002, p.300; Helsel and Hirsch, 1992, p.240).
Testing for a Non-Zero Slope
Consider the null hypothesis of a zero slope coefficient:
The three possible alternative hypotheses are the upper one-sided
alternative (alternative="greater"):
the lower one-sided alternative (alternative="less")
and the two-sided alternative
(alternative="two.sided")
The test of the null hypothesis (14) versus any of the three alternatives (15)-(17) is based on the Student t-statistic:
Under the null hypothesis (14), the t-statistic in (18) follows a Student’s t-distribution with degrees of freedom (Draper and Smith, 1998, p.36; Zar, 2010, p.341; Helsel and Hirsch, 1992, pp.238-239).
The formula for the power of the test of a zero slope depends on
which alternative is being tested. The two subsections below describe
exact and approximate formulas for the power of the test. Note that none
of the equations for the power of the t-test requires knowledge of the
values
or
(the population standard deviation of the error terms), only the ratio
.
The argument slope.over.sigma is this ratio, and it is
referred to as the “scaled slope”.
Exact Power Calculations
(approx=FALSE)
This subsection describes the exact formulas for the power of the t-test
for a zero slope.
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-
if
where
and, as noted previously, denotes the ’th quantile of Student’s t-distribution with degrees of freedom. The power of this test, denoted by , where denotes the probability of a Type II error, is given by:
where
and denotes a non-central Student’s t-random variable with degrees of freedom and non-centrality parameter , and denotes the cumulative distribution function of this random variable evaluated at (Johnson et al., 1995, pp.508-510). Note that when the predictor variable represents equally-spaced measures of time (e.g., days, months, quarters, etc.) and
then the non-centrality parameter in Equation (22) becomes:
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-
if
and the power of this test is given by:
Two-sided alternative
(alternative="two.sided")
The standard Student’s t-test rejects the null hypothesis (14) in favor
of the two-sided alternative hypothesis (17) at
level-
if
and the power of this test is given by:
The power of the t-test given in Equation (28) can also be expressed in terms of the cumulative distribution function of the non-central F-distribution as follows. Let denote a non-central F random variable with and degrees of freedom and non-centrality parameter , and let denote the cumulative distribution function of this random variable evaluated at . Also, let denote the ’th quantile of the central F-distribution with and degrees of freedom. It can be shown that
where denotes “equal in distribution”. Thus, it follows that
so the formula for the power of the t-test given in Equation (28) can also be written as:
Approximate Power Calculations
(approx=TRUE)
Zar (2010, pp.115–118) presents an approximation to the power for the
t-test given in Equations (21), (26), and (28) above. His approximation
to the power can be derived by using the approximation
where 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:
where denotes the cumulative distribution function of the central Student’s t-distribution with degrees of freedom evaluated at .
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 (15) given in Equation
(21) can be approximated as:
where denotes a central Student’s t-random variable with degrees of freedom.
Lower one-sided alternative
(alternative="less")
The power for the lower one-sided alternative (16) given in Equation
(26) can be approximated as:
Two-sided alternative
(alternative="two.sided")
The power for the two-sided alternative (17) given in Equation (28) can
be approximated as: