regrid {emmeans} | R Documentation |
The typical use of this function is to cause EMMs to be computed on a different scale, e.g., the back-transformed scale rather than the linear-predictor scale. In other words, if you want back-transformed results, do you want to average and then back-transform, or back-transform and then average?
regrid(object, transform = c("response", "mu", "unlink", "log", "none"), inv.log.lbl = "response", predict.type)
object |
An object of class |
transform |
Character or logical value. If |
inv.log.lbl |
Character value. This applies only when |
predict.type |
Character value. If provided, the returned object is
updated with the given type, e.g., |
The regrid
function reparameterizes an existing ref.grid
so
that its linfct
slot is the identity matrix and its bhat
slot
consists of the estimates at the grid points. If transform
is
TRUE
, the inverse transform is applied to the estimates. Outwardly,
when transform = "response"
, the result of summary.emmGrid
after applying regrid
is identical to the summary of the original
object using type="response". But subsequent EMMs or
contrasts will be conducted on the new scale – which is
the reason this function exists.
In cases where the degrees of freedom depended on the linear function being estimated, the d.f. from the reference grid are saved, and a kind of “containment” method is substituted in the returned object whereby the calculated d.f. for a new linear function will be the minimum d.f. among those having nonzero coefficients. This is kind of an ad hoc method, and it can over-estimate the degrees of freedom in some cases.
An emmGrid
object with the requested changes
Another way to use regrid
is to supply a transform
argument to ref_grid
(either directly of indirectly via
emmeans
). This is often a simpler approach if the reference
grid has not already been constructed.
pigs.lm <- lm(log(conc) ~ source + factor(percent), data = pigs) # This will yield EMMs as GEOMETRIC means of concentrations: emmeans(pigs.lm, "source", type = "response") # NOTE: pairs() of the above will be RATIOS of these results # This will yield EMMs as ARITHMETIC means of concentrations: emmeans(regrid(ref_grid(pigs.lm, transform = "response")), "source") # Same thing, made simpler: emmeans(pigs.lm, "source", transform = "response") # NOTE: pairs() of the above will be DIFFERENCES of these results