Many thanks to Marcel Baumgartner, Prof Brian D Ripley, Christian Keller
and
Berwin A Turlach for their fast and instructive answers.
the point is to use nnls.fit.
I thought this function easier than lm() to use and more adapted to my
lower level program. Here is a little summary of the answers:
Prof Brian D Ripley : "nnls() is for this purpose"
Christian Keller adds (formula):
"Note that 'nnls.fit' can't handle model formulas,
e.g. you have to write
nnls.fit(cbind(x1,x2), y)
where x1 and x2 are the explanatory variables and y is the
response.
Note also that (by default) 'nnls.fit' does not estimate an
intercept term. To include an intercept, use
nnls.fit(cbind(1,x1,x2), y)
Unfortunately the output is rather poor
(no special print and summary methods)."
Berwin A Turlach adds (intercept) :
"nnls.fit by default restricts *all* coefficients to be non-negative,
also the intercept. If you don't want to impose the non-negativity
constraint on one of the parameters, then the standard trick is to
replicate the corresponding column and to multiplying that new column
by -1. For example, if in the above example you wouldn't want to have
the intercept constrained to be non-negative, then you could do:
> X <- cbind(-X[,1],X)
> nnls.fit(X,Y)
$coefficients:
(Intercept) Dens I(Dens^2) I(Dens^3)
431.8919 0 31.99779 0 0.003626301
So the estimated coefficient for the intercept is -431.8919."
M. Baumgartner suggests to use Excel also, I've not tried yet as I'm a
beginner in excel... He tells me to try nlmind(),which had so-called
box-constraints, but it looks a bit tricky since nlls() does perfectly the
job...
-------------------------------------------------------
Mathieu Ros
mathieuros@bigfoot.com
Universite Paul Sabatier, Toulouse.
-------------------------------------------------------
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|