Description Usage Arguments Value Examples
Makes predictions from a fitted GP model in a similar way
to predict.glm
from GLMs
1 2 3 |
object |
a fitted GP model; an object of class |
newdata |
an optional data frame containing new data to predict to.
If |
type |
the type of prediction required. The default ( |
sd |
whether to report standard deviations of the prediction. |
... |
further arguments to be passed to other methods, currently ignored |
if sd = FALSE
a vector of predictions. If
sd = TRUE
, a list with components: fit
the
predictions (as for sd = FALSE
); sd
estimated
standard deviations of the latent gaussians.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | # make some fake data
n <- 100 # observations
# dataframes
df <- data.frame(x = sort(runif(n, -5, 5)))
prediction_df <- data.frame(x = seq(min(df$x), max(df$x), len = 500))
# fake Gaussian response data
f <- sin(df$x)
y <- rnorm(n, f, 1)
# fit a full (non-sparse) GP model (without updating the hyperparameters)
# with rbf kernel and observation error
m1 <- gp(y ~ rbf('x') + iid(), df, gaussian)
# make predictions from it (only the mean)
mu <- predict(m1, prediction_df)
plot(mu ~ prediction_df$x, type = 'l', ylim = range(y))
points(y ~ df$x, pch = 16)
# now predict with the standard deviations
res <- predict(m1, prediction_df, sd = TRUE)
# get upper and lower 95% credible intervals
upper <- res$fit + 1.96 * res$sd
lower <- res$fit - 1.96 * res$sd
plot(mu ~ prediction_df$x, type = 'l',
ylim = range(y, upper, lower))
lines(upper ~ prediction_df$x, lty = 2)
lines(lower ~ prediction_df$x, lty = 2)
points(y ~ df$x, pch = 16)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.