This function implements the method of Glejser69;textualskedastic for testing for "multiplicative" heteroskedasticity in a linear regression model. Mittelhammer00;textualskedastic gives the formulation of the test used here.
glejser(
mainlm,
auxdesign = NA,
sigmaest = c("main", "auxiliary"),
statonly = FALSE
)
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 data.frame
or
matrix
representing an auxiliary design matrix of
containing exogenous variables that (under alternative hypothesis) are
related to error variance, or a character "fitted.values" indicating
that the fitted \(\hat{y}_i\) values from OLS should be used.
If set to NA
(the default), the
design matrix of the original regression model is used. An intercept
is included in the auxiliary regression even if the first column of
auxdesign
is not a vector of ones.
A character indicating which model residuals to use in the
\(\hat{\sigma}^2\) estimator in the denominator of the test statistic.
If "main"
(the default), the OLS residuals from the original model
are used; this produces results identical to the Glejser Test in SHAZAM
software. If "auxiliary"
, the OLS residuals from the auxiliary
model are used, as in Mittelhammer00;textualskedastic.
Partial matching is used.
A logical. If TRUE
, only the test statistic value
is returned, instead of an object of class
"htest"
. Defaults to FALSE
.
An object of class
"htest"
. If object is
not assigned, its attributes are displayed in the console as a
tibble
using tidy
.
Glejser's Test entails fitting an auxiliary regression model in
which the response variable is the absolute residual from the original
model and the design matrix \(Z\) consists of one or more exogenous
variables that are suspected of being related to the error variance.
In the absence of prior information on a possible choice of \(Z\),
one would typically use the explanatory variables from the original model.
Under the null hypothesis of homoskedasticity, the distribution of the
test statistic is asymptotically chi-squared with parameter
degrees
of freedom. The test is right-tailed.
the description of the test in SHAZAM software (which produces identical results).
# NOT RUN {
mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars)
glejser(mtcars_lm)
# }
Run the code above in your browser using DataLab