nlmixrdevelopment / nlmixr

nlmixr: an R package for population PKPD modeling
https://nlmixrdevelopment.github.io/nlmixr/
GNU General Public License v2.0
115 stars 45 forks source link

parallel computing #523

Closed sliao999 closed 3 years ago

sliao999 commented 3 years ago

I tried parallel computing with this pk model below. Not sure what is missing, it is running, but not using more than one core.

options("RxODE.cache.directory"="~/.rxCache") library(nlmixr) library(doParallel)

define the model

nimo <- function() { ini({

Note that the UI can take expressions

## Also note that these initial estimates should be provided on the log-scale
tcl <- log(109)
tv1 <- log(512)
tq <- log(12)
tv2 <- log(156)
talpha <- log(0.171)
tbeta <- log(1.08)
## Note this covariate effects take expressions
crcl_cl<-0.32
crcl_v1<-0.29
race2_cl<-0.32
form_alpha<-1.47
stat_alpha<-1.98
## Initial estimates should be high for SAEM ETAs
eta.cl  ~ .1
eta.v1  ~ .1
eta.v2 ~ .1
eta.alpha ~ .1
eta.beta ~ .01
##  Also true for additive error (also ignored in SAEM)
add.err <- 0.3

}) model({ CL <- exp(tcl +crcl_cllog(crcl/110)+log(1+race2race2_cl)+ eta.cl) V1 <- exp(tv1 +crcl_v1log(crcl/110)+ eta.v1) V2 <- exp(tv2 + eta.v2) Q <- exp(tq) alpha <- exp(talpha+log(1+formform_alpha)+log(1+stat*stat_alpha) + eta.alpha) beta <- exp(tbeta + eta.beta)+1

C1=centr/V1;
C2=peri/V2;

tad <- tad()

WB=(beta/alpha)*((t/alpha)^(beta-1));
d/dt(depot)=-WB*depot;
d/dt(centr)= WB*(depot)-CL*C1-Q*C1+Q*C2;
d/dt(peri) =+Q*C1-Q*C2;
cp=log(C1)
cp~add(add.err)

}) }

read the data

dat <- read.csv("E:/KKD/Naloxegol ped/poppk3/combined_nm.csv") head(dat) cl <- makeCluster(detectCores()-1) registerDoParallel(cl) fit <- nlmixr(nimo, dat, est="focei")