rlinear-regressionemmeans

Backtranform lsmeans in R


I have created a simple linear regression model in R where I have log transformed the response. The independent variable is categorical with 80 levels. Then I use emmeans for pairwise tests. How can I backtransform the emmeans to have the same scale as the response (not the log scale)? I use the emmeans package in R.


Solution

  • I think this is just

    summary(emmeans(...), type = "response")
    

    ? There is a vignette on transformations and link functions

    e.g.

    library(emmeans)
    m1 <- lm(log(mpg) ~ factor(cyl), mtcars)
    summary(emmeans(m1, ~cyl), type = "response")
    
     cyl response    SE df lower.CL upper.CL
       4     26.3 1.268 29     23.9     29.0
       6     19.7 1.190 29     17.4     22.3
       8     14.9 0.636 29     13.6     16.2
    Confidence level used: 0.95 
    Intervals are back-transformed from the log scale 
    

    Note that if you use pairs(emmeans(m1, ~cyl), type = "response") it will give you the pairwise ratios, but notes that the tests are performed on the log scale (as they should be)