metrumresearchgroup / bbr

R interface for model and project management
https://metrumresearchgroup.github.io/bbr/
Other
22 stars 2 forks source link

Problems summarizing mixture models ($MIX) #412

Open dpolhamus opened 2 years ago

dpolhamus commented 2 years ago

model_summary throws an error with the summary tibble when applied to the output of a model that contains a mixture component ($MIX).

NONMEM example EX-95 in help guide VIII.pdf has a mixture model example that should throw this same error.

Thanks!

> mod444 %>% model_summary
Dataset: ../../../data/derived/dat_nm2.csv                                                                                                                                            

Records: 4590    Observations: 416   Subjects: 325

Objective Function Value (final est. method): 1026.83687760111

Estimation Method(s):

– Laplacian Conditional Estimation 

**Heuristic Problem(s) Detected:**

– prderr 

 Show Traceback

 Rerun with Debug
 Error: All columns in a tibble must be vectors.
x Column `fixed` is NULL. 
kyleam commented 2 years ago

Given that this is triggered by model_summary, $fixed in print.bbi_nonmem_summary seems to be the likely culprit:

https://github.com/metrumresearchgroup/bbr/blob/6d9a1b4498669463c90468f20d785130e1c8940a/R/print.R#L197-L199

If that's true, then you shouldn't see the error if you call print(..., .fixed = TRUE) with the result of model_summary, and, to fix the issue on bbr's end, it might be sufficient to guard against a null value here (though maybe there are other downstream issues).

NONMEM example EX-95 in help guide VIII.pdf has a mixture model example that should throw this same error.

Thanks for pointing to an example for debugging. What's the data that this example references?

$DATA  DATA2 (6F7.0)

To get the example running, I substituted in nm75/examples/example3.csv. I also changed the method to LAPLACIAN to match the estimation method in your output.

diff ```diff diff --git a/ex95.ctl b/ex95.ctl index b2ec6c8..775da32 100644 --- a/ex95.ctl +++ b/ex95.ctl @@ -1,6 +1,7 @@ $PROB PHENOBARB POPULATION DATA MIXTURE MODEL -$DATA DATA2 (6F7.0) -$INPUT ID TIME AMT WT APGR CP=DV +$INPUT C SET ID JID TIME CONC=DV DOSE=AMT RATE EVID MDV CMT VC1 K101 + VC2 K102 SIGZ PROB +$DATA ../example3.csv IGNORE=C $SUBROUTINES ADVAN1 TRANS2 $PK CALLFL=1 @@ -23,5 +24,9 @@ $THETA (0,.0047) (0,1) (0,.99) (0,1) (0,.5,1) $OMEGA BLOCK(2) .05 .01 .03 $OMEGA BLOCK(2) SAME $SIGMA .02 -$ESTM MAXEVAL=500 PRINT=5 +$ESTIMATION + MAXEVAL=9999 + NSIG=4 + METHOD=COND INTERACTION LAPLACIAN + PRINT=5 $TABLE ID EST FIRSTONLY NOAPPEND ```

That looks like it runs successfully, but I'm not able to trigger the failure.

 > m <- new_model("ex95")
 > m %>% submit_model(.mode = "local")
 > m %>% model_summary
 Dataset: ../example3.csv

 Records: 2700    Observations: 2400      Subjects: 300

 Objective Function Value (final est. method): -5674.557

 Estimation Method(s):

  Laplacian Conditional Estimation with Interaction

 **Heuristic Problem(s) Detected:**

  parameter_near_boundary

  has_final_zero_gradient

  minimization_terminated

 |parameter_names |estimate |stderr    |shrinkage |
 |:---------------|:--------|:---------|:---------|
 |THETA1          |6.58e+03 |-1.00e+09 |          |
 |THETA2          |0.0100   |-1.00e+09 |          |
 |THETA3          |952      |-1.00e+09 |          |
 |THETA4          |0.0606   |-1.00e+09 |          |
 |THETA5          |0.00500  |-1.00e+09 |          |
 |OMEGA(1,1)      |68.1     |-1.00e+09 |          |
 |OMEGA(2,2)      |0.798    |-1.00e+09 |          |
 |SIGMA(1,1)      |0.0640   |-1.00e+09 |          |
 Warning message:
 In add_param_shrinkage(param_df, .summary) :
   When using `param_estimates()` with a mixture model (multiple subpops) the `shrinkage` column will be all `NA`.
 Users can manually extract shrinkage for each subpop from the `shrinkage_details` element of the `bbi_nonmem_summary` object.

That's with bbi v3.1.0, nmfe75, and bbr's current develop branch (d9a1b4).

Any ideas what I'm missing?