crsh / papaja

papaja (Preparing APA Journal Articles) is an R package that provides document formats to produce complete APA manuscripts from RMarkdown-files (PDF and Word documents) and helper functions that facilitate reporting statistics, tables, and plots.
https://frederikaust.com/papaja_man/
Other
648 stars 132 forks source link

Model comparison anova-objects for apa_print: other than lm objects #474

Open Misch007 opened 3 years ago

Misch007 commented 3 years ago

Hey!

I hope I am not missing something! As far as I understood (#27) model comparisons are only supported for lm objects? I am comparing linear mixed models created by the function afex::mixed() via anova(). I'd like to report them using apa_print(). What do you think about this support?

Best regards and thanks for the great work! Mischa

mariusbarth commented 3 years ago

Hi @Misch007, model-comparison objects of class anova are indeed not supported. However, objects of class mixed which are the output of mixed() are supported. If you are only testing for single-term deletions you could use

apa_print(mixed(..., method = "LRT")

with the more-complex model specified in the formula to get the same result as from anova(). This is only a workaround and I think we should support model-comparison objects of class anova, soon.

Misch007 commented 3 years ago

Hey @mariusbarth!

Thanks a lot for the quick answer!

I am really sorry, but unfortunately I am not quite following... I did not manage to get the same result as from anova() output with your advice. Would you mind giving an example, this is the data I tried it with:

participant<-c("vp1","vp2","vp3","vp4","vp5")
group<-c("intervention", "control","control","intervention","control")

df<-data.frame(participant,group) %>% 
  group_by(participant,group) %>% 
  summarise(session=c("t1","t2","t3","t4")) %>% 
  group_by(participant, group, session) %>% 
  summarise(task=c("a","b")) %>% 
  ungroup() %>% 
  mutate(errors=floor(runif(n=40,min=0,max=30)))

lmm1 <- mixed(errors~group*session*task+(1|participant), df)
lmm2 <- mixed(errors~group*task+(1|participant), df)

anova(lmm1,lmm2)

Data: data
Models:
lmm2: errors ~ group * task + (1 | participant)
lmm1: errors ~ group * session * task + (1 | participant)
     npar    AIC    BIC  logLik deviance  Chisq Df Pr(>Chisq)    
lmm2    6 289.79 299.93 -138.90   277.79                         
lmm1   18 256.47 286.87 -110.24   220.47 57.322 12  6.915e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Best regards and once again: Thanks a lot! Mischa

mariusbarth commented 3 years ago

Hi @Misch007, unfortunately, this is a case where the workaround won't work: You basically compare a model with two main effects and an interaction term with a more complex model with one three-way interaction, three two-way interactions, and three main effects, so it's not the single-term deletion case. For cases as such, we would really need a method for anova objects.

Misch007 commented 3 years ago

Ah, got it! Thanks for the explanation and good luck on this one!