simulate.NBKP: Simulate from a Fitted NBKP Model

View source: R/simulate_NBKP.R

simulate.NBKPR Documentation

Simulate from a Fitted NBKP Model

Description

Generates random draws from the posterior predictive distribution of a fitted NBKP model at specified input locations.

For NBKP models, posterior samples are generated from Gamma distributions characterizing latent mean count values for negative‑binomial observations.

Usage

## S3 method for class 'NBKP'
simulate(object, nsim = 1, seed = NULL, Xnew = NULL, ...)

Arguments

object

An object of class "NBKP", typically returned by fit_NBKP.

nsim

Number of posterior samples to generate (default 1).

seed

Optional integer seed for reproducibility.

Xnew

A numeric matrix or vector of new input locations at which simulations are generated.

...

Additional arguments (currently unused).

Value

A list with the following components:

samples

A numeric matrix of size nrow(Xnew) × nsim, where each column corresponds to one posterior draw of latent mean counts.

mean

A numeric vector of posterior mean count values at each Xnew.

X

The training input matrix used to fit the NBKP model.

Xnew

The new input locations at which simulations are generated.

References

Zhao J, Qing K, Xu J (2025). BKP: An R Package for Beta Kernel Process Modeling. arXiv. https://doi.org/10.48550/arxiv.2508.10447.

See Also

fit_NBKP for model fitting; predict.NBKP for posterior prediction.

Examples


set.seed(123)

# Define true mean function
true_mu_fun <- function(x) {
  exp(sin(x) + 0.5)
}

n <- 30
Xbounds <- matrix(c(-2, 2), nrow = 1)
X <- tgp::lhs(n = n, rect = Xbounds)
true_mu <- true_mu_fun(X)
y <- rnbinom(n, size = 1, mu = true_mu)

# Fit NBKP model
model <- fit_NBKP(X, y, Xbounds = Xbounds)

# Simulate 5 posterior draws of latent mean counts
Xnew <- matrix(seq(-2, 2, length.out = 5), ncol = 1)
simulate(model, Xnew = Xnew, nsim = 5)



NBKP documentation built on June 18, 2026, 1:06 a.m.