test.homo: Tests for Homoscedasticity in a Linear Model

View source: R/test.homo.R

test.homoR Documentation

Tests for Homoscedasticity in a Linear Model

Description

This function performs the Breusch-Pagan test (Breusch & Pagan, 1979) without or with the studentising modification of Koenker (1981), the White's test with squared terms or squared and interaction terms (White, 1980), Evans-King Generalized Least Squares (GLS) test (Evans & King, 1988), and the Verbyla's Residual Maximum Likelihood test (Verbyla, 1993) for testing homoskedasticity (null hypothesis) against heteroskedasticity (alternative hypothesis) in a linear regression model. By default, the function performs the Evans-King GLS test.

Usage

test.homo(model, method = c("bp", "sbp", "white1", "white2", "evansking", "verbyla"),
          pred = attr(terms(model), which = "term.labels"), lambda.star = 5,
          digits = 2, p.digits = 3,
          plot = FALSE, geom = c("all", "none", "hline", "loess", "ci.loess"),
          filename = NULL, width = NA, height = NA, dpi = 600,
          write = NULL, append = TRUE, check = TRUE, output = TRUE, ...)

Arguments

model

a fitted model of class lm.

method

a character string indicating the method used for testing homoscedasticity, i.e., "bp" for the the Breusch-Pagan test, "sbp" for the Koenker's Studentized Breusch-Pagan test, "white1" for the White's Test regressing squared residuals on predictors and their squares, "white2" for the White's Test regressing squared residuals on predictors, their squares, and two-way interactions, "evansking" (default) for the Evans-King Generalized Least Squares test, and "verbyla" for the Verbyla's Residual Maximum Likelihood test.

pred

a character string or character vector indicating the predictor variables for the auxiliary design matrix that are suspected to be related to the residual variance under the alternative hypothesis. By default, the design matrix of the regression model including all predictor variables is used.

lambda.star

a numeric value (default: 5) indicating the degree of heteroskedasticity under the alternative hypothesis for Evans-King Generalized Least Squares test (method = "evansking"). Evans and King (1985) suggests 2.5, 5, 7.5, and 10 as values to consider, and Evans and King (1988) finds that 2.5 and 5 perform best empirically.

plot

logical: if TRUE, a plot for predicted values against the studentized residuals is drawn. For additional plotting arguments, see Details in the help page of the function plot.misty.object.

geom

a character vector indicating which plot elements to draw, i.e., "all" (default) for drawing all plot elements, "none" for drawing no horizontal or smoothing line, "hline" for drawing a horizontal line at 0, "loess" for drawing the LOESS smoothing curve, and "ci.loess" for drawing confidence bands around the smoothing curve (i.e., se = TRUE).

filename

a character string indilating the filename argument including the file extension in the ggsave function. Note that one of ".eps", ".ps", ".tex", ".pdf" (default), ".jpeg", ".tiff", ".png", ".bmp", ".svg" or ".wmf" needs to be specified as file extension in the file argument. Note that plots can only be saved when plot = TRUE.

width

a numeric value indicating the width argument (default is the size of the current graphics device) for the ggsave function.

height

a numeric value indicating the height argument (default is the size of the current graphics device) for the ggsave function.

dpi

a numeric value indicating the dpi argument (default is 600) for the ggsave function.

write

a character string naming a text file with file extension ".txt" (e.g., "Output.txt") for writing the output into a text file.

append

logical: if TRUE (default), output will be appended to an existing text file with extension .txt specified in write, if FALSE existing text file will be overwritten.

digits

an integer value indicating the number of decimal places to be used for displaying the test statistic.

p.digits

an integer value indicating the number of decimal places to be used for displaying the p-value.

check

logical: if TRUE (default), argument specification is checked.

output

logical: if TRUE (default), output is shown.

...

additional plotting arguments from the plot.misty.object() function, see 'Details in the plot.misty.object function.

Details

Farrar et al. (2025) reviewed 25 different tests for homoscedasticity implemented in the R package scedastic (Farrar, 2025) and presented results of a Monte Carlo simulation demonstrating that the Evans-King GLS test and Verbyla's Residual Maximum Likelihood test outperform commonly used tests for homoskedasticity, such as the Koenker's Studentized Breusch-Pagan test, White’s test, and the Goldfeld-Quandt F test.

