gavinsimpson / gratia

ggplot-based graphics and useful functions for GAMs fitted using the mgcv package
https://gavinsimpson.github.io/gratia/
Other
206 stars 28 forks source link

Using derivatives with random smooths by individual #243

Open gavinsimpson opened 11 months ago

gavinsimpson commented 11 months ago

Discussed in https://github.com/gavinsimpson/gratia/discussions/242

Originally posted by **TSeuH** December 6, 2023 Hello, I have been trying to get the first derivatives for each individual fit from the following model: gam.smooth <- gam(TV ~ groupID + s(time, by = groupID) + s(time, animalID, bs = "fs", m = 1), data = dataTV, method = "REML") fdSmooth <- derivatives(gam.smooth, n = 1000, term = "s(time)", partial_match = TRUE) I see a column "fs_var" in fdSmooth, and I was assuming it would contain "animalID", just like by_var contains "groupID". I thought I could get the first derivative for each animalID, but with this code, I only get the first derivative for each groupID, regardless of the animalID. Would it be possible to have the derivatives by animalID without changing the GAM? Thank you.