classicalTests {fBasics}R Documentation

Classical Statistical Tests

Description

A collection of functions for conventional statistical tests. Most tests are selected from R's cTest and nortest packages which may be of interest for financial and economic applications.

The functions are:

1 ansariTest Ansari–Bradley's test for differences in scale,
2 bartlettTest Bartlett's test for differences in variances,
3 corTest A test for association between paired samples,
4 flignerTest Fligner–Killeen's test for differences in variances,
5 ksTest One or two sample Kolmogorov-Smirnov tests,
6 moodTest Mood's test for differences in scale parameters,
7 shapiroTest Shapiro-Wilk's test for normality,
8 varTest F test for differences in variances,
9 dagoTest D'Agostino normality test,
10 runsTest Runs test for detecting non-randomness,
11 gofnorm Prints a report on 13 different tests of normality.

The following tests are available from the "nortest" package:

1 adTest Anderson–Darling normality test,
2 cvmTest Cramer–von Mises normality test,
3 lillieTest Lilliefors (Kolmogorov-Smirnov) normality test,
4 pearsonTest Pearson chi-square normality test,
5 sfTest Shapiro-Francia normality test.

Usage

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

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

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

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 be performed, either the "omnibus" (by default), the "skewness" or the "kurtosis" test. A character string.
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.

Details

Report from gofnorm:

The function reports the following goodness-of-fit tests for normality:

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.

Value

The tests return a list with class "htest" containing the following components:

statistic the value of the test statistic.
p.value the p-value of the test.
alternative a character string describing the alternative hypothesis.
method a character string indicating what type of test was performed.
data.name a character string giving the name(s) of the data.

Author(s)

R-core team for the tests from R's ctest package,
Adrian Trapletti for the runs test from R's tseries package,
Juergen Gross for the normal tests from R's nortest package,
James Filliben for the Fortran program producing the runs report,
Paul Johnson for the Fortran program producing the gofnorm report,
Diethelm Wuertz for this R-port.

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

## ansariTest - moodTest - varTest -
   xmpBasics("\nStart: 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("\nNext: 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("\nNext: 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("\nNext: 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("\nNext: Runs Test > ")
   runsTest(nyseres)
   runsTest(rnorm(length(nyseres)))

[Package Contents]