Re: [R] least square fit with non-negativity constraints for absorption spectra fitting

From: Joerg van den Hoff <>
Date: Fri 14 Jul 2006 - 22:46:02 EST

Xu, Xiuli (NIH/NHLBI) [E] wrote:
> I would really appreciate it if someone can give suggestions on how to
> do spectra fitting in R using ordinary least square fitting and
> non-negativity constraints. The lm() function works well for ordinary
> least square fitting, but how to specify non-negativity constraints? It
> wouldn't make sense if the fitting coefficients coming out as negative
> in absorption spectra deconvolution.
> Thanks.
> Xiuli

I'm not sure, but would presume that constraints could not be imposed on a linear least squares fit. maybe someone can correct me.

if you move to `nls', i.e. non-linear least squares fitting, you should be able to transform your model function. say, you want some parameter `a' to stay positive. then you could e.g. substitute

`a = exp(b)' in the model function and fit `b' without constraints in the "new" model and calculate `a' afterwards (which obviously is guaranteed now to be positive). note that error estimates would than have to be computed by gaussian error propagation from `b' to `a'.

joerg mailing list PLEASE do read the posting guide! Received on Fri Jul 14 22:53:35 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 15 Jul 2006 - 02:14:18 EST.

Mailing list information is available at Please read the posting guide before posting to the list.