title: constrained multiple linear regression in R
body: <p>Suppose I have to estimate coefficients a,b in regression:  </p>
  
  <pre><code>y=a*x+b*z+c
  </code></pre>
  
  <p>I know in advance that y is always in range y>=0 and y&lt;=x, but regression model produces sometimes y outside of this range.</p>
  
  <p>Sample data:</p>
  
  <pre><code>mydata&lt;-data.frame(y=c(0,1,3,4,9,11),x=c(1,3,4,7,10,11),z=c(1,1,1,9,6,7))
  round(predict(lm(y~x+z,data=mydata)),2) 
      1     2     3     4     5     6 
  -0.87  1.79  3.12  4.30  9.34 10.32 
  </code></pre>
  
  <p>First predicted value is &lt;0.</p>
  
  <p>I tried model without intercept: all predictions are >0, but third prediction of y is >x (4.03>3)</p>
  
  <pre><code>round(predict(lm(y~x+z-1,data=mydata)),2)
     1    2    3    4    5    6 
  0.76 2.94 4.03 4.67 8.92 9.68 
  </code></pre>
  
  <p>I also considered to model <strong>proportion</strong> y/x instead of y:</p>
  
  <pre><code>mydata$y2x&lt;-mydata$y/mydata$x
  round(predict(lm(y2x~x+z,data=mydata)),2)
     1    2    3    4    5    6 
  0.15 0.39 0.50 0.49 0.97 1.04 
  round(predict(lm(y2x~x+z-1,data=mydata)),2)
     1    2    3    4    5    6 
  0.08 0.33 0.46 0.47 0.99 1.07 
  </code></pre>
  
  <p>But now sixth prediction is >1, but proportion should be in range [0,1].</p>
  
  <p>I also tried to apply method where <code>glm</code> is used with <code>offset</code> option: <a href="https://stackoverflow.com/questions/16046726/regression-for-a-rate-variable-in-r">Regression for a Rate variable in R</a> 
  and
  <a href="http://en.wikipedia.org/wiki/Poisson_regression#.22Exposure.22_and_offset" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Poisson_regression#.22Exposure.22_and_offset</a>
  but this was not successfull.</p>
  
  <p>Please note, in my data dependent variable: proportion <strong>y/x</strong> is both zero-inflated and one-inflated.
  Any idea, what is suitable approach to build a model in R ('glm','lm')?</p>