Package {BATTS}


Title: Boosting and Bayesian Additive Trees for Two-Sample Comparison
Version: 0.4.0
Description: Implements boosting and Bayesian additive tree methods for two-sample comparison through density ratio estimation, following Awaya, Xu, and Ma (2025) <doi:10.48550/arXiv.2508.03059>. The package supports both point estimation and uncertainty quantification via Bayesian additive tree ensembles.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.3
Depends: R (≥ 4.0.0)
LinkingTo: Rcpp, RcppArmadillo
Imports: graphics, Rcpp, stats
Suggests: ggplot2, knitr, mvtnorm, rmarkdown, scales
SystemRequirements: C++17
VignetteBuilder: knitr
URL: https://github.com/nawaya040/BATTS/tree/cran/dev, https://arxiv.org/abs/2508.03059
BugReports: https://github.com/nawaya040/BATTS/issues
NeedsCompilation: yes
Packaged: 2026-10-28 11:13:06 UTC; naway
Author: Naoki Awaya [aut, cre, cph], Yuliang Xu [aut, cph], Li Ma [aut, cph]
Maintainer: Naoki Awaya <nawaya@waseda.jp>
Repository: CRAN
Date/Publication: 2026-11-13 22:50:20 UTC

Boosting and Bayesian Additive Trees for Two-Sample Comparison

Description

Estimate the density ratio of two samples using boosting or generalized Bayesian additive trees.

Details

Author(s)

Maintainer: Naoki Awaya nawaya@waseda.jp [copyright holder]

Authors:

References

Awaya, N., Xu, Y., and Ma, L. (2025). Two-sample comparison through additive tree models for density ratios. arXiv:2508.03059. doi:10.48550/arXiv.2508.03059.

See Also

Useful links:


Deprecated functions in BATTS

Description

These functions still work and give the same results as before, but warn once per session. Use the replacements below.

Details

Deprecated Replacement
boots() batts_boost() with boost_control()
batts() batts_bart() with bart_control()
eval_balance_weight() predict() (type = "weight" for the same scale) or density_ratio()

Arguments of boots() and batts() that moved into the control functions:

Old argument New setting
data, group_labels x, group
max_resol depth (boosting)
n_min_obs_per_node min_obs_per_node (boosting)
size_burnin burnin
size_backfitting draws
omega_prior_parameters omega_prior
tree_priors tree_prior
output_BART_ensembles keep_draws

n_ratio_per_node accepted only its default and has no replacement. The batts() arguments max_resol, n_bins, learn_rate, use_gradient and n_min_obs_per_node have no effect on a BART fit and have no replacement in bart_control().

eval_balance_weight(fit, points) returns the balancing weight w = sqrt(p/q); predict(fit, points) returns the log-density ratio 2 * log(w) by default.


Settings for Bayesian additive tree fits

Description

Collect the settings of batts_bart(). The defaults are the settings used in the simulations of Awaya, Xu, and Ma (2025): 200 trees, 2000 burn-in iterations, 1000 saved draws, lambda_0 = 5 and margin 0.1. Each fit starts from unsplit trees.

Usage

bart_control(
  num_trees = 200,
  burnin = 2000,
  draws = 1000,
  thin = 1,
  prob_moves = c(1/3, 1/3, 1/3),
  lambda_0 = 5,
  omega_prior = c(1, 1),
  tree_prior = c(0.95, 2),
  margin_scale = 0.1,
  keep_draws = FALSE
)

Arguments

num_trees

Number of trees in the ensemble.

burnin

Number of discarded backfitting iterations. NULL uses floor(draws / 2).

draws

Number of saved posterior draws.

thin

Number of backfitting sweeps per iteration, including burn-in iterations.

prob_moves

Probabilities of the GROW, PRUNE and CHANGE moves: three positive values summing to one.

lambda_0

Leaf-prior scale per tree; the ensemble scale num_trees * lambda_0 stays fixed during sampling.

omega_prior

Shape and rate of the Gamma prior on the loss temperature.

tree_prior

Two tree-depth prior parameters: the split probability at depth d is tree_prior[1] / (1 + d)^tree_prior[2].

margin_scale

Fraction of each training range added at both ends of the fitted domain.

keep_draws

Logical; save the posterior forests so that the fit can be evaluated at new points with predict(). Saving them does not change the draws or the use of random numbers, but can make the fitted object large (over 100 MB with the default numbers of trees and draws).

Value

An object of class bart_control.

