This function implements the Bartlett's \(M\) Specification Error Test (BAMSET) method of Ramsey69;textualskedastic for testing for heteroskedasticity in a linear regression model.
bamset(
mainlm,
k = 3,
deflator = NA,
correct = TRUE,
omitatmargins = TRUE,
omit = NA,
statonly = FALSE
)
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"
.
An integer. The number of subsets (>= 2) into which the BLUS residuals are to be partitioned. Defaults to 3, the value suggested in Ramsey69;textualskedastic.
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).
A logical. Should the test statistic be divided by a scaling
constant to improve the chi-squared approximation? Defaults to
TRUE
.
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
.
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"
.
A logical. If TRUE
, only the test statistic value
is returned, instead of an object of class
"htest"
. Defaults to FALSE
.
An object of class
"htest"
. If object is
not assigned, its attributes are displayed in the console as a
tibble
using tidy
.
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.
# NOT RUN {
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")
# }
Run the code above in your browser using DataLab