This function implements the methods of Zhou15;textualskedastic for testing for heteroskedasticity in a linear regression model. The authors propose three variations based on comparisons between sandwich and model-based estimators for the variances of individual regression coefficient esimators. The covariate-specific method computes a test statistic and \(p\)-value for each column of the auxiliary design matrix (which is, by default, the original design matrix with intercept omitted). The \(p\)-values undergo a Bonferroni correction to control overall test size. When the null hypothesis is rejected in this case, it also provides information about which auxiliary design variable is associated with the error variance. The pooled method computes a single test statistic and \(p\)-value and is thus an omnibus test. The hybrid method returns the minimum \(p\)-value between the Bonferroni-corrected covariate-specific \(p\)-values and the pooled \(p\)-value, multiplying it by 2 for a further Bonferroni correction. The test statistic returned is that which corresponds to the minimum \(p\)-value. The covariate-specific and pooled test statistics have null distributions that are asymptotically normal with mean 0. However, the variance is intractable and thus perturbation sampling is used to compute \(p\)-values empirically.
zhou_etal(
mainlm,
auxdesign = NA,
method = c("pooled", "covariate-specific", "hybrid"),
Bperturbed = 500L,
seed = 1234,
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"
.
A data.frame
or
matrix
representing an auxiliary design matrix of
containing exogenous variables that (under alternative hypothesis) are
related to error variance, or a character "fitted.values" indicating
that the fitted \(\hat{y}_i\) values from OLS should be used.
If set to NA
(the default), the
design matrix of the original regression model is used. An intercept
is included in the auxiliary regression even if the first column of
auxdesign
is not a vector of ones.
A character specifying which of the three test methods to
implement; one of "pooled"
, "covariate-specific"
, or
"hybrid"
(which combines the other two). Partial matching is
used.
An integer specifying the number of perturbation samples
to generate when estimating the \(p\)-value. Defaults to 500L
.
An integer specifying a seed to pass to
set.seed
for random number generation. This allows
for reproducibility of perturbation sampling. A value of NA
results in not setting a seed.
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
.
# NOT RUN {
mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars)
zhou_etal(mtcars_lm, method = "pooled")
zhou_etal(mtcars_lm, method = "covariate-specific")
zhou_etal(mtcars_lm, method = "hybrid")
# }
Run the code above in your browser using DataLab