Home Â» How to Perform a Breusch-Pagan Test in R

# How to Perform a Breusch-Pagan Test in R

A Breusch-Pagan Test is used to determine ifÂ heteroscedasticityÂ is present in a regression analysis.

This tutorial explains how to perform a Breusch-Pagan Test in R.

### Example: Breusch-Pagan Test in R

In this example we will fit a regression model using the built-in R datasetÂ mtcarsÂ and then perform a Breusch-Pagan Test using theÂ bptestÂ function from theÂ lmtestÂ library to determine if heteroscedasticity is present.

Step 1: Fit a regression model.

First, we will fit a regression model usingÂ mpgÂ as the response variable and dispÂ  andÂ hpÂ as the two explanatory variables.

```#load the dataset
data(mtcars)

#fit a regression model
model #view model summary
summary(model)

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 30.735904   1.331566  23.083  ```

Step 2: Perform a Breusch-Pagan Test.

Next, we will perform a Breusch-Pagan Test to determine if heteroscedasticity is present.

```#load lmtest library
library(lmtest)

#perform Breusch-Pagan Test
bptest(model)

studentized Breusch-Pagan test

data:  model
BP = 4.0861, df = 2, p-value = 0.1296
```

The test statistic isÂ 4.0861 and the corresponding p-value isÂ 0.1296. Since the p-value is not less than 0.05, we fail to reject the null hypothesis.Â We do not have sufficient evidence to say that heteroscedasticity is present in the regression model.

## What To Do Next

If you fail to reject the null hypothesis of the Breusch-Pagan test, thenÂ heteroscedasticity is not present and you can proceed to interpret the output of the original regression.

However, if you reject the nullÂ hypothesis, this means heteroscedasticity is present in the data. In this case, the standard errors that are shown in the output table of the regression may be unreliable.

There are a couple common ways that you can fix this issue, including:

1. Transform the response variable.Â You can try performing a transformation on the response variable. For example, you could use the log of the response variable instead of the original response variable. Typically taking the log of the response variable is an effective way of making heteroscedasticity go away. Another common transformation is to use the square root of the response variable.

2. Use weighted regression.Â This type of regression assigns a weight to each data point based on the variance of its fitted value. Essentially, this gives small weights to data points that have higher variances, which shrinks their squared residuals. When the proper weights are used, this can eliminate the problem of heteroscedasticity.