The first derivative of the smooth functions of a GAM model calculated using finite differences.

fderiv(model, ...)
# S3 method for gam
fderiv(
model,
newdata,
term,
n = 200,
eps = 1e-07,
unconditional = FALSE,
offset = NULL,
...
)
# S3 method for gamm
fderiv(model, ...)

## Arguments

model |
A fitted GAM. Currently only models fitted by `mgcv::gam()` and `mgcv::gamm()` are supported. |

... |
Arguments that are passed to other methods. |

newdata |
a data frame containing the values of the model covariates at which to evaluate the first derivatives of the smooths. |

term |
character; vector of one or more terms for which derivatives are required. If missing, derivatives for all smooth terms will be returned. |

n |
integer; if `newdata` is missing the original data can be reconstructed from `model` and then `n` controls the number of values over the range of each covariate with which to populate `newdata` . |

eps |
numeric; the value of the finite difference used to approximate the first derivative. |

unconditional |
logical; if `TRUE` , the smoothing parameter uncertainty corrected covariance matrix is used, *if available*, otherwise the uncorrected Bayesian posterior covariance matrix is used. |

offset |
numeric; value of offset to use in generating predictions. |

## Value

An object of class `"fderiv"`

is returned.

## Author

Gavin L. Simpson

## Examples

#> Gu & Wahba 4 term additive model

#> Factor `by' variable example

mod <- gam(y ~ s(x0) + s(x1) + fac, data = dat, method = "REML")
## first derivatives of all smooths...
fd <- fderiv(mod)
## ...and a selected smooth
fd2 <- fderiv(mod, term = "x1")