nlmixrdevelopment / nlmixr

nlmixr: an R package for population PKPD modeling
https://nlmixrdevelopment.github.io/nlmixr/
GNU General Public License v2.0
115 stars 45 forks source link

With multiple endpoints, all residual error predictions must be specified with the | syntax. #140

Closed EvanTarbell closed 5 years ago

EvanTarbell commented 5 years ago

Trying to run my model and during the syntax check i got the following error:

nlmixr(pbpk) Error in nlmixrUIModel(.model, ini, fun) : With multiple endpoints, all residual error predictions must be specified with the | syntax. Error in nlmixrUI(object) : Error parsing model.

I looked at the last issue that raised this problem and saw how to address it, but i have a problem. My concentrations are based on several ODEs

d/dt(CPL_Exo1H) = ... d/dt(CPL_Exo1TL1AH ) = ... d/dt(CPL_Exo1MTL1AH)=...

Plasma mAb

      Plasma_Exo1H_total_nM= (CPL_Exo1H + CPL_Exo1TL1AH + CPL_Exo1MTL1AH)*(1e+09);
      CPmAbT=Plasma_Exo1H_total_nM;
  CPmAbT ~  prop(prop.err);

How should i then specify the error?

mattfidler commented 5 years ago

You need to link the resposne to the compartment number in the model.

d/dt(CPL_Exo1H) = ...
d/dt(CPL_Exo1TL1AH ) = ...
d/dt(CPL_Exo1MTL1AH)=...

Plasma_Exo1H_total_nM= (CPL_Exo1H + CPL_Exo1TL1AH + CPL_Exo1MTL1AH)*(1e+09);
      CPmAbT=Plasma_Exo1H_total_nM;
  CPmAbT ~  prop(prop.err);

Would become:

Plasma_Exo1H_total_nM= (CPL_Exo1H + CPL_Exo1TL1AH + CPL_Exo1MTL1AH)*(1e+09);
      CPmAbT=Plasma_Exo1H_total_nM;
  CPmAbT ~  prop(prop.err) | CPL_Exo1H

Depending on what "CMT" number you use for the response.

EvanTarbell commented 5 years ago

If I understand correctly, you're saying that the CMT value in the fitting data should correspond to the CPL_Exo1H value (or either of the other two)? What if the CMT value corresponds to the CPmAbT concentration? Or am I misunderstanding? Thanks

mattfidler commented 5 years ago

The CMT value corresponds to the CMT in the model.

For differential equation models, these CMTs relate to the compartment defined by the differential equations. You could define an additional non-PBPK "compartment" or indicator, but that isn't supported by the stable release, just the github release.

Therefore because your differental equations are defined in terms of:

d/dt(CPL_Exo1H) = ...
d/dt(CPL_Exo1TL1AH ) = ...
d/dt(CPL_Exo1MTL1AH)=...

Your conditions should be defined in terms of these compartments CPL_Exo1H, CPL_Exo1TL1AH, and CPL_Exo1MTL1AH. I believe this is similar to how NONMEM handles compartments. The compartment number is defined by the order of differential equations in the model:

d/dt(mod1)=...# CMT=1
d/dt(mod2)=...# CMT=2
...
d/dt(modN)=... # CMT=n

Therefore the derived concentration Plasma_Exo1H_total_nM would relate to some compartment in your model.

mattfidler commented 5 years ago

I think this is a bit confusing, so on the next release I aim to have the following way to specify compartments:

CPmAbT ~  prop(prop.err) | CPmAbT 

In this release you would specify CMT as CPmAbT and not worry too much about the renumbering of CMTs like you need to in NONMEM.

sarahfcook commented 5 years ago

So it sounds like, in the stable release, it is not possible to fit observations that are a composite (e.g., sum) of the solutions for multiple differential equations. Am I interpreting that correctly?

@mattfidler, could you please clarify what you mean by:

You could define an additional non-PBPK "compartment" or indicator, but that isn't supported by the stable release, just the github release.

I am wondering if there is some workaround that would be possible in the github release to fit observations that are a composite of the solutions from multiple ODEs.

mattfidler commented 5 years ago

Hi @sarahfcook,

You can fit observations that are a composite solution from multiple ODEs with the stable release.

The ODE state CPL_Exo1H is related to the amounts in that compartment and defines how events and amounts in that compartment behave.

In a similar manner, it makes sense that observations related to CPL_Exo1H would be related to the amount in that compartment. However, when nlmixr reads CPL_Exo1H it translates it to the compartment number defined by RxODE. Observations in this compartment number do not have to be related to the amounts in CPL_Exo1H. This compartment number becomes simply an indicator of where the responses may be found, not how they are created.

Therefore in the data, when the compartment number corresponds to CPL_Exo1H with EVID=0 you could actually model the sum of the response instead of the amount in CPL_Exo1H. It all comes down to the model definition.

Plasma_Exo1H_total_nM= (CPL_Exo1H + CPL_Exo1TL1AH + CPL_Exo1MTL1AH)*(1e+09);
      CPmAbT=Plasma_Exo1H_total_nM; # What I want to model
  CPmAbT ~  prop(prop.err) | CPL_Exo1H # Model assuming proportional error w/CMT=CPL_Exo1H
# Note that CPL_Exo1H is just an indicator of where the response is found.

Right now, the only thing you can condition on are names defined in your ODE block. I believe this design causes confusion. In the next release, I will allow conditioning on any name. I also changed nlmixr/RxODE to take named compartments so CMT="CPmAbT" would be completely acceptable and help the legibility of the model.

With that new design, you would simply have to use:

CPmAbT ~  prop(prop.err) | CPmAbT

With CMT=CPmAbT being the compartment indicator. This is what I meant in my comment.

Hopefully this clarifies the situation with the stable release and the plans for the next release.

sarahfcook commented 5 years ago

Ah, I see now. Thanks so much for the clarification @mattfidler. This helps a lot.