dufour_etal: Dufour et al.'s Monte Carlo Test for Heteroskedasticity in a...

View source: R/dufour_etal.R

dufour_etalR Documentation

Dufour et al.'s Monte Carlo Test for Heteroskedasticity in a Linear Regression Model

Description

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

Usage

dufour_etal(
  mainlm,
  hettest,
  R = 1000L,
  alternative = c("greater", "less", "two.sided"),
  errorgen = stats::rnorm,
  errorparam = list(),
  seed = 1234,
  ...
)

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

hettest

A character specifying the name of a function that implements a heteroskedasticity test on a linear regression model. The function is called with the statonly argument set to TRUE to improve computational efficiency.

R

An integer specifying the number of Monte Carlo replicates to generate. Defaults to 1000.

alternative

The tailedness of the test whose statistic is computed by hettest function; one of "greater" (the default), "less", or "two.sided".

errorgen

A function, or a character specifying the name of a function, from which the random errors are to be generated. The function should correspond to a continuous probability distribution that has (or at least can have) a mean of 0. Defaults to rnorm.

errorparam

An optional list of parameters to pass to errorgen. This argument is ignored if errorgen is rnorm, since mean must be set to 0, and sd is set to 1 because the heteroskedasticity test implemented by hettest function is assumed to be scale invariant. If errorgen is not rnorm, errorparam should be chosen in such a way that the error distribution has a mean of 0.

seed

An integer specifying a seed to pass to set.seed for random number generation. This allows reproducibility of Monte Carlo results. A value of NA results in not setting a seed.

...

Additional arguments to pass to function with name hettest

Details

The test implements a Monte Carlo procedure as follows. (1) The observed value of the test statistic T_0 is computed using function with name hettest. (2) R replications of the random error vector are generated from the distribution specified using errorgen. (3) R replications of the test statistic, T_1,T_2,…,T_R, are computed from the generated error vectors. (4) The empirical p-value is computed as \frac{\hat{G}_R(T_0)+1}{R+1}, where \hat{G}_R(x)=∑_{j=1}^{R} 1_{T_j ≥ x}, 1_{\bullet} being the indicator function. The test is right-tailed, regardless of the tailedness of hettest. Note that the heteroskedasticity test implemented by hettest must have a test statistic that is continuous and that is invariant with respect to nuisance parameters (ω and β). Note further that if hettest is goldfeld_quandt with method argument "parametric", the replicated Goldfeld-Quandt F statistics are computed directly within this function rather than by calling goldfeld_quandt, due to some idiosyncratic features of this test. Note that, if alternative is set to "two.sided", the one-sided p-value is doubled (twosidedpval cannot be used in this case).

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)
dufour_etal(mtcars_lm, hettest = "breusch_pagan")


skedastic documentation built on Nov. 10, 2022, 5:43 p.m.