How to Measure Heteroscedasticity in Regression?

Heteroscedasticity in Regression, one of the easiest ways to measure heteroscedasticity is while using the Breusch-Pagan Test.

The test is mainly used to identify if heteroscedasticity is present in a regression analysis.

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

pipe operator in R-Simplify Your Code with %>% »

Heteroscedasticity in Regression

Step 1: Fit a regression model.

First, we will fit a regression model using Wind as the response variable and Temp and Month as the two explanatory variables.

load the airquality dataset

data(airquality)

fit a regression model

model <- lm(Wind~Temp+Month, data= airquality)

view model summary

How to find dataset differences in R Quickly Compare Datasets »

summary(model)

Coefficients:

lm(formula = Wind ~ Temp + Month, data = airquality)
Residuals:
    Min      1Q  Median      3Q     Max
-8.5401 -2.4133 -0.2177  2.0019  9.7670
Coefficients:
            Estimate Std. Error t value Pr(>|t|)   
(Intercept) 23.14224    2.15939  10.717  < 2e-16 ***
Temp        -0.17322    0.02978  -5.817 3.49e-08 ***
Month        0.04382    0.19898   0.220    0.826   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Multiple R-squared:   0.21,           Adjusted R-squared:  0.1995
F-statistic: 19.94 on 2 and 150 DF,  p-value: 2.097e-08

Kruskal Wallis test in R-One-way ANOVA Alternative »

Step 2: Perform a Breusch-Pagan Test.

Here we are going to measure the heteroscedasticity for that we can make utilize a Breusch-Pagan Test.

load lmtest library

library(lmtest)

Execute Breusch-Pagan Test

bptest(model)

               studentized Breusch-Pagan test

data:  model
BP = 2.1131, df = 2, p-value = 0.3477

The test statistic is 2.1131 and the corresponding p-value is 0.3477. Since the p-value is greater than 0.05, we cannot reject the null hypothesis.

This indicates that we do not have sufficient evidence to reject the null hypothesis or sufficient evidence to say heteroscedasticity is present in the regression model.

aggregate Function in R- A powerful tool for data frames »

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

nineteen − thirteen =