Skip to content

Szroeter test for ordered alternatives

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

Detects monotonic changes in variance when observations can be meaningfully ordered—typically by time or another covariate—using the cumulative weighting scheme proposed by Szroeter (1978).

Usage

performSzroeterTest(model, data = NULL, order_by,
  alternative = c("greater", "two.sided", "less"))

Arguments

model
A fitted stats::lm object representing the mean equation under study.
data
A base::data.frame (or compatible tibble) containing the variables used to fit model and the ordering variable supplied via order_by. When NULL, the default, the model frame of model is used, so order_by must then be a variable of the model. The model frame holds the terms of the model rather than its variables (log(x) rather than x), so a model that transforms a variable needs data, as does a model with an offset() term.
order_by
Character scalar naming the column that defines the ordering of observations prior to computing the statistic. The column must be numeric or coercible to an orderable vector.
alternative
Character scalar specifying the alternative hypothesis: "greater" (the default) tests for variance increasing with order_by, "less" for variance decreasing, and "two.sided" for a change in either direction. Szroeter's test targets monotone alternatives, so the one-sided form is the usual choice.

Value

An object of class htest reporting Szroeter's standardised statistic Q, the sample size, the underlying rank-weighted statistic h in estimate, and the p-value from the asymptotic normal reference distribution.

Details

After ordering the residuals \(\hat{e}_{(i)}\) by order_by, the test forms the rank-weighted average of the squared residuals

\[ h = \frac{\sum_{i = 1}^n i \, \hat{e}_{(i)}^2}{\sum_{i = 1}^n \hat{e}_{(i)}^2}, \]

which is Szroeter's (1978) class of statistics evaluated at the canonical weights \(h_i = i\). Under homoskedasticity \(h\) is centred on the mean rank \((n + 1) / 2\) with variance \((n^2 - 1) / (6n)\), so

\[ Q = \frac{h - (n + 1) / 2}{\sqrt{(n^2 - 1) / (6n)}} \]

is asymptotically standard normal. Variance that grows with order_by shifts weight onto the high ranks and drives \(Q\) upwards.

The implementation relies on the package validation helpers to align the supplied data with the model residuals, check that the ordering variable is present, and ensure sufficient sample size and variability in the squared residuals.

Ties in order_by keep the order of the rows the model was fitted to. Unless the rows were sorted by the response, that order does not depend on the residuals, so the test keeps its level under the null hypothesis; but with a discrete ordering variable the statistic depends on the order of the rows.

runHeteroTests(tests = "szroeter"), and anything else that runs the registered diagnostic, orders the observations by the fitted values of model, so its alternative is variance that rises with the mean. With a single regressor that is the order of the regressor when its slope is positive and the reverse order when it is negative. The fitted values are computed from the coefficients, so observations with the same regressors tie exactly, as they do under a factor or a binary regressor, and the ties are broken as above.

Validation

The statistic and its null variance are checked against an independent reconstruction of Szroeter (1978) in tests/testthat/test-pass-a-reference.R. Releases before 0.7.0 divided the centred statistic by a further \(\sqrt{n}\), shrinking \(Q\) by a factor of roughly \(2 / \sqrt{n}\) and leaving the test with essentially no power against any alternative; see NEWS.md.

References

Szroeter, J. (1978). A class of parametric tests for heteroscedasticity in linear econometric models. Econometrica, 46(6), 1311–1327. doi:10.2307/1913833

Godfrey, L. G. (1988). Misspecification Tests in Econometrics. Cambridge University Press. Section 5.4 outlines the Szroeter test.

See also

performKoenkerTest() for the regressor-based alternative and performGQTest() for split-sample diagnostics on ordered data.

Examples

data(mtcars)
mod <- lm(mpg ~ wt + qsec, data = mtcars)
performSzroeterTest(mod, mtcars, order_by = "wt")

# Detect ordered heteroscedasticity in simulated data with variance increasing
# in an index variable
set.seed(404)
n <- 150
x <- sort(runif(n))
y <- 2 + 0.5 * x + rnorm(n, sd = 0.4 + 0.8 * x)
df <- data.frame(y, x)
performSzroeterTest(lm(y ~ x, data = df), df, order_by = "x")

# Two-sided version when the direction of the change is not known in advance
performSzroeterTest(mod, mtcars, order_by = "wt", alternative = "two.sided")