Closed rachel0409 closed 4 years ago
Hi @rachel0409 , Congrats on starting into R. As part of the introduction to R and the mrgsolve package, I'd recommend our recent tutorial in CPT:PSP (https://ascpt.onlinelibrary.wiley.com/doi/full/10.1002/psp4.12467). In that, you'll find a reference table (Table 1) that describes the "chunks" of an mrgsolve model. Those that are in the C++ syntax, including $ODE, require an ";" at each line ending, e.g.,
$ODE
Skin compartment
dxdt_ASk=EDIBW/24Qfbs-ASk/VSk/psQbs-ASk/VSk/psph*kha ;
Hair compartment
dxdt_AHr=ASk/VSk/psphkha-AHr/VHr*kha ;
Hope this helps!
Kind regards, Matt
Hi @rachel0409 -
I fixed the code so that it would compile. As @riggsmm noted, it was missing some ;
at the end of some lines. Also, comments should use //
rather than ##
, throughout the model code..
I'd say the rest of it looks like it's in good shape. Just friendly reminder that quantities that depend on the value in a compartment should only be defined / calculated in $ODE and $TABLE. You have that and probably already get it. Just a reminder for us all. It's a common gotcha for PBPK and QSP.
Please feel free to reach out with other questions as you get started.
Kyle
HumanPBPK.code <- '
$PARAM @annotated
QCC : 20.0 : L/hr scaled by body weight3/4, Cardiac output
Qfbs : 0.05 : Fraction blood flow to skin
BW : 53.3 : kg, Body weight
EDI : 14.77 : ng/d kg bw, estimated daily intake of MeHg
Vfsk : 0.35 : fraction weight of skin
Vfhr : 0.002 : fraction weight of hair
Vfbl : 0.024 : fraction weight of blood
ps : 2 : skin/blood partition coefficient
ph : 248.7 : hair/blood partition coefficient
kha : 7.0e-6 : excretation to hair
$MAIN
double QC = QCC*pow(BW, 0.75); // L/hr, Cardiac output (adjusted for plasma)
double Qbs = Qfbs*QC; // L/hr, blood flow to skin
double VSk = Vfsk*BW; // L, volume of skin
double VHr = Vfhr*BW; // L, volume of hair
double VBl = Vfbl*BW; // L, volume of blood
$CMT @annotated
ASk: MeHg in skin compartment
AHr: MeHg in hair compartment
$ODE
//Skin compartment
dxdt_ASk=EDI*BW/24 * Qfbs - ASk/VSk/ps * Qbs - ASk/VSk/ps*ph*kha;
//Hair compartment
dxdt_AHr=ASk/VSk/ps*ph*kha-AHr/VHr*kha;
$TABLE
capture CSk=ASk/VSk;
capture CHr=AHr/VHr;
'
mod <- mcode ("pbpk", HumanPBPK.code)
Hi @rachel0409 , Congrats on starting into R. As part of the introduction to R and the mrgsolve package, I'd recommend our recent tutorial in CPT:PSP (https://ascpt.onlinelibrary.wiley.com/doi/full/10.1002/psp4.12467). In that, you'll find a reference table (Table 1) that describes the "chunks" of an mrgsolve model. Those that are in the C++ syntax, including $ODE, require an ";" at each line ending, e.g.,
$ODE
Skin compartment
dxdt_ASk=EDIBW/24Qfbs-ASk/VSk/psQbs-ASk/VSk/psph*kha ;
Hair compartment
dxdt_AHr=ASk/VSk/psphkha-AHr/VHr*kha ;
Hope this helps!
Kind regards, Matt
Hi, Matt Thank you so much for your reply. The tutorial is really helpful, and it helps me solve another problem I have encountered.
Best Regards, Rachel
Hi, @kylebaron
Thank you so much for your reply. I also a little confused about setting the dosing events for simulation. In my case, I had exposure data for some patients aged from 18-50 years old. I wanted to regard it as one person who exposed to MeHg for 33 years. And here is the code for setting dosing event, could you please have a look at it? Am I coding it correctly for my purpose?
BW=80 //kg, body weight tinterval=24 // once a day TDoses=36533 //exposed for 33 years DOSEoral=PDOSEoralBW //PDOSEoral=estimated daily intake
Oral<-ev(ID=1,time=0,amt=DOSEoral,ii=tinterval,addl=TDoses-1,replicate=FALSE) // set up the exposure time tsamp=tgrid(0,tinterval(TDoses-1)+2436533,24365)
Best Regards, Rachel
Hi @rachel0409 -
I believe that is what you want; the "event objects" are set up for that sort of application (dosing to be applied to a single unit). mrgsolve version 0.10.0
gained a "total" argument so you can specify the total number of doses (rather than addl). Also, no need to indicate ID=1
or time=0
as that will happen as default and consistent with how it is used.
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
library(mrgsolve)
#>
#> Attaching package: 'mrgsolve'
#> The following object is masked from 'package:stats':
#>
#> filter
PDOSEoral = 1
BW=80 ##kg, body weight
tinterval=24 ## once a day
TDoses=36533 ##exposed for 33 years
DOSEoral=PDOSEoral*BW ##PDOSEoral=estimated daily intake
Oral<-ev(amt=DOSEoral,ii=tinterval,total=TDoses)
## set up the exposure time
tsamp=tgrid(0,tinterval*(TDoses-1)+2436533,24*365)
realize_addl(Oral) %>% as.data.frame() %>% head
#> time amt ii addl cmt evid
#> 1 0 80 0 0 1 1
#> 2 24 80 0 0 1 1
#> 3 48 80 0 0 1 1
#> 4 72 80 0 0 1 1
#> 5 96 80 0 0 1 1
#> 6 120 80 0 0 1 1
stime(tsamp)
#> [1] 0 8760 17520 26280 35040 43800 52560 61320 70080
#> [10] 78840 87600 96360 105120 113880 122640 131400 140160 148920
#> [19] 157680 166440 175200 183960 192720 201480 210240 219000 227760
#> [28] 236520 245280 254040 262800 271560 280320 289080 297840 306600
#> [37] 315360 324120 332880 341640 350400 359160 367920 376680 385440
#> [46] 394200 402960 411720 420480 429240 438000 446760 455520 464280
#> [55] 473040 481800 490560 499320 508080 516840 525600 534360 543120
#> [64] 551880 560640 569400 578160 586920 595680 604440 613200 621960
#> [73] 630720 639480 648240 657000 665760 674520 683280 692040 700800
#> [82] 709560 718320 727080 735840 744600 753360 762120 770880 779640
#> [91] 788400 797160 805920 814680 823440 832200 840960 849720 858480
#> [100] 867240 876000 884760 893520 902280 911040 919800 928560 937320
#> [109] 946080 954840 963600 972360 981120 989880 998640 1007400 1016160
#> [118] 1024920 1033680 1042440 1051200 1059960 1068720 1077480 1086240 1095000
#> [127] 1103760 1112520 1121280 1130040 1138800 1147560 1156320 1165080 1173840
#> [136] 1182600 1191360 1200120 1208880 1217640 1226400 1235160 1243920 1252680
#> [145] 1261440 1270200 1278960 1287720 1296480 1305240 1314000 1322760 1331520
#> [154] 1340280 1349040 1357800 1366560 1375320 1384080 1392840 1401600 1410360
#> [163] 1419120 1427880 1436640 1445400 1454160 1462920 1471680 1480440 1489200
#> [172] 1497960 1506720 1515480 1524240 1533000 1541760 1550520 1559280 1568040
#> [181] 1576800 1585560 1594320 1603080 1611840 1620600 1629360 1638120 1646880
#> [190] 1655640 1664400 1673160 1681920 1690680 1699440 1708200 1716960 1725720
#> [199] 1734480 1743240 1752000 1760760 1769520 1778280 1787040 1795800 1804560
#> [208] 1813320 1822080 1830840 1839600 1848360 1857120 1865880 1874640 1883400
#> [217] 1892160 1900920 1909680 1918440 1927200 1935960 1944720 1953480 1962240
#> [226] 1971000 1979760 1988520 1997280 2006040 2014800 2023560 2032320 2041080
#> [235] 2049840 2058600 2067360 2076120 2084880 2093640 2102400 2111160 2119920
#> [244] 2128680 2137440 2146200 2154960 2163720 2172480 2181240 2190000 2198760
#> [253] 2207520 2216280 2225040 2233800 2242560 2251320 2260080 2268840 2277600
#> [262] 2286360 2295120 2303880 2312640 2321400 2330160 2338920 2347680 2356440
#> [271] 2365200 2373960 2382720 2391480 2400240 2409000 2417760 2426520 2435280
#> [280] 2444040 2452800 2461560 2470320 2479080 2487840 2496600 2505360 2514120
#> [289] 2522880 2531640 2540400 2549160 2557920 2566680 2575440 2584200 2592960
#> [298] 2601720 2610480 2619240 2628000 2636760 2645520 2654280 2663040 2671800
#> [307] 2680560 2689320 2698080 2706840 2715600 2724360 2733120 2741880 2750640
#> [316] 2759400 2768160 2776920 2785680 2794440 2803200 2811960 2820720 2829480
#> [325] 2838240 2847000 2855760 2864520 2873280 2882040 2890800 2899560 2908320
#> [334] 2917080 2925840 2934600 2943360 2952120 2960880 2969640 2978400 2987160
#> [343] 2995920 3004680 3013440 3022200 3030960 3039720 3048480 3057240 3066000
#> [352] 3074760 3083520 3092280 3101040 3109800 3118560 3127320 3136080 3144840
#> [361] 3153600 3162360 3171120 3179880 3188640 3197400 3206160 3214920 3223680
#> [370] 3232440 3241200 3249960 3258720 3267480 3276240 3285000 3293760 3302520
#> [379] 3311280
Created on 2020-02-17 by the reprex package (v0.3.0)
Hi, Kyle
Thanks for your reply. After coding the model in mrgsolve, I want to use the FME package for further parameter optimization, but I found another trouble in model fitting as shown in the picture. I'd like to share the code and data in this email, and could you please have a look at it? [cid:image001.png@01D5E80A.26EE0DF0] I will really appreciate your help.
Best Regards, Rachel
发送自 Windows 10 版邮件https://go.microsoft.com/fwlink/?LinkId=550986应用
发件人: Kyle Baronmailto:notifications@github.com 发送时间: 2020年2月17日 23:41 收件人: metrumresearchgroup/mrgsolvemailto:mrgsolve@noreply.github.com 抄送: rachel0409mailto:yamap.rachel@hotmail.com; Mentionmailto:mention@noreply.github.com 主题: Re: [metrumresearchgroup/mrgsolve] Error: the model build step failed. (#632)
Hi @rachel0409https://github.com/rachel0409 -
I believe that is what you want; the "event objects" are set up for that sort of application (dosing to be applied to a single unit). mrgsolve version 0.10.0 gained a "total" argument so you can specify the total number of doses (rather than addl). Also, no need to indicate ID=1 or time=0 as that will happen as default and consistent with how it is used.
library(dplyr)
library(mrgsolve)
PDOSEoral = 1
BW=80 ##kg, body weight
tinterval=24 ## once a day
TDoses=36533 ##exposed for 33 years
DOSEoral=PDOSEoral*BW ##PDOSEoral=estimated daily intake
Oral<-ev(amt=DOSEoral,ii=tinterval,total=TDoses)
tsamp=tgrid(0,tinterval(TDoses-1)+2436533,24365)
Doses and times
realize_addl(Oral) %>% as.data.frame() %>% head
Observations
stime(tsamp)
Created on 2020-02-17 by the reprex packagehttps://reprex.tidyverse.org (v0.3.0)
― You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/metrumresearchgroup/mrgsolve/issues/632?email_source=notifications&email_token=AOOEJL4EXUWFGYMTTTDNMV3RDKO2HA5CNFSM4KSIQ5YKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL6UYJA#issuecomment-587025444, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOOEJL2UFAUDACMGQS7GCADRDKO2HANCNFSM4KSIQ5YA.
Closing this as we've dealt with several of the mrgsolve-related issues via email. @rachel0409 please open a new issue if there are other questions around mrgsolve. Thanks!
Hi, kylebaron. I am new to R and trying to build a PBPK model, but it failed. Could you please have a look at this? I don't know how to fix this problem. Thank you very much.
`library(mrgsolve) # for PBPK model
HumanPBPK.code <- ' $PARAM @annotated QCC : 20.0 : L/hr scaled by body weight3/4, Cardiac output Qfbs : 0.05 : Fraction blood flow to skin BW : 53.3 : kg, Body weight EDI : 14.77 : ng/d kg bw, estimated daily intake of MeHg Vfsk : 0.35 : fraction weight of skin Vfhr : 0.002 : fraction weight of hair Vfbl : 0.024 : fraction weight of blood ps : 2 : skin/blood partition coefficient
ph : 248.7 : hair/blood partition coefficient kha : 7.0e-6 : excretation to hair
$MAIN
double QC = QCCpow(BW, 0.75); // L/hr, Cardiac output (adjusted for plasma) double Qbs = QfbsQC; // L/hr, blood flow to skin
double VSk = VfskBW; // L, volume of skin double VHr = VfhrBW; // L, volume of hair double VBl = Vfbl*BW; // L, volume of blood
$CMT @annotated ASk: MeHg in skin compartment AHr: MeHg in hair compartment
$ODE
Skin compartment
dxdt_ASk=EDIBW/24Qfbs-ASk/VSk/psQbs-ASk/VSk/psph*kha
Hair compartment
dxdt_AHr=ASk/VSk/psphkha-AHr/VHr*kha
$TABLE capture CSk=ASk/VSk; capture CHr=AHr/VHr; ' mod <- mcode ("pbpk", HumanPBPK.code)`
---:: stderr ::--------------------------------------------- In file included from pbpk-mread-source.cpp:3:0:
pbpk-mread-header.h:47:18: error: expected ';' before 'DADT'
define dxdt_AHr DADT[1]
21:1: note: in expansion of macro 'dxdt_AHr' dxdt_AHr=ASk/VSk/psphkha-AHr/VHr*kha ^ make: *** [C:/PROGRA~1/R/R-35~1.1/etc/x64/Makeconf:215: pbpk-mread-source.o] Error 1
Error: the model build step failed.