Perform Goldfeld-Quandt test for heteroscedasticity¶
Source: man/performGQTest.Rd · Help: ?performGQTest
Implements the Goldfeld-Quandt test on a fitted linear model with directional or two-sided alternatives.
Usage¶
performGQTest(model, data = NULL, order_by, fraction = 0.2,
alternative = c("greater", "two.sided", "less"))
Arguments¶
model- an object of class
lm. data- the data frame
modelwas fitted to, orNULL, the default. The response, design, weights and offset are read from the fit itself, andorder_byfrom the rows ofdatathat hold the observations of the fit. Withoutdatait is read from the model frame ofmodel, which holds it only when it is a variable of the model under its own name (x, notlog(x)); a model that transforms the variable it is ordered by needsdata. Since 0.16.0 the two parts are fitted to their rows of the stored design, with the offset of the fit; before, an unweighted fit was refitted from its formula on each part ofdata, which computed again a term that depends on the rows it is computed from, such asns()orI(x > median(x)), and an offset was left out: anoffset =argument of an unweighted fit, any offset of a weighted one. Since 0.16.0, 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; seetest_results. order_by- single column name used to order observations.
fraction- fraction of observations omitted from the middle; must lie strictly between zero and one.
alternative- alternative hypothesis:
"greater"for increasing variance from segment 1 to segment 2,"less"for decreasing variance, or"two.sided"for either direction.
Value¶
An object of class htest containing the directional GQ statistic, p-value, degrees of freedom and alternative hypothesis.
Details¶
Observations are ordered by a suspected variance-driving variable. With the split point fixed at the sample midpoint, a central fraction is omitted and the model is fitted again on the lower and upper segments: each segment is fitted to its rows of the design, the response and the offset of the fit, as lmtest::gqtest() fits them to the rows of the design. The statistic is the residual mean square of segment 2 divided by the residual mean square of segment 1 and is therefore directional rather than being forced above one. Split arithmetic and p-value conventions match lmtest::gqtest(..., point = 0.5).
Before 0.16.0 the segments of an unweighted fit were refitted from the formula, which computed again, on the rows of each segment, a term that depends on the rows it is computed from: ns(x) and bs(x) placed their knots at quantiles of the segment, and I(x > median(x)) took its median, so the segments were fitted to columns the fit never used; poly(x) computed another basis of the same columns, which changed the last bits only. The refit also left out an offset given as an argument, and a weighted fit was refitted without its offset.
Weighted fits¶
On a fit with weights each segment is refitted with its own weights and the segments are compared on the weighted residual sum of squares, \(\sum w_i e_i^2\). That is the Goldfeld-Quandt statistic of the equivalent unweighted regression, so the test asks whether the weights are adequate. Releases before 0.12.0 refitted the segments without the weights.
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 accepts a model with an offset, given as an argument or as an
offset() term, weighted or not, and gives the value of the model fitted to the response minus
the offset (since 0.16.0).
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¶
Goldfeld, S. M., & Quandt, R. E. (1965). Some tests for homoscedasticity. Journal of the American Statistical Association, 60(310), 539–547. doi:10.1080/01621459.1965.10480811
Greene, W. H. (2018). Econometric Analysis (8th ed.). Pearson.