This function implements the popular method of White80;textualskedastic for testing for heteroskedasticity in a linear regression model.
white_lm(mainlm, interactions = FALSE, 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 logical. Should two-way interactions between explanatory
variables be included in the auxiliary regression? Defaults to
FALSE
, since when interaction terms are present the test is not a
pure test of heteroskedasticity but also of model specification.
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
.
White's Test entails fitting an auxiliary regression model in which the
response variable is the vector of squared residuals from the original
model and the design matrix includes the original explanatory variables,
their squares, and (optionally) their two-way interactions. The test
statistic is the number of observations multiplied by the coefficient of
determination from the auxiliary regression model:
$$T = n r_{\mathrm{aux}}^2$$
White's Test is thus a special case of the method of
Breusch79;textualskedastic. 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.
This function should not be confused with
het.test::whites.htest
and
tseries::white.test
, which do not
implement the method of White80;textualskedastic for
testing for heteroskedasticity in a linear model.
# NOT RUN {
mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars)
white_lm(mtcars_lm)
white_lm(mtcars_lm, interactions = TRUE)
# }
Run the code above in your browser using DataLab