Learn R Programming

fda.usc (version 1.2.3)

predict.fregre.GAM: Predict method for functional regression model

Description

Computes predictions for regression between functional (and non functional) explanatory variables and scalar response.
  • predict.fregre.lm, Predict method for functional linear model offregre.lmfits object using basis or principal component representation.
  • predict.fregre.plm, Predict method for semi-functional linear regression model offregre.plmfits object using using asymmetric kernel estimation.
  • predict.fregre.glm, Predict method for functional generalized linear model offregre.glmfits object using basis or principal component representation.
  • predict.fregre.gsam, Predict method for functional generalized spectral additive model offregre.gsamfits object using basis or principal component representation.
  • predict.fregre.gkam, Predict method for functional generalized kernel additive model offregre.gkamfits object using backfitting algorithm.

Usage

## S3 method for class 'fregre.lm':
predict(object,newx=NULL,type="response",se.fit=FALSE,
      scale = NULL,df=df, interval = "none", level = 0.95,weights = 1, 
      pred.var = res.var/weights, \dots)
## S3 method for class 'fregre.plm':
predict(object,newx=NULL,\dots)
## S3 method for class 'fregre.glm':
predict(object,newx=NULL,type="response",\dots)
## S3 method for class 'fregre.gsam':
predict(object, newx = NULL, type = "response",\dots)
## S3 method for class 'fregre.gkam':
predict(object, newx = NULL, type = "response",\dots)

Arguments

object
fregre.lm, fregre.plm, fregre.glm, fregre.gsam or fregre.gkam object.
newx
An optional data list in which to look for variables with which to predict. If omitted, the fitted values are used. List of new explanatory data.
type
Type of prediction (response or model term).
se.fit
=TRUE (not default) standard error estimates are returned for each prediction.
scale
Scale parameter for std.err. calculation.
df
Degrees of freedom for scale.
interval
Type of interval calculation.
level
Tolerance/confidence level.
pred.var
the variance(s) for future observations to be assumed for prediction intervals. See link{predict.lm} for more details.
weights
variance weights for prediction. This can be a numeric vector or a one-sided model formula. In the latter case, it is interpreted as an expression evaluated in newdata
...
Further arguments passed to or from other methods.

Value

  • Return the predicted values and optionally:
  • predict.lm,predict.glm,predict.gamproduces a vector of predictions or a matrix of predictions and bounds with column names fit, lwr, and upr if interval is set. If se.fit is TRUE, a list with the following components is returned: fit vector or matrix as above.
  • se.fitstandard error of predicted means.
  • residual.scaleresidual standard deviations.
  • dfdegrees of freedom for residual.

Details

These functions use the model fitting function lm, glm or gam properties. If using functional data derived, is recommended to use a number of bases to represent beta lower than the number of bases used to represent the functional data. The first item in the data list of newx argument is called "df" and is a data frame with the response and non functional explanatory variables, as lm, glm or gam. Functional variables (fdata and fd class) are introduced in the following items in the data list of newx argument.

References

Febrero-Bande, M., Oviedo de la Fuente, M. (2012). Statistical Computing in Functional Data Analysis: The R Package fda.usc. Journal of Statistical Software, 51(4), 1-28. http://www.jstatsoft.org/v51/i04/

See Also

See Also as: fregre.lm, fregre.plm, fregre.glm, fregre.gsam and fregre.gkam.

Examples

Run this code
data(tecator)
ind<-1:129
x=tecator$absorp.fdata
x.d2<-fdata.deriv(x,nderiv=2)
tt<-x[["argvals"]]
dataf=as.data.frame(tecator$y)
nbasis.x=11;nbasis.b=7
basis1=create.bspline.basis(rangeval=range(tt),nbasis=nbasis.x)
basis2=create.bspline.basis(rangeval=range(tt),nbasis=nbasis.b)
basis.x=list("x.d2"=basis1)
basis.b=list("x.d2"=basis2)
ldata=list("df"=dataf[ind,],"x.d2"=x.d2[ind])

res=fregre.gsam(Fat~s(Water,k=3)+s(x.d2,k=3),data=ldata,
family=gaussian(),basis.x=basis.x,basis.b=basis.b)
newldata=list("df"=dataf[-ind,],"x.d2"=x.d2[-ind])
pred<-predict.fregre.gsam(res,newldata)
plot(pred,tecator$y$Fat[-ind])

res.glm=fregre.glm(Fat~Water+x.d2,data=ldata,family=gaussian(),
basis.x=basis.x,basis.b=basis.b)
pred.glm<-predict.fregre.glm(res.glm,newldata)
newy<-tecator$y$Fat[-ind]
points(pred.glm,tecator$y$Fat[-ind],col=2)

res.plm=fregre.plm(Fat~Water+x.d2,data=ldata)
pred.plm<-predict.fregre.plm(res.plm,newldata)
points(pred.plm,tecator$y$Fat[-ind],col=3)

# Time-consuming 
res.gkam=fregre.gkam(Fat~Water+x.d2,data=ldata)
pred.gkam=predict(res.gkam,newldata)
points(pred.gkam,tecator$y$Fat[-ind],col=4)

((1/length(newy))*sum((drop(newy)-pred)^2))/var(newy)
((1/length(newy))*sum((newy-pred.plm)^2))/var(newy)    
((1/length(newy))*sum((newy-pred.glm)^2))/var(newy)    
((1/length(newy))*sum((newy-pred.gkam)^2))/var(newy)

Run the code above in your browser using DataLab