ps {lazy.stat}R Documentation

Generate Piecewise Spline Basis

Description

Generate Piecewise Spline Basis

Usage

ps(
  x,
  degree = 3,
  nknots = 0,
  knots = NULL,
  intercept = TRUE,
  xmin = NULL,
  xmax = NULL,
  rescale = 0,
  orth = 0,
  xrange = NULL,
  xrange0 = NULL,
  Xrange0 = NULL,
  print = 0,
  xlab = "new",
  xlim = NULL,
  ylim = NULL,
  title = "p-spline",
  plot = 0
)

Arguments

x

Input vector.

degree

Degree of polynomial to be used.

nknots

# of knots to be used in [xmin, xmax].

knots

vector consisting of (internal) knots to be used.

intercept

= 0 to omit the intercept.

xmin

minimum of internal knots.

xmax

maximum of internal knots.

rescale

= 1 to rescale all the basis in [0,1].

orth

= 1 to orthogonalize the basis.

xrange

New range of x: When present, x will be transformed as
x=xrange[1]+(x-xrange0[1])*(xrange[2]-xrange[1])/(xrange0[2]-xrange0[1])

xrange0

Current range of x

Xrange0

A matrix containing mimimum and maximum values of each column of X before range conversion.

print

= 1 to print the result.

xlab

="org" to label x with original scale when xrange is present.

xlim

xlim for plot.

ylim

ylim for plot.

title

Plot title.

plot

= 1 to plot the result.

Details

When knots are present, it has priority over nknots.
When rescale = 1, the spline basis matrix will be rescaled as
X=t( (t(X)-Xrange0[1,])/(Xrange0[2,]-Xrange0[1,]) )

The old minmax will be stored in Xrange0.

When xrange is present, x will be transformed as
x=xrange[1]+(x-xrange0[1])*(xrange[2]-xrange[1])/(xrange0[2]-xrange0[1])
so that the new range will be xrange[1] <= x xrange[2].

The old range will be stored in xrange0.

xrange0 and Xrange0 will be used in predict_sp.

Value

List of: x
X=length(x) x (nknots+degree+1) spline basis matrix
knots ( boundary + inside )
interior.knots, boundary.knots, degree, nknots rescale, orth x_org and knots_org: x and knots in original x scale before range change.

Examples


n <- 50
x <- seq(10,20,length=n)
res <- ps( x, nknots=4, plot=1 )
res <- ps( x, nknots=4, plot=1, rescale=1 )
res <- ps( x, nknots=4, plot=1, rescale=1, xrange=c(-1,1) )
res <- ps( x, nknots=4, plot=1, rescale=1, xrange=c(-1,1), xlab="org" )



[Package lazy.stat version 0.1.4 Index]