[R] least square fit with non-negativity constraints for absorption spectra fitting
Joerg van den Hoff
j.van_den_hoff at fz-rossendorf.de
Fri Jul 14 14:46:02 CEST 2006
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.
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'.
More information about the R-help