Learn R Programming

fda.usc (version 0.9.4)

predict.fregre.glm: Predict method for functional linear model of fregre.glm fits object

Description

Computes predictions for regression between functional (and no functional) explanatory variables and scalar response using: basis representation.

Usage

predict.fregre.glm(object,newx=NULL,type="response",...)

Arguments

object
fregre.glm 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).
...
Further arguments passed to or from other methods.

Value

  • Return:
  • predict.glmproduces 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

Predicts from a fitted fregre.glm object. This function uses the model fitting function glm 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. Functional variables (fdata and fd class) are introduced in the following items in the data list of newx argument.

References

Ramsay, James O., and Silverman, Bernard W. (2006), Functional Data Analysis, 2nd ed., Springer, New York.

See Also

See Also as: fregre.lm.

Examples

Run this code
data(tecator)                                                                 
ind<-1:129                                                                    
tecator$y$Fat<-ifelse(tecator$y$Fat<20,0,1)                                   
x<-tecator$absorp.fdata
tt=x[["argvals"]]                                                             
dataf=as.data.frame(tecator$y[ind,])                                                                               
x.d2=fdata.deriv(x,nderiv=2,method="fmm")                                           
ldata=list("df"=dataf,"x.d2"=x.d2[ind])  
basis.pc2=create.pc.basis(x.d2[ind],c(1:2))     
basis.x=list("x.d2"=basis.pc2)                 
                             
res.pc=fregre.glm(Fat~x.d2,ldata,family=binomial,basis.x=basis.x)     

basis1=create.fdata.basis(x.d2[ind],type.basis="fourier",l=1:11)              
basis2=create.fdata.basis(x.d2[ind],type.basis="fourier",l=1:5)               
basis.x=list("x.d2"=basis1)                                                   
basis.b=list("x.d2"=basis2)                                      
res.basis=fregre.glm(Fat~x.d2,ldata,family=binomial,basis.x=basis.x,basis.b=basis.b)     

newy<-floor(tecator$y$Fat[-ind])                                              
newx<-tecator$absorp.fdata[-ind,]                                             
newx.d2<-fdata.deriv(newx,nderiv=2,method="fmm")                                    
newdataf=as.data.frame(tecator$y[-ind,])                                      
newldata=list("df"=newdataf,"x.d2"=newx.d2)                                                                                    

pred.pc<-predict.fregre.glm(res.pc,newldata)                                      
y.pred1<-ifelse (pred.pc>0.5,1,0)                                               
table(y.pred1,newy)                                                           
                                                                              
pred.basis<-predict.fregre.glm(res.basis,newldata)                                      
y.pred2<-ifelse (pred.basis>0.5,1,0)                                               
table(y.pred2,newy)

Run the code above in your browser using DataLab