This function implements the two methods of Evans88;textualskedastic for testing for heteroskedasticity in a linear regression model.
evans_king(
mainlm,
method = c("GLS", "LM"),
deflator = NA,
lambda_star = 5,
qfmethod = "imhof",
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 character indicating which of the two tests derived in
Evans88;textualskedastic should be implemented.
Possible values are "GLS"
and "LM"
; partial matching is
used (which is not case-sensitive).
Either a character specifying a column name from the
design matrix of mainlm
or an integer giving the index of a
column of the design matrix. This variable is suspected to be
related to the error variance under the alternative hypothesis.
deflator
may not correspond to a column of 1's (intercept).
Default NA
means the data will be left in its current order
(e.g. in case the existing index is believed to be associated with
error variance).
A double; coefficient representing the degree of
heteroskedasticity under the alternative hypothesis.
Evans85;textualskedastic suggests 2.5, 5, 7.5, and 10 as
values to consider, and Evans88;textualskedastic finds
that 2.5 and 5 perform best empirically. This parameter is used only for
the "GLS"
method; the "LM"
method represents the limiting
case as \(\lambda^\star \to 0\). Defaults to 5
.
A character, either "imhof"
, "davies"
, or
"integrate"
, corresponding to the algorithm
argument
of pRQF
. The default is "imhof"
.
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
.
The test entails putting the data rows in increasing order of
some specified deflator (e.g., one of the explanatory variables) that
is believed to be related to the error variance by some non-decreasing
function. There are two statistics that can be used, corresponding to
the two values of the method
argument. In both cases the test
statistic can be expressed as a ratio of quadratic forms in the errors,
and thus the Imhof algorithm is used to compute \(p\)-values. Both
methods involve a left-tailed test.
Evans85;textualskedastic, which already anticipates one of the tests.
# NOT RUN {
mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars)
evans_king(mtcars_lm, deflator = "qsec", method = "GLS")
evans_king(mtcars_lm, deflator = "qsec", method = "LM")
# }
Run the code above in your browser using DataLab