gmatrix | R Documentation |
Generate Truncated Spline Base
gmatrix(r = 3, iknots = c(0.2, 0.3), lk = 0, hk = 1)
r |
Degree of the splines, must be greater than zero. |
iknots |
A vector of inner knots. |
lk |
lower boundary knot. |
hk |
higher boundary knot. |
$TG^'=B$, note that the matrix $G$ only depends on the degree r
,
inner knots iknots
and outer knots lk
and hk
.
The $G$ matrix that links the truncated base (T-base) and the B-base.
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)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.