New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
restricted cubic splines with emmeans #180
Comments
It would help a lot to see the R code you used to fit the model.
But the main point is that the names of all local variables in that model-fitting call need to be included in params.
|
With some effort I found out where Here's an example using the > my.knots = c(2.5, 3, 3.5)
> mod = lm(Sepal.Length ~ Species*ns(Sepal.Width, knots = my.knots), data = iris) We get an error if we don't specify > ref_grid(mod)
Error in ref_grid(mod) : We are unable to reconstruct the data.
The variables needed are:
Species Sepal.Width my.knots
Are any of these actually constants? (specify via 'params = ')
The dataset name is:
iris
Does the data still exist? Or you can specify a dataset via 'data = ' The clue here is that it's looking for a variable named > ref_grid(mod, params = "my.knots")
'emmGrid' object with variables:
Species = setosa, versicolor, virginica
Sepal.Width = 3.0573 Now here are some results at different x values: > emmeans(mod, ~ Species | Sepal.Width, params = "my.knots",
+ at = list(Sepal.Width = 2:4))
NOTE: Results may be misleading due to involvement in interactions
Sepal.Width = 2:
Species emmean SE df lower.CL upper.CL
setosa 5.09 2.1391 135 0.861 9.32
versicolor 5.48 0.3392 135 4.812 6.15
virginica 6.18 0.7918 135 4.613 7.74
Sepal.Width = 3:
Species emmean SE df lower.CL upper.CL
setosa 4.65 0.1366 135 4.381 4.92
versicolor 6.20 0.0951 135 6.011 6.39
virginica 6.73 0.0934 135 6.547 6.92
Sepal.Width = 4:
Species emmean SE df lower.CL upper.CL
setosa 5.41 0.1269 135 5.159 5.66
versicolor -5.77 9.3033 135 -24.172 12.63
virginica 9.20 0.6478 135 7.916 10.48
Confidence level used: 0.95 I hope this clarifies the purpose and use of |
That's super helpful! Thank you. I had prepared a reproducible example, but I'll read this carefully before proceeding. |
I'm happy to report that I got the Note that
Many thanks for the help and for the emmeans package! |
Terrific! I'm glad you got it to work. Plus, this is a good example; and the care with which you emphasize I am realizing that there isn't an example in the vignettes of using |
No objection, cheers! |
I think we've completed this issue, so closing. But comment further if something comes up. |
Hi both - thanks for this thread, it helped me troubleshoot my own issue using emmeans with a model with an rcs term. I just wanted to add to this to share knowledge based on my troubleshooting of a similar issue, in case it helps someone who comes across this thread. I've found is that, in rms::rcs, if you specify the 'parms' argument as a number and allow the rms::rcs() function to define the knots, it makes your model incompatible with emmeans functions such as emmeans, qdrg and ref_grid, because emmeans can't find the knots parameter (even though they are stored in the 'parms' object of the model. So you have to first make an object with the knots (using the same procedure as the rms::rcs() function would use within it) and then use this as the 'parms' argument in the rms::rcs bit of your model. Below are examples of the same model, but in emmeans incompatible and compatible formats, respectively (based on @nbarrowman's examples above):
|
Thanks. Glad this was helpful |
I am trying to use
emmeans
with anlmer
model with a restricted cubic spline term usingrcs
but I get the following error message:In the "Extending emmeans" vignette there is a brief mention of splines:
I feel like I'm close, but can't quite figure out how to proceed.
Thanks, I love the package!
The text was updated successfully, but these errors were encountered: