Method new()
Create a new Design Space
Creates a new design space from one or more glmmr designs.
Usage
DesignSpace$new(..., weights = NULL, experimental_condition = NULL)
Arguments
...
One or more glmmrBase Model objects. The designs must have an equal number of observations.
weights
Optional. A numeric vector of values between 0 and 1 indicating the prior weights to assign to each of the designs. The weights
are required for optimisation, if a weighted average variance is used across the designs. If not specified then designs are assumed
to have equal weighting.
experimental_condition
Optional. A vector of the same length as the number of observations in each design indicating the unique
identifier of the experimental condition that observation belongs to, see Details. If not provided, then it is assumed that all observations
are separate experimental conditions.
Returns
A `DesignSpace` object
Examples
\dontshow{
glmmrBase::setParallel(FALSE) # for the CRAN check
setParallelOptim(FALSE)
}
df <- nelder(~ ((int(2)*t(3)) > cl(3)) > ind(5))
df$int <- df$int - 1
des <- Model$new(formula = ~ int + factor(t) - 1+ (1|gr(cl)) + (1|gr(cl,t)),
covariance = c(0.04,0.01),
mean = rep(0,4),
data=df,
family=gaussian())
ds <- DesignSpace$new(des)
#add another design
des2 <- Model$new(formula = ~ int + factor(t) - 1 + (1|gr(cl)) + (1|gr(cl,t)),
covariance = c(0.05,0.8),
mean = rep(0,4),
data=df,
family=gaussian())
ds$add(des2)
#report the size of the design
ds$n()
#we can access specific designs
ds$show(2)$n()
#and then remove it
ds$remove(2)
#or we could add them when we construct object
ds <- DesignSpace$new(des,des2)
#we can specify weights
ds <- DesignSpace$new(des,des2,weights=c(0.1,0.9))
#and add experimental conditions
ds <- DesignSpace$new(des,des2,experimental_condition = df$cl)
Method add()
Add a design to the design space
Arguments
x
A `Design` to add to the design space
Examples
#See examples for constructing the class
Removes a design from the design space
Usage
DesignSpace$remove(index)
Arguments
index
Index of the design to remove
Examples
#See examples for constructing the class
Print method for the Design Space
Usage
DesignSpace$print()
Returns
Prints to the console all the designs in the design space
Examples
#See examples for constructing the class
Method n()
Returns the size of the design space and number of observations
Examples
#See examples for constructing the class
Method optimal()
Approximate c-optimal design of size m
Algorithms to identify an approximate c-optimal design of size m within the design space.
Usage
DesignSpace$optimal(
m,
C,
attenuate_pars = FALSE,
V0 = NULL,
rm_cols = NULL,
keep = FALSE,
verbose = TRUE,
algo = c(1),
use_combin = FALSE,
robust_log = FALSE,
kr = FALSE,
p,
tol = 1e-08
)
Arguments
m
A positive integer specifying the number of experimental conditions to include.
C
Either a vector or a list of vectors of the same length as the number of designs, see Details.
attenuate_pars
Logical indicating whether to adapt the marginal expecation in non-linear models
V0
Optional. If a Bayesian c-optimality problem then this should be a list of prior covariance matrices for the model parameters
the same length as the number of designs.
rm_cols
Optional. A list of vectors indicating columns of X to remove from each design, see Details.
keep
Logical indicating whether to "keep" the optimal design in the linked design objects and remove any experimental
conditions and columns that are not part of the optimal design. Irreversible, so that these observations will be lost from the
linked design objects. Defaults to FALSE.
verbose
Logical indicating whether to reported detailed output on the progress of the algorithm. Default is TRUE.
algo
A vector of integers indicating the algorithm(s) to use. 1 = local search, 2 = greedy search, 3 = reverse greedy search.
Declaring `algo = 1` for example will use the local search. Providing a vector such as `c(3,1)` will execute the algorithms in order,
so this would run a reverse greedy search followed by a local search. Note that many combinations will be redundant. For example, running
a greedy search after a local search will not have any effect. One can also use a general weights algorithm called the 'girling' algorithm,
setting `algo="girling"`.
use_combin
Logical. If the experimental conditions are uncorrelated, if this option is TRUE then the hill climbing
algorithm will be used, otherwise if it is FALSE, then a fast approximate alternative will be used. See Details
robust_log
Logical. If TRUE and there are multiple designs in the design space then the robust criterion will be a sum of the log
of the c-optimality criterion weighted by the study weights, and if FALSE then it will be a weighted sum of the absolute value.
kr
Logical. Whether to use the Kenwood-Roger small sample bias corrected variance matrix for the fixed effect parameters. We do not
recommend using this as it can produce some strange results and its behaviour is not well understood.
p
Optional. Positive integer specifying the size of the starting design for the greedy algorithm
tol
Optional scalar specifying the termination tolerance of the Girling algorithm.
Returns
A named list. If using the weighting method then the list contains the optimal experimental weights and a
list of exact designs of size `m`, see apportion. If using a combinatorial algorithm then
the list contains the rows in the optimal design, the indexes of the experimental conditions in the optimal design,
the variance from this design, and the total number of function evaluations. Optionally the linked designs are also modified (see option `keep`).
Examples
\dontshow{
glmmrBase::setParallel(FALSE) # for the CRAN check
setParallelOptim(FALSE)
}
df <- nelder(~(cl(6)*t(5)) > ind(5))
df$int <- 0
df[df$t >= df$cl, 'int'] <- 1
des <- Model$new(
formula = ~ factor(t) + int - 1 + (1|gr(cl)),
covariance = c(0.05),
mean = c(rep(0,5),0.6),
data=df,
family=gaussian(),
var_par = 1
)
ds <- DesignSpace$new(des)#find the optimal design of size 30 individuals using reverse greedy search
# change algo=1 for local search, and algo = 2 for greedy search
opt2 <- ds$optimal(30,C=list(c(rep(0,5),1)),algo=3)
#let the experimental condition be the cluster
# these experimental conditions are independent of one another
ds <- DesignSpace$new(des,experimental_condition = df$cl)
# now find the optimal 4 clusters to include
# approximately, finding the weights for each condition
opt <- ds$optimal(4,C=list(c(rep(0,5),1)))
# or use the local search algorithm
opt <- ds$optimal(4,C=list(c(rep(0,5),1)),use_combin = TRUE,algo=1)
#robust optimisation using two designs
des2 <- Model$new(
formula = ~ factor(t) + int - 1 + (1|gr(cl)*ar1(t)),
covariance = c(0.05,0.8),
mean = c(rep(0,5),0.6),
data=df,
family=gaussian(),
var_par = 1
)
ds <- DesignSpace$new(des,des2)
#weighted average assuming equal weights using local search
\donttest{
opt <- ds$optimal(30,C=list(c(rep(0,5),1),c(rep(0,5),1)),algo=1)
}
Method show()
Returns a linked design
Usage
DesignSpace$show(i)
Arguments
i
Index of the design to return
Examples
#See examples for constructing the class
Method clone()
The objects of this class are cloneable with this method.
Usage
DesignSpace$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.