Learn R Programming

skedastic (version 1.0.0)

anscombe: Anscombe's Test for Heteroskedasticity in a Linear Regression Model

Description

This function implements the method of Anscombe61;textualskedastic for testing for heteroskedasticity in a linear regression model, with or without the studentising modification of Bickel78;textualskedastic.

Usage

anscombe(mainlm, studentise = TRUE, statonly = FALSE)

Arguments

mainlm

Either an object of class "lm" (e.g., generated by lm), or a list of two objects: a response vector and a design matrix. The objects are assumed to be in that order, unless they are given the names "X" and "y" to distinguish them. The design matrix passed in a list must begin with a column of ones if an intercept is to be included in the linear model. The design matrix passed in a list should not contain factors, as all columns are treated 'as is'. For tests that use ordinary least squares residuals, one can also pass a vector of residuals in the list, which should either be the third object or be named "e".

studentise

A logical. Should studentising modification of Bickel78;textualskedastic be implemented? Defaults to TRUE; if FALSE, the original form of the test proposed by Anscombe61;textualskedastic is used.

statonly

A logical. If TRUE, only the test statistic value is returned, instead of an object of class "htest". Defaults to FALSE.

Value

An object of class "htest". If object is not assigned, its attributes are displayed in the console as a tibble using tidy.

Details

Anscombe's Test is among the earliest suggestions for heteroskedasticity diagnostics in the linear regression model. The test is not based on formally derived theory but on a test statistic that Anscombe intuited to be approximately standard normal under the null hypothesis of homoskedasticity. Bickel78;textualskedastic discusses the test and suggests a studentising modification (included in this function) as well as a robustifying modification (included in bickel). The test is two-tailed.

The original form of the test is as follows.

References

See Also

bickel, which is a robust extension of this test.

Examples

Run this code
# NOT RUN {
mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars)
anscombe(mtcars_lm)
anscombe(mtcars_lm, studentise = FALSE)
# Same as first example
mtcars_list <- list("y" = mtcars$mpg, "X" = cbind(1, mtcars$wt, mtcars$qsec, mtcars$am))
anscombe(mtcars_list)

# }

Run the code above in your browser using DataLab