MyNixOS website logo
Description

Co-Data Learning for Bayesian Additive Regression Trees.

Estimate prior variable weights for Bayesian Additive Regression Trees (BART). These weights correspond to the probabilities of the variables being selected in the splitting rules of the sum-of-trees. Weights are estimated using empirical Bayes and external information on the explanatory variables (co-data). BART models are fitted using the 'dbarts' 'R' package. See Goedhart and others (2023) <doi:10.48550/arXiv.2311.09997> for details.

Short description

R package to estimate prior variable weights (the probabilities that variables are selected in the splitting rules) for Bayesian Additive Regression Trees (BART). These prior variable weights are estimated using empirical Bayes and auxiliary information on the variables (termed co-data). For all details on the method see:

https://arxiv.org/abs/2311.09997

In addition to prior variable weights, the package also provides the option to estimate other hyperparameters of BART using empirical Bayes.

Installation

install.packages("EBcoBART") 

Example 1

Simulate data from Friedman function (function g) and define grouped Co-data, i.e. assign each covariate in X to a group. EBcoBART then estimates group specific prior weights. These estimated weights may then be used in a BART sampler (e.g. dbarts).

sigma <- 1.0
N <- 100
p <- 500
G <- 5   # number of groups
CoDat = rep(1:G, rep(p/G,G)) #specify grouping structure
CoDat = data.frame(factor(CoDat))
CoDat <- stats::model.matrix(~., CoDat) #encode groups  by dummies yourself(include intercept)
colnames(CoDat)  = paste0("Group ",1:G)
g <- function(x) {
 10 * sin(pi * x[,1] * x[,2]) + 20 * (x[,101] - 0.5)^2 + 10 * x[,102] +
 10 * x[,3]
}
X <- matrix(runif(N * p), N, p)
Y <- g(X)+ rnorm(N, 0, sigma)
set.seed(4) # for reproducible results
Fit <- EBcoBART(Y=Y,X=X,CoData = CoDat, nIter = 15, model = "continuous",
                EB_k = FALSE, EB_alpha = FALSE, EB_sigma = FALSE, #EB estimation
                verbose = FALSE,
                nchain = 5, nskip = 1000, ndpost = 1000,
                Prob_Init = rep(1/ncol(X),ncol(X)), # initial prior covariate weights
                k = 2, alpha = .95, beta = 2)
                
EstProbs <- Fit$SplitProbs # estimated prior weights of variables (group-specific)
EstProbs[c(1,101,201,301,401)] # check weights for each group
print(Fit)
summary(Fit)

The prior parameter estimate EstProbs can then be used in your favorite BART fitting package. We use dbarts:

FinalFit <- dbarts::bart(x.train = X, y.train = Y,
                        ndpost = 5000,
                        nskip = 5000,
                        nchain = 5,
                        ntree = 50,
                        k = 2, base = .95, power = 2,
                        sigest = stats::sd(Y)*0.667,
                        sigdf = 10, sigquant = .75,
                        splitprobs = EstProbs,
                        combinechains = TRUE, verbose = FALSE)

Example 2

Binary response example using Bloodplatelet data set.

data("Bloodplatelet")
X <- Bloodplatelet$X
Y <- Bloodplatelet$Y
CoDat <- Bloodplatelet$CoData
Fit <- EBcoBART(Y=Y,X=X,CoData = CoDat, nIter = 15, model = "binary",
                EB_k = FALSE, EB_alpha = FALSE, EB_sigma = FALSE, #EB estimation
                verbose = FALSE,
                nchain = 5, nskip = 1000, ndpost = 1000,
                Prob_Init = rep(1/ncol(X),ncol(X)), # initial prior covariate weights
                k = 2, alpha = .95, beta = 2)
                
EstProbs <- Fit$SplitProbs # estimated prior weights of variables (group-specific)
print(Fit)
summary(Fit)
plot(Fit)

The prior parameter estimate EstProbs can then be used in your favorite BART fitting package. We use dbarts:

FinalFit <- dbarts::bart(x.train = X, y.train = Y,
                        ndpost = 5000,
                        nskip = 5000,
                        nchain = 5,
                        ntree = 50,
                        k = 2, base = .95, power = 2,
                        sigest = stats::sd(Y)*0.667,
                        sigdf = 10, sigquant = .75,
                        splitprobs = EstProbs,
                        combinechains = TRUE, verbose = FALSE)
Metadata

Version

1.1.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows