dbarts
dbarts copied to clipboard
Feature request: more convenient updates of splitting probabilities
To implement BART models with hyperpriors on splitting probabilities, for example as in Linero (2018), it is necessary to update the splitting probability in each MCMC iteration. It would be more convenient to do this with a function like setSplitProbabilities( )
for an object of the class dbartsSampler
.
It is also possible to update splitting probabilities with setModel( )
. I include an example below for anyone who would like to know how to update splitting probabilities. Perhaps an example with the Linero (2018) Dirichlet hyperprior could be added to a vignette.
# install.packages("dbarts")
library(dbarts)
f <- function(x) {
10 * sin(pi * x[,1] * x[,2]) + 20 * (x[,3] - 0.5)^2 +
10 * x[,4] + 5 * x[,5]
}
set.seed(99)
sigma <- 1.0
n <- 100
x <- matrix(runif(n * 10), n, 10)
Ey <- f(x)
y <- rnorm(n, Ey, sigma)
data <- data.frame(y, x)
control1 <- dbartsControl(n.samples = 1L,
n.chains = 1L,
n.threads = 1L,keepTrees = TRUE)
tempsplitprobs <- c( rep(0.5/9,9),0.5)
sampler1 <- dbarts(y ~ ., data =data, test = NULL, resid.prior = fixed(1), control = control1,
tree.prior = dbarts:::cgm(power = 2, base = 0.95, split.probs = tempsplitprobs))
niter <- 5
for(i in 1:niter){
samplestemp <- sampler1$run()
print("sigma = ")
print(samplestemp$sigma)
}
sampler1$getTrees()$var
tempcounts <- table(sampler1$getTrees()$var)[-1]
tempcounts
###### UPDATE SPLIT PROBABILITIES ##################
tempmodel <- sampler1$model
[email protected]@splitProbabilities <- c(1, rep(0/9,9))
sampler1$setModel(newModel = tempmodel)
niter <- 50
for(i in 1:niter){
samplestemp <- sampler1$run()
print("sigma = ")
print(samplestemp$sigma)
}
tempcounts <- table(sampler1$getTrees()$var)[-1]
[email protected]@splitProbabilities
tempcounts <- table(sampler1$getTrees()$var)[-1]
tempcounts
Linero, A. R. (2018). Bayesian regression trees for high-dimensional prediction and variable selection. Journal of the American Statistical Association, 113(522), 626-636.