I have read similar questions submitted here, and have looked in Wood's 2017 book (Generalized additive models: An introduction with R, 2nd edition) but cannot find an answer to my problem.
To set up the question, consider first a simple linear model:fit<-lm(Y~X+Z). Once I get the coefficients from this simple model (say, Y_hat=2.1+0.9X+3.2Z) then I can get the predicted values that Y would have if I set the coefficient of Z to zero (Y_hat*=2.1+0.9X) and the residuals of Y around this new equation.
Now, imagine that I do a generalized additive model (say, with the gamm function of the mgcv package): fit<-gamm(Y~s(X)+s(Z)). How can I get the coefficients of this GAM in such a way that I can do the same thing as with the simple linear equation; i.e. get the predicted values that Y would have if I set the coefficients associated with the smooth function of Z to zero and then obtain the residuals around this new equation? If I extract the coefficients of a GAM (eg coef(fit$lme)) then I can see the coefficients associated with the intercept and of each of the basis functions, but I don't know how to proceed after that. Thanks for any suggestions.
predict
?mgcv
provides a method forgam
objects and there'sgammit::predict_gamm
if you want to condition on random effects. $\endgroup$