[R-sig-ME] Problems using Anova functions 'type = 2' or 'type = 3' from car package with lme

Ben Bolker bbo|ker @end|ng |rom gm@||@com
Mon Oct 28 17:23:43 CET 2019



On 2019-10-28 10:11 a.m., Mario Garrido wrote:
> Thanks Julian,
> for your clarification and the recommendation of this package. It would be
> great if at any moment the statistician from your working place, or any
> other expert in this forum, can tell us:
> *1. Why Type II is better?* I personally read different reasons in favour
> or against its use. Also, I read about using Type III, but since Im not an
> expert, I decide to go for Type III since STATISTICA, SPSS and other
> softwares use it.

   There are long arguments about this (see e.g. Venables "exegeses on
linear models", old papers by Nelder et al).  Type 3 can violate the
principle of marginality; type 2 doesn't.  Results of type 3 depend on
the parameterization/contrasts used, and *may* lead to silly tests (or
to not testing what you think you're testing).


> *2. What's different from Type II and Type III?* In my trials, I see that
> both do not depend on the order we 'enter' the data, but differences on the
> F and P-value of the main effects when there is an interaction in the
> model. In any place I read that Type III is better when we have a
> significant interaction while Type II when not. 

  type 3 tests lower-level effects in the presence of higher-level ones.
 Whether you think this makes sense depends on your statistical
philosophy and what you're doing.  It is indeed true that the difference
only emerges in models with interactions.  Tests of the highest-level
interaction in the model should be identical with type 2 vs type 3.

  My personal philosophy is that I try never to base any decision about
statistical procedure (e.g. type 2 vs 3) on whether some component of
the model statistically significant or not.


In any case
> 3. due to marginality principle, neither with Type II or Type III we can
> interpret the main effects when are involved in an interaction, right?

  If you hold to the principle of marginality strictly, yes.


> 4. *Do this affects also interactions? *when a higher-order interaction in
> present, lower order ones can be interpreted?

  Principle of marginality says you shouldn't interpret a *lower-level*
effect in the presence of a *higher-level* effect involving the same
terms (so, if A:B:C interaction is in your model, don't interpret A:B,
B:C, A:C, A, B, or C).

  I don't personally hold strongly to the principle of marginality.  My
rule would be "if you aren't sure exactly what your test of a given
effect means, then don't interpret it".  That means that a type-3 test
*could* be OK, if you know what parameterization you're using and
therefore what hypothesis the test actually corresponds to.  If you'd
rather not think about all this stuff, then never use type 3 (which
violates the principle of marginality).


> 
> Thanks
> 
> El lun., 28 oct. 2019 a las 12:23, Julian Gaviria Lopez (<
> Julian.GaviriaLopez using unige.ch>) escribió:
> 
>> Hi Mario,
>>
>>
>> Glad to hear you found the solution.  Unfortunately I can not validate it,
>> since I am not a stats expert. I was  thinking that maybe the emmeans
>> package could help you for the post-hoc contrasts, and the interaction
>> analysis:
>>
>> https://cran.rstudio.com/web/packages/emmeans/vignettes/interactions.html
>>
>>
>> P.D. The statistician from my dept.  encourages us to work always
>> with ANOVA type II.  Maybe further information about it might be found not
>> here,  but in another list, such as stack overflow.
>>
>>
>> Best,
>>
>> Julian Gaviria
>> Neurology and Imaging of cognition lab (Labnic)
>> University of Geneva. Campus Biotech.
>> 9 Chemin des Mines, 1202 Geneva, CH
>> Tel: +41 22 379 0380
>> Email: Julian.GaviriaLopez using unige.ch
>> ------------------------------
>> *From:* R-sig-mixed-models <r-sig-mixed-models-bounces using r-project.org> on
>> behalf of Mario Garrido <gaadio using post.bgu.ac.il>
>> *Sent:* Monday, October 28, 2019 11:18:44 AM
>> *To:* r-sig-mixed-models using r-project.org
>> *Subject:* Re: [R-sig-ME] Problems using Anova functions 'type = 2' or
>> 'type = 3' from car package with lme
>>
>> Hi,
>> I think I have found the solution using:
>> anova.lme(model,type = "sequential") # same results as anova(model); it
>> seems logical, since Type I is sequential
>> anova.lme(model,type = "marginal") # as far as I know, sorry of Im wrong,
>> Type III is also called marginal
>>
>> Cheers!
>>
>> El lun., 28 oct. 2019 a las 10:33, Mario Garrido (<gaadio using post.bgu.ac.il>)
>> escribió:
>>
>>> Hello,
>>> I use lme to create a linear mixed effects model with three fixed factors
>>> (Treatment, species and Period) and one random factor (individual
>> identity,
>>> ExpID).
>>> After creating the model, I tried to apply Anova from car package to
>>> compute results with both Type II and III Sum of Squares, but I get the
>>> error stated below:
>>> I have UNBALANCED data, more data from sp1 than for the others
>>> These are the data types.
>>>
>>>> str(Data)
>>> 'data.frame':   496 obs. of  27 variables:
>>>  $ Trtmnt2     : Factor w/ 2 levels "Control","Treated": 2 2 2 2 2 2 2 2
>> 1
>>> 1 ...
>>>  $ ExpID       : Factor w/ 62 levels "EA1","EA10","EA11",..: 1 1 1 1 1 1
>> 1
>>> 1 10 10 ...
>>>  $ sp          : Factor w/ 3 levels "sp1","sp2","sp3": 2 2 2 2 2 2 2 2 2
>> 2
>>> ...
>>>  $ Period      : Factor w/ 5 levels "Before","earlypeak",..: 1 5 2 4 3 5
>> 4
>>> 3 1 2 ...
>>>  $ StdzDiff    : num  -51.1 -53.2 -49 22.9 ...
>>>
>>> Here is the code to generate the model
>>>> library(car)
>>>> options(contrasts = c("contr.sum", "contr.poly"))
>>>
>>>> model<- lme(StdzDiff ~ Trtmnt2*sp*Period, data = Data, random = ~
>>> 1|factor(ExpID))
>>>> Anova(model, type=2)  #with type = 3, I have the same problems
>>> Error in I.p[subs.relatives, , drop = FALSE] :
>>>   subscript out of bounds
>>>
>>> I have no problems with 'default' anova. But, I get the same error
>>> working with the following code
>>> model<- lme(StdzDiff ~ Trtmnt2*sp*Period, data =
>>> DataFreqDark_StdzDiff_peakAll, random = ~
>>> 1|factor(ExpID),contrasts=list(Trtmnt2=contr.sum, sp=contr.sum,
>>> Period=contr.sum))
>>>
>>> My questions:
>>> 1) What is my error?
>>> 2) If Anova from car cannot deal with lme, how can I apply Type III to my
>>> model?
>>> 3) To confirm, if I define nothing, anova with lme, is type I by default?
>>>
>>> Thanks!
>>>
>>
>>
>> --
>> Mario Garrido Escudero, PhD
>> Dr. Hadas Hawlena Lab
>> Mitrani Department of Desert Ecology
>> Jacob Blaustein Institutes for Desert Research
>> Ben-Gurion University of the Negev
>> Midreshet Ben-Gurion 84990 ISRAEL
>>
>> gaiarrido using gmail.com; gaadio using post.bgu.ac.il
>> phone: (+972) 08-659-6854
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-mixed-models using r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>>
> 
>



More information about the R-sig-mixed-models mailing list