[R] Constraining Predicted Values to be Greater Than 0

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Sep 26 19:13:07 CEST 2007


You seem to be assuming that 'regression' has to do with 'gaussian 
assumption'.  However, I presume WLS stands for 'weighted least squares', 
and 'regression' is historically associated with fitting linear models by 
least squares.

I don't see why even in the model-based framework you assert that 
Westley cannot impose any constraints he wants on the *means*: the 
positivity constraint is on the means and not on the observations.  E.g. 
in chemistry it is reasonable to assume that concentrations are 
non-negative, but indirectly measured values need not be.  Note though 
that it is more usual to require that all predictions (at new points as 
well as data points) would be non-negative, which typically does reduce to 
constraints on the coefficients.

As to how to do this, a WLS problem with inequality constraints on the 
fitted values is a linearly-constrained quadratic programme.  So one 
avenue is to use solve.QP in package quadprog.  If you have a large 
problem you can make use of the necessary redundancy of the constraints: 
e.g. if the predictions at the convex hull of the data points are 
non-negative, they all are.


On Wed, 26 Sep 2007, Wensui Liu wrote:

> if your regression under gaussian assumption, then you can't
> constraint your predicted to be positive.
> I don't know much about your dep in the model. but given more
> appropriate distribution assumption, the constraint is doable. One
> possibility that I can think of is poisson.
>
> On 9/25/07, Westley Ritz <writz at trchome.com> wrote:
>> I have a WLS regression with 1 dependent variable and 3 independent 
>> variables.  I wish to constrain the predicted values (the fitted 
>> values) so that they are greater than zero (i.e. they are positive). 
>> I do not know how to impose this constraint in R.  Please respond if 
>> you have any suggestions.
>>
>> There are some previous postings about constraining the coefficients, 
>> but this won't accomplish what I am trying to do.  The coefficients can 
>> be negative, just as long as the predicted values are positive.
>>
>> Thank you in advance for your time.
>>
>> Westley A. Ritz
>> Analyst
>> 215-641-2243
>> writz at trchome.com
>>
>> TRC
>> www.trchome.com
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
>
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list