我正在尝试编写一个脚本来为已标记的论文分配主持人/第二标记,但我正在努力使其正确。
我主要有两个条件:
假设标记是 AA、AB、AC 和 AD。我们总共有 17 篇论文。我可以随机分配给 4 个人:
library(randomizr)
mod_list = complete_ra(N = 17, num_arms = 4, conditions = markers)
比如说,11 篇论文分配得很好,但 5 篇论文得到了与评分者相同的主持人:
论文ID | 标记 | 主持人 |
---|---|---|
3 | AA | AA |
8 | 广告 | 广告 |
11 | 交流 | 交流 |
13 | AA | AA |
16 | AB | AB |
如果我随后使用
%>%
mutate(no.self = ifelse(moderator == "AA" & marker == "AA",
sample(c("AB", "AC", "AD"), 2),
ifelse(moderator == "AB" & marker == "AB",
sample(c("AA", "AC", "AD"), 1),
ifelse(moderator == "AC" & marker == "AC",
sample(c("AA", "AB", "AD"), 1),
ifelse(moderator == "AD" & marker == "AD",
sample(c("AA", "AB", "AC"), 1),
moderator)))))
同等品种消失。
我如何确保 (1) 每个版主都需要对其他人的作品进行二次标记,但 (2) 版主之间的分类大致相等?
谢谢!
set.seed(1)
marker <- factor(rep(sample(c("AA", "AB", "AC", "AD")), length.out=10))
moderator <- marker
levels(moderator) <- c(levels(marker)[-1], levels(marker)[1])
dtf <- data.frame(paperID=seq_along(marker), marker, moderator)
dtf
# paperID marker moderator
# 1 1 AB AC
# 2 2 AD AA
# 3 3 AC AD
# 4 4 AA AB
# 5 5 AB AC
# 6 6 AD AA
# 7 7 AC AD
# 8 8 AA AB
# 9 9 AB AC
# 10 10 AD AA
这里标记的顺序是随机的,并且重复了足够的次数。
主持人遵循相同的模式,但 AA 变为 AB,AB 变为 AC,依此类推,保证再次重复。
library(randomizr)
# brute force, resample until they are all different
shuffle <- function(x, y) {
while(any(x == y)) {
y <- sample(y)
}
y
}
i <- apply(df1[-1], 1L, \(x) x[1L] == x[2L])
df1$moderator[i] <- shuffle(df1$marker[i], df1$moderator[i])
df1[i, ]
#> paperID marker moderator
#> 1 1 AD AA
#> 4 4 AB AA
#> 8 8 AA AD
#> 17 17 AA AB
创建于 2023-12-01,使用 reprex v2.0.2
library(randomizr)
set.seed(2023)
markers <- c("AA", "AB", "AC", "AD")
mark_list <- complete_ra(N = 17, num_arms = 4, conditions = markers) |> as.character()
mod_list <- complete_ra(N = 17, num_arms = 4, conditions = markers) |> as.character()
paperID <- seq.int(17)
df1 <- data.frame(paperID, marker = mark_list, moderator = mod_list)