cook_weisberg: Cook-Weisberg Score Test for Heteroskedasticity in a Linear...

View source: R/cook_weisberg.R

cook_weisbergR Documentation

Cook-Weisberg Score Test for Heteroskedasticity in a Linear Regression Model

Description

This function implements the score test of \insertCiteCook83;textualskedastic for testing for heteroskedasticity in a linear regression model.

Usage

cook_weisberg(
  mainlm,
  auxdesign = NA,
  hetfun = c("mult", "add", "logmult"),
  statonly = FALSE
)

Arguments

mainlm

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".

auxdesign

A data.frame or matrix representing an auxiliary design matrix of containing exogenous variables that (under alternative hypothesis) are related to error variance, or a character "fitted.values" indicating that the fitted \hat{y}_i values from OLS should be used. If set to NA (the default), the design matrix of the original regression model is used. An intercept is included in the auxiliary regression even if the first column of auxdesign is not a vector of ones.

hetfun

A character describing the form of w(\cdot), the error variance function under the heteroskedastic alternative. Possible values are "mult" (the default), corresponding to w(Z_i,λ)=\exp≤ft\{∑_{j=1}^{q}λ_j Z_{ij}\right\}, "add", corresponding to w(Z_i,λ)=≤ft(1+∑_{j=1}^{q} λ_j Z_{ij}\right)^2, and "logmult", corresponding to w(Z_i,λ)=\exp≤ft\{∑_{j=1}^{q}λ_j \log Z_{ij}\right\}. The multiplicative and log-multiplicative cases are considered in \insertCiteCook83;textualskedastic; the additive case is discussed, inter alia, by \insertCiteGriffiths86;textualskedastic. Results for the additive and multiplicative models are identical for this test. Partial matching is used.

statonly

A logical. If TRUE, only the test statistic value is returned, instead of an object of class "htest". Defaults to FALSE.

Details

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{ω} 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.

Value

An object of class "htest". If object is not assigned, its attributes are displayed in the console as a tibble using tidy.

References

\insertAllCited

See Also

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.

Examples

mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars)
cook_weisberg(mtcars_lm)
cook_weisberg(mtcars_lm, auxdesign = "fitted.values", hetfun = "logmult")


skedastic documentation built on Nov. 10, 2022, 5:43 p.m.