Skip to contents

Methods for stats::predict(), stats::logLik(), stats::nobs(), stats::fitted(), stats::residuals(), and summary() on exact (gaussianprocesses_model), sparse (gaussianprocesses_sparse_model), heteroscedastic (gaussianprocesses_heteroscedastic_model), latent (gaussianprocesses_latent_model), and state-space (gaussianprocesses_state_space_model) models.

Usage

# S3 method for class 'gaussianprocesses_model'
predict(object, newdata, ...)

# S3 method for class 'gaussianprocesses_sparse_model'
predict(object, newdata, ...)

# S3 method for class 'gaussianprocesses_state_space_model'
predict(object, newdata, ...)

# S3 method for class 'gaussianprocesses_heteroscedastic_model'
predict(object, newdata, ...)

# S3 method for class 'gaussianprocesses_latent_model'
predict(object, newdata, ...)

# S3 method for class 'gaussianprocesses_model'
logLik(object, ...)

# S3 method for class 'gaussianprocesses_sparse_model'
logLik(object, ...)

# S3 method for class 'gaussianprocesses_state_space_model'
logLik(object, ...)

# S3 method for class 'gaussianprocesses_heteroscedastic_model'
logLik(object, ...)

# S3 method for class 'gaussianprocesses_latent_model'
logLik(object, ...)

# S3 method for class 'gaussianprocesses_model'
nobs(object, ...)

# S3 method for class 'gaussianprocesses_sparse_model'
nobs(object, ...)

# S3 method for class 'gaussianprocesses_state_space_model'
nobs(object, ...)

# S3 method for class 'gaussianprocesses_heteroscedastic_model'
nobs(object, ...)

# S3 method for class 'gaussianprocesses_latent_model'
nobs(object, ...)

# S3 method for class 'gaussianprocesses_model'
fitted(object, ...)

# S3 method for class 'gaussianprocesses_sparse_model'
fitted(object, ...)

# S3 method for class 'gaussianprocesses_state_space_model'
fitted(object, ...)

# S3 method for class 'gaussianprocesses_heteroscedastic_model'
fitted(object, ...)

# S3 method for class 'gaussianprocesses_latent_model'
fitted(object, ...)

# S3 method for class 'gaussianprocesses_model'
residuals(object, ...)

# S3 method for class 'gaussianprocesses_sparse_model'
residuals(object, ...)

# S3 method for class 'gaussianprocesses_state_space_model'
residuals(object, ...)

# S3 method for class 'gaussianprocesses_heteroscedastic_model'
residuals(object, ...)

# S3 method for class 'gaussianprocesses_model'
summary(object, ...)

# S3 method for class 'gaussianprocesses_sparse_model'
summary(object, ...)

# S3 method for class 'gaussianprocesses_state_space_model'
summary(object, ...)

# S3 method for class 'gaussianprocesses_heteroscedastic_model'
summary(object, ...)

# S3 method for class 'gaussianprocesses_latent_model'
summary(object, ...)

# S3 method for class 'summary.gaussianprocesses_model'
print(x, ...)

Arguments

object

A fitted model.

newdata

Prediction inputs. If missing, the training inputs (or, for time-series models, the training times) are used.

...

Further arguments passed to the package's prediction function: predict_gp(), forecast_gp(), predict_sparse_gp(), predict_heteroscedastic_gp(), or predict_latent_gp().

x

A summary object.

Value

predict(): a prediction object. logLik(): an object of class logLik. nobs(): the number of training observations. fitted() and residuals(): numeric vectors with one value per training observation. summary(): an object of class summary.gaussianprocesses_model.

Details

predict() returns exactly what the package's prediction function for the model returns. For models from fit_time_series_gp(), newdata are time values and predict() calls forecast_gp(); this includes every state-space model with time metadata.

logLik() returns the log marginal likelihood \(\log p(y \mid X, \hat\theta)\): log_marginal_likelihood() for exact and state-space models and, for sparse models, the FITC approximate marginal likelihood or the VFE lower bound. This is a type-II likelihood, with the latent function integrated out and the hyperparameters \(\hat\theta\) plugged in. Its df attribute counts the hyperparameters estimated from the data: the parameters optimized by optimize_gp() or optimize_sparse_gp(), and 0 for models whose hyperparameters were supplied, plus the mean coefficients when they are estimated. For restricted likelihoods (REML estimates and vague coefficient priors) the nobs attribute is \(n - p\), as for restricted likelihoods elsewhere in R, and such likelihoods are comparable only between models with the same mean. stats::AIC() and stats::BIC() therefore work, but comparing kernels by them is a heuristic: it is not an ordinary maximum-likelihood comparison, and the penalty does not account for the flexibility of the kernel. Heteroscedastic models have no logLik() method, because their noise function is a plug-in estimate rather than a likelihood maximizer. For latent models it is the Laplace approximation to the marginal likelihood, and df counts the parameters optimized by optimize_latent_gp() or the mean coefficients estimated by fit_latent_gp(). For state-space models df counts the parameters optimized by optimize_time_series_gp().

fitted() returns the posterior mean of the latent function at the training inputs, and residuals() returns the observed responses minus those fitted values. For exact models the fitted values are \(y - (\Sigma_\varepsilon + \delta I)\alpha\), which equals \(m(X) + K\alpha\) without forming \(K\); \(\delta\) is the numerical jitter. For state-space models they are the Kalman-smoother means. For latent models fitted() returns the posterior mode \(\hat f\) of the latent function, and there is no residuals() method, because the responses are not on the scale of \(f\).

summary() collects the training size and dimension, kernel, mean, noise, log marginal likelihood, optimization status, and numerical status, and prints them compactly.

Stability

Stable: from version 1.0.0 this interface changes incompatibly only in a major release, after a deprecation period. Results and options that concern an experimental model class, kernel, or argument follow that interface's tier. See gaussianprocesses-package for the policy.

Examples

x <- seq(-2, 2, length.out = 20)
y <- sin(2 * x) + 0.1 * cos(7 * x)
model <- optimize_gp(
  x,
  y,
  kernel = rbf_kernel(),
  noise_variance = 0.05,
  n_starts = 1
)

summary(model)
#> Exact Gaussian-process regression model
#>   observations: 20, input dimensions: 1
#>   kernel: RBF(variance=1.4434, length_scale=1.04306)
#>   mean: ZeroMean()
#>   noise: homoscedastic, variance 0.00668829
#>   log marginal likelihood: 5.045066
#>   optimization: converged (L-BFGS-B, analytical gradient)
#>   starts: 1, reaching 1 distinct optimum
#>   numerical jitter: 0
predict(model, c(-1, 0.5))$mean
#> [1] -0.9065529  0.8430854
logLik(model)
#> 'log Lik.' 5.045066 (df=3)
AIC(model)
#> [1] -4.090132
head(residuals(model))
#> [1] -0.032065637  0.089192853  0.006524851 -0.097799797 -0.026494828
#> [6]  0.091175328