bamset: Ramsey's BAMSET Test for Heteroskedasticity in a Linear...

View source: R/bamset.R

bamsetR Documentation

Ramsey's BAMSET Test for Heteroskedasticity in a Linear Regression Model

Description

This function implements the Bartlett's M Specification Error Test (BAMSET) method of \insertCiteRamsey69;textualskedastic for testing for heteroskedasticity in a linear regression model.

Usage

bamset(
  mainlm,
  k = 3,
  deflator = NA,
  correct = TRUE,
  omitatmargins = TRUE,
  omit = NA,
  categorical = FALSE,
  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".

k

An integer. The number of subsets (>= 2) into which the BLUS residuals are to be partitioned. Defaults to 3, the value suggested in \insertCiteRamsey69;textualskedastic.

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).

correct

A logical. Should the test statistic be divided by a scaling constant to improve the chi-squared approximation? Defaults to TRUE.

omitatmargins

A logical. Should the indices of observations at the margins of the k subsets be passed to blus as the omit argument? If TRUE (the default), this overrides any omit argument passed directly. If FALSE, the omit argument must be specified and cannot be left as NA. If categorical is TRUE, setting omitatmargins to TRUE results in omitting observations from the most frequently occurring factor levels or values.

omit

A numeric vector of length p (the number of columns in the linear model design matrix) giving the indices of p observations to omit in the BLUS residual vector; or a character partially matching "first" (for the first p) observations, "last" (for the last p observations), or "random" (for a random sample of p indices between 1 and n). Defaults to "first".

categorical

A logical. Is the deflator a categorical variable? If so, the number of levels will be used as k with each level forming a subset. Defaults to FALSE.

statonly

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

Details

BAMSET is an analogue of Bartlett's M Test for heterogeneity of variances across independent samples from k populations. In this case the populations are k subsets of the residuals from a linear regression model. In order to meet the independence assumption, BLUS residuals are computed, meaning that only n-p observations are used (where n is the number of rows and p the number of columns in the design matrix). Under the null hypothesis of homoskedasticity, the test statistic is asymptotically chi-squared distributed with k-1 degrees of freedom. The test is right-tailed.

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

Examples

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

# BLUS residuals cannot be computed with given `omit` argument and so
# omitted indices are randomised:
bamset(mtcars_lm, deflator = "qsec", k = 4, omitatmargins = FALSE, omit = "last")


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