Implement Breusch-Pagan Test in R
Now we will discuss how to Implement Breusch-Pagan Test in R Programming Language step by step.
Step 1: Install and Load Required Packages
Here are we first install and load the Required Packages.
install.packages("lmtest")
install.packages("car")
library(lmtest)
library(car)
Step 2: Fit a Linear Regression Model
Here we will fit a Linear Regression Model to Perform a Breusch-Pagan Test.
data(mtcars)
model <- lm(mpg ~ hp + wt, data = mtcars)
summary(model)
Output:
Call:
lm(formula = mpg ~ hp + wt, data = mtcars)
Residuals:
Min 1Q Median 3Q Max
-3.941 -1.600 -0.182 1.050 5.854
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 37.22727 1.59879 23.285 < 2e-16 ***
hp -0.03177 0.00903 -3.519 0.00145 **
wt -3.87783 0.63273 -6.129 1.12e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 2.593 on 29 degrees of freedom
Multiple R-squared: 0.8268, Adjusted R-squared: 0.8148
F-statistic: 69.21 on 2 and 29 DF, p-value: 9.109e-12
Step 3: Perform the Breusch-Pagan Test
Now we will Perform the Breusch-Pagan Test with the help of bptest function.
bp_test <- bptest(model)
print(bp_test)
Output:
studentized Breusch-Pagan test
data: model
BP = 0.88072, df = 2, p-value = 0.6438
Since the p-value (0.6438) is much greater than 0.05, we fail to reject the null hypothesis. This indicates that there is no significant evidence of heteroscedasticity in the residuals of the regression model. Therefore, we can conclude that the assumption of homoscedasticity holds for this model, meaning the variance of the error terms is constant across observations.
How to Perform a Breusch-Pagan Test in R
The Breusch-Pagan test is a statistical test used to detect heteroscedasticity in a regression model. Heteroscedasticity occurs when the variance of the errors is not constant across all levels of the independent variables, which can lead to inefficient estimates and affect the reliability of hypothesis tests.