Learn R Programming

AdaptFitOS (version 0.69)

predict.asp: Semiparametric regression prediction.

Description

Takes a fitted asp object produced by asp2 and obtains predictions at new data values.

Usage

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

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.

Arguments

object

a fitted asp object as produced by asp2(). Does not work with basis="os".

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. Further, minima and maxima should currently coincide with those of the predictors.

se

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

...

other arguments.

Author

Manuel Wiesenfarth, based on implementation of M.P. Wand (package SemiPar).

Details

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

See Also

plot.asp, summary.asp

Examples

Run this code
data(fossil,package="SemiPar")
attach(fossil)
fit <- asp2(strontium.ratio~f(age, basis="tps"))
newdata.age <- data.frame(age=c(90,100,110,120,130))
preds <-  predict(fit,newdata=newdata.age,se=TRUE)
print(preds)

# Use predict to avoid centering of smooths in case of scatterplot 
# smoothing
  fit <- asp2(strontium.ratio~f(age,basis="tps"))
  newdata.age <-data.frame(age=seq(90,130,length.out=50) )
  preds <- predict(fit,newdata=newdata.age,se=TRUE)
  plot(age,strontium.ratio)
  lines(newdata.age$age,preds$fit,col="red")
  lines(unlist(newdata.age),preds$fit+2*preds$se,col="blue")
  lines(unlist(newdata.age),preds$fit-2*preds$se,col="green")

Run the code above in your browser using DataLab