This function implements the two-sided LM Test of Honda89;textualskedastic for testing for heteroskedasticity in a linear regression model.
honda(
mainlm,
deflator = NA,
alternative = c("two.sided", "greater", "less"),
twosidedmethod = c("doubled", "kulinskaya"),
qfmethod = "imhof",
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"
.
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 character specifying the form of alternative
hypothesis. If it is suspected that the error variance is positively
associated with the deflator variable, "greater"
. If it is
suspected that the error variance is negatively associated with deflator
variable, "less"
. If no information is available on the suspected
direction of the association, "two.sided"
. Defaults to
"greater"
.
A character indicating the method to be used to compute
two-sided \(p\)-values for the parametric test when alternative
is "two.sided"
. The argument is passed to
twosidedpval
as its method
argument.
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
.
The test assumes that heteroskedasticity, if present, would be either of the form \(\omega_i = \omega(1+\theta z_i)\) or of the form \(\omega_i = \omega e^{\theta z_i}\), where where \(z_i\) is a deflator (a nonstochastic variable suspected of being related to the error variance), \(\omega\) is some unknown constant, and \(\theta\) is an unknown parameter representing the degree of heteroskedasticity. Since the test statistic \(Q=\frac{e' A_0 e}{e'e}\) is a ratio of quadratic forms in the errors, the Imhof algorithm is used to compute \(p\)-values. Since the null distribution is in general asymmetrical, the two-sided \(p\)-value is computed using the conditional method of Kulinskaya08;textualskedastic, setting \(A=1\).
mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars)
# In this example, only the test statistic is returned, to save time
honda(mtcars_lm, deflator = "qsec", statonly = TRUE)
Run the code above in your browser using DataLab