rpy2 + negative binomial glm
<p>I am trying to call R <code>glm.nb</code> from <code>rpy2</code>:</p>

<pre><code>from rpy2 import robjects 
from rpy2.robjects.packages import importr

MASS = importr('MASS')
stats = importr('stats')

def glm_nb(x,y):
    formula = robjects.Formula('y~x')
    env = formula.environment
    env["x"] = x
    env["y"] = y
    fitted = MASS.glm_nb(formula)
#     fitted = stats.glm(formula)
    return fitted
</code></pre>

<p>Test:</p>

<pre><code>N = 100
x = np.random.rand(N)
y = x + np.random.poisson( 10, N)
fitted = glm_nb(x, np.round(y))
</code></pre>

<p>Returns an error:</p>

<pre><code>    104         for k, v in kwargs.items():
    105             new_kwargs[k] = conversion.py2ri(v)
--&gt; 106         res = super(Function, self).__call__(*new_args, **new_kwargs)
    107         res = conversion.ri2ro(res)
    108         return res

RRuntimeError: Error in x[good, , drop = FALSE] * w : non-conformable arrays
</code></pre>

<p>However when I run simple <code>glm</code> it runs OK. What can be the problem and how can one debug it?</p>