Robust three-group tests for heteroscedasticity in linear regression.
The tests sort the data by a regressor, split them into three equal parts, fit the regression in each part and compare the error scale of the parts.
| Function | What it does |
|---|---|
kah3.test() |
Least squares in each part. The ratio of the largest to the smallest residual mean square follows Hartley’s maximum F-ratio with three groups exactly, so the p-value is exact at every sample size. |
kah.robust.test() |
Least trimmed squares (LTS) in each part, so outliers neither create nor hide heteroscedasticity as easily. Three references: an effective-degrees-of-freedom F-max approximation (default), a Monte Carlo reference, or a residual bootstrap for non-normal errors. |
run.all.het() |
Runs the KaH tests next to Goldfeld-Quandt, Breusch-Pagan (Koenker), White and the robust modified Goldfeld-Quandt test of Rana, Midi and Imon (2008) and, when skedastic is installed, three more recent tests. |
pfmax(), dfmax(), qfmax(),
rfmax() |
Hartley’s maximum F-ratio distribution for any number of groups and any positive degrees of freedom. |
# development version
# install.packages("remotes")
remotes::install_github("ebrahimkhaled/KOTORY")library(KOTORY)
# stopping distance of cars: the spread grows with speed
kah3.test(dist ~ speed, data = cars)
kah.robust.test(dist ~ speed, data = cars)
# all tests side by side
run.all.het(dist ~ speed, data = cars)
# an outlier fools least squares but not the robust test
set.seed(2)
x <- runif(60)
y0 <- 1 + x + rnorm(60)
y <- y0; y[which.min(x)] <- 12
c(clean = kah3.test(y0 ~ x)$p.value, outlier = kah3.test(y ~ x)$p.value)
c(clean = kah.robust.test(y0 ~ x)$p.value, outlier = kah.robust.test(y ~ x)$p.value)The three-group tests were proposed in the doctoral thesis of Ahmed El-Kotory (Alexandria University), where their critical values were tabulated by simulation. This package replaces those tables: the least squares version follows Hartley’s (1950) maximum F-ratio exactly, and the robust version is referred to an effective-degrees-of-freedom approximation, a Monte Carlo reference or a bootstrap.
Ahmed El-Kotory and Ebrahim Khaled Ebrahim (maintainer), Department of Statistics, Faculty of Business, Alexandria University.