1

I would like to ask you to help me with this code below. I do a BART and after I fix seeds and initial burns-in and iteractions, I would like to produce a ggplot but in somehow, it does not work. I use "beta"=5, initial burns-in=1000 and MCMC=5000 and I fix seeds=17

Xc=X=dat2[,-1] # The first column is the response
Xc$z=factor((1:0)[X$z])
library(BayesTree)         

set.seed(17)
bartFit = bart(X,dat2$y,Xc, sigest=NA, sigdf=3, sigquant=.90, k=2.0, 
           power=5.0, base=.95,binaryOffset=0, ntree=200,  
           ndpost=4000, nskip=1000, printevery=500, keepevery=1, 
           keeptrainfits=TRUE,
           usequants=FALSE, numcut=100, printcutoffs=0,
           verbose=TRUE)
pte=apply(bartFit$yhat.train-bartFit$yhat.test,2,mean)


## This distribution is reported in the following histogram: Posterior 
distribution of ATE

ss=dat2$z==1
ggplot()+ geom_histogram(binwidth = 2.0, aes(pte[ss],weights=nw(w[ss])))+ 
geom_vline(xintercept=0)  + labs(x = "PISA Score") + xlim(c=-20,10)

I got the following error message and I do not understand why.

Warning: Ignoring unknown aesthetics: weights
Error in eval(expr, envir, enclos) : object 'pte' not found

I run the same code for another dataset with same variables and content but with 2500 obs. Now, when I do for this dataset with 26000 obs, something goes wrong.

Can someone please understand and tell me what I am doing wrong? It will be very appreciated because I do not understand why same codes do not work with same dataset but different numbers of obs.

Thank you very very much

sicecon
  • 11
  • 2
  • 1
    You are using `ggplot` wrong. Create a data.frame with all the necessary variable sand call those variables from `aes()` to map them to appropriate aesthetics. See [docs.ggplot2.org](http://ggplot2.tidyverse.org/reference/) for many examples. – Roman Luštrik Apr 15 '17 at 09:48
  • Thank you Roman. But why does the same code work with a smaller dataset and same variables? I will take a look at the link – sicecon Apr 15 '17 at 10:18
  • Make your example reproducible and get your ggplot2 code in order. This is fairly trivial to solve if you do things right. See [here](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Roman Luštrik Apr 15 '17 at 13:56

0 Answers0