gmatrix: Generate Truncated Spline Base

View source: R/gmatrix.r

gmatrixR Documentation

Generate Truncated Spline Base

Description

Generate Truncated Spline Base

Usage

gmatrix(r = 3, iknots = c(0.2, 0.3), lk = 0, hk = 1)

Arguments

r

Degree of the splines, must be greater than zero.

iknots

A vector of inner knots.

lk

lower boundary knot.

hk

higher boundary knot.

Details

$TG^'=B$, note that the matrix $G$ only depends on the degree r, inner knots iknots and outer knots lk and hk.

Value

The $G$ matrix that links the truncated base (T-base) and the B-base.

Examples

gmatrix(r=3,iknots=c(0.2,0.3),lk=0,hk=1)
x=sort(runif(1000)) # random numbers to ensure no cherry-picking
knots=c(0.04,0.14,0.26,0.38,0.5,0.62,0.74,0.86,0.96)
lk=0;hk=1 #boundary knots
r=3 #order of splines, i.e. cubic splines
###generate B-base using the splines2 package
B2=splines2::bSpline(x,knots=knots, degree=r, intercept=TRUE,Boundary.knots=c(lk,hk))
###generate B-base using splines package
B1=splines::bs(x,knots=knots, degree=r, intercept = TRUE,Boundary.knots=c(lk,hk))
###t-base
TB0=tbase(x,iknots=knots,lk=lk,hk=hk,deg=r)
###compute the linkage matrix GM
abc=gmatrix(r=r,iknots=knots,lk=lk,hk=hk)
###generate B-base from T-base using the linkage function
TB1=TB0%*%t(abc$GM)
### Check the differences
c(max(abs(B2-B1)),max(abs(B2-TB1)))


marvels2031/PWEALL_1.4.0 documentation built on April 22, 2022, 12:52 a.m.