Compute the power of a parametric test for linear trend, given the sample size or predictor variable values, scaled slope, and significance level.
Usage
linearTrendTestPower(n, x = lapply(n, seq), slope.over.sigma = 0, alpha = 0.05,
alternative = "two.sided", approx = FALSE)Details
Extended methods and derivations are available in
Statistical power and study design: linearTrendTestPower.
Open the vignette locally with
vignette("power-and-study-design", package = "EnvStats").
Arguments
- n
numeric vector of sample sizes. All values of
nmust be positive integers larger than 2. This argument is ignored whenxis supplied. Missing (NA), undefined (NaN), and infinite (Inf,-Inf) values are not allowed.- x
numeric vector of predictor variable values, or a list in which each component is a numeric vector of predictor variable values. Usually, the predictor variable is time (e.g., days, months, quarters, etc.). The default value is
x=lapply(n,seq), which yields a list in which the i'th component is the seqence of integers from 1 to the i'th value of the vectorn. Ifxis a numeric vector, it must contain at least three elements, two of which must be unique. Ifxis a list of numeric vectors, each component ofxmust contain at least three elements, two of which must be unique. Missing (NA), undefined (NaN), and infinite (Inf,-Inf) values are not allowed.- slope.over.sigma
numeric vector specifying the ratio of the true slope to the standard deviation of the error terms (\(\sigma\)). This is also called the "scaled slope". The default value is
slope.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.- alternative
character string indicating the kind of alternative hypothesis. The possible values are
"two.sided"(the default),"greater", and"less".- approx
logical scalar indicating whether to compute the power based on an approximation to the non-central t-distribution. The default value is
FALSE.
References
Berthouex, P.M., and L.C. Brown. (2002). Statistics for Environmental Engineers. Second Edition. Lewis Publishers, Boca Raton, FL.
Draper, N., and H. Smith. (1998). Applied Regression Analysis. Third Edition. John Wiley and Sons, New York, Chapter 1.
Helsel, D.R., and R.M. Hirsch. (1992). Statistical Methods in Water Resources Research. Elsevier, New York, NY, Chapter 9.
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.
Zar, J.H. (2010). Biostatistical Analysis. Fifth Edition. Prentice-Hall, Upper Saddle River, NJ.
Author
Steven P. Millard (EnvStats@ProbStatInfo.com)
Note
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 \(X\) is time (e.g., day, month, quarter, year, etc.), and the \(n\) 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.
You can use the parametric model (1) to model your data, then use the R function
lm to fit the regression coefficients and the summary.lm
function to perform a test for the significance of the slope coefficient. The
function linearTrendTestPower computes the power of this t-test, given a
fixed value of the sample size, scaled slope, and significance level.
You can also use Kendall's nonparametric test for trend
if you don't want to assume the error terms are normally distributed. When the
errors are truly normally distributed, the asymptotic relative efficiency of
Kendall's test for trend versus the parametric t-test for a zero slope is 0.98,
and Kendall's test can be more powerful than the parametric t-test when the errors
are not normally distributed. Thus the function linearTrendTestPower can
also be used to estimate the power of Kendall's test for trend.
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 slope if one of the objectives of the sampling program is to determine
whether a trend is occurring. The functions linearTrendTestPower,
linearTrendTestN, linearTrendTestScaledMds, and plotLinearTrendTestDesign can be used to investigate these
relationships.
Examples
# Look at how the power of the t-test for zero slope 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 <- linearTrendTestPower(n = seq(5, 30, by = 5), slope.over.sigma = 0.1)
round(power, 2)
#> [1] 0.06 0.13 0.34 0.68 0.93 1.00
#[1] 0.06 0.13 0.34 0.68 0.93 1.00
#----------
# Repeat the last example, but compute the approximate power instead of the
# exact:
power <- linearTrendTestPower(n = seq(5, 30, by = 5), slope.over.sigma = 0.1,
approx = TRUE)
round(power, 2)
#> [1] 0.05 0.11 0.32 0.68 0.93 0.99
#[1] 0.05 0.11 0.32 0.68 0.93 0.99
#----------
# Look at how the power of the t-test for zero slope increases with increasing
# scaled slope:
seq(0.05, 0.2, by = 0.05)
#> [1] 0.05 0.10 0.15 0.20
#[1] 0.05 0.10 0.15 0.20
power <- linearTrendTestPower(15, slope.over.sigma = seq(0.05, 0.2, by = 0.05))
round(power, 2)
#> [1] 0.12 0.34 0.64 0.87
#[1] 0.12 0.34 0.64 0.87
#----------
# Look at how the power of the t-test for zero slope increases with increasing
# values of Type I error:
power <- linearTrendTestPower(20, slope.over.sigma = 0.1,
alpha = c(0.001, 0.01, 0.05, 0.1))
round(power, 2)
#> [1] 0.14 0.41 0.68 0.80
#[1] 0.14 0.41 0.68 0.80
#----------
# Show that for a simple regression model, you get a greater power of detecting
# a non-zero slope if you take all the observations at two endpoints, rather than
# spreading the observations evenly between two endpoints.
# (Note: This design usually cannot work with environmental monitoring data taken
# over time since usually observations taken close together in time are not
# independent.)
linearTrendTestPower(x = 1:10, slope.over.sigma = 0.1)
#> [1] 0.1265976
#[1] 0.1265976
linearTrendTestPower(x = c(rep(1, 5), rep(10, 5)), slope.over.sigma = 0.1)
#> [1] 0.2413823
#[1] 0.2413823
#==========
# Clean up
#---------
rm(power)