Thomas Walter wrote:

> pca = r.princomp(r.t(mat), cor=True)
> 
> Okay, this works. But if I want to use the predict functionality of 
> princomp, like:
> pred = r.predict(pca)
> 
> I obtain the following error:
> 
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> rpy.RException: Error in UseMethod("predict") : no applicable method for 
> "predict"
> 
> Does anybody know how I could deal with this problem?

  This is because your 'pca' object in Python is not an R principal 
components object. You need to mess with the conversion system:

 >>> pca=r('princomp(USArrests)')
 >>> pca

  - a big hash/list object appears....

  SO let's change the conversion mode:

 >>> rpy.set_default_mode(rpy.NO_CONVERSION)
 >>> pca=r('princomp(USArrests,cor=TRUE)')
 >>> pca
<Robj object at 0xb7d493f0>

  - now pca is a Robj this is basically the R object. So you can do:

 >>> r.predict(pca)

  but you get:

<Robj object at 0xb7d493e0>

  which isn't very useful as is. You could reset the conversion mode, or 
use r.print_(r.predict(pca)), which gives you the matrix.

Barry



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to