# NOT RUN {
data(tecator)
x=tecator$absorp.fdata
x1<-fdata.deriv(x)
x2<-fdata.deriv(x,nderiv=2)
y=tecator$y$Fat
xcat0<-cut(rnorm(length(y)),4)
xcat1<-cut(tecator$y$Protein,4)
xcat2<-cut(tecator$y$Water,4)
ind <- 1:129
dat <- data.frame("Fat"=y, x1$data, xcat1, xcat2)
ldat <- list("df"=dat[ind,],"x"=x[ind,],"x1"=x1[ind,],"x2"=x2[ind,])
# 3 functionals (x,x1,x2), 3 factors (xcat0, xcat1, xcat2)
# and 100 scalars (impact poitns of x1)
# Time consuming
res.gam1<-fregre.gsam.vs("Fat",data=ldat)
summary(res.gam1$model)
res.gam1$i.predictor
covar <- c("xcat0","xcat1","xcat2","x","x1","x2")
res.gam2<-fregre.gsam.vs(y="Fat", x=covar, data=ldat)
summary(res.gam2$model)
res.gam2$i.predictor
# Prediction like fregre.gsam()
newldat <- list("df"=dat[-ind,],"x"=x[-ind,],"x1"=x1[-ind,],
"x2"=x2[-ind,])
pred.gam1<-predict.fregre.gsam(res.gam1$model,newldat)
pred.gam2<-predict.fregre.gsam(res.gam2$model,newldat)
plot(dat[-ind,"Fat"],pred.gam1)
points(dat[-ind,"Fat"],pred.gam2,col=2)
# }
Run the code above in your browser using DataLab