See Also

batts_bart()

Examples

bart_control(num_trees = 100, burnin = 300, draws = 301, keep_draws = TRUE)

Bayesian additive trees for a two-sample density ratio (deprecated)

Description

Deprecated: use batts_bart() with bart_control(); see BATTS-deprecated for the argument names. batts() still works and returns the same result for the same settings, but warns once per session.

Usage

batts(
  data,
  group_labels,
  num_trees = 200,
  max_resol = 0,
  learn_rate = 0.01,
  n_bins = 100,
  n_min_obs_per_node = 1,
  n_ratio_per_node = 1e-100,
  margin_scale = 0.1,
  use_gradient = FALSE,
  size_burnin = 2000,
  size_backfitting = 1000,
  thin = 1,
  prob_moves = c(1/3, 1/3, 1/3),
  lambda_0 = 5,
  omega_prior_parameters = c(1, 1),
  tree_priors = c(0.95, 2),
  output_BART_ensembles = FALSE,
  quiet = FALSE
)

Arguments

data

Numeric matrix with observations in rows and variables in columns. Values must be finite. With nonnegative margin_scale, each column must vary.

group_labels

Numeric vector of zeros and ones, one per row of data, with both groups present. Group 0 has density p and group 1 has density q.

num_trees

Number of trees in the Bayesian ensemble.

max_resol

Maximum boosting tree depth. For batts, must be zero so that all initial trees are unsplit.

learn_rate

Boosting shrinkage factor; use a positive value.

n_bins

Number of bins used to construct the boosting cut grid. For root-initialized batts, retained for interface compatibility.

n_min_obs_per_node

Minimum count from each group in a boosting child.

n_ratio_per_node

Reserved argument. Only the default 1e-100 is supported.

margin_scale

Nonnegative fraction of each training range added at both ends of the fitted domain. A negative value uses the fixed unit box and requires that the supplied data already lie in that box.

use_gradient

Logical; use gradient boosting when TRUE and forward-stagewise boosting when FALSE. Initialization in batts is unsplit.

size_burnin

Nonnegative integer number of discarded backfitting iterations (default 2000). NULL uses floor(size_backfitting / 2).

size_backfitting

Positive integer number of saved draws (default 1000).

thin

Positive integer giving the number of backfitting sweeps per iteration, including burn-in iterations.

prob_moves

Probabilities of GROW, PRUNE, and CHANGE, in that order; supply three finite positive values summing to one (tolerance 1e-12).

lambda_0

Positive leaf-prior scale per tree; ensemble scale is num_trees * lambda_0 and remains fixed during sampling.

omega_prior_parameters

Shape and rate of the Gamma prior on the loss temperature, as a positive length-two vector.

tree_priors

Two tree-depth prior parameters: split probability at depth d is tree_priors[1] / (1 + d)^tree_priors[2].

output_BART_ensembles

Logical; save posterior forests for subsequent evaluation on new points. Training-point draws are returned in either case.

quiet

Logical; suppress progress messages.

Details

Draw generalized Bayesian balancing weights w = sqrt(p/q) by backfitting.

The defaults (200 trees, 2000 burn-in iterations, 1000 saved draws, lambda_0 = 5 and margin 0.1) are the settings of the paper's simulations.

Each fit starts with unsplit trees (max_resol = 0). Use multiple chains and convergence diagnostics for substantive applications. A short successful run does not establish convergence or frequentist coverage. Sparse overlap and complete separation can produce prior-sensitive estimates and slow mixing. The returned intervals are pointwise; zero inclusion does not establish equality of distributions.

Value

An object of class batts_bart, inheriting batts_fit. It is a list containing balance_weight_BART_data, an observations-by-draws matrix; forest_list, saved forests when requested; omega_store, temperature draws; and lambda_store, fixed leaf-scale values. Also includes tree_list, c, data_info, and Omega for initialization and evaluation.

See Also

boots(), eval_balance_weight(), batts-methods

Examples

set.seed(2)
x <- matrix(c(rnorm(20), rnorm(20, 0.5)), ncol = 1)
g <- rep(0:1, each = 20)
# Small API demonstration; these settings are not a convergence recommendation.
fit <- batts(x, g, num_trees = 4, size_burnin = 5,
             size_backfitting = 10, output_BART_ensembles = TRUE, quiet = TRUE)
dim(fit$balance_weight_BART_data)

Methods for BATTS fits

Description

