if (FALSE) {
data(tecator)
absorp=fdata.deriv(tecator$absorp.fdata,2)
ind=1:129
x=absorp[ind,]
y=tecator$y$Fat[ind]
newx=absorp[-ind,]
newy=tecator$y$Fat[-ind]
## Functional PC regression
res.pc=fregre.pc(x,y,1:6)
pred.pc=predict(res.pc,newx)
# Functional regression with basis representation
res.basis=fregre.basis.cv(x,y)
pred.basis=predict(res.basis[[1]],newx)
# Functional nonparametric regression
res.np=fregre.np.cv(x,y)
pred.np=predict(res.np,newx)
dat <- data.frame("y"=y,x$data)
newdat <- data.frame("y"=newy,newx$data)
res.gam=fregre.gsam(y~s(x),data=list("df"=dat,"x"=x))
pred.gam=predict(res.gam,list("x"=newx))
dc.raw <- LMDC.select("y",data=dat, tol = 0.05, pvalue= 0.05,
plot=F, smo=T,verbose=F)
covar <- paste("X",dc.raw$maxLocal,sep="")
# Preselected design/impact points
covar
ftest<-flm.test(dat[,-1],dat[,"y"], B=500, verbose=F,
plot.it=F,type.basis="pc",est.method="pc",p=4,G=50)
if (ftest$p.value>0.05) {
# Linear relationship, step-wise lm is recommended
out <- LMDC.regre("y",covar,dat,newdat,pvalue=.05,
method ="lm",plot=F,verbose=F)
} else {
# Non-Linear relationship, step-wise gam is recommended
out <- LMDC.regre("y",covar,dat,newdat,pvalue=.05,
method ="gam",plot=F,verbose=F) }
# Final design/impact points
out$xvar
# Predictions
mean((newy-pred.pc)^2)
mean((newy-pred.basis)^2)
mean((newy-pred.np)^2)
mean((newy-pred.gam)^2)
mean((newy-out$pred)^2)
}
Run the code above in your browser using DataLab