kbaabb

Overview

The kbaabb package provides tools for generating an artificial population based on a kNN-based approximation to the approximate Bayesian bootstrap (KBAABB). This methodology is described in White et al. (2025).

Installation

kbaabb can be installed from the CRAN with

install.packages("kbaabb")

Or, the development version of kbaabb can be installed from GitHub:

# install.packages("devtools")
# devtools::install_github("graysonwhite/kbaabb")
install.packages("kbaabb", repos = c('https://graysonwhite.r-universe.dev', 'https://cloud.r-project.org'))

Examples

kbaabb is used to generate artificial populations for the purpose of model evaluation. Given some observed sample survey_data and a population population_data as well as the specification of a formula of the form responses ~ covariates and possible strata, kbaabb can create an artificial populations.

For instance, suppose we have a sample SJC_sample and population SJC_population. They each have covariates tcc and elev, and we wish to impute biomass. Then the code:

pop = kbaabb(
  survey_data = SJC_sample,
  population_data = SJC_population,
  formula = biomass ~ tcc + elev
)
#> No stratifying variables => pooling all data together.

imputes values for each observation. The population can be extracted with

pop$imputed_population_data |> head(5)
#>         island tcc elev tnt             geometry biomass survey_row_id
#> 1 Little Patos  79   19   1 -122.96820, 48.78684 177.909             9
#> 2 Little Patos  78   12   1 -122.95004, 48.78275 177.909             9
#> 3       Stuart  78   82   1 -123.21651, 48.67619  55.249            16
#> 4        Orcas  83   89   1 -122.93809, 48.65553  36.022            25
#> 5        Orcas  82   83   1 -122.93693, 48.65575  55.249            16

An analysis with kbaabb can be expanded in multiple ways. For instance, a strata can be introduced so that kbaabb naturally stratifies the data. For instance, the above population could use the islands as a strata:

pop = kbaabb(
  survey_data = SJC_sample,
  population_data = SJC_population,
  formula = biomass ~ tcc + elev,
  strata = "island" # strata included here
)

Furthermore, kbaabb supports multiple data imputation. To impute multiple variables, they are all included on the left hand side with pluses. For example,

pop = kbaabb(
  survey_data = SJC_sample,
  population_data = SJC_population,
  formula = biomass + measurement_year ~ tcc + elev 
  # ^ multiple data imputation indicated by + on the left hand side
)

Details on the method for variable imputation is included in White et al. (2025).