Display and summary methods for fits from batts_boost() and batts_bart().

Usage

## S3 method for class 'batts_boost'
print(x, ...)

## S3 method for class 'batts_bart'
print(x, ...)

## S3 method for class 'batts_fit'
summary(object, ...)

## S3 method for class 'summary.batts_fit'
print(x, ...)

## S3 method for class 'batts_fit'
nobs(object, ...)

Arguments

x, object

A batts_boost or batts_bart fit, or a summary.batts_fit object.

...

Not used.

Value

print returns its argument invisibly. summary returns an object of class summary.batts_fit. nobs returns the number of training observations.

Examples

set.seed(1)
fit <- batts_boost(rnorm(50), y = rnorm(50, 0.5),
                   control = boost_control(num_trees_max = 50, depth = 2),
                   quiet = TRUE)
fit
summary(fit)
nobs(fit)

Plot a BATTS fit

Description

Diagnostic and summary plots drawn with base graphics.

Usage

## S3 method for class 'batts_boost'
plot(x, which = c("cv", "fit"), ...)

## S3 method for class 'batts_bart'
plot(x, which = c("trace", "fit"), level = 0.95, ...)

Arguments

x

A batts_boost or batts_bart fit.

which

The plot to draw. For a boosting fit the default is "cv" when cross-validation was used and "fit" otherwise; for a Bayesian additive trees fit it is "trace".

...

Graphical parameters passed to plot.default(), such as main, xlab, ylab or col; they replace the defaults.

level

Credible level of the band for which = "fit".

Details

For a boosting fit, which = "cv" plots the cross-validation loss, averaged over folds, against the number of trees and marks the selected number; which = "fit" plots the fitted log-density ratio log(p/q) at the training points. For a Bayesian additive trees fit, which = "trace" plots the saved draws of the loss temperature, and which = "fit" plots the posterior mean of log(p/q) at the training points with a pointwise credible band.

which = "fit" needs a fit with one variable. For more variables, evaluate the fit with predict() and plot the result.

Plotting draws no random numbers.

Value

x, invisibly.

See Also

batts_boost(), batts_bart(), batts-predict

Examples

set.seed(1)
fit <- batts_boost(rnorm(100), y = rnorm(100, 0.5),
                   control = boost_control(num_trees_max = 100, depth = 2),
                   quiet = TRUE)
plot(fit)
plot(fit, which = "fit")

Predict balancing weights and density ratios

Description

Predict balancing weights and density ratios

Usage

## S3 method for class 'batts_boost'
predict(
  object,
  newdata,
  type = c("log_ratio", "ratio", "weight"),
  outside = c("error", "na", "clamp"),
  ...
)

## S3 method for class 'batts_bart'
predict(
  object,
  newdata,
  type = c("log_ratio", "ratio", "weight"),
  summary = c("mean", "median", "none"),
  level = 0.95,
  interval = FALSE,
  outside = c("error", "na", "clamp"),
  ...
)

## S3 method for class 'batts_boost'
fitted(object, type = c("log_ratio", "ratio", "weight"), ...)

## S3 method for class 'batts_bart'
fitted(
  object,
  type = c("log_ratio", "ratio", "weight"),
  summary = c("mean", "median", "none"),
  ...
)

Arguments

object

A batts_boost or batts_bart fit.

newdata

Points at which to evaluate the fit: a numeric matrix or data frame with the training variables, or a numeric vector (several points for a fit with one variable, otherwise one point). When the fit recorded column names and newdata has names, columns are matched by name; otherwise by position. Values must be finite. If omitted, the training observations are used.

type

"log_ratio", the default, returns the log-density ratio 2 * log(w) = log(p/q). "ratio" returns w^2 = p/q. "weight" returns the balancing weight w = sqrt(p/q) itself. The first group is in the numerator throughout.

outside

What to do with points outside the fitted domain (the training range widened by margin_scale): "error" (the default) stops and names the offending values, "na" returns NA for those points, and "clamp" moves each coordinate to the nearest boundary of the domain before evaluating.

...

Not used. A batts_boost fit has no posterior draws, so passing summary, level or interval to it is an error rather than silently ignored.

summary

For a batts_bart fit: "mean" or "median" collapses the posterior draws and "none" returns the points-by-draws matrix. The transformation implied by type is applied to each draw before summarizing, so the result summarizes the posterior of the transformed quantity.

level

Credible level used when interval = TRUE.

interval

For a batts_bart fit, return a matrix with columns fit, lower and upper instead of a vector.

