This function implements the nonparametric test of Diblasi97;textualskedastic for testing for heteroskedasticity in a linear regression model.
diblasi_bowman(
mainlm,
distmethod = c("moment.match", "bootstrap"),
H = 0.08,
ignorecov = TRUE,
B = 500L,
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 character specifying the method by which to estimate
the \(p\)-values, either "moment.match"
or "bootstrap"
.
A hyperparameter denoting the bandwidth matrix in the kernel
function used for weights in nonparametric smoothing. If a double of
length 1 (the default), H
is set to \(h I_{p^\prime}\) where
\(h\) is the scalar bandwidth value entered and \(I_{p^\prime}\)
is the \(p^prime \times p^\prime\) identity matrix (where
\(p^\prime\) is the number of columns in the \(X\) matrix, excluding
an intercept if present). If a double of length \(p^\prime\), H
is set to \(diag(h)\) where \(h\) is the bandwidth vector entered.
If H
is a \(p^\prime\times p^\prime\) matrix it is used as is.
Any other dimensionality of H
results in an error.
A logical. If TRUE
(the default), the
variance-covariance matrix of \(s\) is assumed to be diagonal. (This
assumption is, strictly speaking, invalid, but usually yields a reasonable
approximation. Computation time is
prohibitive for large sample sizes if set to FALSE
).
An integer specifying the number of nonparametric bootstrap
replications to be used, if distmethod="bootstrap"
.
An integer specifying a seed to pass to
set.seed
for random number generation. This allows
reproducibility of bootstrap results. The value NA
results in not setting a seed.
A logical. If TRUE
, only the test statistic value
is returned, instead of an object of class
"htest"
. Defaults to FALSE
.
The test entails undertaking a transformation of the OLS residuals \(s_i=\sqrt{|e_i|}-E_0(\sqrt{|e_i|})\), where \(E_0\) denotes expectation under the null hypothesis of homoskedasticity. The kernel method of nonparametric regression is used to fit the relationship between these \(s_i\) and the explanatory variables. This leads to a test statistic \(T\) that is a ratio of quadratic forms involving the vector of \(s_i\) and the matrix of normal kernel weights. Although nonparametric in its method of fitting the possible heteroskedastic relationship, the distributional approximation used to compute \(p\)-values assumes normality of the errors.
mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars)
diblasi_bowman(mtcars_lm)
diblasi_bowman(mtcars_lm, ignorecov = FALSE)
diblasi_bowman(mtcars_lm, distmethod = "bootstrap")
# Example discussed in Diblasi and Bowman (1997)
malecats_lm <- lm(Hwt ~ Bwt, data = boot::catsM)
diblasi_bowman(malecats_lm, H = (max(boot::catsM$Bwt) - min(boot::catsM$Bwt)) / 8)
Run the code above in your browser using DataLab