Myles English wrote:
> Hello,
> 
> rpy 1.25
> ubuntu 6.10
> python 2.4
> 
> The code below can be copied and pasted in the R interpreter or an empty
> file, as appropriate, to be run easily.  The python code imports
> dataframe.py that is included as an example in the rpy distribution.
> 
> My question is:
>    
> Running the R code in the interpreter prints the list of hubertgamma
> values as:
>     0.6982304 0.6501113 0.5739095 0.5301628 0.4861548 0.4826513   
>     0.4579655 0.4465557 0.4329692 0.4092727
>     
> Running the RPy code in a shell prints the list of hubertgamma values
> as:
>  [0.052761567599982385, -0.0045159859941235163, -0.047153537691912426,
> -0.018242422413064344, -0.022733831895949543, -0.0033926040834361161,
> -0.020580660750514498, -0.018014109040888696, -0.012575979384130119]
>  
> Why aren't these two lists the same?  I think I am missing something in
> the conversion.

It doesn't look like you are setting the seed to the R random number
generator to 1 in the Python code - are you? If not, you will be using
two different sets of input values -> two different sets of answers.

Tim C

> # R code
> #================================================================
> # from http://addictedtor.free.fr/packages
> require(fpc)
> require(A2R)
> d.usa <- dist(USArrests, "euc")
> h.usa <- hclust(d.usa, method="ward")
> set.seed(1)
> some.factor <- letters[1:4][rbinom(50, prob=0.5, size=3)+1]
> hubertgamma <- rep(0,10)
> for(i in 1:10){
>   hubertgamma[i] <- cluster.stats(d.usa, 
>                                   cutree(h.usa, k=i+1),
>                                   G2 = FALSE,
>                                   G3 = FALSE,
>                                   silhouette = FALSE)$hubertgamma
> }
> A2Rplot(h.usa, 
>         k=3, 
>         fact.sup=some.factor, 
>         criteria=hubertgamma,
>         boxes = FALSE,
>         col.up = "gray",
>         col.down = c("orange","royalblue","green3"))
> hubertgamma
> #prints 0.6982304 0.6501113 0.5739095 0.5301628
> # 0.4861548 0.4826513 0.4579655
> # 0.4465557 0.4329692 0.4092727
> 
> # python code using RPy to put in a module
> #=========================================
> from rpy import *
> from dataframe import *         # dataframe.py comes with the rpy
> distribution
> class_table['data.frame'] = DataFrame
> 
> class A(object):
>     def build(self):
>         set_default_mode(NO_CONVERSION) # so that, hclust finds more
> than one item in rdist
>         d = r('USArrests')
>         self.rdist = r.dist(d, method = "euclidean")
>         self.dend = r.hclust(self.rdist, method="ward")
>         r.require('fpc')
>         r.require('A2R')
>         hubertgamma = []
>         set_default_mode(CLASS_CONVERSION)
>         f=['a','b','c','d']
>         self.somefactor = [f[int(i)] for i in r.rbinom(50, prob=0.5,
> size=3)]
>         self.hubertgamma = []
>         for i in range(1,10):   # not zero-based, could cause a problem
>             self.hubertgamma.append(r.cluster_stats(self.rdist, 
>                                   r.cutree(self.dend, k=i+1),
>                                   G2 = False,
>                                   G3 = False,
>                                   silhouette = False)['hubertgamma'])
>         r.x11()
>         r.A2Rplot(self.dend,
>                       k = 3,
>                       fact_sup=self.somefactor,
>                       criteria=self.hubertgamma,
>                       boxes = True,
>                       col_up = "gray",    
>                       col_down = ["orange","royalblue", "green3"])
>         #r.dev_off()
>         return self.hubertgamma
>             
> if __name__ == '__main__':
>     obj = A()
>     print obj.build()
>     #prints [0.052761567599982385, -0.0045159859941235163,
>     # -0.047153537691912426, -0.018242422413064344,
>     # -0.022733831895949543, -0.0033926040834361161,
>     # -0.020580660750514498, -0.018014109040888696,
>     # -0.012575979384130119]
> 
> 
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> rpy-list mailing list
> rpy-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rpy-list
> 


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to