gen_posterior_samples: Generate Posterior Samples

View source: R/pred_functions.R

gen_posterior_samplesR Documentation

Generate Posterior Samples

Description

gen_posterior_samples generates posterior samples of the model parameters from a fitted shrinkGPR, shrinkTPR, shrinkMVGPR or shrinkMVTPR model.

Usage

gen_posterior_samples(mod, nsamp = 1000)

Arguments

mod

A shrinkGPR, shrinkTPR, shrinkMVGPR or shrinkMVTPR object representing the fitted model.

nsamp

Positive integer specifying the number of posterior samples to generate. Default is 1000.

Details

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.

Value

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.

Examples


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)
  }


shrinkGPR documentation built on March 30, 2026, 5:06 p.m.