View source: R/emmGrid-methods.R
regrid | 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", "none", "pass",
links), inv.link.lbl = "response", predict.type,
bias.adjust = get_emm_option("back.bias.adj"), sigma, N.sim,
sim = mvtnorm::rmvnorm, ...)
object |
An object of class |
transform |
Character, list, or logical value. If If |
inv.link.lbl |
Character value. This applies only when |
predict.type |
Character value. If provided, the returned object is
updated with the given type to use by default by |
bias.adjust |
Logical value for whether to adjust for bias in
back-transforming ( |
sigma |
Error SD assumed for bias correction (when
|
N.sim |
Integer value. If specified and |
sim |
A function of three arguments (no names are assumed).
If |
... |
Ignored. |
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.
This function may also be used to simulate a sample of regression
coefficients for a frequentist model for subsequent use as though it were a
Bayesian model. To do so, specify a value for N.sim
and a sample is
simulated using the function sim
. The grid may be further processed in
accordance with the other arguments; or if transform = "pass"
, it is
simply returned with the only change being the addition of the simulated
sample.
An emmGrid
object with the requested changes
In cases where the degrees of freedom depended on the linear function being estimated (e.g., Satterthwaite method), 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 annotation is displayed below any subsequent summary results stating that the degrees-of-freedom method is inherited from the previous method at the time of re-gridding.
Another way to use regrid
is to supply a regrid
argument to ref_grid
(either directly of indirectly via
emmeans
), in which case its value is passed to regrid
as
transform
. 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)
rg <- ref_grid(pigs.lm)
# This will yield EMMs as GEOMETRIC means of concentrations:
(emm1 <- emmeans(rg, "source", type = "response"))
pairs(emm1) ## We obtain RATIOS
# This will yield EMMs as ARITHMETIC means of concentrations:
(emm2 <- emmeans(regrid(rg, transform = "response"), "source"))
pairs(emm2) ## We obtain DIFFERENCES
# Same result, useful if we hadn't already created 'rg'
# emm2 <- emmeans(pigs.lm, "source", regrid = "response")
# Simulate a sample of regression coefficients
set.seed(2.71828)
rgb <- regrid(rg, N.sim = 200, transform = "pass")
emmeans(rgb, "source", type = "response") ## similar to emm1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.