linearTrendTestN {EnvStats} R Documentation

## Sample Size for a t-Test for Linear Trend

### Description

Compute the sample size necessary to achieve a specified power for a t-test for linear trend, given the scaled slope and significance level.

### Usage

  linearTrendTestN(slope.over.sigma, alpha = 0.05, power = 0.95,
alternative = "two.sided", approx = FALSE, round.up = TRUE,
n.max = 5000, tol = 1e-07, maxiter = 1000)


### Arguments

 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. power numeric vector of numbers between 0 and 1 indicating the power associated with the hypothesis test. The default value is power=0.95. 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 approx=FALSE. round.up logical scalar indicating whether to round up the values of the computed sample size(s) to the next smallest integer. The default value is TRUE. n.max positive integer greater than 2 indicating the maximum sample size. The default value is n.max=5000. tol numeric scalar indicating the toloerance to use in the uniroot search algorithm. The default value is tol=1e-7. maxiter positive integer indicating the maximum number of iterations argument to pass to the uniroot function. The default value is maxiter=1000.

### Details

If the arguments slope.over.sigma, alpha, and power are not all the same length, they are replicated to be the same length as the length of the longest argument.

Formulas for the power of the t-test of linear trend for specified values of the sample size, scaled slope, and Type I error level are given in the help file for linearTrendTestPower. The function linearTrendTestN uses the uniroot search algorithm to determine the required sample size(s) for specified values of the power, scaled slope, and Type I error level.

### Value

a numeric vector of sample sizes.

### Note

See the help file for linearTrendTestPower.

### Author(s)

Steven P. Millard (EnvStats@ProbStatInfo.com)

### References

See the help file for linearTrendTestPower.

linearTrendTestPower, linearTrendTestScaledMds, plotLinearTrendTestDesign, lm,
summary.lm, kendallTrendTest, Power and Sample Size, Normal, t.test.

### Examples

  # Look at how the required sample size for the t-test for zero slope
# increases with increasing required power:

seq(0.5, 0.9, by = 0.1)
# 0.5 0.6 0.7 0.8 0.9

linearTrendTestN(slope.over.sigma = 0.1, power = seq(0.5, 0.9, by = 0.1))
# 18 19 21 22 25

#----------

# Repeat the last example, but compute the sample size based on the approximate
# power instead of the exact:

linearTrendTestN(slope.over.sigma = 0.1, power = seq(0.5, 0.9, by = 0.1),
approx = TRUE)
# 18 19 21 22 25

#==========

# Look at how the required sample size for the t-test for zero slope decreases
# with increasing scaled slope:

seq(0.05, 0.2, by = 0.05)
# 0.05 0.10 0.15 0.20

linearTrendTestN(slope.over.sigma = seq(0.05, 0.2, by = 0.05))
# 41 26 20 17

#==========

# Look at how the required sample size for the t-test for zero slope decreases
# with increasing values of Type I error:

linearTrendTestN(slope.over.sigma = 0.1, alpha = c(0.001, 0.01, 0.05, 0.1))
# 33 29 26 25


[Package EnvStats version 2.8.1 Index]