Value

Returns an object of class misty.object, which is a list with following entries:

call

function call

type

type of analysis

model

model specified in model

plot

ggplot2 object for plotting the results

args

specification of function arguments

result

data frame with results

Note

This function is based on the breusch_pagan(), white(), evans_king(), pRQF() and verbyla() function in the skedastic package by Thomas Farrar.

Author(s)

Takuya Yanagida

References

Breusch, T. S., & Pagan, A.R. (1979) A simple test for heteroscedasticity and Random Coefficient Variation. Econometrica, 47, 1287-1294. http://dx.doi.org/10.2307/1911963

Evans, M. A., & King, M. L. (1985). A point optimal test for heteroscedastic disturbances. Journal of Econometrics, 27(2), 163–178.

Evans, M. A., & King, M. L. (1988). A further class of tests for heteroscedasticity. Journal of Econometrics, 37(2), 265–276.

Farrar, T. J. (2025). skedastic: Heteroskedasticity Diagnostics for Linear Regression Models. R Package version 2.0.3. https://github.com/tjfarrar/skedastic

Farrar, T., Blignaut, R., Luus, R., & Steel, S. (2025). A review and comparison of methods of testing for heteroskedasticity in the linear regression model. Journal of applied statistics, 52(16), 3121-3150. https://doi.org/10.1080/02664763.2025.2575038

Koenker, R. (1981). A note on studentizing a test for heteroscedasticity. Journal of Econometrics, 17(1), 107–112. https://doi.org/10.1016/0304-4076(81)90062-2.

Verbyla, A. P. (1993). Modelling variance heterogeneity: Residual maximum likelihood and diagnostics. Journal of the Royal Statistical Society: Series B (Methodological), 55(2), 493–508.

White, H. (1980). A heteroskedasticity-consistent covariance matrix estimator and a direct test for heteroskedasticity. Econometrica, 48(4), 817–838. https://doi.org/10.2307/1912934

See Also

check.resid, test.linear, test.norm, coeff.robust

Examples

## Not run: 
#————————————————————————————————————————————————————————————————————————————
# Tests for Homoscedasticity in a Linear Model

# Estimate linear model
mod <- lm(mpg ~ cyl + disp, data = mtcars)

# Example 1a: Koenker's Studentized Breusch-Pagan test (default)
test.homo(mod)

# Example 1b: White's Test regressing squared residuals on predictors and their squares
test.homo(mod, method = "white1")

# Example 1c: Evans-King Generalized Least Squares test
test.homo(mod, method = "evansking")

# Example 1d: Verbyla's Residual Maximum Likelihood test
test.homo(mod, method = "verbyla")

# Example 2: Predictor variable 'disp' used in the auxiliary design matrix
test.homo(mod, pred = "disp")

#————————————————————————————————————————————————————————————————————————————
# Plot

# Example 3a: Predicted values vs. Studentized residuals
test.homo(mod, plot = TRUE)

# Example 3b: Plot with horizontal line only
test.homo(mod, plot = TRUE, geom = "hline")

# Example 3c: redicted values vs. Studentized residuals, additional arguments
# see Details in the help page of the function plot.misty.object
test.homo(mod, plot = TRUE, point.shape = 2, linetype = "solid", line.col = "blue",
          xlim = c(0, 30))

# Example 3d: Plot results using the plot() function, use additional arguments
# see Details in the help page of the function plot.misty.object
object <- test.homo(mod)
plot(object, point.shape = 2, linetype = "solid", line.col = "blue", xlim = c(0, 30))

#————————————————————————————————————————————————————————————————————————————
# Write Results

# Example 4a: Write results into a text file
test.homo(mod, write = "Test_Homo.txt")

# Example 4b: Write results into an Excel file
test.homo(mod, write = "Test_Homo.xlsx")

# Example 4c: Save plot as PNG file
test.homo(mod, plot = TRUE, filename = "Homo.png", width = 7, height = 6)

## End(Not run)

misty documentation built on Nov. 24, 2026, 5:06 p.m.

Related to test.homo in misty...