find_gam_deriv() Finds a derivative with standard errors of smooth curves from gam model fit by finite differencing. Crucially it computes the probability that derivative is negative at each point.

find_gam_deriv(gam_fit, n_points = 200, x = NULL, N_smooths = 9,
  weights = list(rep(1, 200), sqrt(seq(1, 0, length.out = 200)), 1/(1 +
  seq(1, 0, length.out = 200)^3))[[1]], d = 1/n_points,
  return_gam = FALSE)

# S3 method for gam_deriv
summary(derivs)

# S3 method for gam_deriv
plot(derivs, features = derivs$derivs$y_name,
  title = "First derivative of GAM model: gene expression = function(distance from archetype)")

Arguments

gam_fit

a fitted gam object as produced by gam().

n_points

number of points at which to evaluate derivative

x

numeric vector where to evaluate derivatives

N_smooths

number of bases used to represent the smooth term (s), 4 for cubic splines

weights

how to weight points along x axis when calculating mean (integral) probability

d

numeric vector (1L), finite difference interval

return_gam

return gam model as well? By default only only the first derivative at n_points

Value

find_gam_deriv() list (S3 object, find_gam_deriv) containing function call, a data.table with values of the first derivative, GAM model fit summary (gam_sm) and (optionally) gam model fit; summary entry is NA.

Details

Plot method uses ggplot() to show mean derivative and confidence intervals (2 SD from the mean). This code is a modification of last example in predict.gam.