issue using r function with rpy2
Question: Sorry if my question is not clear enaugh. It is my first question on this
site. 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 
    

Do you have any idea how to solve it?


Answer: 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)
    

