The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Package {magp}


Title: Mapping-Based Additive Gaussian Process Models
Version: 0.8.0
Description: Fits mapping-based additive Gaussian process models for experiments in which each component has both a quantitative level and a position in an ordered sequence. Two model structures are available: a compact two-dimensional mapping and a full mapping with one fewer dimension than the number of components. Both models support parameter estimation, point prediction, and plug-in predictive uncertainty. Input checks validate the sequence data and apply consistent scaling to the quantitative inputs. Computationally intensive covariance and gradient calculations are implemented in C++ with 'Rcpp'. The model was introduced by Xiao et al. (2024) <doi:10.1080/01621459.2022.2123335>.
License: MIT + file LICENSE
Encoding: UTF-8
Imports: Rcpp, nloptr, stats
LinkingTo: Rcpp
Suggests: testthat (≥ 3.0.0)
Config/testthat/edition: 3
NeedsCompilation: yes
RoxygenNote: 7.3.3
Packaged: 2026-08-22 03:51:29 UTC; skr
Author: Tony Wang [aut, cre, cph], Qian Xiao [aut, cph], Yaping Wang [cph], Abhyuday Mandal [cph], Xinwei Deng [cph]
Maintainer: Tony Wang <wangtony883@gmail.com>
Repository: CRAN
Date/Publication: 2026-09-03 11:40:09 UTC

magp: Mapping-Based Additive Gaussian Process Models

Description

Fits additive Gaussian process models for experiments in which each component has both a quantitative level and a position in a sequence.

Details

For q components, the first q input columns contain quantitative levels and the next q columns contain sequence positions. Every sequence row must be a permutation of 1:q. Quantitative columns outside ⁠[0, 1]⁠ are scaled during fitting, and the same transformation is used for new data.

magp2d_fit() represents the sequence positions in two latent dimensions. magpfull_fit() uses q - 1 latent dimensions. Both fitted model classes support stats::predict() for point predictions and plug-in predictive uncertainty. The computational kernels for covariance matrices, analytical gradients, and cross-covariances are implemented in C++ with Rcpp.

Author(s)

Maintainer: Tony Wang wangtony883@gmail.com [copyright holder]

Authors:

Other contributors:


Fit a MaGP model with a two-dimensional sequence map

Description

Fits an additive Gaussian process for data that combine component amounts with a component order. Sequence positions are represented by points in a compact two-dimensional latent map.

Usage

magp2d_fit(
  X,
  y = NULL,
  q = NULL,
  tau = 0.001,
  maxeval = 500,
  xtol_rel = 1e-05,
  lb_sigma = 10,
  ub_sigma = 1000,
  lb_theta = 0.5,
  ub_theta = 1000,
  lb_delta = -1,
  ub_delta = 1,
  seed = NULL
)

Arguments

X

A numeric matrix or data frame. The first q input columns contain quantitative levels and the next q columns contain sequence positions. Each sequence row must be a permutation of 1:q. A column named y may be included as the response.

y

An optional numeric response vector. It may be omitted when X contains a response column named y.

q

The number of components. It is inferred from the number of input columns when omitted. The two-dimensional model requires at least three components; the full model requires at least two.

tau

A fixed nonnegative nugget variance added to the covariance diagonal.

maxeval

Maximum number of objective evaluations used by nloptr.

xtol_rel

Relative parameter tolerance used by nloptr.

lb_sigma, ub_sigma

Lower and upper bounds for the additive variance parameters.

lb_theta, ub_theta

Lower and upper bounds for the quantitative correlation parameters.

lb_delta, ub_delta

Lower and upper bounds for the mapping parameters.

seed

An optional nonnegative integer used to generate the initial parameter vector.

Details

The covariance is a sum of component-specific terms. Each term combines the distance between two quantitative levels with the distance between their mapped sequence positions. The variance, correlation, and mapping parameters are estimated together with bounded optimization.

Quantitative columns outside ⁠[0, 1]⁠ are transformed with column-wise min-max scaling. Their training ranges are stored in the fitted object and reused for prediction. Columns already in ⁠[0, 1]⁠ are left unchanged.

Value