Details

Prediction draws no random numbers.

Value

A numeric vector, or a matrix when summary = "none" or interval = TRUE.

Examples

set.seed(1)
x <- rnorm(50)
y <- rnorm(50, 0.5)
fit_boost <- batts_boost(x, y = y,
                         control = boost_control(num_trees_max = 50, depth = 2),
                         quiet = TRUE)
predict(fit_boost, c(-1, 0, 1))
predict(fit_boost, c(-1, 0, 1), type = "ratio")
head(fitted(fit_boost))
predict(fit_boost, c(-10, 0), outside = "na")

# Small demonstration; these settings are not a convergence recommendation.
fit_bart <- batts_bart(x, y = y,
                       control = bart_control(num_trees = 10, burnin = 20,
                                              draws = 21, keep_draws = TRUE),
                       quiet = TRUE)
predict(fit_bart, c(-1, 0, 1), interval = TRUE)
dim(predict(fit_bart, c(-1, 0, 1), summary = "none"))

Fit a two-sample density ratio by Bayesian additive trees

Description

Draw the balancing weight w = sqrt(p/q) from its generalized posterior, where p is the density of the first group and q the density of the second. The log-density ratio is 2 * log(w).

Usage

batts_bart(x, group = NULL, y = NULL, control = bart_control(), quiet = FALSE)

Arguments

x

Observations in rows and variables in columns: a numeric matrix, a data frame with numeric columns, or a numeric vector for one variable. Values must be finite.

group

Two-valued labels, one per row of x: numeric, logical, character or factor. The first group (the first factor level, otherwise the smaller value in sort order; 0 for 0/1 labels) has density p, the numerator.

y

Instead of group, a second sample with the same columns as x. Then x has density p and y has density q.

control

Settings created by bart_control().

quiet

Logical; suppress progress messages.

Details

Supply exactly one of group and y. Set the seed before fitting.

Use several chains and convergence diagnostics for substantive applications; a short successful run does not establish convergence or frequentist coverage. Sparse overlap and complete separation can produce prior-sensitive estimates and slow mixing. The intervals are pointwise; that an interval contains zero does not establish equality of the distributions.

Value

An object of class batts_bart, inheriting batts_fit. Besides the posterior draws at the training points, it records the call, the settings, the group labels (group_levels, numerator first) and the column names (variable_names). Use predict(), fitted() and density_ratio() to evaluate it; evaluating it at new points requires bart_control(keep_draws = TRUE). Use print(), summary() and plot() to describe it.

See Also

bart_control(), batts_boost(), batts-predict

Examples

set.seed(2)
# Small demonstration; these settings are not a convergence recommendation.
fit <- batts_bart(rnorm(30), y = rnorm(30, 0.5),
                  control = bart_control(num_trees = 10, burnin = 20,
                                         draws = 21, keep_draws = TRUE),
                  quiet = TRUE)
fit
predict(fit, c(-1, 0, 1), interval = TRUE)

Fit a two-sample density ratio by boosting

Description

Fit the balancing weight w = sqrt(p/q) by tree boosting, where p is the density of the first group and q the density of the second. The log-density ratio is 2 * log(w).

Usage

batts_boost(
  x,
  group = NULL,
  y = NULL,
  control = boost_control(),
  quiet = FALSE
)

Arguments

x

Observations in rows and variables in columns: a numeric matrix, a data frame with numeric columns, or a numeric vector for one variable. Values must be finite.

group

Two-valued labels, one per row of x: numeric, logical, character or factor. The first group (the first factor level, otherwise the smaller value in sort order; 0 for 0/1 labels) has density p, the numerator.

y

Instead of group, a second sample with the same columns as x. Then x has density p and y has density q.

control

Settings created by boost_control().

quiet

Logical; suppress progress messages.

Details

Supply exactly one of group and y. Set the seed before fitting; cross-validation folds and subsamples use the R random number generator.

With subsampling, the splits, gradients and leaf values of each tree use its subsample, while the balancing weights of all observations are updated. Cross-validation losses are evaluated on the held-out folds.

Value

An object of class batts_boost, inheriting batts_fit. Besides the fitted trees, it records the call, the settings, the group labels (group_levels, numerator first) and the column names (variable_names). Use predict(), fitted() and density_ratio() to evaluate it, and print(), summary() and plot() to describe it.

See Also

boost_control(), batts_bart(), batts-predict

Examples

