The heteroskedasticity test is one of the assumption tests in the Ordinary Least Squares (OLS) linear regression method, aimed at ensuring that the residual variance remains constant. If the multiple linear regression equation being tested shows non-constant residual variance, this is referred to as heteroskedasticity.
To obtain the Best Linear Unbiased Estimator (BLUE) for time series data, it is essential to ensure that the assumption of constant residual variance is met. Constant residual variance is also known as homoskedasticity.
In this article, I will provide a tutorial on how to perform a heteroskedasticity test in multiple linear regression using R Studio. Before performing the heteroskedasticity test in R Studio, you need to conduct a linear regression analysis.
Example Research Case Study
As a practice exercise, I will use a research case study aimed at analyzing the effects of inflation and unemployment rates on economic growth in a country.
For this case study, I use quarterly time series data with a total of 30 observations. The regression equation for this case study can be specified as follows:
π=π½0+π½1π1+π½2π2+…+π½πππ+π
Where:
π: Economic growth (%),
π1: Inflation rate (%),
π2: Unemployment rate (%),
π½0 : Intercept,
π½1 and π½2: Regression coefficient,
π : Error or residual.
After defining the regression equation, the next step is to input and tabulate the data. The collected data can be entered into Excel and then imported into R Studio. For a tutorial on importing data from Excel to R Studio, please refer to the article I wrote previously.
This is the time series data that we will use as a practice example in this article.
Steps for Conducting a Heteroskedasticity Test in R Studio and Its Interpretation
Once the data has been successfully imported into R Studio, the next step is to perform a multiple linear regression analysis. To conduct multiple linear regression analysis in R Studio, use the following command:
model <- lm(Economic_Growth ~ Inflation_Rate + Unemployment_Rate, data = data)
summary(model)
If the command is entered correctly, pressing Enter will display the R Studio output as follows:
Heteroskedasticity detection can be tested using the Breusch-Pagan test in R Studio. In this article, we will demonstrate how to detect heteroskedasticity using the Breusch-Pagan test.
If you have not installed the βlmtestβ packages before, you need to install it first. If you already have the package installed, you can skip this step.
To install the lmtest package, enter the following command in R Studio:
install.packages(“lmtest”)
Once the lmtest packages has been installed successfully, the next step is to perform the Breusch-Pagan test in R Studio by entering the following command:
library(lmtest)
bptest(model)
If the command is entered correctly without any errors, pressing Enter will display the analysis output as follows:
studentized Breusch-Pagan test
data:Β model
BP = 11.09, df = 2, p-value = 0.003906
Based on the output, we can see that the Breusch-Pagan value for the practice data is 11.09. Next, we observe the p-value, which is 0.003906.
Since the p-value is less than 0.05, we reject the null hypothesis (accept the alternative hypothesis). Thus, it can be concluded that heteroskedasticity exists in the tested regression equation. This indicates that the equation does not meet the assumptions required for OLS linear regression.
This concludes the tutorial on heteroskedasticity testing that I can share at this time. I hope this is useful and enhances the knowledge of those learning and using this analysis. Stay tuned for updates from Kanda Data next week, where we will discuss multicollinearity testing. See you next week!