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
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.
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.
lambda
: 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).
lambda_mean
(optional): A matrix of posterior samples for the mean equation's global shrinkage parameter (if included in the model).
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.