Description Usage Arguments Details References Examples
View source: R/IntegrateDerive.R
This function computes derivatives of a fitted GeDS regression model.
1 |
object |
the |
order |
integer value indicating the order of differentiation required (e.g. first, second or higher derivatives).
Note that |
x |
numeric vector containing values of the independent
variable at which the derivatives of order |
n |
integer value (2, 3 or 4) specifying the order (= degree + 1) of the GeDS fit
to be differentiated.
By default equal to |
The function is based on splineDesign
and
it computes the exact derivative of the fitted GeDS regression.
The function uses the property that the m-th derivative of a spline, m= 1,2,..., expressed in terms of B-splines can be computed by differencing the corresponding B-spline coefficients (see e.g. De Boor, 2001, Chapter X, formula (15)). Since the GeDS fit is a B-spline representation of the predictor, it cannot work on the response scale in the GNM (GLM) framework.
De Boor, C. (2001). A Practical Guide to Splines (Revised Edition). Springer, New York.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.