Single error model in nlmefit and nlmefitsa
Show older comments
Hi, I am trying to do a nonlinear mixed effects fit in SimBiology, primarily with the App. It seems that the error model for mixed effects has only one choice to make, contrary to nonlinear regression. In DATA MAP, I do have 2 responses that are mapped to the model's observables, and they do differ in scales (~100x), where it kind of suggests using 1 error model for both is not the most appropriate. I also did pooled fit and the error model parameter do differ (exponential error model, a=0.46 and a=1.22). Hence I wanted to know if it can be done separately (2 error models for 2 responses). In NONMEM it can be done with an indicator variable or equivalently if/else.
If it is not supported yet is there any workaround? Will a sequential fit for the 2 responses be reasonable enough as alternative? How would that be?
Answers (1)
Umar
on 5 Sep 2026 at 4:20
0 votes
Hi @Haiyang,
You are right, and this isn't a UI limitation you're missing — it's a documented restriction. If you check the fitproblemreference page, the ErrorModel property section spells it out directly:
When FitFunction="sbiofit" (regular nonlinear regression, not mixed-effects), you can pass a vector/cell array of error models, one per response, as long as your FunctionName is one of lsqnonlin, lsqcurvefit, fmincon, fminunc, fminsearch, patternsearch, ga, or particleswarm.
When FitFunction="sbiofitmixed" (which is what runs under the hood for NLME fits, calling nlmefit/nlmefitsa from Statistics and Machine Learning Toolbox), the doc states plainly: "You can specify only one error model." Full stop. So this traces back to nlmefit/nlmefitsa themselves — those functions only take a single ErrorModel argument, there's no per-response option, unlike NONMEM's indicator-variable approach. It's a genuine feature gap in the current release, not something you're configuring wrong in the app.
On your workaround questions:
Sequential fitting — yes, this is workable and probably your most practical option right now. Fit response 1 alone with its own error model, then fit response 2 alone with its own error model. The tradeoff is that you lose the joint covariance structure between the two responses — any shared or correlated random effects across them won't be captured, and your two fits are estimated independently rather than as one coherent model. If the two responses are mechanistically linked in your model (e.g., parent/complex, or two compartments), that's a real loss of information, not just a formality.
Alternative worth trying first — since your problem is really a ~100x scale mismatch, consider just rescaling one or both responses (or log-transforming both) before fitting jointly with a single error model. That often resolves the "one error model doesn't fit both" issue without giving up the joint NLME structure. Worth checking whether your exponential error model discrepancy (a=0.46 vs 1.22) persists after normalizing scale, since exponential error is already scale-invariant to some degree — if it still differs that much post-normalization, it suggests a genuine difference in noise structure between assays/responses, not just a scaling artifact.
If you want a firmer answer on whether this is on a roadmap to fix, I'd flag it to MathWorks tech support directly rather than just posting here — Answers threads on niche SimBiology fitting internals don't always get MathWorks staff eyes quickly.
Categories
Find more on Import Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!