gsp | R Documentation |
From https://github.com/gmonette/spida2 because namespace and dependencies are not properly listed. Source: https://github.com/gmonette/spida2/blob/master/R/gsp.R, https://github.com/gmonette/spida2/blob/master/R/gsp_util.R
gsp(
x,
knots,
degree = 3,
smoothness = pmax(pmin(degree[-1], degree[-length(degree)]) - 1, -1),
lin = NULL,
periodic = FALSE,
intercept = 0,
signif = 3
)
x |
value(s) where spline is evaluated. |
knots |
vector of knots. |
degree |
vector giving the degree of the spline in each interval. Note
the number of intervals is equal to the number of knots + 1. A value of 0
corresponds to a constant in the interval. If the spline should evaluate to
0 in the interval, use the |
smoothness |
vector with the degree of smoothness at each knot
(0 = continuity, 1 = smoothness with continuous first derivative, 2 = continuous
second derivative, etc. The value -1 allows a discontinuity at the knot.
A scalar is recycled so its length equals the number of knots. Alternatively,
a list of length equal to the number of knots. Each element of the list is a
vector of the orders of derivatives which are required to be smooth. THis allows
non-sequential constraints, e.g., to have the same first and second derivative
on either side of a knot but a possible discontinuity and change in
higher-order derivatives, the vector would be c(1,2). Note that if a list is used,
all elements must provide all desired constraints. That is the list argument corresponding
to |
lin |
provides a matrix specifying additional linear contraints on the 'full' parametrization consisting of blocks of polynomials of degree equal to max(degree) in each of the length(knots)+1 intervals of the spline. See below for examples of a spline that is 0 outside of its boundary knots. |
periodic |
if TRUE generates a period spline on the base interval (0,max(knots)). A constraint is generated so that the coefficients generate the same values to the right of max(knots) as they do to the right of 0. Note that all knots should be strictly positive. |
intercept |
value(s) of x at which the spline has value 0, i.e., the value(s) of x for which yhat is estimated by the intercept term in the model. The default is 0. If NULL, the spline is not constrained to evaluate to 0 for any x. |
signif |
number of significant digits used to label coefficients. |
gsp
returns a matrix generating a spline.
Monette, G. georges@yorku.ca
simd <- data.frame(
age = rep(1:50, 2),
y = sin(2 * pi * (1:100) / 5) + rnorm(100),
G = rep(c("male", "female"), c(50, 50))
)
sp <- function(x) {
gsp(x, knots = c(10, 25, 40), degree = c(1, 2, 2, 1), smoothness = c(1, 1 ,1))
}
summary(lm(formula = y ~ sp(age) * G, data = simd))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.