load_mgcv()
# \dontshow{
op <- options(lifecycle_verbosity = "quiet")
# }
dat <- data_sim("eg1", seed = 2)
mod <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat, method = "REML")
## first derivatives of all smooths...
fd <- fderiv(mod)
## now use -->
fd <- derivatives(mod)
## ...and a selected smooth
fd2 <- fderiv(mod, term = "x1")
## now use -->
fd2 <- derivatives(mod, select = "s(x1)")
## Models with factors
dat <- data_sim("eg4", n = 400, dist = "normal", scale = 2, seed = 2)
mod <- gam(y ~ s(x0) + s(x1) + fac, data = dat, method = "REML")
## first derivatives of all smooths...
fd <- fderiv(mod)
## now use -->
fd <- derivatives(mod)
## ...and a selected smooth
fd2 <- fderiv(mod, term = "x1")
## now use -->
fd2 <- derivatives(mod, select = "s(x1)")
Run the code above in your browser using DataLab