andrewhooker / PopED

Population Experimental Design (PopED) in R
https://andrewhooker.github.io/PopED/
GNU Lesser General Public License v3.0
31 stars 21 forks source link

the function for optimizing number of samples (opt_samps) not available #40

Open ericwongyc opened 4 years ago

ericwongyc commented 4 years ago

Hi all,

When planning a PK study over a period of 140 days, I aim to reduce the number of blood samples from 16 time points to a smaller number.

I set opt_samps=T in poped_optim(), but then I get an error message:

poped_optim(poped.db.2cmt.RUVPA, method=c("LS"),parallel=T, opt_xt = F, opt_samps =T)

Error in get_par_and_space_optim(poped.db, opt_xt = opt_xt, opt_a = opt_a, : Sample number optimization is not yet implemented in the R-version of PopED.

Is there a way to optimize the number of samples (or even better optimize both the number of samples and the sampling times at the same time) in popED?

Many thanks for your kind help.

Kind regards, Eric

Here is my popED script:

cppFunction('List two_comp_ode(double Time, NumericVector A, NumericVector Pars) { int n = A.size(); NumericVector dA(n);

        double CL = Pars[0];
        double V1 = Pars[1];
        double Q = Pars[2];
        double V2 = Pars[3];
        double DOSE = Pars[4];
        double TINF = Pars[5];
        double TAU = Pars[6];
        double In;

        if ( fmod(Time,TAU) < TINF ){
        In =  DOSE/TINF;
        }
        else {
        In  =  0;
        }

        dA[0] = In - (CL/V1)*A[0] + (Q/V2)*A[1] - (Q/V1)*A[0];
        dA[1] =                   - (Q/V2)*A[1] + (Q/V1)*A[0];
        return List::create(dA);
        }')

sfg2 <- function(x,a,bpop,b,bocc){ parameters=c( CL=bpop[1]exp(b[1]), V1=bpop[2]exp(b[2]), Q=bpop[3], V2=bpop[4],
DOSE=a[1], TINF=a[2], TAU=a[3]) return( parameters ) }

PK_2comp_ode_inf_rcpp_ff <- function(model_switch, xt, parameters, poped.db){ with(as.list(parameters),{ A_ini <- c(A1=0, A2=0)

times_xt <- drop(xt)
times <- c(0,times_xt) ## add extra time for start of integration
times <- sort(times) 
times <- unique(times) # remove duplicates
out <- ode(A_ini, times, two_comp_ode, parameters)#, events = list(data = eventdat)) #atol=1e-13,rtol=1e-13)
y = out[, "A1"]/(V1)
y=y[match(times_xt,out[,"time"])]
y=cbind(y)
return(list(y=y,poped.db=poped.db))

}) }

numsubject = 6 # number of subject per dose group BW = 80 #kg DOSE_mg = 3 *BW Infusion_duration = 2 /24 # mg/day sampletime_original = c(2/24, 4/24, 6/24, 8/24, 12/24, 24/24, 36/24, 2, 3, 4, 6, 14, 28, 42, 56, 84) # original 16 samples

poped.db.2cmt.RUVPA <- create.poped.database(ff_file = "PK_2comp_ode_inf_rcpp_ff", fError_file="feps.add.prop", fg_file="sfg2", groupsize=numsubject, m=1, #number of groups sigma=c(0.15,0.1), notfixed_sigma = c(0,0), bpop=c(CL=3.2/1000BW,V1=41.5/1000BW,Q=17.3/1000BW,V2=49.4/1000BW), notfixed_bpop=c(1,1,1,1), d=c(CL=0.09,V1=0.09), notfixed_d=c(1,1), xt=sampletime_original, #original 16 samples minxt=2/24 , # original minxt 2/24 maxxt=140 , # original maxxt 140 a=c(DOSE=DOSE_mg,TINF=Infusion_duration,TAU=280), dSeed = 123456)