Skip to content

Robust Breusch–Pagan test with bootstrap and effect sizes

Source: R/robust_implementations.R · Help: ?performBPTestRobust

Enhances performBPTest() by optionally studentising residuals, resampling the test statistic via bootstrap, and reporting effect sizes together with power diagnostics.

Usage

performBPTestRobust(
  model,
  data = NULL,
  studentize = TRUE,
  bootstrap = FALSE,
  B = 999,
  ci_level = 0.95,
  parallel = FALSE,
  studentized
)

Arguments

model
A fitted stats::lm object describing the mean structure whose residual variance is to be assessed.
data
The data frame model was fitted to, or NULL, the default. The response, design, weights and offset are read from the fit itself, so a model that transforms its variables, has an offset() term, or takes its weights or offset from a column of the data needs no data, and the model frame of model is accepted as data (since 0.17.0; before, such models needed data). Data that are given are matched to the observations of the fit: rows with row names of their own by name, in any order; rows that only number themselves (a tibble, a data.table, a data frame whose row names were reset) by the row numbers of the fit, or in the order of the fit when they hold one row per observation. The rows the fit dropped may be there or not. Data whose rows cannot be shown to hold the observations of the fit are refused; see test_results.
studentize
Logical, use studentized residuals for the auxiliary regression (Koenker variant)? Defaults to TRUE. The name matches lmtest::bptest() and performHarveyTest().
bootstrap
Logical, compute bootstrap diagnostics for the statistic and p-value? The bootstrap is bootstrapTestStatistic(), so on a fit returned by fitWLS() each replicate estimates the weights again, its default since 0.15.0. There is no argument to hold them fixed here; bootstrapTestStatistic() with reestimate_weights = FALSE does that.
B
Number of bootstrap replications when bootstrap = TRUE. Defaults to 999, at which a bootstrap p-value of the form (1 + #) / (B + 1) gives an exact test at the 5% and 1% levels; it was 1000 before 0.15.0. The value is recorded in robust_details$bootstrap$B whether or not the bootstrap runs.
ci_level
Confidence level for reported intervals.
parallel
Logical, allow parallel bootstrap evaluation when the parallel package is available. A seeded call gives the same result each time; see Parallel replicates in bootstrapTestStatistic().
studentized
Deprecated since 0.15.0: use studentize. It is still accepted, with a warning, and does what studentize does; it stops working in 1.0.0.

Value

An augmented htest object containing a robust_details element describing the additional diagnostics. Its studentized field records the value of studentize.

Details

Offers expanded reporting for the Breusch–Pagan family of tests including bootstrap p-values and asymptotic confidence intervals. The optional studentize argument toggles between the classic and Koenker versions.

Since 0.18.0 it refuses, with either value of studentize and with or without the bootstrap, an auxiliary regression that fits the squared residuals exactly, as on a paired design, as performBPTest() and performKoenkerTest() refuse it (see their Exact fit): on 30 subjects of two observations it gave 60 on 30 degrees of freedom with studentize = TRUE and 63.25 on 30 with FALSE. Only a fit the design forces is refused; one the data make exact gives a value, as up to 0.17.0.

Supported models

It accepts an lm and a glm with the Gaussian family and the identity link, unweighted or with positive weights, a fitWLS() fit and, since 0.16.0, a rank-deficient fit, which it tests on the estimable part of its design: it gives the value of the same model fitted without the aliased columns. It refuses a glm of another family or link, a survey::svyglm() fit, a fit with a zero weight, a coefficient that is not finite for another reason, and data that lack rows or variables of the fit. It accounts for an offset with studentize = FALSE, and since 0.16.0 with studentize = TRUE, the default, whose refit of the design carries the offset of the fit. It refuses a multivariate lm ("needs a model with one response"), and, since 0.16.0, with studentize = TRUE, the default, an mgcv::gam() fit with penalised smooth terms, which is not the least-squares fit of its design, the basis of its smooths, that the studentized statistic fits again, and, since 0.17.0, such a fit with bootstrap = TRUE, whose replicates are fitted again. With studentize = FALSE and no bootstrap it tests such a fit on its design, as performBPTest() does. Since 0.17.0 a gam that is the least-squares fit of its design, as one whose smooth terms are all fixed (s(x, fx = TRUE)), is tested on that design and gives the value of the lm() of it; before, it was refused as a penalised one. A gam without smooth terms is tested as the Gaussian glm it is (decisions 37 and 38 of the design of the model context). Which model each test accepts, and why, is set out in test_results, under Supported models.

References

Breusch, T. S., & Pagan, A. R. (1979). A simple test for heteroscedasticity and random coefficient variation. Econometrica, 47(5), 1287–1294.

Koenker, R. (1981). A note on studentizing a test for heteroscedasticity. Journal of Econometrics, 17(1), 107–112.

See also

performBPTest() for the baseline test and performKoenkerTest() for the standalone studentised variant.

Examples

data(mtcars)
mod <- lm(mpg ~ wt + qsec, data = mtcars)
performBPTestRobust(mod, mtcars, bootstrap = TRUE, B = 200)