Learn R Programming

fBasics (version 200.10058)

ClassicalTests: Classical Statistical Tests

Description

A collection and description of functions for conventional statistical tests. Most tests are selected from R's 'cTest' and 'nortest' packages. The tests may be of interest for many financial and economic applications. The functions are: ll{ ansariTest Ansari--Bradley's test for differences in scale, bartlettTest Bartlett's test for differences in variances, corTest A test for association between paired samples, flignerTest Fligner--Killeen's test for differences in variances, ksTest One or two sample Kolmogorov-Smirnov tests, moodTest Mood's test for differences in scale parameters, shapiroTest Shapiro-Wilk's test for normality, varTest F test for differences in variances, dagoTest D'Agostino normality test, normalTest S-Plus like Test for Shapiro-Wilk and Jarque-Bera tests, runsTest Runs test for detecting non-randomness, gofnorm Prints a report on 13 different tests of normality. } The following tests are available from the "nortest" package: ll{ adTest Anderson--Darling normality test, cvmTest Cramer--von Mises normality test, lillieTest Lilliefors (Kolmogorov-Smirnov) normality test, pearsonTest Pearson chi-square normality test, sfTest Shapiro-Francia normality test. }

Usage

ansariTest(x, y, ...)
bartlettTest(x, g, ...)
corTest(x, y, alternative = <>, method = <>, ...)
flignerTest(x, g, ...)
ksTest(x, y, alternative = <>, ...)
moodTest(x, y, alternative = <>, ...)
shapiroTest(x)
varTest(x, y, alternative = <>, ...)

adTest(x)            
cvmTest(x)      
lillieTest(x) 
pearsonTest(x, n.classes = <>, adjust = TRUE)    
sfTest(x)   

dagoTest(x, method = c("omnibus", "skewness", "kurtosis"))
normalTest(x, method = <>) 

runsTest(x)

gofnorm(x, doprint = TRUE)

Arguments

adjust
alternative
indicates the alternative hypothesis; must be one of the entries specified by the input vector c("two.sided", "less", "greater").
doprint
if TRUE, an exhaustive report is printed.
g
a vector or factor object giving the group for the corresponding elements of x. Ignored if x is a list.
method
[corTest] - indicates the three different methods for the correlation test; must be one of the entries specified by the input vector c("pearson", "kendall", "spearman"). [dagoTest] - selects the kind of test to b
n.classes
[pearsonTest] - the number of classes. The default is due to Moore (1986): n.classes = ceiling(2 * (n^(2/5))).
x, y
a numeric vector of data values.
...
arguments passed to the underlying function from R's ctest package. Consult the appropriate manual pages.

Value

  • The tests return a list with class "htest" containing the following components:
  • statisticthe value of the test statistic.
  • p.valuethe p-value of the test.
  • alternativea character string describing the alternative hypothesis.
  • methoda character string indicating what type of test was performed.
  • data.namea character string giving the name(s) of the data.

Details

Report from gofnorm: The function reports the following goodness-of-fit tests for normality: rl{ 1 Omnibus Moments Test for Normality 2 Geary's Test of Normality 3 Studentized Range for Testing Normality 4 D'Agostino's D-Statistic Test of Normality 5 Kuiper V-Statistic Modified to Test Normality 6 Watson U-Squared-Statistic Modified to Test Normality 7 Durbin's Exact Test (Normal Distribution 8 Anderson-Darling Statistic Modified to Test Normality 9 Cramer-Von Mises W-Squared-Statistic to Test Normality 10 Kolmogorov-Smirnov D-Statistic to Test Normality 11 Kolmogorov-Smirnov D-Statistic (Lilliefors Critical Values) 12 Chi-Square Test of Normality (Equal Probability Classes) 13 Shapiro-Francia W-Test of Normality for Large Samples } The functions are implemented from the GRASS GIS software package an Open Source project avalaible under the GNU GPL license.

References

Anderson T.W., Darling D.A. (1954); A Test of Goodness of Fit, JASA 49:765--69. Conover, W. J. (1971); Practical nonparametric statistics, New York: John Wiley & Sons. D'Agostino R.B., Pearson E.S. (1973); Tests for Departure from Normality, Biometrika 60, 613--22. D'Agostino R.B., Rosman B. (1974); The Power of Geary's Test of Normality, Biometrika 61, 181--84. Durbin J. (1961); Some Methods of Constructing Exact Tests, Biometrika 48, 41--55. Durbin,J. (1973); Distribution Theory Based on the Sample Distribution Function, SIAM, Philadelphia. Geary R.C. (1947); Testing for Normality; Biometrika 36, 68--97. Kotz S. (1973); Normality versus Lognormality with Applications, Communications in Statistics 1, 113--32. Lehmann E.L. (1986); Testing Statistical Hypotheses, John Wiley and Sons, New York. Linnet K. (1988); Testing Normality of Transformed Data, Applied Statistics 32, 180--186. Moore, D.S. (1986); Tests of the chi-squared type, In: D'Agostino, R.B. and Stephens, M.A., eds., Goodness-of-Fit Techniques, Marcel Dekker, New York. Shapiro S.S., Francia R.S. (1972); An Approximate Analysis of Variance Test for Normality, JASA 67, 215--216. Shapiro S.S., Wilk M.B., Chen V. (1968); A Comparative Study of Various Tests for Normality, JASA 63, 1343--72. Thode H.C. (2002); Testing for Normality, Marcel Dekker, New York. Weiss, M.S. (1978); Modification of the Kolmogorov-Smirnov Statistic for Use with Correlated Data, JASA 73, 872--75.

Examples

Run this code
## ansariTest - moodTest - varTest -
   xmpBasics("Start: Ansari/Mood/Var Test > ")
   # Differences in scale / variances:
   data(nyseres)
   x = nyseres[4001:5000, 1]
   y = nyseres[6001:7000, 1]
   p = c(
     ansariTest(x, y)$p.value,
     moodTest(x, y)$p.value,
     varTest(x, y)$p.value)
   test = c("ansari", "mood", "var") 
   data.frame(test, p)
   
## ansariTest - moodTest - varTest -
   xmpBasics("Next: Ansari/Mood/Var Test > ")
   # Differences in scale / variances:
   x = rnorm(1000)
   y = rnorm(1000)
   p = c(
     ansariTest(x, y)$p.value,
     moodTest(x, y)$p.value,
     varTest(x, y)$p.value)
   test = c("ansari", "mood", "var") 
   data.frame(test, p)
   
## gofnorm -
   xmpBasics("Next: Goodness-of-Fit Test for Normality > ")  
   x = nyseres[1:1000, 1]
   # Standardize the data:
   x = (x-mean(x))/sqrt(var(x))
   # Test:
   r = gofnorm(x, doprint = TRUE)
   
## ksTest -
   # unique: remove ties:
   xmpBasics("Next: Kolmogorov-Smirnov Goodness-of-Fit Test > ")
   nyseres = unique(nyseres[, 1])
   ksTest(nyseres, "pnorm")
   # Do x and y come from the same distribution?
   x = nyseres[1:(length(nyseres)/2)]
   y = nyseres[(length(nyseres)/2+1):length(nyseres)]
   ksTest(x, y)
   # Does x come from an alpha stable distribution?
   alpha = scalinglawPlot(nyseres, doplot = FALSE)$exponent
   ksTest(x = nyseres, y = "psymstb", alpha, alternative = "gr")
   
## runsTest -
   xmpBasics("Next: Runs Test > ")
   runsTest(nyseres)
   runsTest(rnorm(length(nyseres)))

Run the code above in your browser using DataLab