Perform the non-constant variance (NCV) score test (deprecated)¶
Source: man/performNCVTest.Rd · Help: ?performNCVTest
The Cook-Weisberg score test for non-constant error variance, the diagnostic returned by car::ncvTest().
Usage¶
Arguments¶
model- an object of class
lm. data- optional data frame the model was fitted to, in which
var_formulais evaluated, as inperformCookWeisbergTest. WhenNULL, the default, the model frame ofmodelis used. var_formula- optional one-sided formula giving the variance model, evaluated in
data(for example~ x1 + x2). WhenNULLthe fitted values are used. Before 0.15.0var_formulawas the second argument: a formula passed there by position is still read asvar_formula, with a warning; that form stops working in 1.0.0.
Value¶
An object of class htest containing the chi-square score statistic, its degrees of freedom and the p-value.
Details¶
Let \(\hat{e}_i\) denote the OLS residuals and \(\hat{\sigma}^2 = \sum_i \hat{e}_i^2 / n\) the maximum-likelihood variance estimate. The test regresses the scaled squared residuals \(u_i = \hat{e}_i^2 / \hat{\sigma}^2\) on the variance regressors \(Z\) and computes half the explained sum of squares of that auxiliary regression. Under homoscedasticity and normal errors the statistic is asymptotically chi-square with degrees of freedom equal to the number of variance regressors.
With var_formula = NULL the fitted values are the sole variance regressor, matching the default of car::ncvTest() and Stata's estat hettest.
Because the divisor 2 is the null variance of \(\hat{e}^2 / \sigma^2\) under normality, the test is sensitive to non-normal errors; performKoenkerTest provides the studentized variant, which is robust to non-normal kurtosis.
Since 0.18.0 the test refuses a variance model that fits the scaled squared residuals exactly, as performCookWeisbergTest() refuses it (see its details).
Deprecated¶
performNCVTest() is deprecated since 0.14.0: use performCookWeisbergTest, which gained var_formula and is the one entry point for the Cook-Weisberg score test. With a variance formula, performNCVTest(model, var_formula) returns what performCookWeisbergTest(model, var_formula) returns; without one the two return the same statistic, degrees of freedom and p-value, and performCookWeisbergTest() labels the result as the Cook-Weisberg test. The old name still works, returns what it returned and warns.
Weighted fits¶
On a fit with weights the test is computed from the Pearson residuals \(\sqrt{w_i}\, e_i\), so it tests whether the weights are adequate; see the section on weighted fits in performKoenkerTest(), which also covers weights estimated by fitWLS().
Validation¶
Reproduces car::ncvTest() to within 1e-8 for both the default and the var_formula forms; see tests/testthat/test-pass-a-reference.R. Releases before 0.7.0 regressed the absolute residuals on the fitted values and reported a t statistic, which is a Glejser-type test rather than the Cook-Weisberg score test.
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. Since 0.16.0 it is built on the model context, and also refuses
a multivariate lm ("needs a model with one response"), a fit whose coefficients, residuals or
weights were changed after the fit, and a fit with model = FALSE whose model frame, rebuilt
from the data it was fitted to, no longer holds its response, because those data changed after the
fit, with or without data. A fit with model = FALSE whose data are gone is tested on
data that give its response and fitted values, and refused without them. data is
matched to the observations of the fit as by performCookWeisbergTest, with or without
var_formula. Which model each test accepts, and why, is set out in
test_results, under Supported models.
References¶
Cook, R. D., & Weisberg, S. (1983). Diagnostics for heteroscedasticity in regression. Biometrika, 70(1), 1–10. doi:10.1093/biomet/70.1.1
Fox, J., & Weisberg, S. (2019). An R Companion to Applied Regression (3rd ed.). SAGE.
See also¶
performCookWeisbergTest, performKoenkerTest, performBPTest