Learn R Programming

BKP (version 0.2.3)

get_prior: Construct Prior Parameters for BKP/DKP Models

Description

Computes prior parameters for the Beta Kernel Process (BKP, for binary outcomes) or Dirichlet Kernel Process (DKP, for multi-class outcomes). Supports prior = "noninformative", "fixed", and "adaptive" strategies.

Usage

get_prior(
  prior = c("noninformative", "fixed", "adaptive"),
  model = c("BKP", "DKP"),
  r0 = 2,
  p0 = NULL,
  y = NULL,
  m = NULL,
  Y = NULL,
  K = NULL
)

Value

  • If model = "BKP": a list with

    alpha0

    Vector of prior alpha parameters for the Beta distribution, length n.

beta0

Vector of prior beta parameters for the Beta distribution, length n.

  • If model = "DKP": a list containing

    alpha0

    Matrix of prior Dirichlet parameters at each input location (n × q).

  • Arguments

    prior

    Type of prior: "noninformative" (default), "fixed", or "adaptive".

    model

    A character string specifying the model type: "BKP" (binary outcome) or "DKP" (multi-class outcome).

    r0

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

    p0

    For BKP, a scalar in (0,1) specifying the prior mean of success probability when prior = "fixed". For DKP, a numeric vector of length equal to the number of classes specifying the global prior mean, which must sum to 1.

    y

    A numeric vector of observed successes (length n).

    m

    A numeric vector of total binomial trials (length n), corresponding to each y.

    Y

    A numeric matrix of observed class counts (n × q), required only when model = "DKP", where n is the number of observations and q the number of classes.

    K

    A precomputed kernel matrix, typically obtained from kernel_matrix. Can be rectangular (m × n), where n is the number of observed points and m the number of prediction locations.

    Details

    • prior = "noninformative": flat prior; all parameters set to 1.

    • prior = "fixed":

      • BKP: uniform Beta prior Beta(r0 * p0, r0 * (1 - p0)) across locations.

      • DKP: all rows of alpha0 set to r0 * p0.

    • prior = "adaptive":

      • BKP: prior mean estimated at each location via kernel smoothing of observed proportions y/m, with precision r0.

      • DKP: prior parameters computed by kernel-weighted smoothing of observed class frequencies in Y, scaled by r0.

    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_BKP for fitting Beta Kernel Process models, fit_DKP for fitting Dirichlet Kernel Process models, predict.BKP and predict.DKP for making predictions, kernel_matrix for computing kernel matrices used in prior construction.

    Examples

    Run this code
    # -------------------------- BKP ---------------------------
    set.seed(123)
    n <- 10
    X <- matrix(runif(n * 2), ncol = 2)
    y <- rbinom(n, size = 5, prob = 0.6)
    m <- rep(5, n)
    K <- kernel_matrix(X)
    prior_bkp <- get_prior(
      model = "BKP", prior = "adaptive", r0 = 2, y = y, m = m, K = K
    )
    
    # -------------------------- DKP ---------------------------
    set.seed(123)
    n <- 15; q <- 3
    X <- matrix(runif(n * 2), ncol = 2)
    true_pi <- t(apply(X, 1, function(x) {
      raw <- c(
        exp(-sum((x - 0.2)^2)),
        exp(-sum((x - 0.5)^2)),
        exp(-sum((x - 0.8)^2))
      )
      raw / sum(raw)
    }))
    m <- sample(10:20, n, replace = TRUE)
    Y <- t(sapply(1:n, function(i) rmultinom(1, size = m[i], prob = true_pi[i, ])))
    K <- kernel_matrix(X, theta = rep(0.2, 2), kernel = "gaussian")
    prior_dkp <- get_prior(
      model = "DKP", prior = "adaptive", r0 = 2, Y = Y, K = K
    )
    
    

    Run the code above in your browser using DataLab