breusch_pagan: Breusch-Pagan Test for Heteroskedasticity in a Linear...

View source: R/breusch_pagan.R

breusch_paganR Documentation

Breusch-Pagan Test for Heteroskedasticity in a Linear Regression Model

Description

This function implements the popular method of \insertCiteBreusch79;textualskedastic for testing for heteroskedasticity in a linear regression model, with or without the studentising modification of \insertCiteKoenker81;textualskedastic.

Usage

breusch_pagan(mainlm, auxdesign = NA, koenker = TRUE, 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.

koenker

A logical. Should studentising modification of \insertCiteKoenker81;textualskedastic be implemented? Defaults to TRUE; if FALSE, the original form of the test proposed by \insertCiteBreusch79;textualskedastic 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 Breusch-Pagan Test entails fitting an auxiliary regression model in which the response variable is the vector of squared residuals from the original model and the design matrix Z consists of one or more exogenous variables that are suspected of being related to the error variance. In the absence of prior information on a possible choice of Z, one would typically use the explanatory variables from the original model. Under the null hypothesis of homoskedasticity, the distribution of the test statistic is asymptotically chi-squared with parameter 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

lmtest::bptest, which performs exactly the same test as this function; car::ncvTest, which is not the same test but is implemented in cook_weisberg; white, which is a special case of the Breusch-Pagan Test.

Examples

mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars)
breusch_pagan(mtcars_lm)
breusch_pagan(mtcars_lm, koenker = FALSE)
# Same as first example
mtcars_list <- list("y" = mtcars$mpg, "X" = cbind(1, mtcars$wt, mtcars$qsec, mtcars$am))
breusch_pagan(mtcars_list)


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