predict.gp: predict method for Gaussian process models

Description Usage Arguments Value Examples

Description

Makes predictions from a fitted GP model in a similar way to predict.glm from GLMs

Usage

1
2
3
## S3 method for class 'gp'
predict(object, newdata = NULL, type = c("link", "response"),
  sd = FALSE, ...)

Arguments

object

a fitted GP model; an object of class gp produced by gp.

newdata

an optional data frame containing new data to predict to. If NULL, the training data is used instead.

type

the type of prediction required. The default ('link' predicts the value of the latent Gaussian process at the new locations, 'response' instead predicts on the scale of the response variable.

sd

whether to report standard deviations of the prediction.

...

further arguments to be passed to other methods, currently ignored

Value

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.

Examples

 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)

goldingn/gpe documentation built on May 17, 2019, 7:41 a.m.