Question

When I do

from rpy2.robjects import IntVector, Formula
from rpy2 import robjects
rr = Formula('gr_bmr~nationalite_france')
myparams = {'family': 'binomial'}     
formula=robjects.r('gr_bmr~nationalite_simple') 
robjects.r['glm'](rr,data=bdd1,**myparams)

I have this error: Erreur dans eval(expr, envir, enclos) : les valeurs de y doivent être 0 <= y <= 1

RRuntimeError Traceback (most recent call last) in () ----> 1 robjects.r['glm'](rr,data=bdd1,**myparams)

/Library/Python/2.7/site-packages/rpy2/robjects/functions.pyc in call(self, *args, **kwargs) 84 v = kwargs.pop(k) 85 kwargs[r_k] = v ---> 86 return super(SignatureTranslatedFunction, self).call(*args, **kwargs)

/Library/Python/2.7/site-packages/rpy2/robjects/functions.pyc in call(self, *args, **kwargs) 33 for k, v in kwargs.iteritems(): 34 new_kwargs[k] = conversion.py2ri(v) ---> 35 res = super(Function, self).call(*new_args, **new_kwargs) 36 res = conversion.ri2py(res) 37 return res

RRuntimeError: Erreur dans eval(expr, envir, enclos) : les valeurs de y doivent être 0 <= y <= 1

I can translate in English if it is not clear. But, when I do the same thing in R, everything is working find:

glm(gr_bmr~nationalite_france,family=binomial,data=bdd1)

Call: glm(formula = gr_bmr ~ nationalite_france, family = binomial, data = bdd1)

Coefficients: (Intercept) nationalite_franceoui
-2.3609 -0.3604 

How to solve it?

Was it helpful?

Solution 2

I finally solve it by replacing all boolean data ("oui,"non") by (1,0) in bdd1. As it is working without replacing in R, I think this is a bug from rpy2. I don't understant why lgautier votes -1, this is not justified.

BR

OTHER TIPS

In you R code, binomial is a function while in your Python code it is a string. Try:

from rpy2.robjects import Formula
from rpy2.robjects.packages import importr
rr = Formula('gr_bmr~nationalite_france')
stats = importr('stats')
myparams = {'family': stats.binomial}
stats.glm(rr,data=bdd1,**myparams)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top