# NOT RUN {
# }
# NOT RUN {
data(mscm)
mscm=na.omit(mscm)
# logistic regression
ff=htb(x=mscm[,-1],id=mscm$id,time=mscm$day,yindx=3,ntrees=100,
lambda=.1,nsplit=2,nsamp=5,vh=c(2,3),vc=c(1,4:14),cv.fold=10,family="bernoulli")
# cross-validated negative log-likelihood
plot(1:ff$ntrees,ff$cv_error,type="l",col="blue",ylab="",
xlab="iterations",main="Cross-validated error")
# -- 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=htb(x=xx,time=time,id=id,yindx=2,ntrees=100,nsamp=5,lambda=.1,cv.fold=10)
# plot cv-error
plot(1:ff$ntrees,ff$cv_error,type="l",col="blue",xlab="iterations",
ylab="",main="Cross-validated mse")
# plot partial dependence of response on its past
pd=partdep_htb(ff,xindx=2,ngrid=25,subsample=.1)
# variable importance z-scores (barplot)
barplot(varimp_htb(ff,nperm=20),main="Importance z-scores")
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab