-
|
Hi Everyone, code <- '$THETA @Annotated $PARAM @Annotated $CMT $GLOBAL $MAIN double TVCL_F = THETA1; double CL_F = TVCL_F * pow(WT/MWT, 0.75); if(GENDER==0) { if(ROUTEN==0) { $ODE $CAPTURE@annotated |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
|
Hi @JoanaXu - Thanks for reaching out and for sharing the code. I think the model is really close. I've put some suggestions in revised model code below:
Check out the code below and let me know what you think! Kyle library(mrgsolve)
#>
#> Attaching package: 'mrgsolve'
#> The following object is masked from 'package:stats':
#>
#> filter
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
code <- '
$THETA @annotated
2.88 : 1. Female_Clearance (L/h)
2.72 : 2. Male_Clearance (L/h)
4 : 3. Central volume (L)
0.2 : 4. Absorption rate constant (1/h)
0.6 : 5, ALAG1, Absorption lag (h)
0.5 : 6. Bioavalibility PO
$PARAM @annotated
MWT : 32.4 : Median Bodyweight(kg)
$INPUT @annotated
GENDER : 0 : Gender
WT : 30 : Body weight (kg)
$CMT
GUT
CENT
$GLOBAL
#define CP (CENT/V)
$MAIN
//initial dose regimen setting
//double ROUTEN = 0; //Route of administration (0=IV infusion, 1=PO)
//double GENDER = 0; //Gender(0=Female, 1=Male)
//double WT = 30; // Body weight(kg)
//double amt = 480000; //Dose amount (ug)
double TVCL_F = THETA1;
double TVCL_M = THETA2;
double TVV2 = THETA3;
double TVKA = THETA4;
double TVALAG1 = THETA5;
double TVF1 = THETA6;
double CL_F = TVCL_F * pow(WT/MWT, 0.75);
double CL_M = TVCL_M * pow(WT/MWT, 0.75);
double V2 = TVV2 * pow(WT/MWT, 1);
double ALAG1 = TVALAG1;
double KA = TVKA;
double F1 = TVF1;
if(GENDER==0) {
double CL = CL_F;
} else {
CL = CL_M;
}
// Alternatively, you can use this syntax:
// double CL = GENDER==0 ? CL_F : CL_M;
F_CENT = F1;
ALAG_GUT = ALAG1;
$ODE
dxdt_GUT = -KA * GUT;
dxdt_CENT = KA * GUT - (CL/V2)*CENT;
$CAPTURE @annotated
CL: clearance used
CL_F: clearance_female
CL_M:clearance_male
CP=CENT/V2: Central concentration
'
mod <- mcode("model_test", code)
#> Building model_test ...
#> done.
data <- expand.ev(amt = 480000, rate = c(0,480000/2), GENDER = c(0,1))
data <- mutate(
data,
cmt = ifelse(rate > 0, 2, 1),
route = factor(rate > 0, labels = c("po", "iv")),
sex = factor(GENDER, labels = c("female", "male"))
)
data
#> ID time amt rate cmt evid GENDER route sex
#> 1 1 0 480000 0 1 1 0 po female
#> 2 2 0 480000 240000 2 1 0 iv female
#> 3 3 0 480000 0 1 1 1 po male
#> 4 4 0 480000 240000 2 1 1 iv male
out <- mrgsim(mod, data, delta = 0.1, recover = "route,sex")
plot(out, CP ~ time |route*sex, scales = "same")plot(out, CL ~ time |route*sex, scales = "same")Created on 2025-07-14 with reprex v2.1.1 |
Beta Was this translation helpful? Give feedback.
-
|
Hi @kylebaron ,
Thank you so much for your quick reply, the code works well and it was exactly what I want! The working way here much like NONMEM used.
Besides, what is the difference between $PARAM @input and $INPUT?
|
Beta Was this translation helpful? Give feedback.
-
|
Hi @JoanaXu -
Glad the code is working well. Please let me know if I can help with anything else. Kyle |
Beta Was this translation helpful? Give feedback.
-
|
Thank you Kyle, that's very helpful! |
Beta Was this translation helpful? Give feedback.
-
|
You're welcome; best wishes for your simulation. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
Hi @JoanaXu - Can you change if(ROUTEN==0) {
F_CENT=1;
} else {
ALAG_GUT=ALAG1;
F_CENT=F1;}Kyle |
Beta Was this translation helpful? Give feedback.
-
|
Hi @kylebaron , |
Beta Was this translation helpful? Give feedback.



Hi @JoanaXu -
Thanks for reaching out and for sharing the code. I think the model is really close. I've put some suggestions in revised model code below:
GENDERandWTparameters for the model; this will let you update them either from your R code or from the data (see this page in the user guide for more info).amt) should be set in the data set (see code below)ROUTE(iv or po); just set up the model for either and then dose intoGUTorCENT(compartment 1 or 2) as bolus (RATE = 0) or infusion (RATE > 0); all of this is handled in the input data set