| Title: | Virtual Noise Algorithm for Computing D-Optimal Designs with Correlated Observations |
|---|---|
| Description: | Provides an implementation of the Virtual Noise algorithm for D-optimal experimental designs under correlated observations. The package supports flexible covariance structures, multi-dimensional candidate sets, and analytical or numerical computation of regression gradients. It offers a unified framework for constructing design matrices, defining covariance models, and computing optimal design measures. |
| Authors: | Àngela Sebastià Bargues [aut, cre], Irene García-Camacha Gutiérrez [aut] |
| Maintainer: | Àngela Sebastià Bargues <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-09-29 08:33:03 UTC |
| Source: | https://github.com/cran/VNDesign |
Generates a covariance matrix for a set of locations coords,
using different covariance kernel families (exponential, Gaussian,
Matérn, spherical, triangular, Brownian, AR(1), or a user-defined covariance).
build_Sigma( coords, type = c("exp", "gauss", "matern32", "matern52", "spherical", "triangular", "triangular_trunc", "brownian", "ar1", "custom"), sigma2 = 1, range = 1, nugget = 0, phi = NULL, cov_fun = NULL, return_dist = FALSE )build_Sigma( coords, type = c("exp", "gauss", "matern32", "matern52", "spherical", "triangular", "triangular_trunc", "brownian", "ar1", "custom"), sigma2 = 1, range = 1, nugget = 0, phi = NULL, cov_fun = NULL, return_dist = FALSE )
coords |
Coordinates of the observation points. It can be:
|
type |
Type of covariance structure. Options:
|
sigma2 |
Marginal variance parameter multiplying the covariance kernel.
If |
range |
Scale/range parameter. Must be a positive scalar.
In distance-based kernels, it controls the rate of decay of the covariance.
In |
nugget |
Independent noise (nugget effect) added to the diagonal of the covariance matrix. Represents measurement error or small-scale variability not explained by the covariance structure, and may improve numerical stability. Must be a non-negative scalar. |
phi |
AR(1) parameter (used only if |
cov_fun |
User-defined covariance function (used only if |
return_dist |
If |
The implemented covariance structures include exponential, Gaussian, Matérn, spherical, triangular, Brownian and AR(1) covariance models.
For distance-based covariance structures, the pairwise distance matrix
D is computed as:
abs(outer(coords, coords, "-")) when coords is one-dimensional,
as.matrix(dist(coords, method = "euclidean")) when
coords is multidimensional.
For type = "brownian", the Brownian covariance kernel
is used, and therefore coords
must be one-dimensional.
For type = "custom", the covariance matrix is constructed by
evaluating cov_fun(u,v) for each pair of candidate points.
If return_dist = FALSE (default), returns the covariance matrix
Sigma of dimension .
If return_dist = TRUE, returns a list containing:
Sigma: covariance matrix.
D: pairwise distance matrix.
using an analytical gradientConstructs the candidate regressor matrix Xchi by evaluating
the analytical gradient of the predictor
with respect to the parameter vector theta
at each candidate point in chi.
build_Xchi_grad(chi, theta, grad_fun)build_Xchi_grad(chi, theta, grad_fun)
chi |
Candidate set. Either:
|
theta |
Numeric parameter vector of length |
grad_fun |
Function |
Numeric matrix Xchi of dimension ,
where row contains the gradient evaluated at the
candidate point .
## --------------------------------------------- ## Example 1D ## --------------------------------------------- chi <- seq(-1, 1, length.out = 5) theta <- c(0, 1) # eta(x) = theta1 + theta2 * x grad_fun <- function(x, theta) { c(1, x) } build_Xchi_grad(chi, theta, grad_fun) ## --------------------------------------------- ## Example 2D ## --------------------------------------------- chi2 <- cbind(x1 = c(0, 1), x2 = c(0.5, 0.8)) theta <- c(0, 1, -1) grad_fun2 <- function(x, theta) { c(1, x[1], x[2]) } build_Xchi_grad(chi2, theta, grad_fun2)## --------------------------------------------- ## Example 1D ## --------------------------------------------- chi <- seq(-1, 1, length.out = 5) theta <- c(0, 1) # eta(x) = theta1 + theta2 * x grad_fun <- function(x, theta) { c(1, x) } build_Xchi_grad(chi, theta, grad_fun) ## --------------------------------------------- ## Example 2D ## --------------------------------------------- chi2 <- cbind(x1 = c(0, 1), x2 = c(0.5, 0.8)) theta <- c(0, 1, -1) grad_fun2 <- function(x, theta) { c(1, x[1], x[2]) } build_Xchi_grad(chi2, theta, grad_fun2)
via centered finite differencesConstructs the candidate regressor matrix Xchi by numerically
approximating the gradient of the predictor
with respect to the parameter vector theta
using centered finite differences.
build_Xchi_numeric(chi, theta, eta_fun, step = NULL, rel_step = 1e-06)build_Xchi_numeric(chi, theta, eta_fun, step = NULL, rel_step = 1e-06)
chi |
Candidate set. Either:
|
theta |
Numeric parameter vector of length |
eta_fun |
Function |
step |
Step size(s) used in the finite-difference approximation. Can be:
|
rel_step |
Relative step size used when |
Uses the centered scheme
which has error order .
Numeric matrix with the finite-difference gradient approximation.
Computes a lower bound efficiency of a design
under the D-optimality criterion. The bound is based on the formulation
proposed in the literature for correlated observations, and is used as a
stopping criterion for the Virtual Noise algorithm.
efficiency_bound(xi_vec, Xchi, Sigma_chi, M_tilde, kappa, n_target)efficiency_bound(xi_vec, Xchi, Sigma_chi, M_tilde, kappa, n_target)
xi_vec |
Numeric vector of design weights (length |
Xchi |
Numeric matrix |
Sigma_chi |
Numeric covariance matrix |
M_tilde |
Current information matrix used by the Virtual Noise algorithm. |
kappa |
Virtual noise tuning parameter. |
n_target |
Target exact design size used in the efficiency diagnostic. |
The efficiency is expressed in terms of the information matrix
and a deviation term derived from the
sensitivity function .
The efficiency diagnostic is computed as
where and
.
The sensitivity function is constructed using the
transformed matrix and the gradient of .
This quantity provides a practical measure of convergence and can be used as a stopping rule in iterative design algorithms.
A list with the following components:
eff_lb: lower bound for the efficiency of the design.
delta: deviation term measuring how far the design is from optimality.
phi: value of the D-optimality criterion in its multiplicative form .
h_max: maximum value of the sensitivity function.
h_xi_mean: weighted average of the sensitivity function under .
This function currently supports only the D-optimality criterion.
Converts an approximate design measure obtained from
vndesign_Dopt or virtual_noise_Dopt
into an exact design with a fixed number of design points.
exact_design( res, Xchi, Sigma_chi, chi = NULL, n, method = c("random_best", "quantile", "quantile_endpoints"), B = 100, seed = NULL )exact_design( res, Xchi, Sigma_chi, chi = NULL, n, method = c("random_best", "quantile", "quantile_endpoints"), B = 100, seed = NULL )
res |
Output object returned by |
Xchi |
Numeric matrix |
Sigma_chi |
Numeric covariance matrix of dimension |
chi |
Optional candidate set. If |
n |
Target size of the exact design, i.e. the number of selected design points. |
method |
Method used to construct the exact design.
Use |
B |
Number of random candidate designs generated when
|
seed |
Optional random seed for reproducibility. |
A list with components:
idx: selected candidate indices.
points: selected candidate points.
n: number of selected points.
criterion_value: D-criterion value of the exact design.
chi <- seq(-1, 1, length.out = 10) Xchi <- cbind(1, chi) Sigma_chi <- build_Sigma(chi, type = "exp", range = 0.4) res <- list(xi = rep(1 / length(chi), length(chi))) exact_design(res, Xchi, Sigma_chi, chi = chi, n = 3, B = 5, seed = 1)chi <- seq(-1, 1, length.out = 10) Xchi <- cbind(1, chi) Sigma_chi <- build_Sigma(chi, type = "exp", range = 0.4) res <- list(xi = rep(1 / length(chi), length(chi))) exact_design(res, Xchi, Sigma_chi, chi = chi, n = 3, B = 5, seed = 1)
Plots the value of the D-optimality criterion at each iteration of the Virtual Noise algorithm in order to visualize the convergence of the approximate design sequence. The initial value at iteration 0 is omitted from the plot.
plot_convergence(res, main = NULL, xlab = "Iteration", ylab = NULL)plot_convergence(res, main = NULL, xlab = "Iteration", ylab = NULL)
res |
Output object returned by |
main |
Optional title of the plot. If |
xlab |
Label for the x-axis. Default is |
ylab |
Label for the y-axis. Default is
|
Produces a base R convergence plot and returns
NULL invisibly.
## Run the Virtual Noise algorithm chi <- seq(-1, 1, length.out = 50) res <- vndesign_Dopt( chi = chi, theta = c(0, 1), grad_fun = function(x, theta) c(1, x), kappa = 0.99 / length(chi), max_iter = 200 ) ## Plot convergence of the D-criterion plot_convergence(res)## Run the Virtual Noise algorithm chi <- seq(-1, 1, length.out = 50) res <- vndesign_Dopt( chi = chi, theta = c(0, 1), grad_fun = function(x, theta) c(1, x), kappa = 0.99 / length(chi), max_iter = 200 ) ## Plot convergence of the D-criterion plot_convergence(res)
Plots the design weights returned by vndesign_Dopt or
virtual_noise_Dopt. One-dimensional designs are shown as
vertical lines; two-dimensional designs are shown as points with size
proportional to the square root of the weight.
plot_design_weights(res, chi = NULL, main = NULL)plot_design_weights(res, chi = NULL, main = NULL)
res |
Output object returned by |
chi |
Optional candidate set. If |
main |
Optional title of the plot. If |
Produces a base R visualization of the design weights
over the candidate set and returns NULL invisibly.
## Run the Virtual Noise algorithm chi <- seq(-1, 1, length.out = 50) res <- vndesign_Dopt( chi = chi, theta = c(0, 1), grad_fun = function(x, theta) c(1, x), kappa = 0.99 / length(chi), max_iter = 200 ) ## Plot design weights plot_design_weights(res, chi = chi)## Run the Virtual Noise algorithm chi <- seq(-1, 1, length.out = 50) res <- vndesign_Dopt( chi = chi, theta = c(0, 1), grad_fun = function(x, theta) c(1, x), kappa = 0.99 / length(chi), max_iter = 200 ) ## Plot design weights plot_design_weights(res, chi = chi)
Plots the efficiency diagnostic values stored in an object returned by
vndesign_Dopt or virtual_noise_Dopt with
return_eff_bound = TRUE. The initial value at iteration 0 is
omitted from the plot.
plot_efficiency(res, main = NULL)plot_efficiency(res, main = NULL)
res |
Output object containing |
main |
Optional title of the plot. If |
Produces a base R visualization of the efficiency diagnostic
over the iterations of the Virtual Noise algorithm and
returns NULL invisibly.
## Run the Virtual Noise algorithm with efficiency tracking chi <- seq(-1, 1, length.out = 50) res <- vndesign_Dopt( chi = chi, theta = c(0, 1), grad_fun = function(x, theta) c(1, x), kappa = 0.99 / length(chi), max_iter = 200, return_eff_bound = TRUE, n_target = 3 ) ## Plot efficiency diagnostic plot_efficiency(res)## Run the Virtual Noise algorithm with efficiency tracking chi <- seq(-1, 1, length.out = 50) res <- vndesign_Dopt( chi = chi, theta = c(0, 1), grad_fun = function(x, theta) c(1, x), kappa = 0.99 / length(chi), max_iter = 200, return_eff_bound = TRUE, n_target = 3 ) ## Plot efficiency diagnostic plot_efficiency(res)
Implements the Virtual Noise (VN) algorithm for constructing approximate D-optimal experimental designs under correlated observations.
virtual_noise_Dopt( Xchi, Sigma_chi, chi = NULL, kappa, delta = 0.001, max_iter = NULL, xi_init = NULL, verbose = TRUE, vn_alt = 3, vn_lambda = 40, vn_delta = 1e-06, stop_rule = c("max_iter", "efficiency"), return_eff_bound = FALSE, n_target = NULL, eff_tol = NULL )virtual_noise_Dopt( Xchi, Sigma_chi, chi = NULL, kappa, delta = 0.001, max_iter = NULL, xi_init = NULL, verbose = TRUE, vn_alt = 3, vn_lambda = 40, vn_delta = 1e-06, stop_rule = c("max_iter", "efficiency"), return_eff_bound = FALSE, n_target = NULL, eff_tol = NULL )
Xchi |
Numeric matrix of dimension |
Sigma_chi |
Numeric covariance matrix of dimension
|
chi |
Candidate set used to label the selected and support points in the output. Can be:
If |
kappa |
Virtual-noise tuning parameter controlling the
weight penalization and the VN selection rules.
Smaller values of |
delta |
Numerical tolerance used in Step 2 of the VN selection rule. |
max_iter |
Maximum number of iterations of the VN algorithm. |
xi_init |
Optional initial design measure of length
|
verbose |
Logical; if |
vn_alt |
Integer in |
vn_lambda |
Numeric lambda parameter used by virtual-noise alternatives 3 and 4. |
vn_delta |
Numeric stabilization parameter used by virtual-noise alternatives 1 and 2. |
stop_rule |
Stopping rule used by the algorithm.
Use |
return_eff_bound |
Logical; if |
n_target |
Target exact design size used in the
computation of the D-efficiency diagnostic.
Required when |
eff_tol |
Efficiency tolerance in |
The algorithm iteratively updates a design measure over a candidate
set chi by selecting candidate points according to
D-optimality sensitivity rules and incorporating an additional
virtual-noise penalization mechanism.
At each iteration, the method:
Constructs a modified covariance matrix including the virtual-noise term,
Computes the corresponding information matrix,
Evaluates D-optimality selection quantities over the candidate set,
Selects a candidate point according to the VN decision rules,
Updates the design measure exactly.
The algorithm updates the weight vector xi over the candidate
set by selecting, at each iteration, a candidate point
and performing the exact update
where denotes the unit vector associated with the
selected candidate point.
The VN component modifies the covariance structure through
an additional penalization term controlled by kappa and the
selected VN alternative vn_alt.
The D-criterion is implemented as -log det(M_tilde) where
M_tilde = X^T Sigma_tilde^{-1} X and
Sigma_tilde = Sigma_chi + diag(sigma2_xi).
This implementation follows the classical VN heuristic. The optional
efficiency values returned by return_eff_bound = TRUE are useful
convergence diagnostics; they should not be read as certificates from the
convex linear-programming formulation of Pázman et al. (2022).
A list with components:
xi: final weights (length N).
crit_vals: D-criterion values over iterations.
iterations: number of executed iterations.
chosen_indices: indices selected at each iteration.
chosen_points: selected points from chi.
support_idx: indices with positive weight at the end.
support_points: support points from chi.
support_weights: normalized support weights.
If return_eff_bound = TRUE, the list also contains
eff_lb_vals, delta_vals, phi_vals,
h_max_vals, and h_xi_mean_vals.
Pázman, A. (1999). Further developments on virtual noise methods for exact optimal designs.
Pázman, A., Hainy, M., and Müller, W. G. (2022). A convex approach to optimum design of experiments with correlated observations.
López-Fidalgo, J., and Wong, W. K. (2025). Optimal Designs for Correlated Data. Annual Review of Statistics and Its Application.
This is the main user-level function of the package. It provides
a complete workflow for constructing approximate D-optimal designs
under correlated observations using the Virtual Noise (VN) algorithm
implemented in virtual_noise_Dopt.
vndesign_Dopt( chi, Xchi = NULL, theta = NULL, grad_fun = NULL, eta_fun = NULL, kappa, max_iter = NULL, xi_init = NULL, delta = 0.001, verbose = TRUE, stop_rule = c("max_iter", "efficiency"), cov_type = c("exp", "gauss", "matern32", "matern52", "spherical", "triangular", "triangular_trunc", "brownian", "ar1", "custom"), sigma2 = 1, range = 1, nugget = 0, phi = NULL, cov_fun = NULL, vn_alt = 3, vn_lambda = 40, vn_delta = 1e-06, num_step = NULL, num_rel_step = 1e-06, return_components = FALSE, return_eff_bound = FALSE, n_target = NULL, eff_tol = NULL )vndesign_Dopt( chi, Xchi = NULL, theta = NULL, grad_fun = NULL, eta_fun = NULL, kappa, max_iter = NULL, xi_init = NULL, delta = 0.001, verbose = TRUE, stop_rule = c("max_iter", "efficiency"), cov_type = c("exp", "gauss", "matern32", "matern52", "spherical", "triangular", "triangular_trunc", "brownian", "ar1", "custom"), sigma2 = 1, range = 1, nugget = 0, phi = NULL, cov_fun = NULL, vn_alt = 3, vn_lambda = 40, vn_delta = 1e-06, num_step = NULL, num_rel_step = 1e-06, return_components = FALSE, return_eff_bound = FALSE, n_target = NULL, eff_tol = NULL )
chi |
Candidate set. Either:
|
Xchi |
Optional numeric matrix of dimension |
theta |
Numeric parameter vector of length |
grad_fun |
Function |
eta_fun |
Function |
kappa |
Virtual-noise tuning parameter controlling the
weight penalization and the VN selection rules.
For the classical VN algorithm implemented here, |
max_iter |
Maximum number of iterations of the Virtual
Noise algorithm. If |
xi_init |
Optional initial design measure of length
|
delta |
Numerical tolerance used in Step 2 of the VN selection rule. |
verbose |
Logical; if |
stop_rule |
Stopping rule used by the algorithm.
Use |
cov_type |
Covariance structure passed to
|
sigma2 |
Marginal variance parameter multiplying the
covariance kernel. If |
range |
Range or scale parameter of the covariance structure. |
nugget |
Independent noise (nugget effect) added to the diagonal of the covariance matrix. Represents measurement error or small-scale variability not explained by the covariance structure, and may improve numerical stability. |
phi |
AR(1) parameter used only when
|
cov_fun |
User-defined covariance function used only when
|
vn_alt |
Integer in |
vn_lambda |
Numerical parameter used by virtual-noise alternatives 3 and 4. |
vn_delta |
Numerical stabilization parameter used by virtual-noise alternatives 1 and 2. |
num_step |
Step size(s) used in the finite-difference approximation. Can be:
|
num_rel_step |
Relative step size used when
|
return_components |
Logical; if |
return_eff_bound |
Logical; if |
n_target |
Target exact design size used in the
computation of the D-efficiency diagnostic.
Required when |
eff_tol |
Efficiency tolerance in |
The function acts as a high-level wrapper integrating most of the package functionality, including:
construction or validation of the candidate regressor matrix Xchi,
analytical or numerical gradient evaluation,
covariance matrix construction via build_Sigma,
execution of the Virtual Noise algorithm,
computation of optional efficiency diagnostics,
and generation of visualization-ready outputs.
The candidate set chi may be:
a numeric vector (one-dimensional case),
or a matrix / data.frame of dimension ,
where each row represents a candidate point.
Two modes of operation are supported:
Direct mode:
If Xchi is provided, it is used directly and no model specification
through theta, grad_fun, or eta_fun is required.
Model-based mode:
If Xchi is NULL, the function constructs it from
theta using either:
an analytical gradient function grad_fun,
or numerical finite differences via eta_fun.
This function provides a high-level interface to the Virtual Noise
methodology implemented in virtual_noise_Dopt.
For the D-criterion, the implementation minimizes ,
which is equivalent to maximizing the determinant of the information matrix.
When return_eff_bound = TRUE, the function also computes
a Pázman-type D-efficiency diagnostic along the iterations. If
stop_rule = "efficiency", this diagnostic is additionally
used as a stopping criterion, while max_iter acts as a safety
limit. Since this package implements the classical VN heuristic rather
than the convex linear-programming formulation of Pázman et al. (2022),
these values should be interpreted as convergence diagnostics.
A list containing the output of virtual_noise_Dopt.
Main components include:
xi: final design weights over the candidate set.
crit_vals: D-criterion values over the iterations.
iterations: number of executed iterations.
support_idx: indices with positive final weights.
support_points: support points from chi.
support_weights: normalized support weights.
If return_eff_bound = TRUE, the output also includes the efficiency
diagnostic values and related quantities. If return_components = TRUE,
the output additionally includes Xchi, Sigma_chi, and D.
virtual_noise_Dopt,
efficiency_bound,
build_Sigma,
build_Xchi_grad,
build_Xchi_numeric
chi <- seq(-1, 1, length.out = 15) theta <- c(0, 1) grad_fun <- function(x, theta) c(1, x) kappa <- 0.99 / length(chi) res <- vndesign_Dopt( chi = chi, theta = theta, grad_fun = grad_fun, kappa = kappa, max_iter = 5, verbose = FALSE, cov_type = "exp", range = 0.4, vn_alt = 3, vn_lambda = 2 ) head(res$xi)chi <- seq(-1, 1, length.out = 15) theta <- c(0, 1) grad_fun <- function(x, theta) c(1, x) kappa <- 0.99 / length(chi) res <- vndesign_Dopt( chi = chi, theta = theta, grad_fun = grad_fun, kappa = kappa, max_iter = 5, verbose = FALSE, cov_type = "exp", range = 0.4, vn_alt = 3, vn_lambda = 2 ) head(res$xi)