Hello ,

I am trying to use the r.nls function from rpy2 in the same fashion as rpy by importing rpy_classic.


In R: the syntax y ~ x would tell the lm function that y depends on x as its model.

In python using rpy I would use rpy's "evaluate a string" functionality.

i.e.

>>> from rpy import r
>>> my_x = [5.05, 6.75, 3.21, 2.66]
>>> my_y = [1.65, 26.5, -5.93, 7.96]
>>> print r.lm(r("y ~ x"), data = r.data_frame(x=my_x, y=my_y)) ['coefficients']

as described in the man pages:

However, if I do the same with rpy2

>>> from rpy2.rpy_classic import r
>>> my_x = [5.05, 6.75, 3.21, 2.66]
>>> my_y = [1.65, 26.5, -5.93, 7.96]
>>> r.lm(r("y ~ x"), data = r.data_frame(x=my_x, y=my_y))


   I get the following error:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
File "/home/radon00/rivas/lib/python/rpy2/rpy_classic.py", line 265, in __call__
    return self.eval(self.parse(text=s))
File "/home/radon00/rivas/lib/python/rpy2/rpy_classic.py", line 215, in __call__
    res = rpy2py(res)
File "/home/radon00/rivas/lib/python/rpy2/rpy_classic.py", line 174, in rpy2py
    res = rpy2py_basic(obj)
File "/home/radon00/rivas/lib/python/rpy2/rpy_classic.py", line 160, in rpy2py_basic
    raise ValueError("Invalid type for 'obj'.")
ValueError: Invalid type for 'obj'.


any ideas how to do the same operation in rpy2 with rpy_classic?

thanks,
 Manuel Rivas

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to