View source: R/plot_functions.R
plot.shrinkGPR_marg_samples_2D | R Documentation |
shrinkGPR
Generates a 3D surface plot of 2D conditional predictive samples produced by gen_marginal_samples
.
## S3 method for class 'shrinkGPR_marg_samples_2D'
plot(x, ...)
x |
An object of class |
... |
Additional arguments passed to |
The function visualizes the posterior predictive mean across a 2D grid of evaluation points for two covariates. Interactive plotting is handled via the plotly package. Axis labels are automatically inferred from the object.
Note: The plotly package must be installed to use this function.
A plotly
plot object (interactive 3D surface). Can be further customized via pipes and plotly
functions.
Peter Knaus peter.knaus@wu.ac.at
gen_marginal_samples
, plot_ly
, add_surface
Other plotting functions:
plot.shrinkGPR()
,
plot.shrinkGPR_marg_samples_1D()
,
plot.shrinkTPR()
# 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]) * cos(2 * pi * x[, 2]) + 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 marginal predictions for x1 and x2 jointly
marginal_samps_both <- gen_marginal_samples(res, to_eval = c("x1", "x2"), nsamp = 100)
# Plot interactive surface
plot(marginal_samps_both)
# Customize surface appearance
plot(marginal_samps_both, opacity = 0.8, colorscale = "Magma")
# Customize further via plotly
p <- plot(marginal_samps_both, opacity = 0.8, colorscale = "Magma")
p |> plotly::layout(
scene = list(
xaxis = list(title = "Covariate 1"),
yaxis = list(title = "Covariate 2"),
zaxis = list(title = "Expected value")
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.