| gsl.bs | R Documentation | 
gsl.bs generates the B-spline basis matrix for a
polynomial spline and (optionally) the B-spline basis matrix
derivative of a specified order with respect to each predictor 
gsl.bs(...)
## Default S3 method:
gsl.bs(x,
       degree = 3,
       nbreak = 2,
       deriv = 0,
       x.min = NULL,
       x.max = NULL,
       intercept = FALSE,
       knots = NULL,
       ...)
x | 
 the predictor variable. Missing values are not allowed  | 
degree | 
 degree of the piecewise polynomial - default is ‘3’ (cubic spline)  | 
nbreak | 
 number of breaks in each interval - default is ‘2’  | 
deriv | 
  the order of the derivative to be computed-default if
  | 
x.min | 
  the lower bound on which to construct the spline -
defaults to   | 
x.max | 
  the upper bound on which to construct the spline -
defaults to   | 
intercept | 
 if ‘TRUE’, an intercept is included in the basis; default is ‘FALSE’  | 
knots | 
  a vector (default   | 
... | 
 optional arguments  | 
Typical usages are (see below for a list of options and also the examples at the end of this help file)
    B <- gsl.bs(x,degree=10)
    B.predict <- predict(gsl.bs(x,degree=10),newx=xeval)
  
gsl.bs returns a gsl.bs object.  A matrix of dimension
‘c(length(x), degree+nbreak-1)’.  The generic function
predict extracts (or generates) predictions from the
returned object.
A primary use is in modelling formulas to directly specify a piecewise polynomial term in a model. See https://www.gnu.org/software/gsl/ for further details.
Jeffrey S. Racine racinej@mcmaster.ca
Chen, X., T. Christensen and S. Kankanala (2024). “Adaptive Estimation and Uniform Confidence Bands for Nonparametric Structural Functions and Elasticities.” Review of Economic Studies, forthcoming. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/restud/rdae025")}
bs
## Plot the spline bases and their first order derivatives
x <- seq(0,1,length=100)
matplot(x,gsl.bs(x,degree=5),type="l")
matplot(x,gsl.bs(x,degree=5,deriv=1),type="l")
## Regression example
n <- 1000
x <- sort(runif(n))
y <- cos(2*pi*x) + rnorm(n,sd=.25)
B <- gsl.bs(x,degree=5,intercept=FALSE)
plot(x,y,cex=.5,col="grey")
lines(x,fitted(lm(y~B)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.