[R-sig-ME] Replicating type III anova tests for glmer/GLM
Lenth, Russell V
russell-lenth at uiowa.edu
Tue Feb 23 21:31:01 CET 2016
Type III tests were originally formulated in terms of contrasts that give equal weight to levels of any interactions that contain the effect in question. This in turn depends on all those contrasts being estimable. Such contrast-based tests are possible to obtain (one at a time) using the lsmeans package - which does support glmer models. It goes something like this:
require(lsmeans)
rg <- ref.grid(model)
str(rg at nbasis)
If the previous result is a matrix with one or more columns, then that means some contrasts are not estimable; and this throws off some or all of the type III tests obtained using the method below. Otherwise, you can proceed. For example, the type III test of an interaction of factors A and B is obtained by:
test(contrast(lsmeans(rg, ~ A*B), interaction = "trt.vs.ctrl"), joint = TRUE)
Provided everything is estimable, this does NOT depend on a particular coding of the factors.
If there are non-estimable contrasts, the results (and even the degrees of freedom) vary depending on what factor coding is used, and what contrast family (e.g., "trt.vs.ctrl", "consec", "pairwise", etc.) is used. To make any sense at all of them in such a case, you'd have to look at the contrasts themselves to see what is being tested. The same is true in SAS, which offers "type IV" tests, which are also dependent on coding, ordering of levels, etc.
Russ
Russell V. Lenth - Professor Emeritus
Department of Statistics and Actuarial Science
The University of Iowa - Iowa City, IA 52242 USA
Voice (319)335-0712 (Dept. office) - FAX (319)335-3017
Just because you have numbers, that doesn't necessarily mean you have data.
> Dear Pr Fox,
>
> Thanks for your precision. But to summarize this test of, let's say 3 parameters to 0 for a 4-levels factor, by a single value with its SE, as mentionned in Francesco's mail, the linear combination of these parameters that is practically tested by this sum of square is needed, isn't it ?
>
> I mean, if really the parameters are all 0, whatever linear combination could do the job, but type III sum of square just tests one of all possible linear combinations, right?
>
> By the way, I was always very annoyed by the fact that Type III sum of squares are so dependent on coding, but that's another debate...
>
> Best regards,
>
> --
> Emmanuel CURIS
> emmanuel.curis at parisdescartes.fr
More information about the R-sig-mixed-models
mailing list