View source: R/pred_functions.R
| gen_posterior_samples | R Documentation |
gen_posterior_samples generates posterior samples of the model parameters from a fitted shrinkGPR, shrinkTPR, shrinkMVGPR or shrinkMVTPR model.
gen_posterior_samples(mod, nsamp = 1000)
mod |
A |
nsamp |
Positive integer specifying the number of posterior samples to generate. Default is 1000. |
This function draws posterior samples from the latent space and transforms them into the parameter space of the model. These samples can be used for posterior inference or further analysis, such as examining which inverse lengthscale parameters pulled to zero.
For univariate models (shrinkGPR, shrinkTPR), a list containing posterior samples of the model parameters:
thetas: A matrix of posterior samples for the inverse lengthscale parameters.
sigma2: A matrix of posterior samples for the noise variance.
tau: A matrix of posterior samples for the global shrinkage parameter.
betas (optional): A matrix of posterior samples for the mean equation parameters (if included in the model).
tau_mean (optional): A matrix of posterior samples for the mean equation's global shrinkage parameter (if included in the model).
Additionally, for a shrinkTPR model, the list also includes:
nu: A matrix of posterior samples for the degrees of freedom parameter.
For multivariate models (shrinkMVGPR, shrinkMVTPR), the list contains:
thetas: A matrix of posterior samples for the inverse lengthscale parameters.
tau: A matrix of posterior samples for the global shrinkage parameter for the kernel.
sigma2: A matrix of posterior samples for the noise variance.
tau_Om: A matrix of posterior samples for the global shrinkage parameter for the output covariance.
Omega: An array of posterior samples for the output covariance matrix.
Additionally, for a shrinkMVTPR model, the list also includes:
nu: A matrix of posterior samples for the degrees of freedom parameter.
if (torch::torch_is_installed()) {
# Simulate data
set.seed(123)
torch::torch_manual_seed(123)
n <- 100
x <- matrix(runif(n * 2), n, 2)
y <- sin(2 * pi * x[, 1]) + rnorm(n, sd = 0.1)
data <- data.frame(y = y, x1 = x[, 1], x2 = x[, 2])
# Fit GPR model
res <- shrinkGPR(y ~ x1 + x2, data = data)
# Generate posterior samples
samps <- gen_posterior_samples(res, nsamp = 1000)
# Plot the posterior samples
boxplot(samps$thetas)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.