fit_NBKP: Fit a Negative Binomial Kernel Process (NBKP) Model

View source: R/fit_NBKP.R

fit_NBKPR Documentation

Fit a Negative Binomial Kernel Process (NBKP) Model

Description

Fits a Negative Binomial Kernel Process (NBKP) model to count response data using local kernel smoothing. The method constructs a flexible latent mean surface by updating Gamma priors with kernel-weighted observations.

Usage

fit_NBKP(
  X,
  y,
  Xbounds = NULL,
  prior = c("noninformative", "fixed", "adaptive"),
  r0 = 0.1,
  mu0 = mean(y),
  kernel = c("gaussian", "matern52", "matern32"),
  loss = c("mse", "nll"),
  n_multi_start = NULL,
  theta = NULL
)

Arguments

X

A numeric input matrix of size n \times d, where each row corresponds to a covariate vector.

y

A numeric vector of observed counts (length n).

Xbounds

Optional d \times 2 matrix specifying the lower and upper bounds of each input dimension. Used to normalize inputs to [0,1]^d. If NULL, inputs are assumed to be pre-normalized, and default bounds [0,1]^d are applied.

prior

Global prior type: "noninformative" (default), "fixed", or "adaptive".

r0

Global prior precision (used when prior = "fixed" or "adaptive").

mu0

Global prior mean (used when prior = "fixed"). Default is mean(y).

kernel

Kernel function for local weighting: "gaussian" (default), "matern52", or "matern32".

loss

Loss function for kernel hyperparameter tuning: "mse" (default) or "nll".

n_multi_start

Number of random initializations for multi-start optimization. Default is 10 \times d.

theta

Optional. A positive scalar or numeric vector of length d specifying kernel lengthscale parameters directly. If NULL (default), lengthscales are optimized using multi-start L-BFGS-B to minimize the specified loss.

Value

A list of class "NBKP" containing the fitted NBKP model, including:

theta_opt

Optimized kernel hyperparameters (lengthscales).

kernel

Kernel function used, as a string.

loss

Loss function used for hyperparameter tuning.

loss_min

Minimum loss achieved during optimization, or NA if theta was user-specified.

X

Original input matrix (n \times d).

Xnorm

Normalized input matrix scaled to [0,1]^d.

Xbounds

Normalization bounds for each input dimension (d \times 2).

y

Observed counts.

phi

Estimated negative binomial dispersion parameter.

prior

Type of prior used.

r0

Prior precision parameter.

mu0

Prior mean (for fixed priors).

alpha0

Prior Gamma shape parameter \alpha_0(\mathbf{x}).

beta0

Prior Gamma rate parameter \beta_0(\mathbf{x}).

alpha_n

Posterior shape parameter \alpha_n(\mathbf{x}).

beta_n

Posterior rate parameter \beta_n(\mathbf{x}).

Author(s)

Xueqin Li

References

Zhao J, Qing K, Xu J (2025). BKP: An R Package for Beta Kernel Process Modeling.

See Also

predict.NBKP, plot.NBKP, summary.NBKP

Examples

# -------------------------- 1D Example --------------------------
set.seed(123)

true_mu_fun <- function(x) {
  exp(sin(x) + 0.5)
}

n <- 30
Xbounds <- matrix(c(-2, 2), nrow=1)
X <- matrix(seq(-2, 2, length.out = n))
true_mu <- true_mu_fun(X)
y <- rnbinom(n, size = 1, mu = true_mu)

model1 <- fit_NBKP(X, y, Xbounds=Xbounds)
print(model1)


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