Learning White’s Test for Heteroscedasticity in R: A Step-by-Step Guide


The credibility and predictive power of any regression model rely fundamentally on a rigorous set of assumptions concerning its error terms, or residuals. Among the most critical checks performed in econometric and statistical analysis is the assessment for heteroscedasticity. The gold standard methodology used to formally test this crucial assumption is the White’s test.

Heteroscedasticity is a state where the variance of the model’s error terms is not constant across all levels of the independent variables. This variability means that the model predicts some outcomes with high precision (low variance) and others with low precision (high variance). When this assumption is violated, the reliability of Ordinary Least Squares (OLS) estimation is compromised, leading to fundamentally biased standard errors and, consequently, unreliable hypothesis test results.

This comprehensive tutorial is designed to demystify the statistical theory underlying White’s test and provide a practical, step-by-step guide on its implementation and interpretation. By mastering the execution of White’s test within the R programming environment, you can ensure that your statistical inferences are robust and your regression diagnostics are sound.

Why White’s Test is Essential for Regression Diagnostics

A central pillar of linear regression analysis is the assumption of homoscedasticity, which mandates that the variance of the residuals must remain constant regardless of the values predicted by the model. When data exhibits heteroscedasticity, this foundational assumption is violated, causing serious inferential problems even though the coefficient estimates themselves remain technically unbiased.

The primary danger of undetected heteroscedasticity lies in the miscalculation of the model’s variability. While the estimated coefficients might still be consistent, the calculated standard errors will be incorrect—typically underestimated. This inaccuracy renders the derived t-statistics and F-statistics unreliable, potentially leading researchers to draw incorrect conclusions about the statistical significance of their predictor variables.

White’s test, developed by economist Halbert White, is recognized as a powerful, general, and highly robust test for detecting heteroscedasticity. Unlike specialized tests that require assumptions about the specific structure of the variance (e.g., that variance is proportional to a single predictor), White’s test is non-specific. It operates by testing whether the variance of the residuals is systematically related to the independent variables, their squared terms, and all possible cross-products. This generality makes it applicable across a wide array of linear model types.

Theoretical Foundation of the White’s Test Methodology

The strength of White’s test stems from its use of an auxiliary regression. The test hypothesis is constructed by fitting a secondary model where the squared residuals (e²) from the primary regression are used as the dependent variable. The independent variables in this auxiliary regression are the original predictors, their squares, and all their two-way interaction terms.

Formally, if we have a primary model with two predictors (X1 and X2), the auxiliary regression looks like this: e² = β0 + β1X1 + β2X2 + β3X1² + β4X2² + β5(X1X2). The test then assesses whether the R-squared from this auxiliary regression is statistically significant.

The test statistic, calculated as the sample size (n) multiplied by the R-squared (nR²) from the auxiliary regression, follows a chi-squared distribution under the null hypothesis. If the auxiliary regression successfully explains a significant portion of the squared residuals’ variance (meaning the R-squared is large), it indicates that the predictors systematically influence the error variance, leading to the rejection of homoscedasticity.

Setting Up the Analysis Environment in R

To perform White’s test effectively within R, analysts typically rely on specialized packages that simplify the complex auxiliary regression steps. The function required for this task is often the versatile bptest, which is housed within the widely used lmtest library. While primarily designed for the Breusch-Pagan test, bptest can be adapted to perform White’s general test by specifying the full set of necessary predictor terms.

For demonstration purposes, we will use the built-in R dataset, mtcars. This dataset is excellent for illustrating regression diagnostics as it contains information on 32 different motor vehicles, relating metrics like fuel efficiency (mpg), engine displacement (disp), and horsepower (hp). Our specific goal is to model fuel efficiency based on the engine characteristics.

It is essential to ensure that the required lmtest package is installed and loaded into your R session before proceeding with any diagnostic checks. If this package is not yet available on your system, you must first execute the installation command: install.packages("lmtest").

Step 1: Fitting the Initial Linear Model

The foundation of any residual diagnostic, including White’s test, is the primary regression model itself. This model must be fit first to generate the necessary residuals that the diagnostic test will analyze. We define a standard linear model where the response variable is mpg (miles per gallon) and the explanatory variables are disp (displacement) and hp (horsepower).

We use the standard R function, lm(), to fit this model to the mtcars data frame. The resulting model object stores all the required information, including the calculated residuals, which will be the input for the subsequent heteroscedasticity test. Understanding the initial model fit provides necessary context for interpreting the diagnostic results.

A preliminary review of the model summary allows us to observe the estimated coefficients, their associated standard errors, and the overall fit statistics. This process is executed using the following R code:

#load the dataset
data(mtcars)

#fit a regression model
model <- lm(mpg~disp+hp, data=mtcars)

#view model summary
summary(model)

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) 30.735904   1.331566  23.083  < 2e-16 ***
disp        -0.030346   0.007405  -4.098 0.000306 ***
hp          -0.024840   0.013385  -1.856 0.073679 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3.127 on 29 degrees of freedom
Multiple R-squared:  0.7482,	Adjusted R-squared:  0.7309 
F-statistic: 43.09 on 2 and 29 DF,  p-value: 2.062e-09

