【发布时间】:2015-03-07 19:50:48
【问题描述】:
在这项研究中,我要求nRaters 对不同的响应选项进行投票(他们对不同选项的响应概率由ProbabilityDist 定义,如下所示)。对于每个item.i,投票在两种情况下停止(以先到者为准):
- “投票”数超过
AgreementThreshold(即同意某项的人数百分比。 - 回答问题的评分者的最大数量(由
MaxNRaters定义)
例如,如果 Rater1 和 Rater2 响应“A”,则投票停止,但如果 Rater1 响应“A”但 Rater2 响应“B”,则投票继续(在这种情况下,如果 Rater3 响应“A”,则应返回“A”,因为更多已达到 50% 以上。但是,如果 Rater3 响应“C”-“H”,则应返回“NoAgreement”,因为未达到 AgreementThreshold)。
我已经启动了下面的代码,但我一直在思考如何创建一个有条件停止的循环或函数。我也想重复这个,这样我就可以像d.out中的示例输出一样返回输出。
ResponseChoices= LETTERS[1:8]
ProbabilityDist= c(0.6, 0.2, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03)
MaxNRaters=3
AgreementThreshold = .5
#Obtain consensus answer when greater than 50% of raters agree
#e.g., if votes for Item.i = "A" "H" "A" return "A"
### Some kind of conditional loop here ###
### Note: the loop should iterate through multiple items using the stop rules described above
VotesForItem.i <- sample(ResponseChoices, nRaters, replace=TRUE, prob=ProbabilityDist)
##########################################
# return(votes)
#Sample of desired output
items=c(1:5)
VotedResponses=c("A","A","B","NoAgreement","A")
d.out=cbind(items,VotedResponses)
【问题讨论】:
标签: r for-loop while-loop