set.seed(1)
p_sample <- rnorm(50)
q_sample <- rnorm(50, 0.5)
fit <- batts_boost(p_sample, y = q_sample,
                   control = boost_control(num_trees_max = 50, depth = 2),
                   quiet = TRUE)
fit
predict(fit, c(-1, 0, 1))

# The same data as one sample with group labels; the first level is p
x <- c(p_sample, q_sample)
g <- factor(rep(c("p", "q"), each = 50))
ctl <- boost_control(num_trees_max = 50, depth = 2)
set.seed(2); a <- batts_boost(x, g, control = ctl, quiet = TRUE)
set.seed(2); b <- batts_boost(p_sample, y = q_sample, control = ctl, quiet = TRUE)
identical(predict(a, 0), predict(b, 0))

Settings for boosting fits

Description

Collect the settings of batts_boost(). The defaults are the settings used in the simulations of Awaya, Xu, and Ma (2025): gradient boosting with at most 1000 trees selected by 5-fold cross-validation, depth 4, learning rate 0.01, 32 bins, margin 0.1 and per-tree subsampling of one half.

Usage

boost_control(
  num_trees_max = 1000,
  K_CV = 5,
  depth = 4,
  learn_rate = 0.01,
  n_bins = 32,
  margin_scale = 0.1,
  subsample_fraction = 0.5,
  min_obs_per_node = 1,
  use_gradient = TRUE
)

Arguments

num_trees_max

Maximum number of boosting trees.

K_CV

Number of group-stratified cross-validation folds used to select the number of trees, or zero to fit num_trees_max trees without cross-validation. A positive value must be an integer between two and the smaller group size; the number of trees with the smallest mean held-out loss is selected.

depth

Maximum depth of each tree.

learn_rate

Shrinkage factor of each boosting step.

n_bins

Number of bins used to construct the uniformly spaced candidate cut points, relative to the current node.

margin_scale

Fraction of each training range added at both ends of the fitted domain. A negative value uses the unit box and requires the data to lie in it.

subsample_fraction

Fraction of the training observations used to construct each tree, in (0, 1]. Each tree uses ceiling(subsample_fraction * m) of the m training observations (the cross-validation training folds, or all data for the final fit): one from each group and the rest uniformly without replacement. 1 uses all of them and draws no random numbers.

min_obs_per_node

Minimum count from each group in a child node. Splits that would leave fewer are excluded; under complete separation this can prevent informative splits.

use_gradient

Logical; gradient boosting when TRUE, forward-stagewise boosting when FALSE.

Value

An object of class boost_control.

See Also

batts_boost()

Examples

boost_control(depth = 2)

Boosting for a two-sample density ratio (deprecated)

Description

Deprecated: use batts_boost() with boost_control(); see BATTS-deprecated for the argument names. boots() still works and returns the same result for the same settings, but warns once per session.

Usage

boots(
  data,
  group_labels,
  num_trees_max = 1000,
  K_CV = 5,
  max_resol = 4,
  learn_rate = 0.01,
  n_bins = 32,
  n_min_obs_per_node = 1,
  n_ratio_per_node = 1e-100,
  margin_scale = 0.1,
  use_gradient = TRUE,
  quiet = FALSE,
  subsample_fraction = 0.5
)

Arguments

data

Numeric matrix with observations in rows and variables in columns. Values must be finite. With nonnegative margin_scale, each column must vary.

group_labels

Numeric vector of zeros and ones, one per row of data, with both groups present. Group 0 has density p and group 1 has density q.

num_trees_max

Maximum number of boosting trees.

K_CV

Number of group-stratified cross-validation folds, or zero to fit num_trees_max trees without cross-validation. A positive value must be an integer between two and the smaller group size. CV selects the minimum mean held-out balancing loss.

max_resol

Maximum boosting tree depth. For batts, must be zero so that all initial trees are unsplit.

learn_rate

Boosting shrinkage factor; use a positive value.

n_bins

Number of bins used to construct the boosting cut grid. For root-initialized batts, retained for interface compatibility.

n_min_obs_per_node

Minimum count from each group in a boosting child.

n_ratio_per_node

Reserved argument. Only the default 1e-100 is supported.

margin_scale

Nonnegative fraction of each training range added at both ends of the fitted domain. A negative value uses the fixed unit box and requires that the supplied data already lie in that box.

use_gradient

Logical; use gradient boosting when TRUE and forward-stagewise boosting when FALSE. Initialization in batts is unsplit.

