This function implements the two methods of Rackauskas07;textualskedastic for testing for heteroskedasticity in a linear regression model.
rackauskas_zuokas(
mainlm,
alpha = 0,
pvalmethod = c("data", "sim"),
R = 2^14,
m = 2^17,
sqZ = FALSE,
seed = 1234,
statonly = FALSE
)An object of class
"htest". If object is
not assigned, its attributes are displayed in the console as a
Either an object of class "lm"
(e.g., generated by lm), or
a list of two objects: a response vector and a design matrix. The objects
are assumed to be in that order, unless they are given the names
"X" and "y" to distinguish them. The design matrix passed
in a list must begin with a column of ones if an intercept is to be
included in the linear model. The design matrix passed in a list should
not contain factors, as all columns are treated 'as is'. For tests that
use ordinary least squares residuals, one can also pass a vector of
residuals in the list, which should either be the third object or be
named "e".
A double such that \(0 \le \alpha < 1/2\); a hyperparameter of the test. Defaults to 0.
A character, either "data" or "sim",
determining which method to use to compute the empirical
\(p\)-value. If "data", the dataset T_alpha
consisting of pre-generated Monte Carlo replicates from the
asymptotic null distribution of the test statistic is loaded and used to
compute empirical \(p\)-value. This is only available for certain
values of alpha, namely \(i/32\) where \(i=0,1,\ldots,15\).
If "sim", Monte Carlo replicates are generated from the
asymptotic null distribution. Partial matching is used.
An integer representing the number of Monte Carlo replicates to
generate, if pvalmethod == "sim". Ignored if
pvalmethod == "data".
An integer representing the number of standard normal variates to
use when generating the Brownian Bridge for each replicate, if
pvalmethod == "sim". Ignored if pvalmethod == "data". If
number of observations is small,
Rackauskas07;textualskedastic recommends using \(m=n\).
The dataset T_alpha used \(m=2^17\) which is
computationally intensive.
A logical. If TRUE, the standard normal variates used
in the Brownian Bridge when generating from the asymptotic null
distribution are first squared, i.e. transformed to \(\chi^2(1)\)
variates. This is recommended by
Rackauskas07;textualskedastic when the number of
observations is small. Ignored if pvalmethod == "data".
An integer representing the seed to be used for pseudorandom
number generation when simulating values from the asymptotic null
distribution. This is to provide reproducibility of test results.
Ignored if pvalmethod == "data". If user does not wish to set
the seed, pass NA.
A logical. If TRUE, only the test statistic value
is returned, instead of an object of class
"htest". Defaults to FALSE.
Rackauskas and Zuokas propose a class of tests that entails determining the largest weighted difference in variance of estimated error. The asymptotic behaviour of their test statistic \(T_{n,\alpha}\) is studied using the empirical polygonal process constructed from partial sums of the squared residuals. The test is right-tailed.
mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars)
rackauskas_zuokas(mtcars_lm)
rackauskas_zuokas(mtcars_lm, alpha = 7 / 16)
# \donttest{
n <- length(mtcars_lm$residuals)
rackauskas_zuokas(mtcars_lm, pvalmethod = "sim", m = n, sqZ = TRUE)
# }
Run the code above in your browser using DataLab