| plot.NBKP | R Documentation |
Visualizes fitted NBKP (count) models according to the input
dimensionality. For 1D inputs, it shows predicted mean counts with credible
intervals and observed count data. For 2D inputs, it generates contour plots
of posterior summaries. For higher-dimensional inputs, users must specify
which dimensions to plot.
## S3 method for class 'NBKP'
plot(x, only_mean = FALSE, n_grid = 80, dims = NULL, ...)
x |
An object of class |
only_mean |
Logical. If |
n_grid |
Positive integer specifying the number of grid points per
dimension for constructing the prediction grid. Larger values produce
smoother and more detailed surfaces, but increase computation time. Default
is |
dims |
Integer vector indicating which input dimensions to plot. Must
have length 1 (for 1D) or 2 (for 2D). If |
... |
Additional arguments passed to internal plotting routines (currently unused). |
The plotting behavior depends on the dimensionality of the input covariates:
1D inputs:
The function plots the posterior mean curve with a shaded 95 interval, overlaid with the observed counts.
2D inputs:
The function generates contour plots over a 2D prediction grid.
Users can choose to plot only the predictive mean surface (only_mean = TRUE)
or a set of four summary plots (only_mean = FALSE):
Predictive mean
97.5th percentile (upper bound of 95
Predictive variance
2.5th percentile (lower bound of 95
Input dimensions greater than 2:
The function does not automatically support visualization and will terminate with an error.
Users must specify which dimensions to visualize via the dims
argument (length 1 or 2).
This function is called for its side effects and does not return a value. It produces plots visualizing the predicted counts, credible intervals, and posterior summaries.
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.
fit_NBKP for fitting NBKP models;
predict.NBKP for generating predictions from fitted NBKP models.
# -------------------------- 1D Example --------------------------
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
model1 <- fit_NBKP(X, y, Xbounds=Xbounds)
# Plot results
plot(model1)
# -------------------------- 2D Example --------------------------
set.seed(123)
# Define 2D latent function and mean transformation
true_mu_fun <- function(X) {
if(is.null(nrow(X))) X <- matrix(X, nrow=1)
x1 <- 4*X[,1] - 2
x2 <- 4*X[,2] - 2
f <- sin(2*pi*x1) * cos(2*pi*x2)
return(exp(f))
}
n <- 100
Xbounds <- matrix(c(0, 0, 1, 1), nrow = 2)
X <- tgp::lhs(n = n, rect = Xbounds)
true_mu <- true_mu_fun(X)
y <- rnbinom(n, size = 0.5, mu = true_mu)
# Fit NBKP model
model2 <- fit_NBKP(X, y, Xbounds=Xbounds)
# Plot results
plot(model2, n_grid = 50)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.