Skip to content
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

Support for penalized splines/GAMs #51

Open
bwiernik opened this issue Nov 21, 2021 · 4 comments
Open

Support for penalized splines/GAMs #51

bwiernik opened this issue Nov 21, 2021 · 4 comments
Labels
feature feature request

Comments

@bwiernik
Copy link
Contributor

Classification:

Feature Request

Summary

I'm interested in being able to fit meta-analysis models with penalized splines, ala mgcv::gam(). For example, I have a meta-analytic dataset where we want to model change in effect sizes over time using thin plate splines, with Country random effects in both intercepts and the year splines.

Here is how I might fit such a model with brms by using mgcv's tensor product spline implementation.

library(brms)
m2 <- brm(
  bf(yi | se(sqrt(vi)) ~ t2(year2004, Country, bs = c("tp", "re")) + 
       (1  | sample_id)
  ),
  data = filter(dat_mnsd2, param == "mn"),
  backend = "cmdstanr",
  cores = parallel::detectCores(),
  threads = 2
)

Is there any possibility that these sorts of penalized splines might be supported in metafor?

@wviechtb
Copy link
Owner

I will have to find time to figure out how exactly thin plate splines are incorporated into the model.

An alternative might be to use restricted cubic splines, as illustrated here:

https://www.metafor-project.org/doku.php/tips:non_linear_meta_regression

The nice thing is that this just requires creating transformations of the original predictor variable, which can then be added to the model as additional predictors in the usual manner (and one could add random slopes for them as well). If this is how these thin plate splines work, then it would be the same principle.

@bwiernik
Copy link
Contributor Author

The way the splines are implemented is with a design matrix and penalty matrix. The major benefit over restricted cubic splines is that I could include inner/outer-style random effects for the splines via a tensor product of splines for the year and the grouping factor.

@wviechtb
Copy link
Owner

I would have to really study the details, but I suspect that this will not currently be possible with the way things work in metafor.

@wviechtb
Copy link
Owner

wviechtb commented Mar 14, 2022

I happened to have taken Gavin Simpson's excellent course on GAMs in the meantime. So, in principle, one can do the same thing as in the example linked to above with restricted cubic splines. I have expanded the example to illustrate this with a thin plate spline model. However, rma() or rma.mv() do not currently include the necessary functionality for imposing penalties on the model matrix. However, the way this is done in brm() and gamm4() is to add the smooths (on top of a linear term) as random effects and the variance component then controls the wiggliness. That might be possible with rma.mv().

@wviechtb wviechtb added the feature feature request label Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature feature request
Projects
None yet
Development

No branches or pull requests

2 participants