predict_sp {lazy.stat}R Documentation

Predicting from Spline Regression

Description

Predicting from Spline Regression

Usage

predict_sp(object, xnew)

Arguments

object

Output of spreg containing:
knots The internal knots
type Type of spline "b", "p", "m"
beta The regression coefficients
See details.

xnew

A new x varaibale at which to predict y

Details

If the object contains the result of b-spline, it must have boundary.knots parameters.
If the object contains the result of p-spline, it must have all the p-spline options such as
rescale orth, xrange, xrange0, Xrange0.

Value

A list of:
xnew The input
ynew The prediction at xnew: ynew = X %*% beta
X The design matrix

Examples

set.seed(1701)
n <- 20
x <- floor(10*runif(n))
y <- 10*runif(n)+1.5*sort(x)

# spline regression of y on x
res=spreg( y,x, type="b", nknots=2, plot=1, print=1 )

# prediction
xnew=seq(0,10,.1)
res2=predict_sp( res, xnew )
ynew=res2$ynew

# plot
plot(x,y, xlim=c(0,10), ylim=c(0,25))
par(new=TRUE)
plot(xnew,ynew,type="o",xlim=c(0,10), ylim=c(0,25))


[Package lazy.stat version 0.1.3 Index]