[R] add constraints to nls or use another function
Ben Bolker
bbolker at gmail.com
Thu Jun 28 15:11:53 CEST 2012
PtitBleu <ptit_bleu <at> yahoo.fr> writes:
>
> Hello,
>
> I'm trying to fit experimental data with a model and nls.
> For some experiments, I have data with x from 0 to 1.2 and the fit is quite
> good.
> But it can happen that I have data only the [0,0.8] range (see the example
> below) and, then, the fit is not correct.
>
> I would like to add a constraint, for example : the second derivative must
> be positive.
> But I don't know how to add this to nls and, in fact, I'm not sure that it
> is possible.
> If not, could you give me a package and/or a function (and/or a complete
> solution, which will be great ...) ?
>
> Thanks in advance for your help,
> Have a good day,
> Ptit Bleu.
>
This is much less than you asked for -- suggestions rather than
worked solutions -- but -- if you code your own least-squares function
and fit it in optim (or use bbmle::mle2 and specify that
response~dnorm(...)) then you can add a penalty term to the objective
function that is zero when the second derivative is positive and
increases quadratically when the second derivative becomes negative.
There may also (?) be a way to impose such a constraint on
spline fits.
By the way, it looks like your model is actually linear
in the parameters, which might simplify things considerably ...
Ben Bolker
More information about the R-help
mailing list