Learn R Programming

snpar (version 1.0)

cs.test: Cox-Stuart Trend Test

Description

Perform one-sample Cox-Stuart trend test.

Usage

cs.test(x, alternative = c("two.sided", "increasing", "decreasing"), exact = TRUE, correct = TRUE)

Arguments

x
a numeric vector of data values.
alternative
indicates the alternative hypothesis and must be one of "two.sided" (default), "increasing", or "decreasing".
exact
TRUE (default) or FALSE indicating whether an exact p-value should be computed. See 'Details' for the meaning of TRUE.
correct
a logical indicating whether to apply continuity correction in the normal approximation for the p-value. The default is TRUE.

Value

A list with class "htest" containing the following components:
data.name
a character string giving the names of the data.
method
the type of test applied.
alternative
a character string describing the alternative hypothesis.
p.value
the p-value for the test.
statistic
the value of the test statistic with a name describing it.

Details

Cox-Stuart trend analysis is a robust method to detect the presence of the trend regardless of the distribution of the data. Given the independent data, i.e., $X[1],...,X[n]$, one can divide the data into two sequences with equal number of observations cutted in the midpoint and then take the paired difference, i.e., $D = X[i] - X[i+c], i = 1, ..., floor(n/2)$, where $c$ is the index of midpoint. The totals of the positive or negative sign in $D$ is defined as $S+$ or $S-$. Under null hypothesis, $S+$ or $S-$ has a binomial distribution with the number of experiment being the number of elements in $D$ after removing element(s) 0 and probability $p = 0.5$. The exact method (exact = TRUE) is based on binomial distribution of statistic $S+$ ("increasing") or $S-$ ("decreasing") or $S = min(S+, S-)$ ("two.sided") and one can thus compute the exact p-value. When the sample size is large, one can also use the normal approximation (argument exact = TRUE) to the binomial distribution with or without continuity correction. Missing values have been removed.

References

D.R. Cox and A. Stuart (1955). Some quick sign tests for trend in location and dispersion. Biometrika, Vol. 42, pp. 80-95.

Examples

Run this code
x <- 0.5*c(1:100) + rnorm(100,2,20)
# exact method
cs.test(x)
# approximate method
cs.test(x, exact = FALSE)

Run the code above in your browser using DataLab