Manuel A. Rivas wrote:
> Thanks Laurent,
>
> I've decided to change to rpy2 instead and use that framework:
>
> A few questions I have :
>
>
> I am able to create a model using nls or lm
>
> say
> model = robjects.r.nls("y~a*x^3 + b*x^2 + c*x + d",start =
> robjects.r.list(a = 0, b = 0, c = 0, d = 0))
>
> it succesfully creates the model .
>
> Now, in rpy I would extract the $coefficients , $fitted from nls
> by
> pointing to the model as a dictionary
>
> list(r.print_(model['m']['fitted'])())
> would return a list of the fitted points
>
> now in rpy2 i successfully get to point to 'm'
>
> by returning model.r['m']
> which returns a vector
>
> however, i am having difficulty getting to $fitted under $m and printing
> the results.
with rpy2-2.0.x the robjects high-level interface is a little rough:
model.r['fitted'][0]
(see
http://rpy.sourceforge.net/rpy2/doc/html/introduction.html#linear-models )
with rpy2-2.1.x this is is getting (likely) better:
model.rx2('fitted')
(see
http://rpy.sourceforge.net/rpy2/doc-dev/html/robjects.html#extracting-elements
)
An other delegator ".rxd" ("R extract dollar") should complement ".rx"
("R extract [") and ".rx2" ("[[") in the future.
L.
>
> any ideas would be appreciated.
>
> thanks,
> manuel
>
>
> On Aug 5, 2009, at 12:12 PM, Laurent Gautier wrote:
>
>> Are you using rpy2-2.1dev ?
>>
>> If so, there were issues and you will want a (very) fresh update of
>> the code on the bitbucket repository.
>>
>>
>> L.
>>
>>
>> Manuel A. Rivas wrote:
>>> Thanks Laurent,
>>> Were you able to succesfully create the lm ?
>>> I get the following error with NO_CONVERSION:
>>> >>> rpy.r.lm(rpy.r("y ~ x"), data = rpy.r.data_frame(x=my_x, y=my_y))
>>> 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 199,
>>> in __call__
>>> a = a.getSexp()
>>> AttributeError: 'Robj' object has no attribute 'getSexp'
>>> thanks,
>>> manuel
>>> On Aug 5, 2009, at 11:17 AM, Laurent Gautier wrote:
>>>> Manuel A. Rivas wrote:
>>>>> 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?
>>>>
>>>> Try adding this to the beginning:
>>>>
>>>> import rpy2.rpy_classic as rpy
>>>> rpy.set_default_mode(rpy.NO_CONVERSION)
>>>>
>>>>
>>>> (rpy_classic is way behind the rest of rpy2 because of limited time
>>>> on my end, and seemingly limited interest/contributions from users
>>>> in having it improved to a full compatibility).
>>>>
>>>>
>>>>
>>>> L.
>>>>
>>>>
>>>>> 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
>>>>> [email protected] <mailto:[email protected]>
>>>>> https://lists.sourceforge.net/lists/listinfo/rpy-list
>>>>
>>
>
------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/rpy-list