Never mind, I solved it. The trick was to do:

larscv=lars.cv_lars(Xr,yr)

instead of the code I presented. Sorry for the apparent spam :-).

2012/8/1 Néstor Espinoza <nestor.espino...@gmail.com>

> Dear all,
>
>  I'm having trouble calling the cv.lars 
> function<http://cran.r-project.org/web/packages/lars/lars.pdf>in Python from 
> the 'lars' package. I suppose the problem is that the
> function has to be called with an extra point, which is not described in
> the examples on the page. My attempt was to do (the part in bold is the
> important one):
>
> import rpy2.robjects as robj
> from pylab import *
> X=ones([10,2])                      # We create a matrix with 2 columns,
> 10 rows (10 observations, 2 predictors)
> X[:,1]=arange(10)                  # The second column is 0,1,2,...9
> (we're trying to form the y=ax+b model)
> y=arange(10)+normal(0.0,1.0,10)              # The observations!
> lars=robj.packages.importr("lars")              # We import the lars
> package
> sts=robj.packages.importr("stats")             # We import the stats
> package.
> # We convert the python array to a R matrix.
> nr,nc=X.shape
> Xvec=robj.FloatVector(X.transpose().reshape(X.size))
> Xr=robj.r.matrix(Xvec,nrow=nr,ncol=nc)     # -> This is an R matrix!
> yr=robj.FloatVector(y)                             # -> This is "y" as an
> R vector
> *larscv=lars.cv.lars(Xr,yr)                      # This doesn't work!*
>
> When I execute this Python code, I get:
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: 'SignatureTranslatedPackage' object has no attribute 'cv'
>
> What am I doing wrong?
>
> Thanks in advance!
>
> --
> Néstor
>



-- 
Néstor
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to