Learn R Programming

SciencesPo (version 1.3.9)

bartels.rank: Bartels Rank Test of Randomness

Description

Performs Bartels rank test of randomness. The default method for testing the null hypothesis of randomness is two.sided. By using the alternative left.sided, the null hypothesis is tested against a trend. By using the alternative right.sided, the null hypothesis of randomness is tested against a systematic oscillation in the observed data.

Usage

bartels.rank(x, alternative = "two.sided", pvalue = "normal")

## S3 method for class 'default': bartels.rank(x, alternative = "two.sided", pvalue = "normal")

Arguments

x
A numeric vector of data values.
alternative
A method for hypothesis testing, must be one of "two.sided" (default), "left.sided" or "right.sided".
pvalue
A method for asymptotic aproximation used to compute the p-value.

Value

  • statisticThe value of the RVN statistic test and the theoretical mean value and variance of the RVN statistic test.
  • nthe sample size, after the remotion of consecutive duplicate values.
  • p.valuethe asymptotic p-value.
  • methoda character string indicating the test performed.
  • data.namea character string giving the name of the data.
  • alternativea character string describing the alternative.

Details

Missing values are by default removed. The RVN test statistic is $$RVN=\frac{\sum_{i=1}^{n-1}(R_i-R_{i+1})^2}{\sum_{i=1}^{n}\left(R_i-(n+1)/2\right)^2}$$ where $R_i=rank(X_i), i=1,\dots, n$. It is known that $(RVN-2)/\sigma$ is asymptotically standard normal, where $\sigma^2=\frac{4(n-2)(5n^2-2n-9)}{5n(n+1)(n-1)^2}$.

References

Bartels, R. (1982). The Rank Version of von Neumann's Ratio Test for Randomness, Journal of the American Statistical Association, 77(377), 40-46.

Gibbons, J.D. and Chakraborti, S. (2003). Nonparametric Statistical Inference, 4th ed. (pp. 97-98). URL: http://books.google.pt/books?id=dPhtioXwI9cC&lpg=PA97&ots=ZGaQCmuEUq

Examples

Run this code
# Example 5.1 in Gibbons and Chakraborti (2003), p.98.
# Annual data on total number of tourists to the United States for 1970-1982.
 years <- 1970:1982
tourists <- c(12362, 12739, 13057, 13955, 14123,  15698, 17523,
 18610, 19842, 20310, 22500, 23080, 21916)

 # See it graphically
 qplot(factor(years), tourists)+ geom_point()

# Test the null against a trend
 bartels.rank(tourists, alternative="left.sided", pvalue="beta")

Run the code above in your browser using DataLab