Torsten One or Two compartment IV model error

@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?


  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]], 
                                       theta, biovar, tlag);

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

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.

It’s fixed. 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).

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