# NOT RUN {
set.seed(2000)
# }
# NOT RUN {
N<-50;M<-24
X<-rnorm(N,mean=0)
time<-seq(0,1,length.out=M)
Y<-simulate_simple_dfrr(beta0=function(t){cos(pi*t+pi)},
beta1=function(t){2*t},
X=X,time=time)
#The argument T_E indicates the number of EM algorithm.
#T_E is set to 1 for the demonstration purpose only.
#Remove this argument for the purpose of converging the EM algorithm.
dfrr_fit<-dfrr(Y~X,yind=time,T_E=1)
plot(dfrr_fit)
# }
# NOT RUN {
#Fitting dfrr model to the Madras Longitudinal Schizophrenia data
data(madras)
ids<-unique(madras$id)
N<-length(ids)
ydata<-data.frame(.obs=madras$id,.index=madras$month,.value=madras$y)
xdata<-data.frame(Age=rep(NA,N),Gender=rep(NA,N))
for(i in 1:N){
dt<-madras[madras$id==ids[i],]
xdata[i,]<-c(dt$age[1],dt$gender[1])
}
rownames(xdata)<-ids
#The argument T_E indicates the number of EM algorithm.
#T_E is set to 1 for the demonstration purpose only.
#Remove this argument for the purpose of converging the EM algorithm.
#J is the number of basis functions that will be used in estimating the functional parameters.
madras_dfrr<-dfrr(Y~Age+Gender+Age*Gender, data=xdata, ydata=ydata, J=11,T_E=1)
# }
# NOT RUN {
coefs<-coef(madras_dfrr)
plot(coefs)
fpcs<-fpca(madras_dfrr)
plot(fpcs)
plot(fpcs,plot.eigen.functions=FALSE,plot.contour=TRUE,plot.3dsurface = TRUE)
oldpar<-par(mfrow=c(2,2))
fitteds<-fitted(madras_dfrr) #Plot first four fitted functions
plot(fitteds,id=c(1,2,3,4))
par(oldpar)
resids<-residuals(madras_dfrr)
plot(resids)
newdata<-data.frame(Age=c(1,1,0,0),Gender=c(1,0,1,0))
preds<-predict(madras_dfrr,newdata=newdata)
plot(preds)
newdata<-data.frame(Age=c(1,1,0,0),Gender=c(1,0,1,0))
newydata<-data.frame(.obs=rep(1,5),.index=c(0,1,3,4,5),.value=c(1,1,1,0,0))
preds<-predict(madras_dfrr,newdata=newdata,newydata = newydata)
plot(preds)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab