Learn R Programming

mixAK (version 2.2)

BsBasis: B-spline basis

Description

It creates a B-spline basis based on a specific dataset. B-splines are assumed to have common boundary knots and equidistant inner knots.

Usage

BsBasis(degree, ninner, knotsBound, knots, intercept=FALSE,
        x, tgrid, Bname="B", plot=FALSE, lwd=1,
        col="blue", xlab="Time", ylab="B(t)",
        pch=16, cex.pch=1, knotcol="red")

Arguments

degree
degree of the B-spline.
ninner
number of inner knots.
knotsBound
2-component vector with boundary knots.
knots
knots of the B-spline (including boundary ones). If knots is given ninner and knotsBound are ignored.
intercept
logical, if FALSE, the first basis B-spline is removed from the B-spline basis and it is assumed that intercept is added to the statistical models used afterwards.
x
a numeric vector to be used to create the B-spline basis.
tgrid
if given then it is used to plot the basis.
Bname
label for the created columns with the B-spline basis.
plot
logical, if TRUE the B-spline basis is plotted.
lwd, col, xlab, ylab
arguments passed to the plotting function.
pch, cex.pch
plotting character and cex used to plot knots
knotcol
color for knots on the plot with the B-spline basis.

Value

  • A matrix with the B-spline basis. Number of rows is equal to the length of x.

    Additionally, the resulting matrix has attributes:

  • degreeB-spline degree
  • interceptlogical indicating the presence of the intercept B-spline
  • knotsa numeric vector of knots
  • knotsInnera numeric vector of innner knots
  • knotsBounda numeric vector of boundary knots
  • dfthe length of the B-spline basis (number of columns of the resulting object).
  • tgrida numeric vector which can be used on x-axis to plot the basis.
  • Xgrida matrix with length(tgrid) rows and df columns which can be used to plot the basis.

See Also

bs.

Examples

Run this code
set.seed(20101126)
t <- runif(20, 0, 100)

oldPar <- par(mfrow=c(1, 2), bty="n")
Bs <- BsBasis(degree=3, ninner=3, knotsBound=c(0, 100), intercept=FALSE,
              x=t, tgrid=0:100, plot=TRUE)
print(Bs)

Bs2 <- BsBasis(degree=3, ninner=3, knotsBound=c(0, 100), intercept=TRUE,
               x=t, tgrid=0:100, plot=TRUE)
print(Bs2)
par(oldPar)

print(Bs)
print(Bs2)

Run the code above in your browser using DataLab