我试图用 R 开发一个程序来估计 Spearman 与 Rcpp 的相关性。我做到了,但它只适用于向量范围小于 45 00 - 50 000 的矩阵。我不知道为什么,但它只适用于那个维度。我想这种类型的信息是有限制的,也许如果我像 data.frame 一样处理它?如果有人给我见解,我将非常感激。
我在这里发布我的代码。我一直在尝试限制我称之为“分母”的最大整数,它超出了它。也许你可以帮助我。
cppFunction('double spearman(NumericMatrix x){
int nrow = x.nrow(), ncol = x.ncol();
int nrow1 = nrow - 1;
double out = 0;
double cont = 0;
double cont1 = 0;
double r = 0;
int denominador = ncol*(pow(ncol,2.0)-1)
for(int i = 0; i < nrow1; i++){
#Here i use every combination of vectors starting with the first one, and so on
for(int j = i +1; j < nrow; j++){
cont1 = 0;
for(int t = 0; t < ncol; t++){
cont = pow(x(i,t)-x(j,t), 2.0);
cont1 += cont;
}
#Here i begin to store the mean correlation, in order to a final mean of all the possible correlations
r = 2*(1-6*(cont1/denominador))/(nrow*nrow1);
out += r;
}
}
return out;
}')
更简洁地重复一遍:
向量中可以包含超过 2^31-1 个元素。
矩阵是向量dim
属性。
矩阵中可以有超过 2^31-1 个元素(即n
times k
)
您的行索引和列索引仍然限制为 2^31。
大向量的示例:
R> n <- .Machine$integer.max + 100
R> tmpVec <- 1:n
R> length(tmpVec)
[1] 2147483747
R> newVec <- sqrt(tmpVec)
R>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)