[R] non-linear regression and root finding

Berwin A Turlach
2023-11-07T04:10:08Z

G'day Troels,

On Mon, 6 Nov 2023 20:43:10 +0100
Troels Ring <tring at gvdnet.dk> wrote:

> Thanks a lot! This was amazing. I'm not sure I see how the conditiion
> pK1 < pK2 < pK3 is enforced?

One way of enforcing such constraints (well, in finite computer
arithemtic only "<=" can be enforced) is to rewrite the parameters
as:

pK1 = exp(theta1)       ## only if pK1 > 0
pK2 = pK1 + exp(theta2)
pK3 = pk2 + exp(theta3)

And then use your optimiser to optimise over theta1, theta2 and theta3.

There might be better approaches depending on the specific problem.

Cheers,

	Berwin