我需要计算一项调查的受访者之间的分歧。
第一步是计算两名受访者之间的分歧
function disagree(DISAG, otherMember) {
return Math.abs(DISAG.localeCompare(otherMember));
}
第二步是计算一个受访者与所有其他受访者之间的平均分歧。
要手动完成,我必须这样做:
1/(N-1) * (disagree(DISAG, otherMember) + disagree(DISAG, othermember2)) etc
为了尝试一次性完成,我编写了以下函数作为测试
function TEST(DISAG) {
var otherMembers = ["No problem", "Can improve", "Can improve"]
var indivDisag = []
var sum = 0
for (var i in otherMembers) {
indivDisag[i] = DISAG.localeCompare(otherMembers[i])
};
for (var i in indivDisag) {
sum += Math.abs(indivDisag[i]);
};
return sum / indivDisag.length
}
编辑:我原来的问题是由于拼写错误。我现在在电子表格中返回一个数字,但无论DISAG的值是多少,数字总是相同的。必须是在编写函数时我没有正确解释数学。
数学看起来像这样:
d(i,j) = disagreement of an individual (i) with another (j).
if i == j, then d(i,j) = 0. if i != j then d(i,j) = 1
di = average agreement of one person with the rest of the group.
di = 1/(N-1) * SUM( d(i,j)*f(j) )
where N = number of people who answered the survey
and f(j) is a function of the different individual disagreements.
用简单的英语:一个人的平均协议是她个人协议总和除以小组中可能的对数(N-1)的结果。
感谢您的帮助
答案 0 :(得分:0)
几点意见
我没有链接google脚本知道localCompare()是什么。 因此,如果您修复此问题,它会认为您已将函数附加到对象。
调试器不会在你的函数上运行,因为它希望传递一个变量。
function TEST(DISAG) {
运行调试器时,它不会知道“DISAG”指的是什么。所以当它在
中遇到它时indivDisag = DISAG.localCompare(otherMembers[i])
它不知道该怎么做。
您可以将它作为变量包含在函数TEST()中,以便进行调试。