View source: R/harrison_mccabe.R
harrison_mccabe | R Documentation |
This function implements the method of \insertCiteHarrison79;textualskedastic for testing for heteroskedasticity in a linear regression model.
harrison_mccabe(
mainlm,
deflator = NA,
m = 0.5,
alternative = c("less", "greater", "two.sided"),
twosidedmethod = c("doubled", "kulinskaya"),
qfmethod = "imhof",
statonly = FALSE
)
mainlm |
Either an object of |
deflator |
Either a character specifying a column name from the
design matrix of |
m |
Either a |
alternative |
A character specifying the form of alternative
hypothesis. If it is suspected that the error variance is positively
associated with the deflator variable, |
twosidedmethod |
A character indicating the method to be used to compute
two-sided |
qfmethod |
A character, either |
statonly |
A logical. If |
The test assumes that heteroskedasticity, if present, is
monotonically related to one of the explanatory variables (known as the
deflator). The OLS residuals e
are placed in increasing order of
the deflator variable and we let A
be an n\times n
selector
matrix whose first m
diagonal elements are 1 and all other elements
are 0. The alternative hypothesis posits that the error variance changes
around index m
. Under the null hypothesis of homoskedasticity, the
ratio of quadratic forms Q=\frac{e' A e}{e'e}
should be close to
\frac{m}{n}
. Since the test statistic Q
is a ratio of
quadratic forms in the errors, the Imhof algorithm is used to compute
p
-values (with normality of errors assumed).
An object of class
"htest"
. If object is
not assigned, its attributes are displayed in the console as a
tibble
using tidy
.
lmtest::hmctest
, another
implementation of the Harrison-McCabe Test. Note that the p
-values
from that function are simulated rather than computed from the
distribution of a ratio of quadratic forms in normal random vectors.
mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars)
harrison_mccabe(mtcars_lm, deflator = "qsec")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.