library(BayesTree) #-------------------------------------------------- if(1) { # simulate data f = function(x){ 10*sin(pi*x[,1]*x[,2]) + 20*(x[,3]-.5)^2+10*x[,4]+5*x[,5] } n = 500 #number of observations in each simulated data set sigma = 1.0 # y = f(x) + sigma*z , z~N(0,1) set.seed(99) x=matrix(runif(n*10),n,10) Ey=f(x) y=Ey+sigma*rnorm(n) } #-------------------------------------------------- if(1) { # run BART m=10 # use ``small'' m for variable selection brt = bart(x,y,ntree=m,nskip=5000,ndpost=10000) } #-------------------------------------------------- if(1) { # get percent use vc = brt$varcount #(i,j) element is number of times var j is used at draw i vpercent = vc/apply(vc,1,sum) #divide each row by its sum vppostmean = apply(vpercent,2,mean) } #-------------------------------------------------- if(1) { #plot plot(vppostmean) }