View source: R/cook_weisberg.R
cook_weisberg | R Documentation |
This function implements the score test of \insertCiteCook83;textualskedastic for testing for heteroskedasticity in a linear regression model.
cook_weisberg(
mainlm,
auxdesign = NA,
hetfun = c("mult", "add", "logmult"),
statonly = FALSE
)
mainlm |
Either an object of |
auxdesign |
A |
hetfun |
A character describing the form of |
statonly |
A logical. If |
The Cook-Weisberg Score Test entails fitting an auxiliary
regression model in which the response variable is the vector of
standardised squared residuals e_i^2/\hat{\omega}
from the original
OLS model and the design matrix is some function of Z
, an
n \times q
matrix consisting of q
exogenous variables,
appended to a column of ones. The test statistic is half the residual sum
of squares from this auxiliary regression. Under the null hypothesis of
homoskedasticity, the distribution of the test statistic is
asymptotically chi-squared with q
degrees of freedom. The test is
right-tailed.
An object of class
"htest"
. If object is
not assigned, its attributes are displayed in the console as a
tibble
using tidy
.
car::ncvTest
, which implements the same
test. Calling car::ncvTest
with var.formula
argument omitted
is equivalent to calling skedastic::cook_weisberg
with
auxdesign = "fitted.values", hetfun = "additive"
. Calling
car::ncvTest
with var.formula = ~ X
(where X
is the
design matrix of the linear model with the intercept column omitted) is
equivalent to calling skedastic::cook_weisberg
with default
auxdesign
and hetfun
values. The
hetfun = "multiplicative"
option has no equivalent in
car::ncvTest
.
mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars)
cook_weisberg(mtcars_lm)
cook_weisberg(mtcars_lm, auxdesign = "fitted.values", hetfun = "logmult")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.