| test.homo | R Documentation |
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.
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, ...)
model |
a fitted model of class |
method |
a character string indicating the method used for testing
homoscedasticity, i.e., |
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: |
plot |
logical: if |
geom |
a character vector indicating which plot elements to draw,
i.e., |
filename |
a character string indilating the |
width |
a numeric value indicating the |
height |
a numeric value indicating the |
dpi |
a numeric value indicating the |
write |
a character string naming a text file with file extension
|
append |
logical: if |
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 |
output |
logical: if |
... |
additional plotting arguments from the |
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.
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 |
plot |
ggplot2 object for plotting the results |
args |
specification of function arguments |
result |
data frame with results |
This function is based on the breusch_pagan(), white(),
evans_king(), pRQF() and verbyla() function
in the skedastic package by Thomas Farrar.
Takuya Yanagida
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
check.resid, test.linear, test.norm, coeff.robust
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.