I am trying to calculate pairwise comparisons using the {emmeans} package after fitting a linear model with an inverse-transformed response. Here is the data and fitted model. The data comes from the {faraway} package.
> data("rats", package = "faraway")
> m <- lm(1/time ~ treat + poison, data = rats)
After fitting the model I can get estimated marginal means that are back-transformed using the following code:
> emmeans(m3, specs = "treat", type = "response", tran = "inverse")
treat response SE df lower.CL upper.CL
A 0.284 0.0115 42 0.263 0.309
B 0.537 0.0411 42 0.465 0.635
C 0.339 0.0164 42 0.309 0.376
D 0.463 0.0305 42 0.408 0.534
Results are averaged over the levels of: poison
Confidence level used: 0.95
Intervals are back-transformed from the inverse scale
However, when I then try to calculate pairwise comparisons using the contrast() function, the results are not back-transformed.
> emmeans(m3, specs = "treat", type = "response", tran = "inverse") |>
+ contrast("pairwise")
contrast estimate SE df t.ratio p.value
A - B 1.657 0.201 42 8.233 <.0001
A - C 0.572 0.201 42 2.842 0.0335
A - D 1.358 0.201 42 6.747 <.0001
B - C -1.085 0.201 42 -5.391 <.0001
B - D -0.299 0.201 42 -1.485 0.4551
C - D 0.786 0.201 42 3.905 0.0018
Results are averaged over the levels of: poison
Note: contrasts are still on the inverse scale
P value adjustment: tukey method for comparing a family of 4 estimates
I have tried moving the type = "response", tran = "inverse" arguments to the contrast() function but that produces unusual results:
> emmeans(m3, specs = "treat") |>
+ contrast("pairwise", type = "response", tran = "inverse")
contrast response SE df null t.ratio p.value
A - B 1 0 42 Inf 8.233 <.0001
A - C 2 1 42 Inf 2.842 0.0335
A - D 1 0 42 Inf 6.747 <.0001
B - C Inf Inf 42 Inf -5.391 <.0001
B - D Inf Inf 42 Inf -1.485 0.4551
C - D 1 0 42 Inf 3.905 0.0018
I have also tried the following but still get the same result (comparisons still on inverse scale).
tran <- make.tran("inverse")
m2 <- with(tran, lm(linkfun(time) ~ treat + poison, data = rats))
emmeans(m2, specs = "treat", type = "response") |>
contrast("pairwise")
My question: Is there a way to get contrasts that are back-transformed from the inverse scale?
This is well-documented and is a matter of deciding what you want to be talking about. If you do
emm <- emmeans(..., type = "response")
then the means in emm are still on the transformed scale, but back-transformed to the response scale. When we do
contrast(emm, ...)
the contrasts are still computed on the transformed scale. If type = "response" is in force, then those results are back-transformed, but only if there is a valid way to do that. For example, if the transformation is the log, then a comparison of two means is of the form log(a) - log(b) which is equal to log(a/b), hence back-transforming it will yield an estimate of a/b.
However, with the inverse scale, because there is no way to back-transform 1/a - 1/b, so the results are reported on the inverse scale, with a message.
If really what you wanted was an estimate of mean(1/a) - mean(1/b), that can be done but we don't do mind-reading, you have to ask for it. That is accomplished via the regrid() function, which re-casts all the estimates to a new scale:
remm <- regrid(emm) # back-transforms to the response scale by default
contrast(remm, ...)
By the same token, if you really wanted to estimate the ratios of the response means, you could do
contrast(regrid(emm, transform = "log"), ...)
See the help page for regrid() for more information. You can also find a detailed discussion of how transformations are dealt with in the "transformations" vignette.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With