# Torsten One or Two compartment IV model error

**URL:** <https://discourse.mc-stan.org/t/torsten-one-or-two-compartment-iv-model-error/12170>\
**Category:** Modeling\
**Created:** [December 3, 2019, 7:23pm UTC](https://discourse.mc-stan.org/t/torsten-one-or-two-compartment-iv-model-error/12170 "2019-12-03T19:23:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ntjames](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ntjames/32/7545_2.png) [@ntjames](https://discourse.mc-stan.org/u/ntjames)\
**Post date:** [December 3, 2019, 7:23pm UTC](https://discourse.mc-stan.org/t/torsten-one-or-two-compartment-iv-model-error/12170/1 "2019-12-03T19:23:16Z")

</div>

@billg, @yizhang, @charlesm93

I’m attempting to fit several IV infusion population PK models using Torsten. The user manual says that first-order absorption can be eliminated by setting ka=0, however when I set that parameter to 0 (theta[3]=0 using PKModelOneCpt() or theta[5]=0 using PKModelTwoCpt()), I get the following error and no sampling is done.

Chain 1: Rejecting initial value:  
Chain 1: Error evaluating the log probability at the initial value.  
Chain 1: Exception: PMXTwoCptModel: ka is 0, but must be \> 0! (in ‘modela845d45a7de\_3a354a9e89043ae5921a28b76b8a46e3’ at line 79)

The relevant section of the transformed parameters block is shown below. Any idea how to correct this so one and two compartment models can be used with IV data?

Thanks

```stan
...
  thetaHat[1] = CLHat;
  thetaHat[2] = QHat;
  thetaHat[3] = V1Hat;
  thetaHat[4] = V2Hat;
  thetaHat[5] = kaHat;

  // Matt's trick to use unit scale 
  thetaM = (rep_matrix(thetaHat, nSubjects) .* exp(diag_pre_multiply(omega, L * etaStd)))'; 
  
  for(j in 1:nSubjects)
  {
    theta[1] = thetaM[j, 1]; // CL
    theta[2] = thetaM[j, 2]; // Q
    theta[3] = thetaM[j, 3]; // V1
    theta[4] = thetaM[j, 4]; // V2
    //theta[5] = thetaM[j, 5]; // ka
    theta[5] = 0; // ka

    x[first[j]:last[j]] = PKModelTwoCpt(time[first[j]:last[j]], 
                                       amt[first[j]:last[j]],
                                       rate[first[j]:last[j]],
                                       ii[first[j]:last[j]],
                                       evid[first[j]:last[j]],
                                       cmt[first[j]:last[j]],
                                       addl[first[j]:last[j]],
                                       ss[first[j]:last[j]],
                                       theta, biovar, tlag);
...                 

```

---

<div class="post-metadata">

**Author:** ![yizhang](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yizhang/32/15673_2.png) [@yizhang](https://discourse.mc-stan.org/u/yizhang)\
**Post date:** [December 3, 2019, 7:25pm UTC](https://discourse.mc-stan.org/t/torsten-one-or-two-compartment-iv-model-error/12170/2 "2019-12-03T19:25:23Z")

</div>

Thanks for reporting. It’s a bug. I’ll fix it asap.

---

<div class="post-metadata">

**Author:** ![billg](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/billg/32/19991_2.png) [@billg](https://discourse.mc-stan.org/u/billg)\
**Post date:** [December 3, 2019, 7:56pm UTC](https://discourse.mc-stan.org/t/torsten-one-or-two-compartment-iv-model-error/12170/3 "2019-12-03T19:56:20Z")

</div>

It should work if you set ka to a fixed non-zero value. Just be sure that cmt[i] does not equal 1 when evid == 1.

---

<div class="post-metadata">

**Author:** ![yizhang](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yizhang/32/15673_2.png) [@yizhang](https://discourse.mc-stan.org/u/yizhang)\
**Post date:** [December 4, 2019, 4:09am UTC](https://discourse.mc-stan.org/t/torsten-one-or-two-compartment-iv-model-error/12170/4 "2019-12-04T04:09:28Z")

</div>

It’s [fixed](https://github.com/metrumresearchgroup/Torsten/pull/25). Now `ka=0` would have same effect as @billg mentioned above. Note that `ka > 0 ` is still checked in a steady-state dosing event.

It’s actually easier to submit issues to Torsten(which is [what I did anyway](https://github.com/metrumresearchgroup/Torsten/issues/24)).

---

<div class="post-metadata">

**Author:** ![ntjames](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ntjames/32/7545_2.png) [@ntjames](https://discourse.mc-stan.org/u/ntjames)\
**Post date:** [December 5, 2019, 1:01am UTC](https://discourse.mc-stan.org/t/torsten-one-or-two-compartment-iv-model-error/12170/5 "2019-12-05T01:01:18Z")

</div>

Thanks for the quick fix @yizhang! I’ll submit any future issues to github. @billg, your explanation makes perfect sense!