Step 2: Executing the General White’s Test in R

Although the bptest function is often utilized for the Breusch-Pagan test, we leverage its flexibility to execute the specific requirements of White’s general test. This involves running the auxiliary regression where the squared residuals are regressed against the full set of terms: original predictors, their squared terms, and their cross-products.

The critical part of the R command is defining the comprehensive formula: ~ disp*hp + I(disp^2) + I(hp^2). The term disp*hp conveniently includes the main effects (disp and hp) and their interaction term. We explicitly add the squared terms using I(disp^2) and I(hp^2). This formulation rigorously fulfills the demands of White’s methodology, ensuring all potential sources of variance dependence are checked.

Executing this command provides the test statistic (often labeled BP in the output, which corresponds to nR² in the auxiliary model) and, crucially, the corresponding p-value. The p-value serves as the ultimate metric for determining whether the assumption of homoscedasticity can be maintained.

#load lmtest library
library(lmtest)

#perform White's test
bptest(model, ~ disp*hp + I(disp^2) + I(hp^2), data = mtcars)

	studentized Breusch-Pagan test

data:  model
BP = 7.0766, df = 5, p-value = 0.215

Interpretation and Hypothesis Testing

The output generated by the bptest function provides all the metrics necessary for a formal assessment of heteroscedasticity. These metrics—the BP statistic, the degrees of freedom, and the p-value—must be interpreted within the established framework of statistical hypothesis testing.

For White’s test, the formal hypotheses are clearly defined:

  • Null Hypothesis (H0): The variance of the errors is constant (i.e., Homoscedasticity holds).
  • Alternative Hypothesis (HA): The variance of the errors is not constant (i.e., Heteroscedasticity is present).

Analyzing the specific results from our example, we observe the following key values:

  • The test statistic (BP) is X² = 7.0766.
  • The degrees of freedom (df) is 5 (corresponding to the number of non-intercept terms in the auxiliary regression).
  • The corresponding p-value is 0.215.

Since the calculated p-value (0.215) is considerably higher than the standard significance level (α = 0.05), we fail to reject the Null Hypothesis (H0). Therefore, based on the results of White’s test, we conclude that there is insufficient statistical evidence to suggest that heteroscedasticity is a significant problem in this regression model. We can confidently proceed with interpreting the primary model summary, trusting the reliability of the reported standard errors.

Strategies for Correcting Heteroscedasticity

If the p-value from White’s test were less than 0.05, you would be forced to reject the Null Hypothesis and confirm the presence of heteroscedasticity. As previously noted, this violation renders the primary model’s standard errors biased, invalidating confidence intervals and t-tests. When this occurs, corrective measures must be implemented to restore the statistical validity of the inferences.

For data exhibiting heteroscedasticity, there are two principal strategies that analysts employ to obtain reliable estimates and standard errors:

  1. Transformation of Variables.
  2. Use of Robust Standard Errors or Weighted Least Squares.

The first approach involves applying a mathematical transformation, such as the logarithm or the square root, to the dependent variable. These transformations can often stabilize the variance of the error terms, thereby effectively resolving the heteroscedasticity issue and restoring the assumption of homoscedasticity. However, transformation alters the interpretation of the coefficients, requiring careful consideration.

Alternatively, the use of heteroscedasticity-robust standard errors (often called HC or White standard errors) allows the researcher to maintain the original model structure while correcting the standard errors. A more sophisticated method is Weighted Least Squares (WLS), which is a form of generalized OLS. WLS assigns a specific weight to each observation, typically inversely proportional to the estimated variance of its error term. By giving less influence to data points with higher error variance, WLS delivers efficient and unbiased coefficient estimates along with accurate standard errors, making it a powerful tool for robust regression analysis.

Cite this article

Mohammed looti (2025). Learning White’s Test for Heteroscedasticity in R: A Step-by-Step Guide. PSYCHOLOGICAL STATISTICS. Retrieved from https://statistics.arabpsychology.com/perform-whites-test-in-r-with-examples/

Mohammed looti. "Learning White’s Test for Heteroscedasticity in R: A Step-by-Step Guide." PSYCHOLOGICAL STATISTICS, 6 Nov. 2025, https://statistics.arabpsychology.com/perform-whites-test-in-r-with-examples/.

Mohammed looti. "Learning White’s Test for Heteroscedasticity in R: A Step-by-Step Guide." PSYCHOLOGICAL STATISTICS, 2025. https://statistics.arabpsychology.com/perform-whites-test-in-r-with-examples/.

Mohammed looti (2025) 'Learning White’s Test for Heteroscedasticity in R: A Step-by-Step Guide', PSYCHOLOGICAL STATISTICS. Available at: https://statistics.arabpsychology.com/perform-whites-test-in-r-with-examples/.

[1] Mohammed looti, "Learning White’s Test for Heteroscedasticity in R: A Step-by-Step Guide," PSYCHOLOGICAL STATISTICS, vol. X, no. Y, ص Z-Z, November, 2025.

Mohammed looti. Learning White’s Test for Heteroscedasticity in R: A Step-by-Step Guide. PSYCHOLOGICAL STATISTICS. 2025;vol(issue):pages.

Download Post (.PDF)
Scroll to Top