View source: R/pred_functions.R
| predict.shrinkMVGPR | R Documentation |
predict.shrinkMVGPR generates posterior predictive samples from a fitted shrinkMVGPR model at specified covariates.
## S3 method for class 'shrinkMVGPR'
predict(object, newdata, nsamp = 100, ...)
object |
A |
newdata |
Optional data frame containing the covariates for the prediction points. If missing, the training data is used. |
nsamp |
Positive integer specifying the number of posterior samples to generate. Default is 100. |
... |
Currently ignored. |
This function generates predictions by sampling from the posterior predictive distribution.
A 3-dimensional array of dimensions nsamp x N_new x M containing posterior predictive samples
for each covariate combination in newdata.
if (torch::torch_is_installed()) {
# Simulate data
set.seed(123)
torch::torch_manual_seed(123)
n <- 100
x <- matrix(runif(n * 2), n, 2)
y1 <- sin(2 * pi * x[, 1])
y2 <- cos(2 * pi * x[, 2])
y <- cbind(y1, y2) + matrix(rnorm(n * 2, sd = 0.1), n, 2)
data <- data.frame(y1 = y1, y2 = y2, x1 = x[, 1], x2 = x[, 2])
# Fit MVGPR model
res <- shrinkMVGPR(cbind(y1, y2) ~ x1 + x2, data = data)
# Example usage for in-sample prediction
preds <- predict(res)
# Example usage for out-of-sample prediction
newdata <- data.frame(x1 = runif(10), x2 = runif(10))
preds <- predict(res, newdata = newdata)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.