daniel1noble / orchaRd

Extending the Orchard Plot for Meta-analysis
https://daniel1noble.github.io/orchaRd/
11 stars 6 forks source link

Option to plot non-linear meta-regressions in bubble_plot() #52

Open befriendabacterium opened 1 year ago

befriendabacterium commented 1 year ago

Is your feature request related to a problem? Please describe. Currently there's no way to plot commonly used non-linear meta-regressions via bubble_plot().

Describe the solution you'd like Would be good if bubble_plot() could at least handle the four non-linear options given in https://www.metafor-project.org/doku.php/tips:non_linear_meta_regression (polynomial, restricted cubic spline, natural cubic spline, or thin plate spline).

Describe alternatives you've considered You can do this outside the function and then add your predictions a blank bubble plot without any model predictions (I added this option here: https://github.com/daniel1noble/orchaRd/pull/51), but it's much preferable if the model could automatically handle it.

Additional context I've made a start on doing this for restricted cubic splines for my own purposes here (https://github.com/befriendabacterium/orchaRd/tree/nonlinear), but needs improvement and the other non-linear options done too.

befriendabacterium commented 1 year ago

Hi @daniel1noble and @itchyshin - me again ... sorry...

So I've been revisiting this the last couple of days and come up with what I think is a better solution - well, borrowed/adapted this one: https://stackoverflow.com/a/64493228/8349925.

Basically, instead of having different solutions for predicting and plotting model fits for each different model specification (e.g. linear, polynomial, restricted cubic spline), we can read the model's formula and then use predict.rma() in such a way as to predict for any model specification. I've implemented and done some testing of this at https://github.com/befriendabacterium/orchaRd/commit/bea94098f0354c289967add34afa63835128d998 and it seems to work well, producing equivelent plots to the emmeans method that currently only works for linear models.

When you get a chance, have a look as I think it could allow orchard_plot() to work a bit more universally and also saves a few lines of code I think!

Cheers Matt