gamlss-dev / gamlss

gamlss: Generalized Additive Models for Location Scale and Shape
https://CRAN.R-project.org/package=gamlss
10 stars 4 forks source link

Extracting values used in term.plot #6

Open Cole-Monnahan-NOAA opened 4 months ago

Cole-Monnahan-NOAA commented 4 months ago

A colleague and I have been puzzling over how to get the data out of the term.plot() function so that we can replot the figures as we want to. Basically I am running separate models on 6 populations and want to create a nice multipanel plot of the effect of Month on each population, as below.

image

Unfortunately, I can't seem to find a way of getting the mean and SD out of term.plot() for my model; we looked through the underlying R code for term.plot() and it was not immediately obvious how to extract the plotted values.

term.plot() does not return the values plotted if you set plot=FALSE

summary(results, save=TRUE)$mu.coef.table
this does return the values needed but not the mean and SD for month 1 only for months 2-12.

I also tried the base function x <- termplot(plot=FALSE) and this does return the mean and SD for months 1-12, the mean is the same (offset by the intercept), but the SD is smaller than for the model, probably because the GAMLSS model uses beta-binomial likelihood.

No doubt there is an easier way of finding this!

Alternatively, perhaps it's worth considering in a future update, adding the plot=FALSE option to term.plot and having it return the plotted values in the same way that termplot does.