背景/问题
我试图使用函数在两个向量的所有成对组合上应用一个函数作为参数。在我的例子中,其中一个输入是一个字符向量,它应该作为内部函数(cor())的参数,需要在它上运行match.arg()。
例1(起作用)
当内部函数不需要这一点时(比如paste() ),这是很好的工作方式。
# define function to test
f1 <- function(method, vec_len){
paste(method, vec_len)
}
# define inputs to test
methods <- c("pearson", "spea
我目前正在尝试对X数据集和Y数据集运行spearman秩相关测试,这两个数据集都包含3行(个人)。我可以使用cor()运行Spearman并获得值,它们都是:-1、-.5、-5或1。我的数据集里没有任何0。但是,当我使用rcorr()时,它会给出一个错误:
Error in rcorr(BPT2, y = FunT2, type = "spearman") :
must have >4 observations
我在比较肠道中的细菌物理(我的)和代谢读数(我的)。
所以我的问题是:
我得到的结果准确吗?
首先,我应该使用Spearman等级关联吗?
我一直在尝试使用pandas DataFrame生成基于corr矩阵的spearman。尽管我在DataFrame对象中插入了200+ nd.array,但所有结果都给了我190X190矩阵。 import pandas as pd
vectors # list of 200 nd.array with the same size
df = pd.DataFrame(vectors)
mat = df.corr(method="spearman")
print (len(mat)) 这行应该打印190,而我期望看到200,corr函数是否只支持最多190个元素?
我使用以下代码从mtcar关联计算Spearman r值:
library(plyr)
library(dplyr)
mtcars[mtcars==3.440] <- NA
mtcars[mtcars==4.22] <- NA
mtcars[mtcars==18.90] <- NA
selected <- select(mtcars, "cyl", "disp", "wt")
mtcars$cyl <- as.factor(mtcars$cyl)
for (i in "cyl") {
我试图在applyInPandas中使用appears函数,当我在某个类中转换它时,它会引发一些错误,比如this:pickle.PicklingError:未能序列化对象:异常:看起来您试图从广播变量、操作或转换引用SparkContext。SparkContext只能在驱动程序上使用,而不能在它在工作人员上运行的代码中使用。有关更多信息,请参见火花-5063。
我的脚本在函数类型编码方面运行良好:
from scipy.stats import kendalltau
import numpy as np
import pandas as pd
def kendall(dat, a, b)
我想运行每个列与pandas中所有其他列的Spearman关联。我只需要相关性的分布(数组),而不需要相关矩阵。
我知道我可以使用df.corr(method='spearman'),但是我只需要两两相关,而不是整个相关矩阵或对角线。我认为这可能会加快计算速度,因为我将只计算(( N^2 ) - N)/2相关性,而不是N^2。
然而,这只是一个假设--因为矩阵将是对称的,也许pandas已经通过计算相关矩阵的一半并相应地填充其余矩阵来工作。
到目前为止,我的解决方案非常低效:
import pandas as pd
import scipy.stats as ss
# d i
我试图执行与cor()函数的Pearson关联,但是输出只给出了1和-1,而不是系数本身。所以,当我用corrplot()绘制矩阵时,我只看到那些1和-1的值。我该怎么解决这个问题?可以找到我的数据集,并在下面看到我的脚本:
##Must load the libraries we will need! IF you have not installed the packages, do that before you start.
library("corrplot")
##Load in your datasets
D1=BPT5test
##if you don