Previously, fit_c3_aci performed a check to ensure that the initial guess returned by initial_guess_fun lies within the lower and upper bounds supplied by the user (lower and upper, respectively):
However, the default_optimizer uses the dfoptim::nmkb function, which requires that the initial guess lies within (but not on) the bounds. If the initial guess lies on the bounds, no error is produced, but the optimizer's behavior becomes undefined and it may begin making guesses of NA for some parameter values.
This can lead to some weird behavior. E.g. if there is a strange looking A-Ci curve, initial_guess_c3_aci may produce a negative estimate for Rd, which then gets reset by fit_c3_aci to the default lower bound of 0, which then causes an issue with the optimizer. Ultimately, an error will occur when a value of Rd = NA is passed to calculate_c3_assimilation. This whole process is very difficult to debug because the (uninformative) error message does not indicate that the real issue is related to the initial guess being on the bounds.
This PR addresses this problem by modifying fit_c3_aci. Now, the initial_guess is checked (and possibly modified) to ensure that it lies within (but not on) the user-supplied bounds:
Previously,
fit_c3_aci
performed a check to ensure that the initial guess returned byinitial_guess_fun
lies within the lower and upper bounds supplied by the user (lower
andupper
, respectively):However, the
default_optimizer
uses thedfoptim::nmkb
function, which requires that the initial guess lies within (but not on) the bounds. If the initial guess lies on the bounds, no error is produced, but the optimizer's behavior becomes undefined and it may begin making guesses ofNA
for some parameter values.This can lead to some weird behavior. E.g. if there is a strange looking A-Ci curve,
initial_guess_c3_aci
may produce a negative estimate forRd
, which then gets reset byfit_c3_aci
to the default lower bound of 0, which then causes an issue with the optimizer. Ultimately, an error will occur when a value ofRd = NA
is passed tocalculate_c3_assimilation
. This whole process is very difficult to debug because the (uninformative) error message does not indicate that the real issue is related to the initial guess being on the bounds.This PR addresses this problem by modifying
fit_c3_aci
. Now, theinitial_guess
is checked (and possibly modified) to ensure that it lies within (but not on) the user-supplied bounds:This is an important bug fix, so it justifies a new version of the package.