title: Constrained regression in Python with multiple constraints
body: <p>I am currently working on setting up a constrained regression in Python using </p>
  
  <pre><code>import statsmodels.api as sm
  
  model = sm.GLM(Y,X)    
  model.fit_constrained 
  
  '''Setting the restrictions on parameters in the form of (R, q), where R 
  and q are constraints' matrix and constraints' values, respectively. As
  for the restriction in the aforementioned regression model, i.e., 
  c = b - 1 or b - c = 1, R = [0, 1, -1] and q = 1.'''
  </code></pre>
  
  <p>function from StatsModel but running into some issues when I try to set it up with multiple constraints.  I have seven coefficients, including a constant.  I want to set it up so that a weighted sum of dummy 1 and dummy 2 equals zero and a weighted sum of dummy 3 and dummy 4 equals zero.  To use a single constraint example, </p>
  
  <pre><code>results = model.fit_constrained(([0, 0, 0, a, b, 0, 0], 0))
  </code></pre>
  
  <p>where a and b are the weights on dummy 3 and dummy 4 and are variables I've predefined.</p>
  
  <p>If I didn't have the a and b variables, and the dummies were equally weighted, I could just use the syntax</p>
  
  <pre><code>fit_constrained('Dummy1 + Dummy2, Dummy3 + Dummy4')
  </code></pre>
  
  <p>but when I try to use a similar syntax using</p>
  
  <pre><code>results = model.fit_constrained(([0, 0, 0, a, b, 0, 0], 0),([0, c, d, 0, 0, 0, 0], 0)) 
  </code></pre>
  
  <p>I get the error</p>
  
  <pre><code>ValueError: shapes (2,) and (7,6) not aligned: 2 (dim 0) != 7 (dim 0)
  </code></pre>
  
  <p>Does anyone have any ideas? Thanks so much!</p>