Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotting optimized output seems to used wrong times #43

Closed
krimobe opened this issue Dec 12, 2019 · 1 comment
Closed

Plotting optimized output seems to used wrong times #43

krimobe opened this issue Dec 12, 2019 · 1 comment

Comments

@krimobe
Copy link

krimobe commented Dec 12, 2019

When trying to visualize the optimized sample times on top of the predicted curve, this points seem to be off. To me it looks like a problem with the times.

`library(PopED)
library(deSolve)

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)
}

system("R CMD SHLIB one_comp_oral_CL.c")
dyn.load(paste("one_comp_oral_CL", .Platform$dynlib.ext, sep = ""))

ff.ODE.compiled <- function(model_switch,xt,parameters,poped.db){
with(as.list(parameters),{
A_ini <- c(A1 = DOSE*Favail, A2 = 0)
times <- drop(xt)##xt[,,drop=T]
times <- sort(times)
times <- c(0,times) ## add extra time for start of integration
out <- ode(A_ini, times, func = "derivs", parms = c(CL,V,KA),
#jacfunc = "jac", # not really needed, speed up is minimal if this is defined or not.
dllname = "one_comp_oral_CL",
initfunc = "initmod", nout = 1, outnames = "Sum")
y = out[,"A2"]/(V)
y=y[-1] # remove initial time for start of integration
y = cbind(y) # must be a column matrix
return(list( y= y,poped.db=poped.db))
})
}

-- Define initial design and design space

poped.db.compiled <- create.poped.database(ff_fun=ff.ODE.compiled,
fg_fun = sfg,
fError_fun = 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,
maxxt=120,
a=c(DOSE=70),
mina=c(DOSE=0),
maxa=c(DOSE=100))

create plot of model with variability

plot_model_prediction(poped.db.compiled,IPRED=T,DV=T)

making optimization times more resonable

output <- poped_optim(poped.db.compiled ,opt_xt=T, opt_a=T, parallel=T, dlls = c('one_comp_oral_CL'))

plot_model_prediction(output$poped.db,IPRED=T,DV=T)`

Plot before optimization

image

Plot after optimization

image

@andrewhooker
Copy link
Owner

Hi.

It seems the ff.ode.compiled function is a bit outdated and is doing a strange filtering. I would change it to

ff.ODE.compiled <- function(model_switch,xt,parameters,poped.db){
  with(as.list(parameters),{
    A_ini <- c(A1 = DOSE*Favail, A2 = 0)
    times_xt <- drop(xt) #xt[,,drop=T] 
    times <- sort(times_xt)
    times <- c(0,times) ## add extra time for start of integration
    out <- ode(A_ini, times, func = "derivs", parms = c(CL,V,KA),
               #jacfunc = "jac", # not really needed, speed up is minimal if this is defined or not.
               dllname = "one_comp_oral_CL",
               initfunc = "initmod", nout = 1, outnames = "Sum")
    y = out[, "A2"]/(V)
    y=y[match(times_xt,out[,"time"])]
    y = cbind(y) # must be a column matrix
    return(list( y= y,poped.db=poped.db))
  })
} 

Which gives the plot after optimization of :

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants