import numpy as np
def kendall_w(expt_ratings):
if expt_ratings.ndim!=2:
raise 'ratings matrix must be 2-dimensional'
m = expt_ratings.shape[0] #raters
n = expt_ratings.shape[1] # items rated
denom = m**2*(n**3-n)
rating_sums = np.sum(expt_ratings, axis=0)
S = m*np.var(rating_sums)
return 12*S/denom
the_ratings = np.array([[1,2,3,4],[2,1,3,4],[1,3,2,4],[1,3,4,2]])
m = the_ratings.shape[0]
n = the_ratings.shape[1]
W = kendall_w(the_ratings)
count = 0
for trial in range(1000):
perm_trial = []
for _ in range(m):
perm_trial.append(list(np.random.permutation(range(1, 1+n))))
count += 1 if kendall_w(np.array(perm_trial)) > W else 0
print ('Calculated value of W:', W, ' exceeds permutation values in', count, 'out of 1000 cases')
如果有“m”评分器和“n”项,不应该是“n”的乘法而不是“S”中的“m”?在
我相信它没有被注意到,因为你在例子中使用了4个评分者和4个项目,所以'm=n'。我注意到了,因为我使用了这个代码,并且得到了大于1的值。在
我也不知道。但是,您可以用这种方法在Python中计算置换测试。请注意,我没有在公式“W”中包括对捆绑值的修正。在
在这种情况下,结果是
^{pr2}$您还应该注意,由于这些是随机排列,因此报告的值的数量会有一些变化。例如,在我做的一个试验中,我认为0.575的计算值只超过了1000个病例中的48个。在
相关问题 更多 >
编程相关推荐