Perform Bartlett's test for equality of variances¶
Source: man/performBartlettTest.Rd · Help: ?performBartlettTest
Uses bartlett.test on model residuals grouped by a factor.
Usage¶
Arguments¶
model- an object of class
lm. data- The data frame
modelwas fitted to, orNULL, the default. The residuals and weights are read from the fit itself, andgroupfrom the rows ofdatathat hold the observations of the fit; the observations whose group is missing are left out, with a warning. 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 grouping variable the model does not use needsdata. 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. group- name of the grouping variable.
Value¶
An object of class htest containing the chi-squared statistic, p-value and degrees of freedom.
Details¶
The test statistic compares the pooled variance to the individual group variances. It is computed as \(\chi^2 = (N - k) \ln S_p^2 - \sum (n_i - 1) \ln s_i^2\), where \(S_p^2\) is the pooled variance and \(s_i^2\) the group variances. Under the null it approximates a chi-square distribution with \(k-1\) degrees of freedom.
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 refuses a multivariate lm ("needs a model with one response"), since 0.16.0; before, it
stopped with a coercion error. An mgcv::gam() fit is tested as before 0.16.0, with penalised
smooth terms too: the test reads its residuals and does not fit it again, so it does not take them
for least-squares residuals (decision 37 of the design of the model context); since 0.16.0 its
observations are matched to the rows of data by the row names of its model frame. Before,
they were matched by position, since the residuals of a gam carry no names, and data
with the rows of the fit in another order gave a wrong value.
Which model each test accepts, and why, is set out in
test_results, under Supported models.
References¶
Bartlett, M. S. (1937). Properties of sufficiency and statistical tests. Proceedings of the Royal Society of London, 160(901), 268–282. doi:10.1098/rspa.1937.0109
Hartley, H. O. (1950). The maximum F-ratio as a short-cut test for heterogeneity of variance. Biometrika, 37(3/4), 308–312. doi:10.2307/2332383