Closed MarcRieraDominguez closed 1 year ago
I thought I had this covered in a recent update: emtrends()
calls ref_grid()
twice, and a coding error caused it to not pass the data correctly the second time. That did indeed fix part of it. However, there was another subtle error than came up in the recover_data.averaging()
whereby it (incorrectly) needed the response variable. That's probably TMI, but anyway I have it working:
> emtrends(mod.avg, specs = ~ mpg, var = "mpg", trans = "response", data = dataset)
In 'ref_grid()', use 'regrid = ...' rather than 'transform = ...' to avoid this message.
In 'ref_grid()', use 'regrid = ...' rather than 'transform = ...' to avoid this message.
mpg mpg.trend SE df lower.CL upper.CL
20.1 -0.00414 0.0255 28 -0.0564 0.0481
Results are averaged over the levels of: vs
Confidence level used: 0.95
Please note the message that shows twice (due to the two calls to ref_grid()
). Instead of trans = "response"
, you should specify regrid = "response"
. You had those messages too, and they didn't go away. But also, it's pretty unusual to have the same variable in specs
and var
. Here's another example to show some clean results with no messages:
> emtrends(mod.avg, specs = ~ vs, var = "mpg", regrid = "response", data = dataset)
vs mpg.trend SE df lower.CL upper.CL
0 -0.00725 0.04443 28 -0.0982 0.0838
1 -0.00104 0.00687 28 -0.0151 0.0130
Confidence level used: 0.95
BTW, no big deal, but I would have preferred you use the native pipe operator |>
thence requiring me to load fewer packages to reproduce your results.
The updated code will be pushed up soon (there'll be a message on this page when that happens), then you can install from GitHub and it should work.
Thanks for reporting this.
Super! Thank you for all your work!
I think this is resolved, so am closing this issue.
Describe the bug
The
emtrends()
function in version 1.8.5 does not compute slopes with models of class "averaging". If I understand correctly, it cannot find the dataset, even if it is supplied toemtrends()
as adata
argument.emmeans()
works fine with averaged models.To reproduce
Created on 2023-03-29 with reprex v2.0.2
Expected behavior
I would expect the same output from
emtnreds()
applied to the linear model: slope with uper and lower confidence interval at the untransformed scale.Additional context
My aim is to calculate marginal means and slopes from model-averaged binomial GLMs (
stats::glm()
). The models include 9 continuous predictors and 1 factor, and does not contain interactions. The vignettes explicilty mention models of class averaging (https://cran.r-project.org/web/packages/emmeans/vignettes/models.html#I), butemtnreds()
is not mentioned. Apologies if I have missed it!Thank you for your time!