Repository navigation
Expand file tree
/
Copy pathoud_mrgsolve_model.R
More file actions
431 lines (391 loc) · 21.4 KB
/
Copy pathoud_mrgsolve_model.R
File metadata and controls
431 lines (391 loc) · 21.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
## Opioid Use Disorder (OUD) — QSP / PK-PD Model
## ============================================================================
## Disease : OUD — mu-opioid receptor (MOR) agonism drives acute reward/
## analgesia, chronic neuroadaptation (tolerance, opponent-process
## withdrawal via locus-coeruleus noradrenergic rebound), and
## dose-dependent respiratory depression/overdose risk. Model
## tracks receptor occupancy from competing ligands (illicit
## fentanyl, methadone, buprenorphine, naloxone, naltrexone) and
## downstream withdrawal, craving, respiratory, and cardiac
## (methadone QTc) endpoints.
## Authors : Generated by Claude Code Routine (QSP Disease Model Library)
## Engine : mrgsolve (>=1.5)
##
## Scope : 23 ODE compartments — drug PK (illicit fentanyl 3 [gut+central+
## peripheral], methadone 2, buprenorphine 3 [SL depot+XR depot+
## central], naloxone 2, naltrexone 3 [oral+XR depot+central],
## lofexidine 2 = 15) + disease/PD network (MOR tolerance,
## locus-coeruleus/noradrenergic tone, withdrawal COWS, craving
## VAS, respiratory-drive index, methadone QTc, phasic dopamine/
## euphoria, treatment-retention index = 8).
## Time : hours (acute PK/overdose minutes-hours; tolerance/withdrawal
## hours-days; treatment retention weeks). Default horizon
## 0-672 h (4 weeks); acute-overdose scenarios use 0-6 h.
## Units : dose mg; concentration mg/L (ng/mL numerically equal x1000
## scale handled via V); MOR occupancy fraction 0-1; COWS 0-48
## (clinical scale, rescaled 0-100 internally then reported 0-48);
## craving VAS 0-100; QTc ms; dopamine/euphoria index 0-100;
## respiratory index 1.0 = normal minute ventilation, 0 = apnea.
## Scenarios: 10 prebuilt — see OUD_simulate_scenarios() at bottom.
## Anchors : Volkow 2016 NEJM (neurobiology of addiction, mesolimbic/LC
## opponent-process model); Koob & Volkow 2016 Lancet Psychiatry
## (anti-reward/dynorphin-KOR system); Wesson & Ling 2003 J
## Psychoactive Drugs (COWS scale); Dahan 2010 Br J Anaesth /
## Dahan 2005 Anesthesiology (opioid-induced respiratory
## depression, competitive-antagonism PK/PD & buprenorphine
## ceiling); Walsh 1994 Clin Pharmacol Ther / Greenwald 2003
## Neuropsychopharmacology (buprenorphine MOR occupancy PET,
## ceiling on subjective/physiologic effects); Comer 2005 Am J
## Psychiatry (naltrexone XR blockade duration); Krupitsky 2011
## Lancet (naltrexone XR RCT); Kampman & Jarvis 2015 ASAM
## National Practice Guideline (dosing anchors); Chou 2014 Ann
## Intern Med (methadone QTc / torsades risk review); Krantz 2009
## Ann Intern Med (methadone-associated QT prolongation); Gowing
## 2016 Cochrane (lofexidine/alpha2-agonist withdrawal
## management); Mattick 2014 Cochrane (buprenorphine/methadone
## maintenance treatment retention); Sordo 2017 BMJ (mortality
## risk reduction with agonist maintenance treatment).
## Disclaimer: For research / education / hypothesis generation only. Not a
## substitute for clinical judgment, addiction-medicine practice
## guidelines, or regulatory decision-making.
## ============================================================================
[PROB]
QSP model of opioid use disorder (OUD) linking competitive mu-opioid-receptor
(MOR) occupancy from illicit fentanyl, methadone, buprenorphine, naloxone, and
naltrexone to chronic-tolerance/withdrawal neuroadaptation (locus-coeruleus
noradrenergic rebound), craving/relapse risk, dose-dependent respiratory
depression/overdose, methadone-associated QTc prolongation, and treatment-
retention outcomes, with symptomatic alpha2-agonist (lofexidine) withdrawal
management.
[PLUGIN] Rcpp
[PARAM] @annotated
//--- Patient / history
AGE : 34 : age (years)
WT : 72 : body weight (kg)
YEARS_USE : 5 : years of regular opioid use (chronic-exposure driver)
BASE_TOL : 0.55 : baseline MOR tolerance/adaptation index (0=naive,1=max)
BASE_COWS : 2 : baseline (inter-dose) COWS withdrawal score (0-48)
BASE_CRAVE : 30 : baseline craving VAS (0-100)
BASE_RETAIN : 0.20 : baseline treatment-retention index (0-1)
BENZO_COUSE : 0 : 1 = concurrent benzodiazepine/sedative co-use (synergistic resp. depression)
XYLAZINE_ADULT : 0 : 1 = illicit supply adulterated with xylazine (naloxone-refractory sedation component)
COUNSELING : 0 : 1 = structured counseling/contingency-management engaged
//--- Illicit fentanyl/heroin PK (surrogate "fentanyl-equivalent"; IV/IN/smoked;
// highly lipophilic, rapid central-peripheral redistribution; central t1/2~20 min,
// context-sensitive terminal t1/2 lengthens with repeated dosing)
CL_FENT : 55 : L/h (hepatic, high extraction)
V1_FENT : 25 : L (central)
V2_FENT : 175 : L (peripheral, lipophilic)
Q_FENT : 45 : L/h (inter-compartmental)
KA_FENT_IN : 6.0 : 1/h (intranasal/smoked absorption; IV = direct bolus into V1)
F_FENT_IN : 0.70
//--- Methadone PK (oral; long, variable t1/2 8-59h; CYP3A4/CYP2B6)
KA_METH : 0.9
F_METH : 0.85
CL_METH : 5.0 : L/h (low, variable clearance drives long t1/2)
V_METH : 300 : L (large Vd)
//--- Buprenorphine PK (sublingual film/tablet or SC depot; high affinity, long
// receptor residence; SL F~0.30; depot near-zero-order release ~1 month)
KA_BUP_SL : 1.2
F_BUP_SL : 0.30
CL_BUP : 80 : L/h
V_BUP : 300 : L
KREL_BUP_XR : 0.0014 : 1/h (depot zero-order-like slow release, ~monthly duration)
//--- Naloxone PK (IN/IM/auto-injector; short t1/2 ~30-90 min)
KA_NLX : 3.5
F_NLX_IN : 0.50
CL_NLX : 120 : L/h
V_NLX : 200 : L
//--- Naltrexone PK (oral daily 50 mg; XR-IM depot 380 mg/month, Vivitrol-type
// near-zero-order release with initial burst)
KA_NTX_PO : 1.5
F_NTX_PO : 0.90
CL_NTX : 150 : L/h
V_NTX : 500 : L
KREL_NTX_XR : 0.0018 : 1/h (slow depot release, ~monthly duration)
//--- Lofexidine PK (oral alpha2-agonist; t1/2 ~12-16h)
KA_LOF : 0.8
F_LOF : 0.72
CL_LOF : 15 : L/h
V_LOF : 240 : L
//--- MOR occupancy (algebraic, competitive Emax across agonists/antagonists;
// relative affinity constants, Ki in ng/mL-equivalent units — buprenorphine
// highest affinity, naloxone/naltrexone high affinity but zero intrinsic
// activity, fentanyl/methadone high efficacy full agonists)
KI_FENT : 1.0 : ng/mL-equiv affinity constant (reference)
KI_METH : 25 : ng/mL-equiv (lower potency than fentanyl by mass)
KI_BUP : 0.20 : ng/mL-equiv (very high affinity)
KI_NLX : 1.0 : ng/mL-equiv (high affinity, zero efficacy)
KI_NTX : 0.80 : ng/mL-equiv (high affinity, zero efficacy)
EFF_FENT : 1.00 : intrinsic efficacy (full agonist)
EFF_METH : 1.00 : intrinsic efficacy (full agonist)
EFF_BUP : 0.45 : intrinsic efficacy (partial agonist, ceiling)
//--- Tolerance / receptor adaptation turnover (days-scale)
KOUT_TOL : 0.006 : 1/h
TOL_DRIVE_GAIN: 0.9 : max tolerance driven by sustained high MOR occupancy
//--- Locus-coeruleus noradrenergic tone / withdrawal drive turnover
KOUT_LC : 0.35 : 1/h (fast, reflects acute occupancy-drop rebound)
LC_REBOUND_GAIN: 3.2 : LC-tone gain per unit (tolerance x occupancy-deficit)
EC50_LOF_LC : 0.008 : mg/L, lofexidine EC50 for LC noradrenergic suppression
EMAX_LOF_LC : 0.70 : max fractional LC-tone suppression from lofexidine
//--- Withdrawal (COWS surrogate, 0-48) turnover
KOUT_COWS : 0.45 : 1/h (fast, tracks LC tone closely)
SCALE_COWS_LC : 46 : COWS points per unit LC-tone excess above 1.0
//--- Craving (VAS 0-100) turnover
KOUT_CRAVE : 0.020 : 1/h (slower, days-scale)
SCALE_CRAVE_COWS : 0.9 : craving points per COWS point
SCALE_CRAVE_TOL : 25 : craving points per unit tolerance
COUNSELING_CRAVE_RED : 0.35 : fractional craving reduction from counseling/contingency management
//--- Respiratory drive index (1.0 normal, fast turnover minutes)
KOUT_RESP : 2.0 : 1/h
RESP_EMAX_MOR : 0.97 : max fractional respiratory-drive suppression at full agonist saturation
RESP_GAMMA : 1.6 : Hill coefficient (steep dose-response near overdose threshold)
BUP_CEILING_OCC : 0.55 : occupancy ceiling above which buprenorphine's partial-agonist effect plateaus
BENZO_RESP_MULT : 1.6 : multiplicative respiratory-suppression synergy factor if BENZO_COUSE=1
XYLAZINE_RESP_ADD : 0.15 : additive respiratory-suppression from xylazine (naloxone-refractory)
RESP_APNEA_THRESHOLD : 0.25 : respiratory index below which apnea/overdose flagged
//--- Methadone-associated QTc (ms) turnover (slow, accumulation-linked)
KOUT_QTC : 0.01 : 1/h
QTC_BASE : 420 : ms
EC50_METH_QTC : 0.30 : mg/L, methadone EC50 for hERG-linked QTc prolongation
EMAX_METH_QTC : 65 : ms, max QTc prolongation from methadone
//--- Phasic dopamine / euphoria index (0-100, fast turnover)
KOUT_DA : 1.2 : 1/h
DA_GAIN_NEWOCC: 140 : dopamine points per unit of *newly acquired* MOR occupancy (delta, blunted by tolerance)
//--- Treatment-retention index (0-1, slow weeks-scale)
KOUT_RETAIN : 0.004 : 1/h
RETAIN_TARGET_BASE : 0.25
RETAIN_MAT_BONUS : 0.55 : retention bonus from being on agonist/antagonist maintenance (occupancy-stabilized)
RETAIN_COWS_PENALTY: 0.02 : retention loss per COWS point
RETAIN_COUNSEL_BONUS: 0.20 : retention bonus from counseling engagement
[CMT] @annotated
GUT_FENT : Illicit fentanyl IN/smoked depot (mg)
CEN_FENT : Fentanyl central plasma (mg)
PER_FENT : Fentanyl peripheral/tissue (mg)
GUT_METH : Methadone gut depot (mg)
CEN_METH : Methadone plasma (mg)
GUT_BUP : Buprenorphine SL depot (mg)
DEPOT_BUP_XR : Buprenorphine XR-SC depot (mg)
CEN_BUP : Buprenorphine plasma (mg)
GUT_NLX : Naloxone IN/IM depot (mg)
CEN_NLX : Naloxone plasma (mg)
GUT_NTX : Naltrexone oral depot (mg)
DEPOT_NTX_XR : Naltrexone XR-IM depot (mg)
CEN_NTX : Naltrexone plasma (mg)
GUT_LOF : Lofexidine gut depot (mg)
CEN_LOF : Lofexidine plasma (mg)
TOL : MOR tolerance/adaptation index (0-1)
LC : Relative locus-coeruleus noradrenergic tone (1.0=normal)
COWS : Clinical Opiate Withdrawal Scale composite (0-48)
CRAVE : Craving VAS (0-100)
RESP : Relative respiratory-drive index (1.0=normal, 0=apnea)
QTC : Methadone-associated QTc interval (ms)
DA : Phasic dopamine/euphoria index (0-100)
RETAIN : Treatment-retention index (0-1)
[MAIN]
GUT_FENT_0 = 0; CEN_FENT_0 = 0; PER_FENT_0 = 0;
GUT_METH_0 = 0; CEN_METH_0 = 0;
GUT_BUP_0 = 0; DEPOT_BUP_XR_0 = 0; CEN_BUP_0 = 0;
GUT_NLX_0 = 0; CEN_NLX_0 = 0;
GUT_NTX_0 = 0; DEPOT_NTX_XR_0 = 0; CEN_NTX_0 = 0;
GUT_LOF_0 = 0; CEN_LOF_0 = 0;
TOL_0 = BASE_TOL;
LC_0 = 1.0 + (BASE_COWS/SCALE_COWS_LC);
COWS_0 = BASE_COWS;
CRAVE_0 = BASE_CRAVE;
RESP_0 = 1.0;
QTC_0 = QTC_BASE;
DA_0 = 0;
RETAIN_0 = BASE_RETAIN;
[ODE]
// ---------- PK ----------
double CFENT1 = CEN_FENT / V1_FENT;
double CFENT2 = PER_FENT / V2_FENT;
double CMETH = CEN_METH / V_METH;
double CBUP = CEN_BUP / V_BUP;
double CNLX = CEN_NLX / V_NLX;
double CNTX = CEN_NTX / V_NTX;
double CLOF = CEN_LOF / V_LOF;
dxdt_GUT_FENT = -KA_FENT_IN * GUT_FENT;
dxdt_CEN_FENT = F_FENT_IN * KA_FENT_IN * GUT_FENT
- (CL_FENT/V1_FENT) * CEN_FENT
- (Q_FENT/V1_FENT) * CEN_FENT + (Q_FENT/V2_FENT) * PER_FENT;
dxdt_PER_FENT = (Q_FENT/V1_FENT) * CEN_FENT - (Q_FENT/V2_FENT) * PER_FENT;
dxdt_GUT_METH = -KA_METH * GUT_METH;
dxdt_CEN_METH = F_METH * KA_METH * GUT_METH - (CL_METH/V_METH) * CEN_METH;
dxdt_GUT_BUP = -KA_BUP_SL * GUT_BUP;
dxdt_DEPOT_BUP_XR = -KREL_BUP_XR * DEPOT_BUP_XR;
dxdt_CEN_BUP = F_BUP_SL * KA_BUP_SL * GUT_BUP + KREL_BUP_XR * DEPOT_BUP_XR
- (CL_BUP/V_BUP) * CEN_BUP;
dxdt_GUT_NLX = -KA_NLX * GUT_NLX;
dxdt_CEN_NLX = F_NLX_IN * KA_NLX * GUT_NLX - (CL_NLX/V_NLX) * CEN_NLX;
dxdt_GUT_NTX = -KA_NTX_PO * GUT_NTX;
dxdt_DEPOT_NTX_XR = -KREL_NTX_XR * DEPOT_NTX_XR;
dxdt_CEN_NTX = F_NTX_PO * KA_NTX_PO * GUT_NTX + KREL_NTX_XR * DEPOT_NTX_XR
- (CL_NTX/V_NTX) * CEN_NTX;
dxdt_GUT_LOF = -KA_LOF * GUT_LOF;
dxdt_CEN_LOF = F_LOF * KA_LOF * GUT_LOF - (CL_LOF/V_LOF) * CEN_LOF;
// ---------- MOR occupancy: competitive-antagonism / multi-ligand Emax ----------
// Convert plasma "mg/L" to ng/mL-equivalent (numerically identical) for Ki comparison.
double a_fent = CFENT1 / KI_FENT;
double a_meth = CMETH / KI_METH;
double a_bup = CBUP / KI_BUP;
double a_nlx = CNLX / KI_NLX;
double a_ntx = CNTX / KI_NTX;
double sum_a = a_fent + a_meth + a_bup + a_nlx + a_ntx;
double occ_total = sum_a / (1.0 + sum_a); // total fractional MOR occupancy (all ligands)
double occ_agonist_frac = (sum_a > 1e-9) ? (a_fent + a_meth + a_bup) / sum_a : 0.0;
// Effective agonist-weighted occupancy (partial agonist ceiling applied to buprenorphine share)
double occ_full = (sum_a > 1e-9) ? occ_total * ((a_fent*EFF_FENT + a_meth*EFF_METH + a_bup*EFF_BUP) / sum_a) : 0.0;
double occ_eff = occ_full;
if (occ_eff > BUP_CEILING_OCC && (a_bup > a_fent) && (a_bup > a_meth)) {
// buprenorphine-dominated regime: enforce partial-agonist ceiling
occ_eff = BUP_CEILING_OCC + (occ_eff - BUP_CEILING_OCC) * 0.15;
}
// ---------- Tolerance/adaptation (slow; driven by sustained effective occupancy) ----------
double TOL_target = TOL_DRIVE_GAIN * occ_eff + BASE_TOL * (1.0 - occ_eff*0.3);
if (TOL_target > 1.0) TOL_target = 1.0;
dxdt_TOL = KOUT_TOL * (TOL_target - TOL);
// ---------- Locus-coeruleus tone (opponent-process rebound on occupancy deficit) ----------
double occ_deficit = TOL - occ_eff; // positive when tolerance exceeds current occupancy (withdrawal state)
if (occ_deficit < 0) occ_deficit = 0;
double lof_fx = EMAX_LOF_LC * CLOF / (EC50_LOF_LC + CLOF);
double LC_target = 1.0 + LC_REBOUND_GAIN * occ_deficit * (1.0 - lof_fx);
dxdt_LC = KOUT_LC * (LC_target - LC);
// ---------- Withdrawal (COWS) ----------
double lc_excess = LC - 1.0;
if (lc_excess < 0) lc_excess = 0;
double COWS_target = SCALE_COWS_LC * lc_excess;
if (COWS_target > 48) COWS_target = 48;
dxdt_COWS = KOUT_COWS * (COWS_target - COWS);
// ---------- Craving ----------
double counsel_fx = (COUNSELING > 0) ? (1.0 - COUNSELING_CRAVE_RED) : 1.0;
double CRAVE_target = (SCALE_CRAVE_COWS * COWS + SCALE_CRAVE_TOL * TOL) * counsel_fx;
if (CRAVE_target > 100) CRAVE_target = 100;
if (CRAVE_target < 0) CRAVE_target = 0;
dxdt_CRAVE = KOUT_CRAVE * (CRAVE_target - CRAVE);
// ---------- Respiratory drive (Hill suppression by full-agonist occupancy; synergy/adulterant terms) ----------
double occ_h = pow(occ_eff, RESP_GAMMA);
double resp_supp = RESP_EMAX_MOR * occ_h / (pow(0.5, RESP_GAMMA) + occ_h);
double benzo_fx = (BENZO_COUSE > 0) ? BENZO_RESP_MULT : 1.0;
double xyl_fx = (XYLAZINE_ADULT > 0) ? XYLAZINE_RESP_ADD : 0.0;
double RESP_target = 1.0 - resp_supp*benzo_fx - xyl_fx;
if (RESP_target < 0) RESP_target = 0;
dxdt_RESP = KOUT_RESP * (RESP_target - RESP);
// ---------- Methadone QTc ----------
double meth_qtc_fx = EMAX_METH_QTC * CMETH / (EC50_METH_QTC + CMETH);
double QTC_target = QTC_BASE + meth_qtc_fx;
dxdt_QTC = KOUT_QTC * (QTC_target - QTC);
// ---------- Phasic dopamine / euphoria (driven by newly acquired occupancy, blunted by tolerance) ----------
double new_occ = occ_eff - TOL;
if (new_occ < 0) new_occ = 0;
double DA_target = DA_GAIN_NEWOCC * new_occ * (1.0 - 0.6*TOL);
if (DA_target > 100) DA_target = 100;
dxdt_DA = KOUT_DA * (DA_target - DA);
// ---------- Treatment retention ----------
int on_maintenance = (a_bup > 0.05 || CMETH > (5.0/V_METH) || CNTX > (1.0/V_NTX)) ? 1 : 0;
double counsel_bonus = (COUNSELING > 0) ? RETAIN_COUNSEL_BONUS : 0.0;
double RETAIN_target = RETAIN_TARGET_BASE + (on_maintenance ? RETAIN_MAT_BONUS : 0.0)
- RETAIN_COWS_PENALTY*COWS + counsel_bonus;
if (RETAIN_target > 1.0) RETAIN_target = 1.0;
if (RETAIN_target < 0) RETAIN_target = 0;
dxdt_RETAIN = KOUT_RETAIN * (RETAIN_target - RETAIN);
[TABLE]
capture conc_fentanyl = CEN_FENT / V1_FENT;
capture conc_methadone = CEN_METH / V_METH;
capture conc_buprenorphine = CEN_BUP / V_BUP;
capture conc_naloxone = CEN_NLX / V_NLX;
capture conc_naltrexone = CEN_NTX / V_NTX;
capture conc_lofexidine = CEN_LOF / V_LOF;
capture MOR_occupancy_total = ( (CEN_FENT/V1_FENT)/KI_FENT + (CEN_METH/V_METH)/KI_METH + (CEN_BUP/V_BUP)/KI_BUP + (CEN_NLX/V_NLX)/KI_NLX + (CEN_NTX/V_NTX)/KI_NTX ) / (1.0 + (CEN_FENT/V1_FENT)/KI_FENT + (CEN_METH/V_METH)/KI_METH + (CEN_BUP/V_BUP)/KI_BUP + (CEN_NLX/V_NLX)/KI_NLX + (CEN_NTX/V_NTX)/KI_NTX );
capture Tolerance_idx = TOL;
capture LC_tone_idx = LC;
capture COWS_score = COWS;
capture Craving_VAS = CRAVE;
capture Respiratory_idx = RESP;
capture Overdose_flag = (RESP < RESP_APNEA_THRESHOLD) ? 1 : 0;
capture QTc_ms = QTC;
capture Dopamine_idx = DA;
capture Retention_idx = RETAIN;
[CAPTURE]
conc_fentanyl conc_methadone conc_buprenorphine conc_naloxone conc_naltrexone
conc_lofexidine MOR_occupancy_total Tolerance_idx LC_tone_idx COWS_score
Craving_VAS Respiratory_idx Overdose_flag QTc_ms Dopamine_idx Retention_idx
## ============================================================================
## R-side scenario helpers (parsed by users, not by mrgsolve)
## ============================================================================
##
## library(mrgsolve); library(dplyr); library(tidyr); library(ggplot2)
## mod <- mread_cache("oud_mrgsolve_model.R")
##
## # ---------- 10 prebuilt scenarios (end_h = simulation horizon, hours) ----------
##
## OUD_simulate_scenarios <- function(end_h = 672) {
##
## sc <- list(
## "1. Untreated chronic illicit fentanyl use (IN, q4-6h)" =
## ev(amt=1.5, cmt="GUT_FENT", ii=5, addl=ceiling(end_h/5)),
##
## "2. Fentanyl overdose (IV bolus) + naloxone rescue at 5 min" =
## seq(ev(amt=3.0, cmt="CEN_FENT", time=0),
## ev(amt=4.0, cmt="GUT_NLX", time=5/60)),
##
## "3. Methadone maintenance treatment (100 mg PO QD, steady state)" =
## ev(amt=100, cmt="GUT_METH", ii=24, addl=ceiling(end_h/24)),
##
## "4. Buprenorphine/naloxone SL maintenance (16 mg PO QD)" =
## ev(amt=16, cmt="GUT_BUP", ii=24, addl=ceiling(end_h/24)),
##
## "5. Precipitated withdrawal: buprenorphine induced too early" =
## seq(ev(amt=1.5, cmt="GUT_FENT", ii=5, addl=6),
## ev(amt=8, cmt="GUT_BUP", time=2)), # induced 2h after last use, high residual occupancy
##
## "6. Naltrexone XR-IM depot (380 mg, post-detox relapse prevention)" =
## ev(amt=380, cmt="DEPOT_NTX_XR", time=0),
##
## "7. Untreated abrupt cessation (\"cold turkey\") + lofexidine" =
## ev(amt=0.6, cmt="GUT_LOF", ii=8, addl=3*ceiling(end_h/24)), # after chronic-use history via BASE_TOL
##
## "8. Illicit fentanyl + benzodiazepine co-use (synergistic depression)" =
## ev(amt=1.5, cmt="GUT_FENT", ii=5, addl=ceiling(end_h/5)), # + BENZO_COUSE=1
##
## "9. High-dose methadone (140 mg QD) with QTc-risk comorbidity" =
## ev(amt=140, cmt="GUT_METH", ii=24, addl=ceiling(end_h/24)),
##
## "10. Relapse after buprenorphine discontinuation (tolerance lost)" =
## seq(ev(amt=16, cmt="GUT_BUP", ii=24, addl=30),
## ev(amt=1.5, cmt="GUT_FENT", time=35*24)) # return-to-use after 5-day taper gap
## )
##
## purrr::imap_dfr(sc, function(e, lab) {
## mod %>% mrgsim(e, end=end_h, delta=0.1) %>%
## as_tibble() %>% mutate(scenario=lab)
## })
## }
##
## # ---------- Calibration anchors ----------
## # MOR occupancy / respiratory Hill relationship (Dahan 2005/2010): steep,
## # near-threshold suppression of hypoxic ventilatory response at high
## # full-agonist occupancy; buprenorphine plateaus ~40-50% max suppression
## # even at supratherapeutic doses (Walsh 1994; Greenwald 2003 PET occupancy)
## # Naloxone renarcotization (t1/2 30-90 min vs fentanyl/methadone t1/2 hours):
## # repeat dosing/infusion required, esp. for long-acting agonist overdose
## # Methadone QTc (Krantz 2009; Chou 2014 ASAM/ACP guideline): dose-dependent
## # hERG block, torsades risk rises sharply >120-150 mg/day or with
## # hypokalemia/other QT-prolonging drugs
## # Naltrexone XR blockade duration (Comer 2005; Krupitsky 2011 Lancet):
## # near-complete MOR blockade sustained ~28 days per depot injection;
## # overdose risk markedly increases if a lapse in blockade coincides with
## # reduced tolerance and return to prior illicit dosing
## # Maintenance treatment retention & mortality (Mattick 2014 Cochrane; Sordo
## # 2017 BMJ): agonist/partial-agonist maintenance approximately halves
## # all-cause and overdose mortality vs no opioid-agonist treatment
## # COWS/LC-noradrenergic rebound kinetics (Wesson & Ling 2003; Volkow 2016
## # NEJM opponent-process model): peak withdrawal ~36-72h post-short-acting
## # opioid cessation, later/blunted with long-acting agents (methadone)
##
## # ---------- Quick sanity plots ----------
## # df <- OUD_simulate_scenarios(672)
## # ggplot(df, aes(time, MOR_occupancy_total, colour=scenario)) + geom_line() + xlab("hour")
## # ggplot(df, aes(time, Respiratory_idx, colour=scenario)) + geom_line() +
## # geom_hline(yintercept=0.25, lty=2) + xlab("hour")