# NOT RUN {
# --------------------------------------------------------------------------------------------- ##
# Boston Housing data
# Comparison of Z-score variable importance with coefficient Z-scores from linear model
# --------------------------------------------------------------------------------------------- ##
# Boston Housing data
library(mlbench)
data(BostonHousing)
dat=as.data.frame(na.omit(BostonHousing))
dat$chas=as.numeric(dat$chas)
# -- random forest
h=hrf(x=dat,yindx="medv",ntrees=500)
# -- tree boosting
hb=htb(x=dat,yindx="medv",ntrees=500,cv.fold=10)
# -- Comparison of variable importance Z-scores and Z-scores from linear model
vi=varimp_hrf(h)
vb=varimp_htb(hb)
dvi=data.frame(var=rownames(vi),Z_hrf=vi$Z)
dvb=data.frame(var=rownames(vb),Z_htb=vb$Z)
dlm=summary(lm(medv~.,dat))$coeffi
dlm=data.frame(var=rownames(dlm),Z_lm=round(abs(dlm[,3]),3))
dlm=merge(dlm[-1,],dvi,by="var",all.x=TRUE)
# -- Z-scores of hrf and lm for predictor variables
merge(dlm,dvb,by="var",all.x=TRUE)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab