Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: more convenient updates of splitting probabilities #67

Open
EoghanONeill opened this issue Mar 14, 2024 · 0 comments
Open

Comments

@EoghanONeill
Copy link

EoghanONeill commented Mar 14, 2024

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
tempmodel@tree.prior@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]

sampler1$model@tree.prior@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant