horn | R Documentation |
This function implements the nonparametric test of \insertCiteHorn81;textualskedastic for testing for heteroskedasticity in a linear regression model.
horn(
mainlm,
deflator = NA,
restype = c("ols", "blus"),
alternative = c("two.sided", "greater", "less"),
exact = (nres <= 10),
statonly = FALSE,
...
)
mainlm |
Either an object of |
deflator |
Either a character specifying a column name from the
design matrix of |
restype |
A character specifying which residuals to use: |
alternative |
A character specifying the form of alternative
hypothesis; one of |
exact |
A logical. Should exact |
statonly |
A logical. If |
... |
Optional further arguments to pass to |
The test entails specifying a 'deflator', an explanatory variable
suspected of being related to the error variance. Residuals are ordered
by the deflator and the nonparametric trend statistic
D=\sum (R_i - i)^2
proposed by
\insertCiteLehmann75;textualskedastic is
then computed on the absolute residuals and used to test for an
increasing or decreasing trend, either of which would correspond to
heteroskedasticity. Exact probabilities for the null distribution of
D
can be obtained from functions dDtrend
and
pDtrend
, but since computation time increases rapidly with
n
, use of a normal approximation is recommended for n>10
.
\insertCiteLehmann75;textualskedastic proves that D
is
asymptotically normally distributed and the approximation of the
statistic Z=(D-E(D))/\sqrt{V(D)}
to the standard normal
distribution is already quite good for n=11
.
The expectation and variance of D
(when ties are absent) are
respectively E(D)=\frac{n^3-n}{6}
and
V(D)=\frac{n^2(n+1)^2(n-1)}{36}
; see
\insertCiteLehmann75;textualskedastic for E(D)
and V(D)
when ties are present. When ties are absent, a continuity correction
is used to improve the normal approximation. When
exact distribution is used, two-sided p
-value is computed by
doubling the one-sided p
-value, since the distribution of D
is symmetric. The function does not support the exact distribution of
D
in the presence of ties, so in this case the normal approximation
is used regardless of n
.
An object of class
"htest"
. If object is
not assigned, its attributes are displayed in the console as a
tibble
using tidy
.
mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars)
horn(mtcars_lm, deflator = "qsec")
horn(mtcars_lm, deflator = "qsec", restype = "blus")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.