Title: | Testing for Symmetry of Data and Model Residuals |
---|---|
Description: | Implementations of a large number of tests for symmetry and their bootstrap variants, which can be used for testing the symmetry of random samples around a known or unknown mean. Functions are also there for testing the symmetry of model residuals around zero. Currently, the supported models are linear models and generalized autoregressive conditional heteroskedasticity (GARCH) models (fitted with the 'fGarch' package). All tests are implemented using the 'Rcpp' package which ensures great performance of the code. |
Authors: | Blagoje Ivanović [aut, cre] Bojana Milošević [aut] Marko Obradović [aut] |
Maintainer: | Blagoje Ivanović <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.3 |
Built: | 2024-11-28 06:52:48 UTC |
Source: | CRAN |
Generates random numbers from a mixture of 2 normal distributions
rmixnorm(n, mean1 = 0, sd1 = 1, mean2 = 0, sd2 = 1, p = 0.5)
rmixnorm(n, mean1 = 0, sd1 = 1, mean2 = 0, sd2 = 1, p = 0.5)
n |
number of observations |
mean1 |
mean of the first normal |
sd1 |
standard deviation of the first normal |
mean2 |
mean of the second normal |
sd2 |
standard deviation of the second normal |
p |
probability of the first normal |
Vector of random numbers from the specified mixture of normals.
Generates random numbers from the skew logistic distribution
rsl(n = 1, xi = 0, omega = 1, alpha = 0, dp = NULL)
rsl(n = 1, xi = 0, omega = 1, alpha = 0, dp = NULL)
n |
sample size. |
xi |
vector of location parameters. |
omega |
vector of (positive) scale parameters. |
alpha |
vector of slant parameters. |
dp |
a vector of length 3 whose elements represent the parameters
described above. If |
Vector of random numbers from Azzalini skew logistic distribution.
The package contains a large number of tests for symmetry (and their bootstrap variants), which can be used to test the symmetry of random samples or of model residuals. Currently, the supported models are linear models and generalized autoregressive conditional heteroskedasticity (GARCH) models (fitted with the 'fGarch' package). The tests are implemented using the 'Rcpp' package which ensures great performance.
To see the available tests, see TestStatistics
For documentation on how to perform the tests, see symmetry_test
This is a generic function used to perform symmetry tests on numeric vectors or objects of class lm (linear models) and objects of class fGARCH (GARCH mdels fitted with the fGarch package).
symmetry_test(x, ...) ## Default S3 method: symmetry_test( x, stat, mu = NULL, bootstrap = TRUE, B = 1000, boot_method = c("sign", "reflect"), trim = 0, k = 0, ... ) ## S3 method for class 'lm' symmetry_test( x, stat, B = 1000, boot_method = c("sign", "reflect"), k = 0, ... ) ## S3 method for class 'fGARCH' symmetry_test( x, stat, B = 1000, burn = 0, boot_method = c("sign", "reflect"), k = 0, approximate = FALSE, ... )
symmetry_test(x, ...) ## Default S3 method: symmetry_test( x, stat, mu = NULL, bootstrap = TRUE, B = 1000, boot_method = c("sign", "reflect"), trim = 0, k = 0, ... ) ## S3 method for class 'lm' symmetry_test( x, stat, B = 1000, boot_method = c("sign", "reflect"), k = 0, ... ) ## S3 method for class 'fGARCH' symmetry_test( x, stat, B = 1000, burn = 0, boot_method = c("sign", "reflect"), k = 0, approximate = FALSE, ... )
x |
an object of class numeric, lm or fGARCH |
... |
not used |
stat |
a character vector indicating the test statistic to be used (see Available Test Statistics) |
mu |
the centre parameter around which to test symmetry |
bootstrap |
a logical indicating whether to use bootstrap |
B |
the number of bootstrap replications |
boot_method |
the method of bootstrap sample generation (see Details) |
trim |
the trim value used for estimating the centre (as used in "mean") |
k |
the k parameter of the statistic, ignored if the test statistic doesn't depend on a parameter (see Test Statistics) |
burn |
the number of elements to remove from the beginning of the time series for testing |
approximate |
a logical indicating whether to use the faster approximate bootstrap method (see Details) |
The tests are performed using bootstrap procedures or using asymptotic results, where applicable. Currently, two methods of generating a bootstrap sample from the null distribution are available. The "sign" method generates the bootstrap sample by multiplying the existing sample by -1 or 1 at random (with equal probabilities), essentially randomizing the sign of the data, giving a symmetric distribution. The "reflect" method reflects the sample around zero and samples length(x) elements with replacement. In practice, it has been shown that the "sign" method is almost always better, thus is the default.
For numeric data, the tests can be performed around a known (parameter "mu") or unknown centre. When the centre is known, the bootstrap method gives the same results as a Monte Carlo simulation of the p value, for tests which are distribution free. For unknown centre (when mu = NULL), bootstrap must be used and the estimate of the centre used is the trimmed mean, with trim parameter "trim". By default, the mean is taken (trim = 0).
For linear models, the tests are based on a bootstrap procedure as in (Allison and Pretorius 2017) and are used to test the symmetry of the residuals around zero.
For GARCH models (must be fitted with the 'fGarch' package), the tests are also based on bootstrap and test for symmetry of the residuals around zero. An approximation of the bootstrap procedure is available where the residuals are treated as iid data, which is much faster and has been shown to give similar results to the default bootstrap procedure (described in (Klar et al. 2012)).
For a comparison of the performance of various tests of symmetry around an unknown centre, see (Milošević and Obradović 2019)).
An object of class "htest" containing the results of the testing.
Allison JS, Pretorius C (2017).
“A Monte Carlo evaluation of the performance of two new tests for symmetry.”
Computational Statistics, 32(4), 1323–1338.
doi:10.1007/s00180-016-0680-4.
Klar B, Lindner FL, Meintanis SG (2012).
“Specification tests for the error distribution in GARCH models.”
Computational Statistics & Data Analysis, 56(11), 3587–3598.
doi:10.1016/j.csda.2010.05.029.
Milošević B, Obradović M (2019).
“Comparison of efficiencies of some symmetry tests around an unknown centre.”
Statistics, 53(1), 43–57.
set.seed(1) # IID samples x <- rnorm(50) symmetry_test(x, "MOI", bootstrap = FALSE, k = 3, mu = 0) symmetry_test(x, "MOI", bootstrap = TRUE, k = 3, mu = 0) symmetry_test(x, "MOI", bootstrap = TRUE, k = 3) x <- rsl(50, alpha = 1.5) symmetry_test(x, "MOI", bootstrap = FALSE, k = 3, mu = 0) symmetry_test(x, "MOI", bootstrap = TRUE, k = 3, mu = 0) symmetry_test(x, "MOI", bootstrap = TRUE, k = 3) # Linear models lin_model <- lm(dist ~ speed, cars) symmetry_test(lin_model, "B1") # Garch models library(fGarch) specskew19 = fGarch::garchSpec(model = list(omega = 0.1, alpha = 0.3, beta = 0.3, skew = 1.9), cond.dist = "snorm") x <- fGarch::garchSim(specskew19, n = 500) g <- fGarch::garchFit(~garch(1,1), x, cond.dist = "QMLE", include.mean = FALSE, trace = FALSE) symmetry_test(g, "FM", B=400, burn = 100) # slower symmetry_test(g, "FM", B=400, burn = 100, approximate = TRUE)
set.seed(1) # IID samples x <- rnorm(50) symmetry_test(x, "MOI", bootstrap = FALSE, k = 3, mu = 0) symmetry_test(x, "MOI", bootstrap = TRUE, k = 3, mu = 0) symmetry_test(x, "MOI", bootstrap = TRUE, k = 3) x <- rsl(50, alpha = 1.5) symmetry_test(x, "MOI", bootstrap = FALSE, k = 3, mu = 0) symmetry_test(x, "MOI", bootstrap = TRUE, k = 3, mu = 0) symmetry_test(x, "MOI", bootstrap = TRUE, k = 3) # Linear models lin_model <- lm(dist ~ speed, cars) symmetry_test(lin_model, "B1") # Garch models library(fGarch) specskew19 = fGarch::garchSpec(model = list(omega = 0.1, alpha = 0.3, beta = 0.3, skew = 1.9), cond.dist = "snorm") x <- fGarch::garchSim(specskew19, n = 500) g <- fGarch::garchFit(~garch(1,1), x, cond.dist = "QMLE", include.mean = FALSE, trace = FALSE) symmetry_test(g, "FM", B=400, burn = 100) # slower symmetry_test(g, "FM", B=400, burn = 100, approximate = TRUE)
The list of implemented test statistics and their functions
B1(X) BH2(X) BHC1(X, k) BHC2(X, k) BHI(X) BHK(X) CM(X) FM(X) HM(X, k) K2U(X) K2(X) KS(X) SGN(X) WCX(X) MGG(X) MI(X) MOI(X, k) MOK(X, k) NAC1(X, k) NAC2(X, k) NAI(X, k) NAK(X, k) RW(X)
B1(X) BH2(X) BHC1(X, k) BHC2(X, k) BHI(X) BHK(X) CM(X) FM(X) HM(X, k) K2U(X) K2(X) KS(X) SGN(X) WCX(X) MGG(X) MI(X) MOI(X, k) MOK(X, k) NAC1(X, k) NAC2(X, k) NAI(X, k) NAK(X, k) RW(X)
X |
the numeric vector for which to calculate the test statistic |
k |
the 'k' parameter in the formula (if applicable) |
Below is a list of the implemented test statistics in the package. Each statistic is listed by it's name, a code string (e.g. 'B1', CM','MOI') and the formula of the statistic which is evaluated. The code string is used as an argument to the symmetry_test function. Some statistics depend on a parameter 'k' which can be seen from the formulas and is also passed as an argument.
Each statistic is implemented as a function with the same name as the code string, so the name of the function is passed as the argument "stat" to the symmetry_test function
The value of the test statistic.
The list of available statitics in the format "code(s) : name (reference)"
MI : The Mira test statistic (see (Mira 1999))
CM : The Cabilio–Masaro test statistic (see (Cabilio and Masaro 1996))
MGG : The Miao, Gel and Gastwirth test statistic (see (Miao et al. 2006))
B1 : The test statistic (see (Milošević and Obradović 2019))
KS : The Kolmogorov–Smirnov test statistic (see (Milošević and Obradović 2019))
SGN : The Sign test statistic (see (Milošević and Obradović 2019))
KS : The Wilcoxon test statistic (see (Milošević and Obradović 2019))
FM : The characterization based test statistic (see (Feuerverger et al. 1977))
RW : The Rothman-Woodroofe test statistic (see (Gaigall 2019))
BHI : The Litvinova test statistic (see (Litvinova 2001))
BHK : The Baringhaus and Henze supremum-type test statistic (see (Baringhaus and Henze 1992))
BH2 : The Baringhaus-Henze test statistic (see (Baringhaus and Henze 1992))
MOI and MOK : The Milošević and Obradović test statistics (see (Milošević and Obradović 2016))
NAI and NAK : The Nikitin and Ahsanullah test statistics (see (Nikitin and Ahsanullah 2015))
K2 and K2U : The Božin, Milošević, Nikitin and Obradović Kolmogorov type statistics based on V- and U- statistics respectively (see (Božin et al. 2018))
NAC1, NAC2, BHC1 and BHC2 : The Allison and Pretorius test statistics (see (Allison and Pretorius 2017))
Allison JS, Pretorius C (2017).
“A Monte Carlo evaluation of the performance of two new tests for symmetry.”
Computational Statistics, 32(4), 1323–1338.
doi:10.1007/s00180-016-0680-4.
Baringhaus L, Henze N (1992).
“A characterization of and new consistent tests for symmetry.”
Communications in statistics-theory and methods, 21(6), 1555–1566.
doi:10.1080/03610929208830863.
Božin V, Milošević B, Nikitin Y, Obradović M (2018).
“New Characterization-Based Symmetry Tests.”
Bulletin of the Malaysian Mathematical Sciences Society, 10–1007.
doi:10.1007/s40840-018-0680-3.
Cabilio P, Masaro J (1996).
“A simple test of symmetry about an unknown median.”
Canadian Journal of Statistics, 24(3), 349–361.
doi:10.2307/3315744.
Feuerverger A, Mureika RA, others (1977).
“The empirical characteristic function and its applications.”
The Annals of Statistics, 5(1), 88–97.
doi:10.1214/aos/1176343742.
Gaigall D (2019).
“Rothman-Woodroofe symmetry test statistic revisited.”
Computational Statistics & Data Analysis, 106837.
Litvinova VV (2001).
“New nonparametric test for symmetry and its asymptotic efficiency.”
Vestnik St. Petersburg University Mathematics, 34(4), 12–14.
Miao W, Gel YR, Gastwirth JL (2006).
“A new test of symmetry about an unknown median.”
In Random Walk, Sequential Analysis And Related Topics: A Festschrift in Honor of Yuan-Shih Chow, 199–214.
World Scientific.
Milošević B, Obradović M (2016).
“Characterization based symmetry tests and their asymptotic efficiencies.”
Statistics & Probability Letters, 119, 155–162.
Milošević B, Obradović M (2019).
“Comparison of efficiencies of some symmetry tests around an unknown centre.”
Statistics, 53(1), 43–57.
Mira A (1999).
“Distribution-free test for symmetry based on Bonferroni's measure.”
Journal of Applied Statistics, 26(8), 959–972.
doi:10.1080/02664769921963.
Nikitin Y, Ahsanullah M (2015).
“New U-empirical Tests of Symmetry Based on Extremal Order Statistics, and their Efficiencies.”
In Mathematical Statistics and Limit Theorems, 231–248.
Springer.
doi:10.1007/978-3-319-12442-1_13.