When type = "lpmatrix", which is how fitted_samples() etc uses predict.gam(), predict.gam() doesn't include the offset in the Xp matrix. Instead, predict.gam() returns the Xp matrix with an attribute model.offset containing the vector of values for the offset term:
> Xp <- predict(mod, type = "lpmatrix")
> head(attr(Xp, "model.offset"))
[1] 6.907755 6.906755 6.907755 6.908755 6.907755 6.908755
When
type = "lpmatrix"
, which is howfitted_samples()
etc usespredict.gam()
,predict.gam()
doesn't include the offset in the Xp matrix. Instead,predict.gam()
returns the Xp matrix with an attributemodel.offset
containing the vector of values for the offset term:So, modify the line
to be
Originally posted by @gavinsimpson in https://github.com/gavinsimpson/gratia/discussions/231#discussioncomment-6719974