Fits a DKP model for multinomial response data by locally smoothing observed counts to estimate latent Dirichlet parameters.
Arguments
- X
A numeric input matrix of size \(n \times d\), where each row represents a covariate vector.
- Y
Matrix of observed multinomial counts, with dimension \(n \times q\).
- 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
Xbounds
isNULL
, the input is assumed to have already been normalized, and the default bounds are set to \([0,1]^d\).- prior
Type of prior to use. One of
"noninformative"
,"fixed"
, or"adaptive"
.- r0
Global prior precision (only used when
prior = "fixed"
or"adaptive"
).- p0
Global prior mean vector (only used when
prior = "fixed"
). Must be of length \(q\).- kernel
Kernel function for local weighting. Choose from
"gaussian"
,"matern52"
, or"matern32"
.- loss
Loss function for kernel hyperparameter tuning. One of
"brier"
(default) or"log_loss"
.- n_multi_start
Number of random initializations for multi-start optimization. Default is
10 × d
.
Value
A list of class "DKP"
representing the fitted DKP model, with
the following components:
theta_opt
Optimized kernel hyperparameters (lengthscales).
kernel
Kernel function used, as a string.
loss
Loss function used for hyperparameter tuning.
loss_min
Minimum loss value achieved during optimization.
X
Original (unnormalized) input matrix of size
n × d
.Xnorm
Normalized input matrix scaled to \([0,1]^d\).
Xbounds
Matrix specifying normalization bounds for each input dimension.
Y
Observed multinomial counts of size
n × q
.prior
Type of prior used.
r0
Prior precision parameter.
p0
Prior mean (for fixed priors).
alpha0
Prior Dirichlet parameters at each input location (scalar or matrix).
alpha_n
Posterior Dirichlet parameters after kernel smoothing.
See also
fit.BKP
for modeling binomial responses using the Beta
Kernel Process. predict.DKP
, plot.DKP
,
simulate.DKP
for making predictions, visualizing results, and
generating simulations from a fitted DKP model. summary.DKP
,
print.DKP
for inspecting fitted model summaries.
Examples
#-------------------------- 1D Example ---------------------------
set.seed(123)
# Define true class probability function (3-class)
true_pi_fun <- function(X) {
p <- (1 + exp(-X^2) * cos(10 * (1 - exp(-X)) / (1 + exp(-X)))) / 2
return(matrix(c(p/2, p/2, 1 - p), nrow = length(p)))
}
n <- 30
Xbounds <- matrix(c(-2, 2), nrow = 1)
X <- tgp::lhs(n = n, rect = Xbounds)
true_pi <- true_pi_fun(X)
m <- sample(100, n, replace = TRUE)
# Generate multinomial responses
Y <- t(sapply(1:n, function(i) rmultinom(1, size = m[i], prob = true_pi[i, ])))
# Fit DKP model
model1 <- fit.DKP(X, Y, Xbounds = Xbounds)
print(model1)
#> --------------------------------------------------
#> Dirichlet Kernel Process (DKP) Model
#> --------------------------------------------------
#> Number of observations (n): 30
#> Input dimensionality (d): 1
#> Output dimensionality (q): 3
#> Kernel type: gaussian
#> Loss function used: brier
#> Optimized kernel parameters: 0.0407
#> Minimum achieved loss: 0.00058
#>
#> Prior specification:
#> Noninformative prior: Dirichlet(1,...,1).
#> --------------------------------------------------
#-------------------------- 2D Example ---------------------------
set.seed(123)
# Define latent function and transform to 3-class probabilities
true_pi_fun <- function(X) {
if (is.null(nrow(X))) X <- matrix(X, nrow = 1)
m <- 8.6928; s <- 2.4269
x1 <- 4 * X[,1] - 2
x2 <- 4 * X[,2] - 2
a <- 1 + (x1 + x2 + 1)^2 *
(19 - 14*x1 + 3*x1^2 - 14*x2 + 6*x1*x2 + 3*x2^2)
b <- 30 + (2*x1 - 3*x2)^2 *
(18 - 32*x1 + 12*x1^2 + 48*x2 - 36*x1*x2 + 27*x2^2)
f <- (log(a * b) - m) / s
p <- pnorm(f)
return(matrix(c(p/2, p/2, 1 - p), nrow = length(p)))
}
n <- 100
Xbounds <- matrix(c(0, 0, 1, 1), nrow = 2)
X <- tgp::lhs(n = n, rect = Xbounds)
true_pi <- true_pi_fun(X)
m <- sample(100, n, replace = TRUE)
# Generate multinomial responses
Y <- t(sapply(1:n, function(i) rmultinom(1, size = m[i], prob = true_pi[i, ])))
# Fit DKP model
model2 <- fit.DKP(X, Y, Xbounds = Xbounds)
print(model2)
#> --------------------------------------------------
#> Dirichlet Kernel Process (DKP) Model
#> --------------------------------------------------
#> Number of observations (n): 100
#> Input dimensionality (d): 2
#> Output dimensionality (q): 3
#> Kernel type: gaussian
#> Loss function used: brier
#> Optimized kernel parameters: 0.1245, 0.0706
#> Minimum achieved loss: 0.00061
#>
#> Prior specification:
#> Noninformative prior: Dirichlet(1,...,1).
#> --------------------------------------------------