fderiv: First derivatives of fitted GAM functions

Description Usage Arguments Value Author(s) Examples

Description

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

Usage

1
2
3
4
5
6
7
8
fderiv(model, ...)

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

## S3 method for class '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.

Value

An object of class "fderiv" is returned.

Author(s)

Gavin L. Simpson

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
library("mgcv")
set.seed(2)
dat <- gamSim(1, n = 400, dist = "normal", scale = 2)
mod <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat, method = "REML")

## first derivatives of all smooths...
fd <- fderiv(mod)

## ...and a selected smooth
fd2 <- fderiv(mod, term = "x1")

## Models with factors
set.seed(2)
dat <- gamSim(4, n = 400, dist = "normal", scale = 2)
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")

gavinsimpson/tsgam documentation built on May 16, 2019, 10:11 p.m.