# NOT RUN {
# }
# NOT RUN {
data(mscm)
mscm=na.omit(mscm)
ff=hrf(x=mscm[,-1],id=mscm$id,time=mscm$day,yindx=3,ntrees=100,nsamp=5,vh=c(2,3),vc=c(1,4:14))
plot(1:length(ff$error),ff$error,type="l",col="blue")
# -- random intercept example --- #
p=5;sigma_e=.5;sigma_a=.5;v=rep(1,p);n=500;pnoise=2
random_intercept=rnorm(n,sd=sigma_a^.5)
random_intercept=as.numeric(matrix(random_intercept,nrow=p,ncol=n,byrow=TRUE))
x=random_intercept+rnorm(n*p,sd=sigma_e^.5)
id=sort(rep(1:n,p))
time<-rep(1:p,n)
znoise=matrix(rnorm(n*p*pnoise),ncol=pnoise)
xx=cbind(time,x,znoise)
# fit historical random forest
ff=hrf(x=xx,time=time,id=id,yindx=2,ntrees=100,mtry=4,nsamp=5)
# plot oob-error
plot(1:ff$ntrees,ff$error,type="l",col="blue")
# fit forest, also do noisy-bootstrap for standard error estimates
ff=hrf(x=xx,time=time,id=id,yindx=2,ntrees=100,mtry=4,nsamp=5,se=TRUE)
# plot partial dependence of response on its past
pd=partdep_hrf(ff,xindx=2,ngrid=25,subsample=.1)
# variable importance z-scores (barplot)
barplot(varimp_hrf(ff,nperm=20),main="Importance z-scores")
# }
Run the code above in your browser using DataLab