Last active
September 11, 2015 22:49
-
-
Save nkurz/b64b07fea23928753581 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bestAllocation = function(treatedList=c(0,1,8,39,152), # treated in each category | |
totalsList=rep(200, 5), # treated + untreated in each | |
numToAdd=100) { # number new treated available | |
addedList = rep(0, length(treatedList)) # start with nothing added | |
while (numToAdd > 0) { | |
ratio = (treatedList + addedList) / (totalsList + addedList) | |
lowest = which.min(ratio) | |
addedList[[lowest]] = addedList[[lowest]] + 1 | |
numToAdd = numToAdd - 1 | |
} | |
addedList | |
} | |
X = c(0,1,8,39,152) | |
n = rep(200,length(X)) | |
X / n | |
# [1] 0.000 0.005 0.040 0.195 0.760 | |
(a = bestAllocation(X, n, 100)) | |
# [1] 37 36 27 0 0 | |
(X + a) / (n + a) | |
# [1] 0.1561181 0.1567797 0.1541850 0.1950000 0.7600000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment