Skip to content

Studentized Breusch–Pagan test (deprecated)

Source: R/additional_tests.R · Help: ?performStudentizedBPTest

performStudentizedBPTest() is deprecated since 0.14.0: use performKoenkerTest(), which computes the same statistic. It still works and warns, and returns what it returned before except on a fit returned by fitWLS(). The model frame of that fit holds the weights of the model fitWLS() refitted (none, for an unweighted model), not the estimated weights, and before 0.15.0 performStudentizedBPTest() read them from there, so it computed the statistic of the unweighted fit. Since 0.15.0 it reads the weights of the fit, as performKoenkerTest() does, and the two agree. On a model with an offset they agree since 0.16.0: before, the refit of the design left the offset out, and performStudentizedBPTest() returned the statistic of another model.

Usage

performStudentizedBPTest(model, data = NULL)

Arguments

model
A fitted stats::lm object providing the residuals and design matrix for the auxiliary regression.
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.16.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.

Value

An object of class htest reporting the chi-squared statistic and p-value for the null hypothesis of constant error variance.

Details

Computes Koenker's (1981) studentized form of the Breusch–Pagan Lagrange multiplier statistic, \(n R^2\) from the regression of the squared residuals on the regressors. The classical Breusch–Pagan statistic assumes normal errors and this one does not: in the simulations of inst/validation/ it holds its level under \(t_5\) errors, where the classical statistic rejects far too often.

Following Koenker (1981) and the implementation in lmtest::bptest(), the procedure fits an auxiliary regression of \(e_i^2 - \hat{\sigma}^2\) on the regressors from the original model (including the intercept), where \(e_i\) denotes the residuals and \(\hat{\sigma}^2 = \sum e_i^2 / n\) the mean of their squares. With \(\hat{g}_i\) the fitted values of that regression, the statistic \(T = n \sum \hat{g}_i^2 / \sum (e_i^2 - \hat{\sigma}^2)^2\) is its \(n R^2\). Under homoskedasticity it is asymptotically chi-squared with degrees of freedom equal to the number of regressors beyond the intercept, whether or not the errors are normal. On a weighted fit \(e_i\) is the Pearson residual \(\sqrt{w_i}\) times the raw residual and the auxiliary regression is unweighted; see the section on weighted fits in performKoenkerTest(). This departs from lmtest::bptest(), which keeps the raw residuals and weights the auxiliary regression. The residuals are those of the refit of the design of the fit to its response, with its weights and its offset, so on a model with an offset the statistic is that of the model fitted to the response minus the offset, Koenker's statistic of the model (since 0.16.0). The implementation shares the validation helpers used across the package to ensure that: (i) the model satisfies minimum sample-size thresholds via rvalidateModelInputs(), (ii) the response, design, weights and offset are those of the fit itself, with the rows of data matched to its observations (the model context, since 0.16.0), and (iii) the requirements registered for this test in rvalidateTestRequirements() are met.

Since 0.18.0 it refuses an auxiliary regression that fits the squared residuals exactly, as on a paired design, as performKoenkerTest() refuses it (see its Exact fit), and so does the registered "student_bp": on 30 subjects of two observations it gave 60 on 30 degrees of freedom, the number of observations. 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. A model with an offset is accepted since 0.16.0: the refit of the design carries the offset, as performKoenkerTest() accounts for it. It refuses a multivariate lm ("needs a model with one response"), and, since 0.16.0, 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 test fits again. 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

Koenker, R. (1981). A note on studentizing a test for heteroscedasticity. Journal of Econometrics, 17(1), 107–112. doi:10.1016/0304-4076(81)90062-2

Davidson, R., & MacKinnon, J. G. (2004). Econometric Theory and Methods. Oxford University Press. Section 7.5 derives the test as \(n R^2\) from the regression of the squared residuals on the variance regressors.

See also

performBPTest() for the classical LM statistic, which assumes normal errors, and performKoenkerTest(), which computes the same studentized \(n R^2\) statistic on the squared residuals. The robust workflow in performBPTestRobust() augments the studentized statistic with bootstrap diagnostics.

Examples

data(mtcars)
mod <- lm(mpg ~ wt + qsec, data = mtcars)
# Deprecated: warns, and returns the statistic of performKoenkerTest()
suppressWarnings(performStudentizedBPTest(mod, mtcars))
performKoenkerTest(mod, mtcars)