bartisan: Generalized Bayesian Additive Regression Trees
Source:R/bartisan-package.R
bartisan-package.RdFits Bayesian additive regression trees (BART) models for likelihoods outside the conditionally conjugate Gaussian case, using the Laplace-approximation reversible-jump sampler of Linero (2025) doi:10.1080/01621459.2024.2337156 . Supported response families include Gaussian, binomial, Poisson, negative binomial, gamma, beta, ordered beta, ordinal (cumulative link), multinomial, zero-inflated counts, a Tweedie compound Poisson for a non-negative response with a point mass at zero, accelerated failure time and proportional hazards models for right-censored survival data, location-scale regression, and a Dirichlet process mixture for the error distribution. Decision rules may be hard, as in standard BART, or soft, as in the 'SoftBart' model of Linero and Yang (2018) doi:10.1111/rssb.12293 , which yields smoother fits. The interface follows that of glm(), so that a model is specified with a formula, a data frame, and a family.
Details
Fits Bayesian additive regression trees (BART) the way stats::glm() fits a
generalized linear model: a formula, a data frame, and a family. The forest
replaces the linear predictor, so nothing has to be said about which terms
enter the model, which are curved, or which interact.
fit <- bartisan(y ~ x1 + x2 + x3, data = d)Common Tasks
Most of what a fitted model is used for is handled by a package that already does that job well, and bartisan registers the methods those packages need. This table is the map.
| Task | Use |
| fit a model | bartisan() |
| choose a likelihood | bartisan-families, vignette("families") |
| change the sampler's settings | bartisan_control() |
| predict for new data | predict.bartisan_fit() |
| a prediction with an interval | marginaleffects::predictions() |
| an interval for a new observation, noise included | posterior_predict() |
| how much a predictor moves the outcome | marginaleffects::avg_comparisons()
, vignette("effects") |
| a partial dependence plot | partial_dependence() |
| which predictors the forest uses | variable_importance() |
| to tell the prior which predictors matter | split_prior in bartisan_control() |
| to see what prior a fit was given | prior_summary() |
| to see what that prior implies about the outcome | prior_only in bartisan() |
| to give one forest its own predictors or settings | a list of formulas, and per-forest arguments; see bartisan-families |
| a coefficient that varies with the other predictors | vc() in the formula, vignette("varying") |
| a treatment effect with its own prior | bcf(), vignette("causal") |
| the ATE, ATT or the effect for each unit | estimate_effect() |
| to check it converged and mixed | diagnose(), then as_draws() with bayesplot, vignette("diagnostics") |
| to check it fits | pp_check(), residuals() |
| to compare two models | loo(), vignette("comparison") |
| survival data | ph(), dpm_aft(), vignette("survival") |
| a likelihood of one's own | custom_family() |
Before the First Fit
There are a few things worth knowing first, and none of them requires knowing anything about Bayesian statistics.
A forest has no slope to read off, so the effect of a predictor is found by
asking the fitted model what it predicts under one value of that predictor
and under another, and taking the difference.
marginaleffects::avg_comparisons(fit, variables = "x") does exactly that,
and reports an interval with it. This is a better habit than reading
coefficients even where coefficients exist (i.e., in a linear model), and
here it is the only habit available.
A 95% interval from any of the above is the range the model considers most plausible given the data and the model. It already includes the uncertainty from not knowing the shape of the relationship, which is the part a linear model leaves out by assuming it away.
The defaults are meant to be used. The settings in bartisan_control()
are there for the analyses that need them; the priors and the number of trees
are chosen to work across a wide range of problems, and tuning them is rarely
where the gains are. Choosing the right family matters
much more.
Flexibility and Its Limits
The model is flexible about the shape of the relationship and about nothing else. Whether a predictor is a cause, whether the sample represents the population, and whether the outcome was measured well are assumptions the analysis brings to the model rather than things it can supply: a forest fitted to confounded data returns a confounded answer with a tight interval around it.
See also
bartisan() to fit a model; bartisan-families to choose a likelihood;
bartisan-marginaleffects and bartisan-interop for the packages that read a
fit; vignette("bartisan") for a worked analysis and
vignette("implementation") for how the sampler works.
Author
Maintainer: Noah Greifer noah.greifer@gmail.com (ORCID) [copyright holder]
Authors:
Noah Greifer noah.greifer@gmail.com (ORCID) [copyright holder]
Other contributors:
Antonio R. Linero (Author of FlexBart, the reference implementation of Linero (2025), from which the MCMC engine is adapted) [contributor, copyright holder]