quiet

Logical; suppress progress messages.

subsample_fraction

Fraction of the training observations used to construct each tree, in (0, 1]. With the default 0.5, each tree uses ceiling(subsample_fraction * m) of the m training observations (the CV training folds, or all data for the final fit), drawn as in ada with bag.frac: one observation from each group, and the rest uniformly without replacement regardless of group. 1 uses all of them.

Details

Fit an additive tree estimate of the balancing weight w = sqrt(p/q). The full log-density ratio is obtained as 2 * log(w).

The defaults (gradient boosting with at most 1000 trees selected by 5-fold CV, depth 4, learning rate 0.01, 32 bins, margin 0.1 and per-tree subsampling of one half) are the settings of the paper's simulations. Set the seed before fitting; CV folds and subsamples use the R random number generator.

Boosting uses uniformly spaced candidate cuts; Bayesian cut proposals are uniform. Candidate cuts are relative to the current node. Splits requiring children with too few observations from either group are excluded. Under complete separation this restriction can prevent informative splits. Forward-stagewise fits include a multiplicative normalization constant. With subsampling, splits, gradients, and leaf values use the tree's subsample, while the balancing weights of all observations are updated and the forward-stagewise normalization uses the whole training set. CV losses are evaluated on the held-out folds. Subsampling uses the R random number generator; subsample_fraction = 1 does not.

Value

An object of class batts_boost, inheriting batts_fit. It is a list containing balance_weight_boosting_data (training weights), tree_list (fitted trees), c (normalization), data_info (training domain and group sizes), and Omega (domain bounds). With CV, also returns loss_CV_store (folds by candidate tree count).

See Also

batts(), eval_balance_weight(), batts-methods

Examples

set.seed(1)
x <- matrix(c(rnorm(30), rnorm(30, 0.5)), ncol = 1)
g <- rep(0:1, each = 30)
fit <- boots(x, g, num_trees_max = 5, quiet = TRUE)
head(2 * log(fit$balance_weight_boosting_data))

Density ratio of a fitted BATTS model

Description

The density ratio p/q with group 0 in the numerator, that is w^2 for the fitted balancing weight w. Equivalent to predict(object, newdata, type = "ratio").

Usage

density_ratio(object, newdata, ...)

## S3 method for class 'batts_fit'
density_ratio(object, newdata, ...)

Arguments

object

A batts_boost or batts_bart fit.

newdata

Evaluation points; see batts-predict. If omitted, the training observations are used.

...

Passed to the predict method.

Value

A numeric vector, or a matrix for a batts_bart fit with summary = "none" or interval = TRUE.

See Also

batts-predict

Examples

set.seed(1)
fit <- batts_boost(rnorm(50), y = rnorm(50, 0.5),
                   control = boost_control(num_trees_max = 50, depth = 2),
                   quiet = TRUE)
density_ratio(fit, c(-1, 0, 1))

Evaluate fitted balancing weights (deprecated)

Description

Deprecated: use predict() (with type = "weight" for the same scale) or density_ratio(). eval_balance_weight() still works and returns the same result, but warns once per session.

Usage

eval_balance_weight(list_result, eval_points, is_Bayes = FALSE)

Arguments

list_result

Result of boots() or batts().

eval_points

Finite numeric matrix with the same columns, in the same order, as the training matrix. All points must lie inside Omega.

is_Bayes

Logical; additionally evaluate posterior forests. Requires fitting with output_BART_ensembles = TRUE.

Details

Evaluate stored trees at points inside the fitted domain. Weights have scale w = sqrt(p/q), with group 0 in the numerator; use 2 * log(w) for log ratios.

Prediction does not draw random numbers. With is_Bayes = TRUE, the boosting component describes the initialization; the posterior draws are in balancing_weight_BART. Missing posterior forests cause an error.

Value

A list with balancing_weight_boosting, a one-column numeric matrix, and, when is_Bayes = TRUE, balancing_weight_BART, an evaluation-points-by-draws matrix. Both include the fitted normalization constant.

See Also

boots(), batts(), batts-predict, density_ratio()

Examples

set.seed(3)
x <- matrix(c(rnorm(20), rnorm(20, 0.5)), ncol = 1)
fit <- boots(x, rep(0:1, each = 20), num_trees_max = 5, quiet = TRUE)
pred <- eval_balance_weight(fit, x[1:3, , drop = FALSE])
pred$balancing_weight_boosting