Learn R Programming

olsrr (version 0.4.0)

ols_bp_test: Breusch Pagan Test

Description

Test for constant variance. It assumes that the error terms are normally distributed.

Usage

ols_bp_test(model, fitted.values = TRUE, rhs = FALSE, multiple = FALSE,
  p.adj = c("none", "bonferroni", "sidak", "holm"), vars = NA)

Arguments

model

an object of class lm

fitted.values

logical; if TRUE, use fitted values of regression model

rhs

logical; if TRUE, specifies that tests for heteroskedasticity be performed for the right-hand-side (explanatory) variables of the fitted regression model

multiple

logical; if TRUE, specifies that multiple testing be performed

p.adj

p value adjustment, following options are available: bonferroni, holm, sidak and none

vars

variables to be used for for heteroskedasticity test

Value

ols_bp_test returns an object of class "ols_bp_test". An object of class "ols_bp_test" is a list containing the following components:

bp

breusch pagan statistic

p

p-value of bp

fv

fitted values of the regression model

rhs

names of explanatory variables of fitted regression model

multiple

logical value indicating if multiple tests should be performed

padj

adjusted p values

vars

variables to be used for heteroskedasticity test

resp

response variable

preds

predictors

Details

Breusch Pagan Test was introduced by Trevor Breusch and Adrian Pagan in 1979. It is used to test for heteroskedasticity in a linear regression model. It test whether variance of errors from a regression is dependent on the values of a independent variable.

  • Null Hypothesis: Equal/constant variances

  • Alternative Hypothesis: Unequal/non-constant variances

Computation

  • Fit a regression model

  • Regress the squared residuals from the above model on the independent variables

  • Compute \(nR^2\). It follows a chi square distribution with p -1 degrees of freedom, where p is the number of independent variables, n is the sample size and \(R^2\) is the coefficient of determination from the regression in step 2.

References

T.S. Breusch & A.R. Pagan (1979), A Simple Test for Heteroscedasticity and Random Coefficient Variation. Econometrica 47, 1287<U+2013>1294

Cook, R. D.; Weisberg, S. (1983). "Diagnostics for Heteroskedasticity in Regression". Biometrika. 70 (1): 1<U+2013>10.

Examples

Run this code
# NOT RUN {
# model
model <- lm(mpg ~ disp + hp + wt + drat, data = mtcars)

# Use fitted values of the model
ols_bp_test(model)

# Use independent variables of the model
ols_bp_test(model, rhs = TRUE)

# Use independent variables of the model and perform multiple tests
ols_bp_test(model, rhs = TRUE, multiple = TRUE)

# Bonferroni p value Adjustment
ols_bp_test(model, rhs = TRUE, multiple = TRUE, p.adj = 'bonferroni')

# Sidak p value Adjustment
ols_bp_test(model, rhs = TRUE, multiple = TRUE, p.adj = 'sidak')

# Holm's p value Adjustment
ols_bp_test(model, rhs = TRUE, multiple = TRUE, p.adj = 'holm')

# }

Run the code above in your browser using DataLab