Skip to content
Prev 14271 / 20628 Next

Replicating type III anova tests for glmer/GLM

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.