Title: | Calculating Optimal and D-Augmented Designs |
---|---|
Description: | Calculates D-, Ds-, A- and I-optimal designs for non-linear models, via an implementation of the cocktail algorithm (Yu, 2011, <doi:10.1007/s11222-010-9183-2>). Compares designs via their efficiency, and D-augments any design with a controlled efficiency. An efficient rounding function has been provided to transform approximate designs to exact designs. |
Authors: | Carlos de la Calle-Arroyo [aut, cre] , Jesús López-Fidalgo [aut] , Licesio J. Rodríguez-Aragón [aut] |
Maintainer: | Carlos de la Calle-Arroyo <[email protected]> |
License: | GPL-3 |
Version: | 2.1.1 |
Built: | 2024-11-09 05:54:10 UTC |
Source: | https://github.com/kezrael/optedr |
Add two designs
add_design(design_1, design_2, alpha)
add_design(design_1, design_2, alpha)
design_1 |
A dataframe with 'Point' and 'Weight' as columns that represent the first design to add |
design_2 |
A dataframe with 'Point' and 'Weight' as columns that represent the second design to add |
alpha |
Weight of the first design |
A design as a dataframe with the weighted addition of the two designs
Given a set of points, a weight and the design, the function adds these points to the new design with uniform weight, and combined weight alpha
add_points(points, alpha, design)
add_points(points, alpha, design)
points |
Points to be added to the design |
alpha |
Combined weight of the new points to be added to the design |
design |
A design as a dataframe with "Point" and "Weight" columns |
A design as a dataframe with "Point" and "Weight" columns that is the addition of the design and the new points
Augments a design. The user gives an initial design for which he would like to add points and specifies the weight of the new points. Then he is prompted to choose a minimum efficiency. After that, the candidate points region is calculated and the user can choose the points and weights to add.
augment_design( criterion, init_design, alpha, model, parameters, par_values, design_space, calc_optimal_design, par_int = NA, matB = NULL, distribution = NA, weight_fun = function(x) 1 )
augment_design( criterion, init_design, alpha, model, parameters, par_values, design_space, calc_optimal_design, par_int = NA, matB = NULL, distribution = NA, weight_fun = function(x) 1 )
criterion |
character variable with the chosen optimality criterion. Can be one of the following:
|
init_design |
dataframe with "Point" and "Weight" columns that represents the initial design to augment |
alpha |
combined weight of the new points |
model |
formula that represents the model with x as the independent variable |
parameters |
character vector with the unknown parameters of the model to estimate |
par_values |
numeric vector with the initial values of the unknown parameters |
design_space |
numeric vector with the limits of the space of the design |
calc_optimal_design |
boolean parameter, if TRUE, the optimal design is calculated and efficiencies of the initial and augmented design are given |
par_int |
optional numeric vector with the index of the |
matB |
optional matrix of dimensions k x k, for L-optimality. |
distribution |
character specifying the probability distribution of the response. Can be one of the following:
|
weight_fun |
optional one variable function that represents the square of the structure of variance, in case of heteroscedastic variance of the response |
A dataframe that represents the D-augmented design
init_des <- data.frame("Point" = c(30, 60, 90), "Weight" = c(1/3, 1/3, 1/3)) augment_design("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), TRUE) augment_design("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), FALSE)
init_des <- data.frame("Point" = c(30, 60, 90), "Weight" = c(1/3, 1/3, 1/3)) augment_design("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), TRUE) augment_design("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), FALSE)
Function to check that the inputs given to the function opt_des
are correct. If not, throws the
correspondent error message.
check_inputs( criterion, model, parameters, par_values, design_space, init_design, join_thresh, delete_thresh, delta, tol, tol2, par_int, matB, reg_int, desired_output, weight_fun )
check_inputs( criterion, model, parameters, par_values, design_space, init_design, join_thresh, delete_thresh, delta, tol, tol2, par_int, matB, reg_int, desired_output, weight_fun )
criterion |
character variable with the chosen optimality criterion. Can be one of the following:
|
model |
formula describing the model to calculate the optimal design. Must use x as the variable. |
parameters |
character vector with the parameters of the models, as written in the |
par_values |
numeric vector with the parameters nominal values, in the same order as given in |
design_space |
numeric vector with the limits of the space of the design. |
init_design |
optional dataframe with the initial design for the algorithm. A dataframe with two columns:
|
join_thresh |
optional numeric value that states how close, in real units, two points must be in order to be joined together by the join heuristic. |
delete_thresh |
optional numeric value with the minimum weight, over 1 total, that a point needs to have in order to not be deleted from the design. |
delta |
optional numeric value in (0, 1), parameter of the algorithm. |
tol |
optional numeric value for the convergence of the weight optimizing algorithm. |
tol2 |
optional numeric value for the stop criterion: difference between maximum of sensitivity function and optimality criterion. |
par_int |
optional numeric vector with the index of the |
matB |
optional matrix of dimensions k x k, for L-optimality. |
reg_int |
optional numeric vector of two components with the bounds of the interest region for I-Optimality. |
desired_output |
not functional yet: decide which kind of output you want. |
weight_fun |
optional one variable function that represents the square of the structure of variance, in case of heteroscedastic variance of the response. |
Given an approximate design and a number of points, computes all the possible combinations of roundings of each point to the nearest integer, keeps the ones that amount to the requested number of points, and returns the one with the best value for the criterion function
combinatorial_round( design, n, criterion = NULL, model = NULL, parameters = NULL, par_values = NULL, weight_fun = function(x) 1, par_int = NULL, reg_int = NULL, matB = NULL )
combinatorial_round( design, n, criterion = NULL, model = NULL, parameters = NULL, par_values = NULL, weight_fun = function(x) 1, par_int = NULL, reg_int = NULL, matB = NULL )
design |
either a dataframe with the design to round, or an object of class "optdes". If the former, the criterion, model and parameters must be specified. The dataframe should have two columns:
|
n |
integer with the desired number of points of the resulting design. |
criterion |
character variable with the chosen optimality criterion. Can be one of the following:
|
model |
formula describing the model. Must use x as the variable. |
parameters |
character vector with the parameters of the models, as written in the |
par_values |
numeric vector with the parameters nominal values, in the same order as given in |
weight_fun |
optional one variable function that represents the square of the structure of variance, in case of heteroscedastic variance of the response. |
par_int |
optional numeric vector with the index of the |
matB |
optional matrix of dimensions k x k, for L-optimality. |
A data.frame with the rounded design to n number of points
aprox_design <- opt_des("D-Optimality", y ~ a * exp(-b / x), c("a", "b"), c(1, 1500), c(212, 422)) combinatorial_round(aprox_design, 27)
aprox_design <- opt_des("D-Optimality", y ~ a * exp(-b / x), c("a", "b"), c(1, 1500), c(212, 422)) combinatorial_round(aprox_design, 27)
Depending on the criterion input, the function returns the output of the corresponding criterion function given the information matrix.
crit(criterion, M, k = 0, par_int = c(1), matB = NA)
crit(criterion, M, k = 0, par_int = c(1), matB = NA)
criterion |
character variable with the chosen optimality criterion. Can be one of the following:
|
M |
information matrix for which the criterion value wants to be calculated. |
k |
numeric variable with the number of parameters of the model. Taken from the number of rows of the matrix if omitted. |
par_int |
numeric vector with the index of the parameters of interest of the model. Only for "Ds-Optimality". |
matB |
optional matrix of dimensions k x k, for I- and L-optimality. |
Numeric value of the optimality criterion for the information matrix.
Given the parameters for augmenting a design, this function calculates the crosspoints in the efficiency function that delimit the candidate points region
crosspoints(val, sens, gridlength, tol, xmin, xmax)
crosspoints(val, sens, gridlength, tol, xmin, xmax)
val |
Efficiency value to solve in the curve relationing the space of the design and efficiency of new design |
sens |
Sensitivity function of the design for the model |
gridlength |
Number of points in the grid to find the crosspoints |
tol |
Tolerance that establishes how close two points close to one another are considered the same |
xmin |
Minimum of the space of the design |
xmax |
Maximum of the space of the design |
A numeric vector of crosspoints that define the candidate points region
D-Augments a design. The user gives an initial design for which he would like to add points and specifies the weight of the new points. Then he is prompted to choose a minimum efficiency. After that, the candidate points region is calculated and the user can choose the points and weights to add.
daugment_design( init_design, alpha, model, parameters, par_values, design_space, calc_optimal_design, weight_fun = function(x) 1 )
daugment_design( init_design, alpha, model, parameters, par_values, design_space, calc_optimal_design, weight_fun = function(x) 1 )
init_design |
dataframe with "Point" and "Weight" columns that represents the initial design to augment |
alpha |
combined weight of the new points |
model |
formula that represents the model with x as the independent variable |
parameters |
character vector with the unknown parameters of the model to estimate |
par_values |
numeric vector with the initial values of the unknown parameters |
design_space |
numeric vector with the limits of the space of the design |
calc_optimal_design |
boolean parameter, if TRUE, the optimal design is calculated and efficiencies of the initial and augmented design are given |
weight_fun |
optional one variable function that represents the square of the structure of variance, in case of heteroscedastic variance of the response |
A dataframe that represents the D-augmented design
Other augment designs:
dsaugment_design()
,
laugment_design()
init_des <- data.frame("Point" = c(30, 60, 90), "Weight" = c(1/3, 1/3, 1/3)) augment_design("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), TRUE) augment_design("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), FALSE)
init_des <- data.frame("Point" = c(30, 60, 90), "Weight" = c(1/3, 1/3, 1/3)) augment_design("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), TRUE) augment_design("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), FALSE)
Calculates the value of the D-Optimality criterion function, which follows the expression:
dcrit(M, k)
dcrit(M, k)
M |
information matrix for which the criterion value wants to be calculated. |
k |
numeric variable with the number of parameters of the model. Taken from the number of rows of the matrix if omitted. |
numeric value of the D-optimality criterion for the information matrix.
Removes the points of a design with a weight lower than a threshold, delta
, and distributes that weights
proportionally to the rest of the points.
delete_points(design, delta)
delete_points(design, delta)
design |
The design from which to remove points as a dataframe with two columns:
|
delta |
The threshold from which the points with such a weight or lower will be removed. |
The design without the removed points.
Takes an optimal design provided from the function opt_des
and a user given design and compares their
efficiency
design_efficiency(opt_des_obj, design)
design_efficiency(opt_des_obj, design)
opt_des_obj |
an object given by the function |
design |
dataframe that represents the design. Must have two columns:
|
The efficiency as a value between 0 and 1
opt_des
result <- opt_des("D-Optimality", y ~ a * exp(-b / x), c("a", "b"), c(1, 1500), c(212, 422)) design <- data.frame("Point" = c(220, 240, 400), "Weight" = c(1 / 3, 1 / 3, 1 / 3)) design_efficiency(result, design)
result <- opt_des("D-Optimality", y ~ a * exp(-b / x), c("a", "b"), c(1, 1500), c(212, 422)) design <- data.frame("Point" = c(220, 240, 400), "Weight" = c(1 / 3, 1 / 3, 1 / 3)) design_efficiency(result, design)
Ds-Augments a design. The user gives an initial design for which he would like to add points and specifies the weight of the new points. Then he is prompted to choose a minimum efficiency. After that, the candidate points region is calculated and the user can choose the points and weights to add.
dsaugment_design( init_design, alpha, model, parameters, par_values, par_int, design_space, calc_optimal_design, weight_fun = function(x) 1 )
dsaugment_design( init_design, alpha, model, parameters, par_values, par_int, design_space, calc_optimal_design, weight_fun = function(x) 1 )
init_design |
dataframe with "Point" and "Weight" columns that represents the initial design to augment |
alpha |
combined weight of the new points |
model |
formula that represents the model with x as the independent variable |
parameters |
character vector with the unknown parameters of the model to estimate |
par_values |
numeric vector with the initial values of the unknown parameters |
par_int |
optional numeric vector with the index of the |
design_space |
numeric vector with the limits of the space of the design |
calc_optimal_design |
boolean parameter, if TRUE, the optimal design is calculated and efficiencies of the initial and augmented design are given |
weight_fun |
optional one variable function that represents the square of the structure of variance, in case of heteroscedastic variance of the response |
A dataframe that represents the Ds-augmented design
Other augment designs:
daugment_design()
,
laugment_design()
init_des <- data.frame("Point" = c(30, 60, 90), "Weight" = c(1/3, 1/3, 1/3)) augment_design("Ds-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), par_int = c(1), TRUE) augment_design("Ds-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), par_int = c(1), FALSE)
init_des <- data.frame("Point" = c(30, 60, 90), "Weight" = c(1/3, 1/3, 1/3)) augment_design("Ds-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), par_int = c(1), TRUE) augment_design("Ds-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), par_int = c(1), FALSE)
Calculates the value of the Ds-Optimality criterion function, which follows the expression:
dscrit(M, par_int)
dscrit(M, par_int)
M |
information matrix for which the criterion value wants to be calculated. |
par_int |
numeric vector with the index of the parameters of interest of the model. |
Numeric value of the Ds-optimality criterion for the information matrix.
Calculates the sensitivity function from the gradient vector and the Identity Matrix.
dsens(grad, M)
dsens(grad, M)
grad |
A function in a single variable that returns the partial derivatives vector of the model. |
M |
Information Matrix for the sensitivity function. |
The sensitivity function as a matrix of single variable.
Calculates the sensitivity function from the gradient vector, the Identity Matrix and the parameters of interest.
dssens(grad, M, par_int)
dssens(grad, M, par_int)
grad |
A function in a single variable that returns the partial derivatives vector of the model. |
M |
Information Matrix for the sensitivity function. |
par_int |
Numeric vector of the indexes of the parameters of interest for Ds-Optimality. |
The sensitivity function as a matrix of single variable.
Function that calculates the Ds-Optimal designs for the interest parameters given by intPar
. The
rest of the parameters can help the convergence of the algorithm.
DsWFMult( init_design, grad, par_int, min, max, grid.length, join_thresh, delete_thresh, delta_weights, tol, tol2 )
DsWFMult( init_design, grad, par_int, min, max, grid.length, join_thresh, delete_thresh, delta_weights, tol, tol2 )
init_design |
optional dataframe with the initial design for the algorithm. A dataframe with two columns:
|
grad |
function of partial derivatives of the model. |
par_int |
numeric vector with the index of the |
min |
numeric value with the inferior bound of the space of the design. |
max |
numeric value with the upper bound of the space of the design. |
grid.length |
numeric value that gives the grid to evaluate the sensitivity function when looking for a maximum. |
join_thresh |
numeric value that states how close, in real units, two points must be in order to be joined together by the join heuristic. |
delete_thresh |
numeric value with the minimum weight, over 1 total, that a point needs to have in order to not be deleted from the design. |
delta_weights |
numeric value in (0, 1), parameter of the algorithm. |
tol |
numeric value for the convergence of the weight optimizing algorithm. |
tol2 |
numeric value for the stop condition of the algorithm. |
list correspondent to the output of the correspondent algorithm called, dependent on the criterion. A list of two objects:
optdes: a dataframe with the optimal design in two columns, Point
and Weight
.
sens: a plot with the sensitivity function to check for optimality of the design.
Other cocktail algorithms:
DWFMult()
,
IWFMult()
,
WFMult()
Function that calculates the DsOptimal design. The rest of the parameters can help the convergence of the algorithm.
DWFMult( init_design, grad, min, max, grid.length, join_thresh, delete_thresh, k, delta_weights, tol, tol2 )
DWFMult( init_design, grad, min, max, grid.length, join_thresh, delete_thresh, k, delta_weights, tol, tol2 )
init_design |
optional dataframe with the initial design for the algorithm. A dataframe with two columns:
|
grad |
function of partial derivatives of the model. |
min |
numeric value with the inferior bound of the space of the design. |
max |
numeric value with the upper bound of the space of the design. |
grid.length |
numeric value that gives the grid to evaluate the sensitivity function when looking for a maximum. |
join_thresh |
numeric value that states how close, in real units, two points must be in order to be joined together by the join heuristic. |
delete_thresh |
numeric value with the minimum weight, over 1 total, that a point needs to have in order to not be deleted from the design. |
k |
number of unknown parameters of the model. |
delta_weights |
numeric value in (0, 1), parameter of the algorithm. |
tol |
numeric value for the convergence of the weight optimizing algorithm. |
tol2 |
numeric value for the stop condition of the algorithm. |
list correspondent to the output of the correspondent algorithm called, dependent on the criterion. A list of two objects:
optdes: a dataframe with the optimal design in two columns, Point
and Weight
.
sens: a plot with the sensitivity function to check for optimality of the design.
Other cocktail algorithms:
DsWFMult()
,
IWFMult()
,
WFMult()
Efficiency between two Information Matrices
eff(criterion, mat1, mat2, k = 0, intPars = c(1), matB = NA)
eff(criterion, mat1, mat2, k = 0, intPars = c(1), matB = NA)
criterion |
character variable with the chosen optimality criterion. Can be one of the following:
|
mat1 |
first information matrix, for the numerator. |
mat2 |
second information matrix, for the denominator. |
k |
number of parameters of the model. Taken from the number of rows of the matrix if omitted. |
intPars |
numeric vector with the index of the parameters of interest of the model. Only for "Ds-Optimality". |
matB |
matrix of the integral of the information matrix over the interest region. Only for "I-Optimality". |
Efficiency of first design with respect to the second design, as a decimal number.
Takes an approximate design, and a number of points and converts the design to an approximate design. It uses the multiplier (n - l/2) and evens the total number of observations afterwards.
efficient_round(design, n, tol = 1e-05)
efficient_round(design, n, tol = 1e-05)
design |
a dataframe with columns "Point" and "Weight" that represents a design |
n |
an integer that represents the desired number of observations of the exact design |
tol |
optional parameter for the consideration of an integer in the rounding process |
a data.frame with columns "Point" and "Weight" representing an exact design with n observations
design_test <- data.frame("Point" = seq(1, 5, length.out = 7), "Weight" = c(0.1, 0.0001, 0.2, 0.134, 0.073, 0.2111, 0.2818)) efficient_round(design_test, 20) exact_design <- efficient_round(design_test, 21) aprox_design <- exact_design aprox_design$Weight <- aprox_design$Weight/sum(aprox_design$Weight)
design_test <- data.frame("Point" = seq(1, 5, length.out = 7), "Weight" = c(0.1, 0.0001, 0.2, 0.134, 0.073, 0.2111, 0.2818)) efficient_round(design_test, 20) exact_design <- efficient_round(design_test, 21) aprox_design <- exact_design aprox_design$Weight <- aprox_design$Weight/sum(aprox_design$Weight)
Searches the maximum of a function over a grid on a given interval.
findmax(sens, min, max, grid.length)
findmax(sens, min, max, grid.length)
sens |
A single variable numeric function to evaluate. |
min |
Minimum value of the search interval. |
max |
Maximum value of the search interval. |
grid.length |
Length of the search interval. |
The value at which the maximum is obtained
Searches the maximum of a function over a grid on a given interval.
findmaxval(sens, min, max, grid.length)
findmaxval(sens, min, max, grid.length)
sens |
A single variable numeric function to evaluate. |
min |
Minimum value of the search interval. |
max |
Maximum value of the search interval. |
grid.length |
Length of the search interval. |
The value of the maximum
Searches the maximum of a function over a grid on a given grid.
findminval(sens, min, max, grid.length)
findminval(sens, min, max, grid.length)
sens |
a single variable numeric function to evaluate. |
min |
minimum value of the search grid. |
max |
maximum value of the search grid. |
grid.length |
length of the search grid. |
The value of the minimum
Given a model and criterion, calculates the candidate points region. The user gives an initial design for which he would like to add points and specifies the weight of the new points. Then he is prompted to choose a minimum efficiency. After that, the candidate points region is calculated.
get_augment_region( criterion, init_design, alpha, model, parameters, par_values, design_space, calc_optimal_design, par_int = NA, matB = NA, distribution = NA, weight_fun = function(x) 1 )
get_augment_region( criterion, init_design, alpha, model, parameters, par_values, design_space, calc_optimal_design, par_int = NA, matB = NA, distribution = NA, weight_fun = function(x) 1 )
criterion |
character with the chosen optimality criterion. Can be one of the following:
|
init_design |
dataframe with "Point" and "Weight" columns that represents the initial design to augment |
alpha |
combined weight of the new points |
model |
formula that represent the model with x as the independent variable |
parameters |
character vector with the unknown parameters of the model to estimate |
par_values |
numeric vector with the initial values of the unknown parameters |
design_space |
numeric vector with the limits of the space of the design |
calc_optimal_design |
boolean parameter, if TRUE, the optimal design is calculated and efficiencies of the initial and augmented design are given |
par_int |
optional numeric vector with the index of the |
matB |
optional matrix of dimensions k x k, for L-optimality. |
distribution |
character specifying the probability distribution of the response. Can be one of the following:
|
weight_fun |
optional one variable function that represents the square of the structure of variance, in case of heteroscedastic variance of the response |
A vector of the points limiting the candidate points region
init_des <- data.frame("Point" = c(30, 60, 90), "Weight" = c(1/3, 1/3, 1/3)) get_augment_region("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), TRUE) get_augment_region("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), FALSE)
init_des <- data.frame("Point" = c(30, 60, 90), "Weight" = c(1/3, 1/3, 1/3)) get_augment_region("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), TRUE) get_augment_region("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), FALSE)
Given a model, calculates the candidate points region for D-Optimality. The user gives an initial design for which he would like to add points and specifies the weight of the new points. Then he is prompted to choose a minimum efficiency. After that, the candidate points region is calculated.
get_daugment_region( init_design, alpha, model, parameters, par_values, design_space, calc_optimal_design, weight_fun = function(x) 1 )
get_daugment_region( init_design, alpha, model, parameters, par_values, design_space, calc_optimal_design, weight_fun = function(x) 1 )
init_design |
dataframe with "Point" and "Weight" columns that represents the initial design to augment |
alpha |
combined weight of the new points |
model |
formula that represent the model with x as the independent variable |
parameters |
character vector with the unknown parameters of the model to estimate |
par_values |
numeric vector with the initial values of the unknown parameters |
design_space |
numeric vector with the limits of the space of the design |
calc_optimal_design |
boolean parameter, if TRUE, the optimal design is calculated and efficiencies of the initial and augmented design are given |
weight_fun |
optional one variable function that represents the square of the structure of variance, in case of heteroscedastic variance of the response |
A vector of the points limiting the candidate points region
init_des <- data.frame("Point" = c(30, 60, 90), "Weight" = c(1/3, 1/3, 1/3)) get_augment_region("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), TRUE) get_augment_region("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), FALSE)
init_des <- data.frame("Point" = c(30, 60, 90), "Weight" = c(1/3, 1/3, 1/3)) get_augment_region("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), TRUE) get_augment_region("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), FALSE)
Given a model, calculates the candidate points region for Ds-Optimality. The user gives an initial design for which he would like to add points and specifies the weight of the new points. Then he is prompted to choose a minimum efficiency. After that, the candidate points region is calculated.
get_dsaugment_region( init_design, alpha, model, parameters, par_values, par_int, design_space, calc_optimal_design, weight_fun = function(x) 1 )
get_dsaugment_region( init_design, alpha, model, parameters, par_values, par_int, design_space, calc_optimal_design, weight_fun = function(x) 1 )
init_design |
dataframe with "Point" and "Weight" columns that represents the initial design to augment |
alpha |
combined weight of the new points |
model |
formula that represent the model with x as the independent variable |
parameters |
character vector with the unknown parameters of the model to estimate |
par_values |
numeric vector with the initial values of the unknown parameters |
par_int |
optional numeric vector with the index of the |
design_space |
numeric vector with the limits of the space of the design |
calc_optimal_design |
boolean parameter, if TRUE, the optimal design is calculated and efficiencies of the initial and augmented design are given |
weight_fun |
optional one variable function that represents the square of the structure of variance, in case of heteroscedastic variance of the response |
A vector of the points limiting the candidate points region
Other augment region:
get_laugment_region()
init_des <- data.frame("Point" = c(30, 60, 90), "Weight" = c(1/3, 1/3, 1/3)) get_augment_region("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), TRUE) get_augment_region("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), FALSE)
init_des <- data.frame("Point" = c(30, 60, 90), "Weight" = c(1/3, 1/3, 1/3)) get_augment_region("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), TRUE) get_augment_region("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), FALSE)
Given a model, calculates the candidate points region for L-Optimality. The user gives an initial design for which he would like to add points and specifies the weight of the new points. Then he is prompted to choose a minimum efficiency. After that, the candidate points region is calculated.
get_laugment_region( init_design, alpha, model, parameters, par_values, design_space, calc_optimal_design, matB, weight_fun = function(x) 1 )
get_laugment_region( init_design, alpha, model, parameters, par_values, design_space, calc_optimal_design, matB, weight_fun = function(x) 1 )
init_design |
dataframe with "Point" and "Weight" columns that represents the initial design to augment |
alpha |
combined weight of the new points |
model |
formula that represent the model with x as the independent variable |
parameters |
character vector with the unknown parameters of the model to estimate |
par_values |
numeric vector with the initial values of the unknown parameters |
design_space |
numeric vector with the limits of the space of the design |
calc_optimal_design |
boolean parameter, if TRUE, the optimal design is calculated and efficiencies of the initial and augmented design are given |
matB |
optional matrix of dimensions k x k, for L-optimality. |
weight_fun |
optional one variable function that represents the square of the structure of variance, in case of heteroscedastic variance of the response |
A vector of the points limiting the candidate points region
Other augment region:
get_dsaugment_region()
init_des <- data.frame("Point" = c(30, 60, 90), "Weight" = c(1/3, 1/3, 1/3)) get_augment_region("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), TRUE) get_augment_region("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), FALSE)
init_des <- data.frame("Point" = c(30, 60, 90), "Weight" = c(1/3, 1/3, 1/3)) get_augment_region("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), TRUE) get_augment_region("D-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), FALSE)
Given the start of the candidates points region, the parity of the crosspoints and the boundaries of the space of the design returns the effective limits of the candidate points region. Those points, taken in pairs from the first to the last delimit the region.
getCross2(cross, min, max, start, par)
getCross2(cross, min, max, start, par)
cross |
Vector of crosspoints in the sensitivity function given an efficiency and weight |
min |
Minimum of the space of the design |
max |
Maximum of the space of the design |
start |
Boolean that gives the effective start of the candidate points region |
par |
Boolean with the parity of the region |
Vector of effective limits of the candidate points region. Taken in pairs from the beginning delimit the region.
Determines if the number of crosspoints is even or odd given the vector of crosspoints
getPar(cross)
getPar(cross)
cross |
Vector of crosspoints in the sensitivity function given an efficiency and weight |
True if the number of crosspoints is even, false otherwise
Given the crosspoints and the sensitivity function, this function finds where the candidate points region starts, either on the extreme of the space of the design or the first crosspoints
getStart(cross, min, max, val, sens_opt)
getStart(cross, min, max, val, sens_opt)
cross |
Vector of crosspoints in the sensitivity function given an efficiency and weight |
min |
Minimum of the space of the design |
max |
Maximum of the space of the design |
val |
Value of the sensitivity function at the crosspoints |
sens_opt |
Sensitivity function |
True if the candidate points region starts on the minimum, False otherwise
Calculates the gradient function of a model
with respect to the parameters, char_vars
, evaluates
it at the provided values
and returns the result as a function of the variable x
.
gradient(model, char_vars, values, weight_fun = function(x) 1)
gradient(model, char_vars, values, weight_fun = function(x) 1)
model |
formula describing the model, which must contain only |
char_vars |
character vector of the parameters of the model. |
values |
numeric vector with the nominal values of the parameters in |
weight_fun |
optional function variable that represents the square of the structure of variance, in case of heteroscedastic variance of the response |
A function depending on x
that's the gradient of the model
with respect to char_vars
Calculates the gradient function of a model
with respect to a subset of the parameters given in
par_int
, char_vars
, evaluates it at the provided values
and returns the result as
a function of the variable x
.
gradient22(model, char_vars, values, par_int, weight_fun = function(x) 1)
gradient22(model, char_vars, values, par_int, weight_fun = function(x) 1)
model |
formula describing the model, which must contain only |
char_vars |
character vector of the parameters of the model. |
values |
numeric vector with the nominal values of the parameters in |
par_int |
vector of indexes indicating the subset of variables to omit in the calculation of the gradient. |
weight_fun |
optional one variable function that represents the square of the structure of variance, in case of heteroscedastic variance of the response |
A function depending on x
that's the gradient of the model
with respect to char_vars
Calculates the value of the I-Optimality criterion function, which follows the expression:
icrit(M, matB)
icrit(M, matB)
M |
information matrix for which the criterion value wants to be calculated. |
matB |
matrix of the integral of the information matrix over the interest region. Identity matrix for A-Optimality. |
Numeric value of the I-optimality criterion for the information matrix.
Given the gradient vector of a model in a single variable model and a design, calculates the information matrix.
inf_mat(grad, design)
inf_mat(grad, design)
grad |
A function in a single variable that returns the partial derivatives vector of the model. |
design |
A dataframe that represents the design. Must have two columns:
|
The information matrix of the design, a matrix where k is the length of the gradient.
Integrates the information matrix over the region of interest to calculate matrix B to be used in I-Optimality calculation.
integrate_reg_int(grad, k, reg_int)
integrate_reg_int(grad, k, reg_int)
grad |
function of partial derivatives of the model. |
k |
number of unknown parameters of the model. |
reg_int |
optional numeric vector of two components with the bounds of the interest region for I-Optimality. |
The integrated information matrix.
Calculates the sensitivity function from the gradient vector, the Information Matrix and the integral of the one-point Identity Matrix over the interest region. If instead the identity matrix is used, it can be used for A-Optimality.
isens(grad, M, matB)
isens(grad, M, matB)
grad |
A function in a single variable that returns the partial derivatives vector of the model. |
M |
Information Matrix for the sensitivity function. |
matB |
Matrix resulting from the integration of the one-point Information Matrix along the interest region or lineal matrix for L-Optimality. |
The sensitivity function as a matrix of single variable.
Function that calculates the I-Optimal designs given the matrix B (should be integral of the information matrix over the interest region), or A-Optimal if given diag(k). The rest of the parameters can help the convergence of the algorithm.
IWFMult( init_design, grad, matB, min, max, grid.length, join_thresh, delete_thresh, delta_weights, tol, tol2, crit_name )
IWFMult( init_design, grad, matB, min, max, grid.length, join_thresh, delete_thresh, delta_weights, tol, tol2, crit_name )
init_design |
optional dataframe with the initial design for the algorithm. A dataframe with two columns:
|
grad |
function of partial derivatives of the model. |
matB |
optional matrix of dimensions k x k, for L-optimality. |
min |
numeric value with the inferior bound of the space of the design. |
max |
numeric value with the upper bound of the space of the design. |
grid.length |
numeric value that gives the grid to evaluate the sensitivity function when looking for a maximum. |
join_thresh |
numeric value that states how close, in real units, two points must be in order to be joined together by the join heuristic. |
delete_thresh |
numeric value with the minimum weight, over 1 total, that a point needs to have in order to not be deleted from the design. |
delta_weights |
numeric value in (0, 1), parameter of the algorithm. |
tol |
numeric value for the convergence of the weight optimizing algorithm. |
tol2 |
numeric value for the stop condition of the algorithm. |
list correspondent to the output of the correspondent algorithm called, dependent on the criterion. A list of two objects:
optdes: a dataframe with the optimal design in two columns, Point
and Weight
.
sens: a plot with the sensitivity function to check for optimality of the design.
Other cocktail algorithms:
DWFMult()
,
DsWFMult()
,
WFMult()
L-Augments a design. The user gives an initial design for which he would like to add points and specifies the weight of the new points. Then he is prompted to choose a minimum efficiency. After that, the candidate points region is calculated and the user can choose the points and weights to add.
laugment_design( init_design, alpha, model, parameters, par_values, design_space, calc_optimal_design, matB, weight_fun = function(x) 1 )
laugment_design( init_design, alpha, model, parameters, par_values, design_space, calc_optimal_design, matB, weight_fun = function(x) 1 )
init_design |
dataframe with "Point" and "Weight" columns that represents the initial design to augment |
alpha |
combined weight of the new points |
model |
formula that represents the model with x as the independent variable |
parameters |
character vector with the unknown parameters of the model to estimate |
par_values |
numeric vector with the initial values of the unknown parameters |
design_space |
numeric vector with the limits of the space of the design |
calc_optimal_design |
boolean parameter, if TRUE, the optimal design is calculated and efficiencies of the initial and augmented design are given |
matB |
optional matrix of dimensions k x k, for L-optimality. |
weight_fun |
optional one variable function that represents the square of the structure of variance, in case of heteroscedastic variance of the response |
A dataframe that represents the L-augmented design
Other augment designs:
daugment_design()
,
dsaugment_design()
init_des <- data.frame("Point" = c(30, 60, 90), "Weight" = c(1/3, 1/3, 1/3)) augment_design("I-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), TRUE) augment_design("I-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), FALSE)
init_des <- data.frame("Point" = c(30, 60, 90), "Weight" = c(1/3, 1/3, 1/3)) augment_design("I-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), TRUE) augment_design("I-Optimality", init_des, 0.25, y ~ 10^(a-b/(c+x)), c("a","b","c"), c(8.07131, 1730.63, 233.426), c(1, 100), FALSE)
The opt_des function calculates the optimal design for an optimality criterion and a model input from the user. The parameters allows for the user to customize the parameters for the cocktail algorithm in case the default set does not provide a satisfactory output. Depending on the criterion, additional details are necessary. For 'Ds-Optimality' the par_int parameter is necessary. For 'I-Optimality' either the matB or reg_int must be provided.
opt_des( criterion, model, parameters, par_values = c(1), design_space, init_design = NULL, join_thresh = -1, delete_thresh = 0.02, delta = 1/2, tol = 1e-05, tol2 = 1e-05, par_int = NULL, matB = NULL, reg_int = NULL, desired_output = c(1, 2), distribution = NA, weight_fun = function(x) 1 )
opt_des( criterion, model, parameters, par_values = c(1), design_space, init_design = NULL, join_thresh = -1, delete_thresh = 0.02, delta = 1/2, tol = 1e-05, tol2 = 1e-05, par_int = NULL, matB = NULL, reg_int = NULL, desired_output = c(1, 2), distribution = NA, weight_fun = function(x) 1 )
criterion |
character variable with the chosen optimality criterion. Can be one of the following:
|
model |
formula describing the model to calculate the optimal design. Must use x as the variable. |
parameters |
character vector with the parameters of the models, as written in the |
par_values |
numeric vector with the parameters nominal values, in the same order as given in |
design_space |
numeric vector with the limits of the space of the design. |
init_design |
optional dataframe with the initial design for the algorithm. A dataframe with two columns:
|
join_thresh |
optional numeric value that states how close, in real units, two points must be in order to be joined together by the join heuristic. |
delete_thresh |
optional numeric value with the minimum weight, over 1 total, that a point needs to have in order to not be deleted from the design. |
delta |
optional numeric value in (0, 1), parameter of the algorithm. |
tol |
optional numeric value for the convergence of the weight optimizing algorithm. |
tol2 |
optional numeric value for the stop criterion: difference between maximum of sensitivity function and optimality criterion. |
par_int |
optional numeric vector with the index of the |
matB |
optional matrix of dimensions k x k, for L-optimality. |
reg_int |
optional numeric vector of two components with the bounds of the interest region for I-Optimality. |
desired_output |
not functional yet: decide which kind of output you want. |
distribution |
character variable specifying the probability distribution of the response. Can be one of the following:
|
weight_fun |
optional one variable function that represents the square of the structure of variance, in case of heteroscedastic variance of the response. |
a list of two objects:
optdes: a dataframe with the optimal design in two columns, Point
and Weight
.
sens: a plot with the sensitivity function to check for optimality of the design.
opt_des("D-Optimality", y ~ a * exp(-b / x), c("a", "b"), c(1, 1500), c(212, 422))
opt_des("D-Optimality", y ~ a * exp(-b / x), c("a", "b"), c(1, 1500), c(212, 422))
Plots the criterion value on each of the steps of the algorithm, both for optimizing weights and points, against the total step number.
plot_convergence(convergence)
plot_convergence(convergence)
convergence |
A dataframe with two columns:
|
A ggplot object with the criteria
in the y
axis and step
in the x
axis.
Plots the sensitivity function and the value of the Equivalence Theorem as an horizontal line, which helps assess the optimality of the design of the given sensitivity function.
plot_sens(min, max, sens_function, criterion_value)
plot_sens(min, max, sens_function, criterion_value)
min |
Minimum of the space of the design, used in the limits of the representation. |
max |
Maximum of the space of the design, used in the limits of the representation. |
sens_function |
A single variable function, the sensitivity function. |
criterion_value |
A numeric value representing the other side of the inequality of the Equivalence Theorem. |
A ggplot
object that represents the sensitivity function
Plot function for optdes
## S3 method for class 'optdes' plot(x, ...)
## S3 method for class 'optdes' plot(x, ...)
x |
An object of class |
... |
Possible extra arguments for plotting dataframes |
rri <- opt_des(Criterion = "I-Optimality", model = y ~ a * exp(-b / x), parameters = c("a", "b"), par_values = c(1, 1500), design_space = c(212, 422), reg_int = c(380, 422)) plot(rri)
rri <- opt_des(Criterion = "I-Optimality", model = y ~ a * exp(-b / x), parameters = c("a", "b"), par_values = c(1, 1500), design_space = c(212, 422), reg_int = c(380, 422)) plot(rri)
Print function for optdes
## S3 method for class 'optdes' print(x, ...)
## S3 method for class 'optdes' print(x, ...)
x |
An object of class |
... |
Possible extra arguments for printing dataframes |
rri <- opt_des(Criterion = "I-Optimality", model = y ~ a * exp(-b / x), parameters = c("a", "b"), par_values = c(1, 1500), design_space = c(212, 422), reg_int = c(380, 422)) print(rri)
rri <- opt_des(Criterion = "I-Optimality", model = y ~ a * exp(-b / x), parameters = c("a", "b"), par_values = c(1, 1500), design_space = c(212, 422), reg_int = c(380, 422)) print(rri)
Calculates the sensitivity function given the desired Criterion
, an information matrix and other
necessary values depending on the chosen criterion.
sens(Criterion, grad, M, par_int = c(1), matB = NA)
sens(Criterion, grad, M, par_int = c(1), matB = NA)
Criterion |
character variable with the chosen optimality criterion. Can be one of the following:
|
grad |
A function in a single variable that returns the partial derivatives vector of the model. |
M |
Information Matrix for the sensitivity function. |
par_int |
Numeric vector of the indexes of the parameters of interest for Ds-Optimality. |
matB |
Matrix resulting from the integration of the one-point Information Matrix along the interest region or lineal matrix for L-Optimality. |
The sensitivity function as a matrix of single variable.
Launches the demo shiny application to D-augment several prespecified models
shiny_augment()
shiny_augment()
shiny_augment()
shiny_augment()
Launches the demo shiny application to calculate optimal designs for Antoine's Equation
shiny_optimal()
shiny_optimal()
shiny_optimal()
shiny_optimal()
Summary function for optdes
## S3 method for class 'optdes' summary(object, ...)
## S3 method for class 'optdes' summary(object, ...)
object |
An object of class |
... |
Possible extra arguments for the summary |
rri <- opt_des(Criterion = "I-Optimality", model = y ~ a * exp(-b / x), parameters = c("a", "b"), par_values = c(1, 1500), design_space = c(212, 422), reg_int = c(380, 422)) summary(rri)
rri <- opt_des(Criterion = "I-Optimality", model = y ~ a * exp(-b / x), parameters = c("a", "b"), par_values = c(1, 1500), design_space = c(212, 422), reg_int = c(380, 422)) summary(rri)
Return the mathematical trace of a matrix, the sum of its diagonal elements.
tr(M)
tr(M)
M |
The matrix from which to calculate the trace. |
The trace of the matrix.
Updates a design adding a new point to it. If the added point is closer than delta
to an existing
point of the design, the two points are merged together as their arithmetic average. Then updates the weights
to be equal to all points of the design.
update_design(design, xmax, delta, new_weight)
update_design(design, xmax, delta, new_weight)
design |
Design to update. It's a dataframe with two columns:
|
xmax |
The point to add as a numeric value. |
delta |
Threshold which defines how close the new point has to be to any of the existing ones in order to merge with them. |
new_weight |
Number with the weight for the new point. |
The updated design.
Takes a design and merge together all points that are closer between them than a certain threshold delta
.
update_design_total(design, delta)
update_design_total(design, delta)
design |
The design to update. It's a dataframe with two columns:
|
delta |
Threshold which defines how close two points have to be to any of the existing ones in order to merge with them. |
The updated design.
Within a vector of points, deletes points that are close enough (less than the tol parameter). Returns the points without the "duplicates"
update_sequence(points, tol)
update_sequence(points, tol)
points |
Points to be updated |
tol |
Tolerance for which two points are considered the same |
The points without duplicates
Implementation of the weight update formula for D-Optimality used to optimize the weights of a design, which is to be applied iteratively until no sizable changes happen.
update_weights(design, sens, k, delta)
update_weights(design, sens, k, delta)
design |
Design to optimize the weights from. It's a dataframe with two columns:
|
sens |
Sensibility function for the design and model. |
k |
Number of parameters of the model. |
delta |
A parameter of the algorithm that can be tuned. Must be |
returns the new weights of the design after one iteration.
Implementation of the weight update formula for Ds-Optimality used to optimize the weights of a design, which is to be applied iteratively until no sizable changes happen.
update_weightsDS(design, sens, s, delta)
update_weightsDS(design, sens, s, delta)
design |
Design to optimize the weights from. It's a dataframe with two columns:
|
sens |
Sensibility function for the design and model. |
s |
number of parameters of interest of the model |
delta |
A parameter of the algorithm that can be tuned. Must be |
returns the new weights of the design after one iteration.
Implementation of the weight update formula for I-Optimality used to optimize the weights of a design, which is to be applied iteratively until no sizable changes happen. A-Optimality if instead of the integral matrix the identity function is used.
update_weightsI(design, sens, crit, delta)
update_weightsI(design, sens, crit, delta)
design |
Design to optimize the weights from. It's a dataframe with two columns:
|
sens |
Sensibility function for the design and model. |
crit |
Value of the criterion function for I-Optimality. |
delta |
A parameter of the algorithm that can be tuned. Must be |
returns the new weights of the design after one iteration.
Weight function per distribution
weight_function(model, char_vars, values, distribution = "Homoscedasticity")
weight_function(model, char_vars, values, distribution = "Homoscedasticity")
model |
formula describing the model to use. Must use x as the variable. |
char_vars |
character vector with the parameters of the models, as written in the |
values |
numeric vector with the parameters nominal values, in the same order as given in |
distribution |
character variable specifying the probability distribution of the response. Can be one of the following:
|
one variable function that represents the square of the structure of variance, in case of heteroscedastic variance of the response.
Depending on the Criterion
the cocktail algorithm for the chosen criterion is called,
and the necessary parameters for the functions are given from the user input.
WFMult( init_design, grad, criterion, par_int = NA, matB = NA, min, max, grid.length, join_thresh, delete_thresh, k, delta_weights, tol, tol2 )
WFMult( init_design, grad, criterion, par_int = NA, matB = NA, min, max, grid.length, join_thresh, delete_thresh, k, delta_weights, tol, tol2 )
init_design |
optional dataframe with the initial design for the algorithm. A dataframe with two columns:
|
grad |
function of partial derivatives of the model. |
criterion |
character variable with the chosen optimality criterion. Can be one of the following:
|
par_int |
numeric vector with the index of the |
matB |
optional matrix of dimensions k x k, for L-optimality. |
min |
numeric value with the inferior bound of the space of the design. |
max |
numeric value with the upper bound of the space of the design. |
grid.length |
numeric value that gives the grid to evaluate the sensitivity function when looking for a maximum. |
join_thresh |
numeric value that states how close, in real units, two points must be in order to be joined together by the join heuristic. |
delete_thresh |
numeric value with the minimum weight, over 1 total, that a point needs to have in order to not be deleted from the design. |
k |
number of unknown parameters of the model. |
delta_weights |
numeric value in (0, 1), parameter of the algorithm. |
tol |
numeric value for the convergence of the weight optimizing algorithm. |
tol2 |
numeric value for the stop condition of the algorithm. |
list correspondent to the output of the correspondent algorithm called, dependent on the criterion. A list of two objects:
optdes: a dataframe with the optimal design in two columns, Point
and Weight
.
sens: a plot with the sensitivity function to check for optimality of the design.
Other cocktail algorithms:
DWFMult()
,
DsWFMult()
,
IWFMult()