View source: R/pred_functions.R
calc_pred_moments | R Documentation |
calc_pred_moments
calculates the predictive means and variances for a fitted shrinkGPR
model at new data points.
calc_pred_moments(object, newdata, nsamp = 100)
object |
A |
newdata |
Optional data frame containing the covariates for the new data points. If missing, the training data is used. |
nsamp |
Positive integer specifying the number of posterior samples to use for the calculation. Default is 100. |
This function computes predictive moments by marginalizing over posterior samples from the fitted model. If the mean equation is included in the model, the corresponding covariates are used.
A list with two elements:
means
: A matrix of predictive means for each new data point, with the rows being the samples and the columns the data points.
vars
: An array of covariance matrices, with the first dimension corresponding to the samples and second and third dimensions to the data points.
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)
# Calculate predictive moments
momes <- calc_pred_moments(res, nsamp = 100)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.