Learn R Programming

SemiPar (version 1.0-4.2)

predict.spm: Semiparametric regression prediction.

Description

Takes a fitted spm object produced by spm() and obtains predictions at new data values.

Usage

# S3 method for spm
predict(object,newdata,se,...)

Arguments

object

a fitted spm object as produced by spm().

newdata

a data frame containing the values of the predictors at which predictions are required. The columns should have the same name as the predictors.

se

when this is TRUE standard error estimates are returned for each prediction. The default is FALSE.

...

other arguments.

Value

If se=FALSE then a vector of predictions at `newdata' is returned. If se=TRUE then a list with components named `fit' and `se' is returned. The `fit' component contains the predictions. The `se' component contains standard error estimates.

Details

Takes a fitted spm object produced by spm() and obtains predictions at new data values as specified by the `newdata' argument. If `se=TRUE' then standard error estimates are also obtained.

References

Ruppert, D., Wand, M.P. and Carroll, R.J. (2003) Semiparametric Regression Cambridge University Press. http://stat.tamu.edu/~carroll/semiregbook/

Ganguli, B. and Wand, M.P. (2005) SemiPar 1.0 Users' Manual. http://matt-wand.utsacademics.info/SPmanu.pdf

See Also

spm lines.spm plot.spm summary.spm

Examples

Run this code
# NOT RUN {
library(SemiPar)
data(fossil)
attach(fossil)
fit <- spm(strontium.ratio~f(age))
newdata.age <- data.frame(age=c(90,100,110,120,130))
preds <-  predict(fit,newdata=newdata.age,se=TRUE)
print(preds)

plot(fit,xlim=c(90,130))
points(unlist(newdata.age),preds$fit,col="red")
points(unlist(newdata.age),preds$fit+2*preds$se,col="blue")
points(unlist(newdata.age),preds$fit-2*preds$se,col="green")
# }

Run the code above in your browser using DataLab