magp

magp is designed for experiments in which every component has both an amount and a position in a sequence. It fits an additive Gaussian process that uses both parts of the input, then returns predictions with optional uncertainty estimates. You can choose a compact two-dimensional mapping or a full mapping with q - 1 dimensions. The most intensive covariance and gradient calculations run in C++ through Rcpp.

Installation

Install Rcpp and nloptr, then install the source package:

install.packages(c("Rcpp", "nloptr"))
install.packages("magp_0.8.0.tar.gz", repos = NULL, type = "source")
library(magp)

A C++ toolchain is required when installing from source.

Data format

For q components, the input must contain 2*q columns:

  1. the first q columns contain quantitative inputs;
  2. the last q columns contain sequence positions.

Every row in the sequence columns must contain each value from 1 to q exactly once. A response column named y may be included in the same data frame; when it is present, the fitting functions can identify both y and q automatically.

Quantitative columns outside [0, 1] are transformed by min-max scaling during fitting. The fitted ranges are saved and used again for prediction. Inputs already in [0, 1] are not changed.

Example

train <- read.table(
  system.file("extdata", "example_train.txt", package = "magp"),
  header = TRUE
)
test <- read.table(
  system.file("extdata", "example_test.txt", package = "magp"),
  header = TRUE
)

fit_2d <- magp2d_fit(train, tau = 0.001, seed = 1)
prediction_2d <- predict(fit_2d, test)
magp2d_rmse(prediction_2d, test$y)

fit_full <- magpfull_fit(train, tau = 0.001, seed = 1)
prediction_full <- predict(fit_full, test)
magp2d_rmse(prediction_full, test$y)

uncertainty <- predict(
  fit_2d,
  test[1:5, ],
  se.fit = TRUE,
  type = "response"
)
data.frame(
  prediction = uncertainty$fit,
  standard_error = uncertainty$se.fit
)

tau is a fixed nugget variance added to the covariance diagonal. It is a variance, not a standard deviation.

Prediction types

The reported standard errors treat the fitted covariance parameters as fixed.