harrison_mccabe: Harrison and McCabe's Test for Heteroskedasticity in a Linear...

View source: R/harrison_mccabe.R

harrison_mccabeR Documentation

Harrison and McCabe's Test for Heteroskedasticity in a Linear Regression Model

Description

This function implements the method of \insertCiteHarrison79;textualskedastic for testing for heteroskedasticity in a linear regression model.

Usage

harrison_mccabe(
  mainlm,
  deflator = NA,
  m = 0.5,
  alternative = c("less", "greater", "two.sided"),
  twosidedmethod = c("doubled", "kulinskaya"),
  qfmethod = "imhof",
  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".

deflator

Either a character specifying a column name from the design matrix of mainlm or an integer giving the index of a column of the design matrix. This variable is suspected to be related to the error variance under the alternative hypothesis. deflator may not correspond to a column of 1's (intercept). Default NA means the data will be left in its current order (e.g. in case the existing index is believed to be associated with error variance).

m

Either a double giving the proportion of the n diagonal elements of A that are ones, or an integer giving the index m up to which the diagonal elements are ones. Defaults to 0.5.

alternative

A character specifying the form of alternative hypothesis. If it is suspected that the error variance is positively associated with the deflator variable, "less". If it is suspected that the error variance is negatively associated with deflator variable, "greater". If no information is available on the suspected direction of the association, "two.sided". Defaults to "less".

twosidedmethod

A character indicating the method to be used to compute two-sided p-values for the parametric test when alternative is "two.sided". The argument is passed to twosidedpval as its method argument.

qfmethod

A character, either "imhof", "davies", or "integrate", corresponding to the algorithm argument of pRQF. The default is "imhof".

statonly

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

Details

The test assumes that heteroskedasticity, if present, is monotonically related to one of the explanatory variables (known as the deflator). The OLS residuals e are placed in increasing order of the deflator variable and we let A be an n\times n selector matrix whose first m diagonal elements are 1 and all other elements are 0. The alternative hypothesis posits that the error variance changes around index m. Under the null hypothesis of homoskedasticity, the ratio of quadratic forms Q=\frac{e' A e}{e'e} should be close to \frac{m}{n}. Since the test statistic Q is a ratio of quadratic forms in the errors, the Imhof algorithm is used to compute p-values (with normality of errors assumed).

Value

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

References

\insertAllCited

See Also

lmtest::hmctest, another implementation of the Harrison-McCabe Test. Note that the p-values from that function are simulated rather than computed from the distribution of a ratio of quadratic forms in normal random vectors.

Examples

mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars)
harrison_mccabe(mtcars_lm, deflator = "qsec")


skedastic documentation built on May 29, 2024, 12:20 p.m.