# How to Measure Heteroscedasticity in Regression?

**Methods – finnstats**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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 »

The post How to Measure Heteroscedasticity in Regression? appeared first on finnstats.

**leave a comment**for the author, please follow the link and comment on their blog:

**Methods – finnstats**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.