singmann / afex

Analysis of Factorial EXperiments (R package)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Anova table data heading incorrect

cbrnr opened this issue · comments

When passing an object to the data argument of mixed(), the Anova table shows the correct data that was used in the calculation, e.g.

mixed(rt ~ group * distance + (1|id), data=df)
Mixed Model Anova Table (Type 3 tests, LRT-method)

Model: rt ~ group * distance + (1 | id)
Data: df
...

However, I often filter the input data, because I do not want to create names just for fitting a model, e.g.

mixed(rt ~ group * distance + (1|id), data=data=df |> filter(correct, order=="ordered"))

The data output in the table is then incorrect, because multiple lines are shown:

Mixed Model Anova Table (Type 3 tests, LRT-method)

Model: rt ~ group * distance + (1 | id)
Data: filter
Data: df
Data: correct
Data: order == "ordered"
...

Would it be possible to fix this so that only one line is shown with the original expression? Alternatively, is there some way to disable printing the data line(s)?

Thanks for the report, this should indeed be better. I have tried to fix it in the current development version:

suppressPackageStartupMessages(library("afex"))
suppressPackageStartupMessages(library("dplyr"))
data("Machines", package = "MEMSS") 

mixed(score ~ Machine + (Machine|Worker), data = subset(Machines, score > 0))
#> Contrasts set to contr.sum for the following variables: Machine, Worker
#> Mixed Model Anova Table (Type 3 tests, S-method)
#> 
#> Model: score ~ Machine + (Machine | Worker)
#> Data: subset(Machines, score > 0)
#>    Effect      df         F p.value
#> 1 Machine 2, 5.00 41.01 ***   <.001
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1

mixed(score ~ Machine + (Machine|Worker), data = filter(Machines, score > 0))
#> Contrasts set to contr.sum for the following variables: Machine, Worker
#> Mixed Model Anova Table (Type 3 tests, S-method)
#> 
#> Model: score ~ Machine + (Machine | Worker)
#> Data: filter(Machines, score > 0)
#>    Effect      df         F p.value
#> 1 Machine 2, 5.00 41.01 ***   <.001
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1

Created on 2022-05-21 by the reprex package (v2.0.1)

Looks great, thanks a lot!