Optimize the objective function. The function works for both discrete and continuous optimization variables. This function takes information from the PopED database supplied as an argument. The PopED database supplies information about the the model, parameters, design and methods to use. Some of the arguments coming from the PopED database can be overwritten; if they are supplied then they are used instead of the arguments from the PopED database.
poped_optimize(poped.db, ni = NULL, xt = NULL, model_switch = NULL,
x = NULL, a = NULL, bpop = NULL, d = NULL, maxxt = NULL,
minxt = NULL, maxa = NULL, mina = NULL, fmf = 0, dmf = 0,
trflag = TRUE, opt_xt = poped.db$settings$optsw[2],
opt_a = poped.db$settings$optsw[4], opt_x = poped.db$settings$optsw[3],
opt_samps = poped.db$settings$optsw[1],
opt_inds = poped.db$settings$optsw[5], cfaxt = poped.db$settings$cfaxt,
cfaa = poped.db$settings$cfaa, rsit = poped.db$settings$rsit,
rsit_output = poped.db$settings$rsit_output,
fim.calc.type = poped.db$settings$iFIMCalculationType,
ofv_calc_type = poped.db$settings$ofv_calc_type,
approx_type = poped.db$settings$iApproximationMethod,
bUseExchangeAlgorithm = poped.db$settings$bUseExchangeAlgorithm, iter = 1,
d_switch = poped.db$settings$d_switch,
ED_samp_size = poped.db$settings$ED_samp_size,
bLHS = poped.db$settings$bLHS,
use_laplace = poped.db$settings$iEDCalculationType, ...)
A PopED database.
A vector of the number of samples in each group.
A matrix of sample times. Each row is a vector of sample times for a group.
A matrix that is the same size as xt, specifying which model each sample belongs to.
A matrix for the discrete design variables. Each row is a group.
A matrix of covariates. Each row is a group.
Matrix defining the fixed effects, per row (row number = parameter_number) we should have:
column 1 the type of the distribution for E-family designs (0 = Fixed, 1 = Normal, 2 = Uniform, 3 = User Defined Distribution, 4 = lognormal and 5 = truncated normal)
column 2 defines the mean.
column 3 defines the variance of the distribution (or length of uniform distribution).
Can also just supply the parameter values as a vector c()
if no uncertainty around the
parameter value is to be used.
Matrix defining the diagnonals of the IIV (same logic as for the fixed efects
matrix bpop to define uncertainty). One can also just supply the parameter values as a c()
.
Matrix or single value defining the maximum value for each xt sample. If a single value is supplied then all xt values are given the same maximum value.
Matrix or single value defining the minimum value for each xt sample. If a single value is supplied then all xt values are given the same minimum value
Vector defining the max value for each covariate. If a single value is supplied then all a values are given the same max value
Vector defining the min value for each covariate. If a single value is supplied then all a values are given the same max value
The initial value of the FIM. If set to zero then it is computed.
The inital OFV. If set to zero then it is computed.
Should the optimization be output to the screen and to a file?
Should the sample times be optimized?
Should the continuous design variables be optimized?
Should the discrete design variables be optimized?
Are the nuber of sample times per group being optimized?
Are the nuber of individuals per group being optimized?
First step factor for sample times
Stochastic Gradient search first step factor for covariates
Number of Random search iterations
Number of iterations in random search between screen output
The method used for calculating the FIM. Potential values:
0 = Full FIM. No assumption that fixed and random effects are uncorrelated. See mftot0
.
1 = Reduced FIM. Assume that there is no correlation in the FIM between the fixed and random effects, and set these elements in
the FIM to zero. See mftot1
.
2 = weighted models (placeholder).
3 = Not currently used.
4 = Reduced FIM and computing all derivatives with respect to the standard deviation of the residual unexplained variation (sqrt(SIGMA) in NONMEM).
This matches what is done in PFIM, and assumes that the standard deviation of the residual unexplained variation is the estimated parameter
(NOTE: NONMEM estimates the variance of the resudual unexplained variation by default). See mftot4
.
5 = Full FIM parameterized with A,B,C matrices & derivative of variance. See mftot5
.
6 = Calculate one model switch at a time, good for large matrices. See mftot6
.
7 = Reduced FIM parameterized with A,B,C matrices & derivative of variance See mftot7
.
OFV calculation type for FIM
1 = "D-optimality". Determinant of the FIM: det(FIM)
2 = "A-optimality". Inverse of the sum of the expected parameter variances: 1/trace_matrix(inv(FIM))
4 = "lnD-optimality". Natural logarithm of the determinant of the FIM: log(det(FIM))
6 = "Ds-optimality". Ratio of the Determinant of the FIM and the Determinant of the uninteresting rows and columns of the FIM: det(FIM)/det(FIM_u)
7 = Inverse of the sum of the expected parameter RSE: 1/sum(get_rse(FIM,poped.db,use_percent=FALSE))
Approximation method for model, 0=FO, 1=FOCE, 2=FOCEI, 3=FOI.
Use Exchange algorithm (1=TRUE, 0=FALSE)
The number of iterations entered into the blockheader
function.
******START OF CRITERION SPECIFICATION OPTIONS**********
D-family design (1) or ED-familty design (0) (with or without parameter uncertainty)
Sample size for E-family sampling
How to sample from distributions in E-family calculations. 0=Random Sampling, 1=LatinHyperCube --
Should the Laplace method be used in calculating the expectation of the OFV?
arguments passed to other functions. See Doptim
.
M. Foracchia, A.C. Hooker, P. Vicini and A. Ruggeri, "PopED, a software fir optimal experimental design in population kinetics", Computer Methods and Programs in Biomedicine, 74, 2004.
J. Nyberg, S. Ueckert, E.A. Stroemberg, S. Hennig, M.O. Karlsson and A.C. Hooker, "PopED: An extended, parallelized, nonlinear mixed effects models optimal design tool", Computer Methods and Programs in Biomedicine, 108, 2012.
Other Optimize: Doptim
,
LEDoptim
, RS_opt_gen
,
RS_opt
, a_line_search
,
bfgsb_min
, calc_autofocus
,
calc_ofv_and_grad
, mfea
,
optim_ARS
, optim_LS
,
poped_optim
# NOT RUN {
library(PopED)
############# START #################
## Create PopED database
## (warfarin model for optimization)
#####################################
## Warfarin example from software comparison in:
## Nyberg et al., "Methods and software tools for design evaluation
## for population pharmacokinetics-pharmacodynamics studies",
## Br. J. Clin. Pharm., 2014.
## Optimization using an additive + proportional reidual error
## to avoid sample times at very low concentrations (time 0 or very late samples).
## find the parameters that are needed to define from the structural model
ff.PK.1.comp.oral.sd.CL
## -- parameter definition function
## -- names match parameters in function ff
sfg <- function(x,a,bpop,b,bocc){
parameters=c(CL=bpop[1]*exp(b[1]),
V=bpop[2]*exp(b[2]),
KA=bpop[3]*exp(b[3]),
Favail=bpop[4],
DOSE=a[1])
return(parameters)
}
## -- Define initial design and design space
poped.db <- create.poped.database(ff_file="ff.PK.1.comp.oral.sd.CL",
fg_file="sfg",
fError_file="feps.add.prop",
bpop=c(CL=0.15, V=8, KA=1.0, Favail=1),
notfixed_bpop=c(1,1,1,0),
d=c(CL=0.07, V=0.02, KA=0.6),
sigma=c(0.01,0.25),
groupsize=32,
xt=c( 0.5,1,2,6,24,36,72,120),
minxt=0.01,
maxxt=120,
a=70,
mina=0.01,
maxa=100)
############# END ###################
## Create PopED database
## (warfarin model for optimization)
#####################################
##############
# D-family Optimization
##############
# below are a number of ways to optimize the problem
# RS+SG+LS optimization of DOSE and sample times
# optimization with just a few iterations
# only to check that things are working
out_1 <- poped_optimize(poped.db,opt_a=TRUE,opt_xt=TRUE,
rsit=2,sgit=2,ls_step_size=2,
iter_max=1)
# }
# NOT RUN {
# RS+SG+LS optimization of sample times
# (longer run time than above but more likely to reach a maximum)
output <- poped_optimize(poped.db,opt_xt=T)
get_rse(output$fmf,output$poped.db)
plot_model_prediction(output$poped.db)
# MFEA optimization with only integer times allowed
mfea.output <- poped_optimize(poped.db,opt_xt=1,
bUseExchangeAlgorithm=1,
EAStepSize=1)
get_rse(mfea.output$fmf,mfea.output$poped.db)
plot_model_prediction(mfea.output$poped.db)
# Examine efficiency of sampling windows
plot_efficiency_of_windows(mfea.output$poped.db,xt_windows=0.5)
plot_efficiency_of_windows(mfea.output$poped.db,xt_windows=1)
# Random search (just a few samples here)
rs.output <- poped_optimize(poped.db,opt_xt=1,opt_a=1,rsit=20,
bUseRandomSearch= 1,
bUseStochasticGradient = 0,
bUseBFGSMinimizer = 0,
bUseLineSearch = 0)
get_rse(rs.output$fmf,rs.output$poped.db)
# line search, DOSE and sample time optimization
ls.output <- poped_optimize(poped.db,opt_xt=1,opt_a=1,
bUseRandomSearch= 0,
bUseStochasticGradient = 0,
bUseBFGSMinimizer = 0,
bUseLineSearch = 1,
ls_step_size=10)
# Stochastic gradient search, DOSE and sample time optimization
sg.output <- poped_optimize(poped.db,opt_xt=1,opt_a=1,
bUseRandomSearch= 0,
bUseStochasticGradient = 1,
bUseBFGSMinimizer = 0,
bUseLineSearch = 0,
sgit=20)
# BFGS search, DOSE and sample time optimization
bfgs.output <- poped_optimize(poped.db,opt_xt=1,opt_a=1,
bUseRandomSearch= 0,
bUseStochasticGradient = 0,
bUseBFGSMinimizer = 1,
bUseLineSearch = 0)
##############
# E-family Optimization
##############
# Adding 10% log-normal Uncertainty to fixed effects (not Favail)
bpop_vals <- c(CL=0.15, V=8, KA=1.0, Favail=1)
bpop_vals_ed_ln <- cbind(ones(length(bpop_vals),1)*4, # log-normal distribution
bpop_vals,
ones(length(bpop_vals),1)*(bpop_vals*0.1)^2) # 10% of bpop value
bpop_vals_ed_ln["Favail",] <- c(0,1,0)
bpop_vals_ed_ln
## -- Define initial design and design space
poped.db <- create.poped.database(ff_file="ff.PK.1.comp.oral.sd.CL",
fg_file="sfg",
fError_file="feps.add.prop",
bpop=bpop_vals_ed_ln,
notfixed_bpop=c(1,1,1,0),
d=c(CL=0.07, V=0.02, KA=0.6),
sigma=c(0.01,0.25),
groupsize=32,
xt=c( 0.5,1,2,6,24,36,72,120),
minxt=0,
maxxt=120,
a=70,
mina=0,
maxa=100)
# ED optimization using Random search (just a few samples here)
output <- poped_optimize(poped.db,opt_xt=1,opt_a=1,rsit=10,d_switch=0)
get_rse(output$fmf,output$poped.db)
# ED with laplace approximation,
# optimization using Random search (just a few samples here)
output <- poped_optimize(poped.db,opt_xt=1,opt_a=1,rsit=10,
d_switch=0,use_laplace=TRUE,laplace.fim=TRUE)
get_rse(output$fmf,output$poped.db)
# }
Run the code above in your browser using DataLab