godfrey_orme: Godfrey and Orme's Nonparametric Bootstrap Test for...

View source: R/godfrey_orme.R

godfrey_ormeR Documentation

Godfrey and Orme's Nonparametric Bootstrap Test for Heteroskedasticity in a Linear Regression Model

Description

This function implements the method of \insertCiteGodfrey99;textualskedastic for testing for heteroskedasticity in a linear regression model. The procedure is more clearly described in \insertCiteGodfrey06;textualskedastic.

Usage

godfrey_orme(
  mainlm,
  hettest,
  B = 1000L,
  alternative = c("greater", "less", "two.sided"),
  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.

B

An integer specifying the number of nonparametric bootstrap samples to generate. Defaults to 1000L.

alternative

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

seed

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

...

Additional arguments to pass to function with name hettest

Details

The procedure runs as follows. (1) The observed value of the test statistic T_0 is computed using function with name hettest. (2) A sample e_1^\star,e_2^\star,\ldots,e_n^\star is drawn with replacement from the OLS residuals. (3) Bootstrapped response values are computed as y_i^{\star}=x_i' \hat{\beta}+e_i^\star,i=1,2,\ldots,n. (4) Bootstrapped test statistic value T^\star is computed from the regression of y^\star on X using function hettest. (5) Steps (2)-(4) are repeated until B bootstrapped test statistic values are computed. (6) Empirical p-value is computed by comparing the bootstrapped test statistic values to the observed test statistic value. 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)
godfrey_orme(mtcars_lm, hettest = "breusch_pagan")


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