An object of class magp2d.

Examples


train <- read.table(
  system.file("extdata", "example_train.txt", package = "magp"),
  header = TRUE
)
fit <- magp2d_fit(train, seed = 1)
fit


Calculate root-mean-squared prediction error

Description

Calculates the root-mean-squared error between predicted and observed values.

Usage

magp2d_rmse(pred, actual)

Arguments

pred

Numeric vector of predictions.

actual

Numeric vector of observed values with the same length as pred.

Value

A single nonnegative numeric value.


Fit a MaGP model with a full sequence map

Description

Fits the quantitative-sequence model with q - 1 latent mapping dimensions, giving the sequence positions a less constrained coordinate representation.

Usage

magpfull_fit(
  X,
  y = NULL,
  q = NULL,
  tau = 0.001,
  maxeval = 500,
  xtol_rel = 1e-05,
  lb_sigma = 10,
  ub_sigma = 1000,
  lb_theta = 0.5,
  ub_theta = 1000,
  lb_delta = -1,
  ub_delta = 1,
  seed = NULL
)

Arguments

X

A numeric matrix or data frame. The first q input columns contain quantitative levels and the next q columns contain sequence positions. Each sequence row must be a permutation of 1:q. A column named y may be included as the response.

y

An optional numeric response vector. It may be omitted when X contains a response column named y.

q

The number of components. It is inferred from the number of input columns when omitted. The two-dimensional model requires at least three components; the full model requires at least two.

tau

A fixed nonnegative nugget variance added to the covariance diagonal.

maxeval

Maximum number of objective evaluations used by nloptr.

xtol_rel

Relative parameter tolerance used by nloptr.

lb_sigma, ub_sigma

Lower and upper bounds for the additive variance parameters.

lb_theta, ub_theta

Lower and upper bounds for the quantitative correlation parameters.

lb_delta, ub_delta

Lower and upper bounds for the mapping parameters.

seed

An optional nonnegative integer used to generate the initial parameter vector.

Details

The data layout, quantitative scaling, and covariance construction are the same as in magp2d_fit(). The difference is the number of latent coordinates used to represent the sequence positions.

Value

An object of class magpfull.

Examples


train <- read.table(
  system.file("extdata", "example_train.txt", package = "magp"),
  header = TRUE
)
fit <- magpfull_fit(train, seed = 1)
fit


Predict outcomes from a fitted MaGP model

Description

Returns predictions for new quantitative-sequence inputs. Plug-in standard errors and variances can be returned with the predictions.

Usage

## S3 method for class 'magp2d'
predict(
  object,
  newdata,
  se.fit = FALSE,
  type = c("script", "response", "latent"),
  ...
)

## S3 method for class 'magpfull'
predict(
  object,
  newdata,
  se.fit = FALSE,
  type = c("script", "response", "latent"),
  ...
)

Arguments

object

A fitted magp2d or magpfull object.

newdata

A numeric matrix or data frame with the same quantitative and sequence inputs used for fitting. A response column named y is ignored.

se.fit

Logical; if TRUE, return predictive standard errors and variances in addition to fitted values.

type

Prediction convention. "script" uses the fitted training-row convention when newdata exactly matches a training row. "response" includes the nugget variance for a future response, and "latent" returns uncertainty for the noise-free surface.

...

Additional arguments, currently unused.

Value

If se.fit = FALSE, a numeric vector of predictions. Otherwise, a list with components fit, se.fit, variance, and type.

Examples


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 <- magp2d_fit(train, seed = 1)
predict(fit, test[1:3, ], se.fit = TRUE, type = "response")


Summarize a fitted two-dimensional MaGP model

Description

Prints the model size, nugget variance, fitted mean, objective value, and optimizer status.

Usage

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

Arguments

x

A magp2d model returned by magp2d_fit().

...

Unused.

Value

x, invisibly.


Summarize a fitted full-mapping MaGP model

Description

Prints the mapping dimension, model size, nugget variance, fitted mean, objective value, and optimizer status.

Usage

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

Arguments

x

A magpfull model returned by magpfull_fit().

...

Unused.

Value

x, invisibly.

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.