To Be Finished
for (i in 1:length(luckfactor)) {
for (j in 1:length(selected)) {
for (k in 1:R) {
simulationresults <- tibble(Skill = runif(n = N, min = minscore, max = maxscore), Luck = runif(n = N, min = minscore, max = maxscore)) %>%
mutate(Score = Skill * (1 - luckfactor[i]) + Luck * luckfactor[i])
luckyFew <- simulationresults %>%
mutate(SkillRank = N - rank(Skill) + 1,
ScoreRank = N - rank(Score) + 1,
SkillSelected = SkillRank <= selected[j] * N) %>%
arrange(ScoreRank) %>%
head(selected[j] * N)
results[[i]][[j]][k,] <- c(mean(luckyFew$Skill), mean(luckyFew$Luck), sum(luckyFew$SkillSelected), luckfactor[i], selected[j])
}
results[[i]][[j]] <- as.data.frame(results[[i]][[j]])
}
results[[i]] <- bind_rows(results[[i]])
}
results <- bind_rows(results)
colnames(results) <- c("Skill", "Luck", "SkillSelected", "LuckFactor", "ProportionSelected")
results$LuckFactor <- as.factor(results$LuckFactor)
results$ProportionSelectedfct <- as.factor(results$ProportionSelected)
results %>%
group_by(LuckFactor, ProportionSelectedfct) %>%
summarize(meanSkill = mean(Skill),
meanLuck = mean(Luck),
meanSelected = mean(SkillSelected),
medianSkill = median(Skill),
medianLuck = median(Luck),
medianSelected = median(SkillSelected),
propSelected = mean(SkillSelected/ProportionSelected)/N)
## `summarise()` has grouped output by 'LuckFactor'. You can override using the `.groups` argument.
## # A tibble: 16 x 9
## # Groups: LuckFactor [4]
## LuckFactor ProportionSelectedfct meanSkill meanLuck meanSelected medianSkill
## <fct> <fct> <dbl> <dbl> <dbl> <dbl>
## 1 0.01 5e-04 99.9 89.5 2.2 99.9
## 2 0.01 0.001 99.8 85.9 8.2 99.8
## 3 0.01 0.01 99.5 57.6 176. 99.5
## 4 0.01 0.1 95.0 51.4 1975. 95.0
## 5 0.02 5e-04 99.8 92.4 2.3 99.9
## 6 0.02 0.001 99.8 89.5 6.1 99.8
## 7 0.02 0.01 99.3 66.4 154. 99.3
## 8 0.02 0.1 95.1 52.1 1950. 95.1
## 9 0.05 5e-04 99.7 95.9 1.1 99.8
## 10 0.05 0.001 99.6 93.3 3.5 99.6
## 11 0.05 0.01 98.9 79.7 104. 98.9
## 12 0.05 0.1 94.9 54.7 1872. 94.9
## 13 0.1 5e-04 99.7 96.7 1 99.7
## 14 0.1 0.001 99.5 95.7 2.4 99.5
## 15 0.1 0.01 98.4 86.3 78.9 98.5
## 16 0.1 0.1 94.5 59.5 1728. 94.5
## # … with 3 more variables: medianLuck <dbl>, medianSelected <dbl>,
## # propSelected <dbl>