Table of Contents
The integrity of statistical inference derived from an regression model often hinges upon whether the fundamental assumptions of Ordinary Least Squares (OLS) have been met. One of the most critical assumptions is homoscedasticity—the principle that the variance of the error terms (residuals) remains constant across all levels of the independent variables. When this assumption is violated, we encounter a condition known as heteroskedasticity.
To rigorously assess the presence of this variance inequality, statisticians employ several diagnostic tools. Among the most powerful and widely used is White’s test (also known as the White general test), a robust statistical procedure designed specifically to detect non-constant residual variance in a regression model. This comprehensive guide details the conceptual basis of White’s test and provides step-by-step instructions for executing and interpreting the results within the R programming environment.
Understanding White’s Test and Heteroskedasticity
At its core, White’s test evaluates whether the variance of the residuals from a fitted model is related to the predictor variables or the squared terms of those predictors. Unlike simpler tests like the Breusch-Pagan test, which primarily detect linear forms of heteroskedasticity, White’s test is more general because it does not require prior assumptions about the specific form of the heteroskedasticity.
When heteroskedasticity is present, it means that the spread (variance) of the residuals is unequal across the range of the predictor variables. For instance, the errors might be very small for low values of the independent variable but become much larger for high values. This violates the OLS assumption that residuals are equally scattered at each level of the response variable, leading to significant complications in statistical inference.
The consequence of undetected heteroskedasticity is that while the OLS coefficient estimates (betas) remain unbiased and consistent, the standard errors of these estimates become biased and inconsistent. In practical terms, this means that hypothesis tests (like t-tests and F-tests) relying on these standard errors are unreliable, potentially leading researchers to draw incorrect conclusions about the significance of the predictors.
Why is Heteroskedasticity a Problem?
The validity of statistical inference is directly tied to the accurate calculation of coefficient precision, which is quantified by the standard errors. When OLS assumptions hold, the standard error formulas are valid, and confidence intervals accurately reflect the uncertainty around the estimates. However, when heteroskedasticity exists, the calculated standard errors often underestimate the true variability, leading to inflated t-statistics and, consequently, p-values that are too small.
This systematic underestimation of variability leads to an overconfidence in the model results. A variable that is truly not statistically significant might be falsely declared significant (Type I error). Therefore, diagnosing and addressing heteroskedasticity is a crucial step in ensuring that the statistical findings derived from the regression model are trustworthy and robust.
The White test provides a formal, data-driven method to check this assumption. It is fundamentally a test of the fit of the residual variance, seeking any pattern in the squared residuals that can be explained by the original predictors, their squares, or their cross-products (interactions). If such a relationship exists, the test indicates a rejection of the null hypothesis of homoscedasticity.
The Mechanics of White’s Test (Hypotheses and Logic)
White’s test operates by running an auxiliary regression model where the dependent variable is the squared residuals ($hat{e}^2_i$) from the original regression, and the independent variables include the original predictors, their squared terms, and all cross-products (interaction terms).
The test relies on the following formal hypotheses:
- Null Hypothesis (H0): The variance of the error terms is constant (Homoscedasticity is present). Mathematically, this implies that the coefficients in the auxiliary regression are zero.
- Alternative Hypothesis (HA): The variance of the error terms is not constant (Heteroscedasticity is present). This implies that at least one coefficient in the auxiliary regression is statistically significant.
The test statistic, derived from the R-squared value of this auxiliary regression multiplied by the sample size (n), follows a Chi-squared distribution with degrees of freedom equal to the number of non-intercept independent variables in the auxiliary regression. A large test statistic, corresponding to a small p-value, suggests that the squared residuals are indeed related to the predictors, leading to the rejection of H0 and confirmation of heteroskedasticity.
Prerequisites for Performing the Test in R
While the car package provides a dedicated whitesTest() function, a common and often preferred method in R, especially within the context of linear models and time series analysis, is to utilize the powerful lmtest package. Specifically, we use the bptest() function, which implements the Breusch-Pagan test. By specifying the formula correctly to include the necessary squared and interaction terms, we can adapt bptest() to execute the full White’s test specification.
Therefore, before proceeding with the example, it is essential to ensure that the necessary statistical libraries are installed and loaded into your R session. The primary package required for this procedure is lmtest, which provides comprehensive tools for diagnostic testing in linear models.
The specific syntax for using bptest() to perform White’s general test requires explicitly listing all first-order terms, all second-order (squared) terms, and all cross-product (interaction) terms involving the original predictors. This comprehensive specification is what distinguishes the White test from the standard Breusch-Pagan test.
Example Implementation in R: Fitting the Regression Model (Step 1)
For this practical illustration, we will employ the well-known built-in R dataset, mtcars, which contains data on various characteristics of 32 automobiles. Our goal is to fit an initial linear regression model and then subject its residuals to White’s test.
We will designate mpg (Miles per Gallon) as the response variable, with disp (Displacement) and hp (Horsepower) serving as the two explanatory variables. This step involves loading the data and fitting the OLS model using the standard R function lm().
The following code block executes the initial model fitting and provides a summary of the results, which forms the basis for the subsequent diagnostic test. The summary helps us confirm the model structure and the initial estimates before proceeding to check assumptions.
#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
The initial summary shows that both disp and hp are negatively related to mpg, and the overall model is highly significant (F-statistic p-value is very low). However, the reliability of the reported standard errors and individual p-values depends entirely on the homoscedasticity assumption, which we address next.
Executing and Interpreting White’s Test (Step 2)
To perform White’s test using bptest(), we must specify the formula for the auxiliary regression. Given that our original model uses disp and hp, the auxiliary regression must include: disp, hp, the interaction term disp*hp, the squared term I(disp^2), and the squared term I(hp^2). The I() function in R is crucial here as it protects the expression, ensuring it is interpreted as a mathematical term rather than a standard regression operator.
The full formula specified in the bptest() call is thus ~ disp*hp + I(disp^2) + I(hp^2). This formulation captures all necessary first-order, second-order, and cross-product terms required for the generalized White test. The following code executes the test and provides the output for analysis.
#load lmtest library library(lmtest) #perform White's test (using bptest with squared and interaction terms) 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
The output provides the results of the studentized Breusch-Pagan test, which, given the comprehensive formula, serves as the White test statistic. We must analyze three key components of this output to make a final decision regarding the null hypothesis:
- The test statistic (BP): The computed value is $chi^2$ = 7.0766.
- The degrees of freedom (df): This value is 5, corresponding to the number of predictors (including squared and interaction terms) in the auxiliary regression.
- The corresponding p-value: The probability of observing this test statistic (or more extreme) under the assumption of H0 is 0.215.
To conclude the test, we compare the p-value to a predetermined significance level, typically $alpha = 0.05$. Since the calculated p-value (0.215) is significantly greater than 0.05, we fail to reject the null hypothesis (H0). Based on this evidence, we conclude that there is insufficient statistical evidence to suggest that heteroskedasticity is present in the regression model. We can proceed with interpreting the original model results, confident that the standard errors are likely reliable.
Addressing Heteroskedasticity When Detected
Had the White test resulted in a rejection of the null hypothesis (p-value < 0.05), indicating the presence of heteroskedasticity, two primary strategies are commonly employed to correct the model and obtain reliable standard errors:
Use Heteroskedasticity-Consistent Standard Errors (HCSE) or Robust Standard Errors: This is generally the most straightforward and preferred approach. Rather than altering the structure of the model or the data, this method adjusts the calculation of the standard errors to remain valid even when the homoscedasticity assumption is violated. These robust standard errors, such as those introduced by Huber-White, produce correct t-statistics and p-values without changing the original coefficient estimates. This preserves the economic or scientific interpretation of the model while ensuring statistical validity.
Transform the Response Variable: In cases where the heteroskedasticity is severe or due to the intrinsic scale of the data, applying a mathematical transformation to the response variable can sometimes stabilize the variance of the residuals. A common approach is the logarithmic transformation (e.g., taking the natural log of the response variable). If the data is positive and skewed, this transformation often reduces the effect of large outliers and compresses the scale, thereby stabilizing the residual variance and leading to homoscedastic residuals.
Use Weighted Least Squares (WLS) or Weighted Regression: WLS is an alternative estimation technique where each observation is assigned a weight inversely proportional to the variance of its error term. Essentially, data points associated with larger variances (which contribute to heteroskedasticity) are given smaller weights, diminishing their influence on the estimation process. When the proper weights (which require estimating the structure of the heteroskedasticity) are utilized, WLS can effectively eliminate the problem and produce efficient, unbiased estimators and reliable standard errors.
Cite this article
stats writer (2025). How to Perform White’s Test in R (With Examples). PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-to-perform-whites-test-in-r-with-examples/
stats writer. "How to Perform White’s Test in R (With Examples)." PSYCHOLOGICAL SCALES, 16 Dec. 2025, https://scales.arabpsychology.com/stats/how-to-perform-whites-test-in-r-with-examples/.
stats writer. "How to Perform White’s Test in R (With Examples)." PSYCHOLOGICAL SCALES, 2025. https://scales.arabpsychology.com/stats/how-to-perform-whites-test-in-r-with-examples/.
stats writer (2025) 'How to Perform White’s Test in R (With Examples)', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-to-perform-whites-test-in-r-with-examples/.
[1] stats writer, "How to Perform White’s Test in R (With Examples)," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, December, 2025.
stats writer. How to Perform White’s Test in R (With Examples). PSYCHOLOGICAL SCALES. 2025;vol(issue):pages.