Predictive Models – How to Back Transform predict.gam() from NB Link Log Model Run

back-transformationgeneralized-additive-modellink-functionmgcvpredictive-models

I have model with 1 covariate. I would like to run y values from gam in another model. I used nb(log=link) in gam model. Because I used nb and link log in gam, do I need to back transform to use output from predict.gam() to match real values? I would like to run predicted in another model and to compare with other real data.
 

Simple model ex:

 
gam model

model_a <- gam(species_count~ s(slope), data=dat,
               family=nb(link = "log"), method="ML")

Use predict.gam to grab y values

speciesct_a <- predict.gam(model_a,type="response")

Best Answer

No, you don't need to do a further transformation to the response scale as you have already specified type = "response" in your call to predict().

Note that you can't use the standard errors returned by adding se.fit = TRUE to your predict() call if you continue to use type = "response" because there's no easy way to do it once everything is transformed back to the response scale. If you do want to form confidence/credible intervals, use type = "link", se.fit = TRUE and then create the confidence/credible interval and then manually use exp() to back transform the fitted/predicted values and the interval to the response scale.

Or you could use my {gratia} package and its fitted_values() function which takes care of this for you and with scale = "response" would give you an interval on the response scale that has been created properly (following the brief steps I outlined above).