2013-04-10 34 views
1

我在下面定制的N×N的距离矩阵numpy的/ SciPy的:送入距离矩阵与R集群从Rpy2

dist_matrix = array([array([5, 4, 2, 3, 2, 3]), 
         array([4, 5, 2, 3, 2, 2]), 
         array([2, 2, 5, 2, 2, 1]), 
         array([3, 3, 2, 5, 4, 2]), 
         array([2, 2, 2, 4, 5, 1]), 
         array([3, 2, 1, 2, 1, 5])]) 

我如何使用这个矩阵做聚类和情节树状图中R/GGPLOT2?如果我尝试通过rpy2这个距离矩阵送入R作为:

r.hclust(dist_matrix) 

我得到的错误:

res = super(Function, self).__call__(*new_args, **new_kwargs) 
rpy2.rinterface.RRuntimeError: Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed 65536") : 
    missing value where TRUE/FALSE needed 
+0

是'dist_matrix'是一个NxN数组,还是它是1d数组的形状为'(N,)'和dtype'object'的1d数组,因为它似乎显示? – askewchan 2013-04-10 19:59:59

+0

@askewchan:我可以用任何一种格式制作它......我尝试了两种方法并得到错误...但无论如何,我可以在两者之间来回切换 – user248237dfsf 2013-04-10 22:13:25

回答

1

R函数hclust()正在 “距离” 的对象:

from rpy2.robjects.packages import importr 
stats = importr("stats") 
d = stats.as_dist(m) 
hc = r.hclust(d) 

[注意:错误信息也暗示了rpy2中可能的转换错误。你能提交一份错误报告吗?谢谢]