afex icon indicating copy to clipboard operation
afex copied to clipboard

Standardized responses with emmeans

Open rvlenth opened this issue 5 years ago • 0 comments

Henrik,

Just a note that I have figured out a way to auto-detect the parameters of a response transformation of scale(), provided the needed information is in the result of terms(). I've done a little testing, and it does not appear to work with aov_ez or its relatives. Nor does it work directly with mixed, but in this case it comes close:

> library(afex)
> library(emmeans)
> 
> data("Machines", package = "MEMSS") 
> m1 <- mixed(scale(score) ~ Machine + (Machine|Worker), data=Machines)
>
> ref_grid(m1)
NOTE: Unable to recover scale() parameters. See '? make.tran'
'emmGrid' object with variables:
    Machine = A, B, C
>
> ref_grid(m1$full_model)
'emmGrid' object with variables:
    Machine = A, B, C
Transformation: “scale(59.6, 8.08)” 

The reason the second one works is because if a response transformation of "scale" is found, it tries to parse the predvars attribute of terms(object):

> attr(terms(m1), "predvars")
Error in terms.default(m1) : no terms component nor attribute

> attr(terms(m1$full_model), "predvars")
list(scale(score, center = 59.65, scale = 8.07625800703682), 
    Machine)

An additional note is that terms(an.aov.object) does not have this attribute, and that's why it doesn't work with aov_ez().

Anyway, I might suggest that you alter or add a terms() method that will have the needed attribute. This will not come into effect for a little while because I just recently updated emmeans on CRAN. But it does seem like something your users would like to have supported in the future. The update of emmeans on github does have this extension, so you'd be able to test it.

rvlenth avatar May 30 '20 22:05 rvlenth