Learn R Programming

GeDS (version 0.3.3)

Derive: Derivative of GeDS Objects

Description

This function computes derivatives of a fitted GeDS regression model.

Usage

Derive(object, order = 1L, x, n = 3L)

Arguments

object

An object of class "GeDS" containing the GeDS fit which should be differentiated. It should be the result of fitting a univariate GeDS regression via NGeDS or GGeDS.

order

Integer value indicating the order of differentiation required (e.g. first, second or higher derivatives). Note that order should be lower than n and that non-integer values will be passed to the function as.integer.

x

Numeric vector containing values of the independent variable at which the derivatives of order order should be computed.

n

Integer value (2, 3 or 4) specifying the order (\(=\) degree \( + 1\)) of the GeDS fit to be differentiated. By default equal to 3L.

Details

This function relies on the splineDesign function to compute the exact derivatives of the GeDS fit. Specifically, it leverages the well-known property that the \(m\)-th derivative of a spline (for \(m = 1, 2, \ldots\)) can be obtained by differentiating its B-spline basis functions. This property is detailed, e.g., in De Boor (2001, Chapter X, formula (15)).

Note that the GeDS fit is a B-spline representation of the predictor. Consequently, the derivative is computed with respect to the predictor scale and not the response scale. This implies that, in the GNM(GLM) framework, the function does not return derivatives of the conditional mean on the response scale, but rather of the underlying linear predictor scale.

References

De Boor, C. (2001). A Practical Guide to Splines (Revised Edition). Springer, New York.

Examples

Run this code

# Generate a data sample for the response variable
# Y and the covariate X
set.seed(123)
N <- 500
f_1 <- function(x) (10*x/(1+100*x^2))*4+4
X <- sort(runif(N, min = -2, max = 2))
# Specify a model for the mean of Y to include only
# a component non-linear in X, defined by the function f_1
means <- f_1(X)
# Add (Normal) noise to the mean of Y
Y <- rnorm(N, means, sd = 0.1)

# Fit GeDS regression with only a spline component in the predictor model
Gmod <- NGeDS(Y ~ f(X), beta = 0.6, phi = 0.995, Xextr = c(-2,2))

# Compute the second derivative of the cubic GeDS fit
# at the points 0, -1 and 1
Derive(Gmod, x = c(0, -1, 1), order = 2, n = 4)

Run the code above in your browser using DataLab