Here is an implementation in R, with reproducible examples, as well. It is worth noting that it always returns a warning message about the anticipated errors in the ICM figures.
Code:
SICM <- function(stacks, prizes, sims=1000) {
if(length(prizes) != length(stacks)) {stop("Number of prizes not equal to number of remaining stacks. You might need to add prizes of value 0.")}
normstacks <- 1/(stacks / mean(stacks))
res <- matrix(nrow=sims, ncol=length(stacks))
for(i in 1:sims) {
rnums <- runif(length(stacks))
places <- rnums^normstacks
res[i,] <- prizes[length(places)+1 - rank(places, ties.method="random")]
}
out <- data.frame("Start.Stack"=stacks, "ICM.EV"=colMeans(res))
warning(paste("Errors are proportional to", 1/sqrt(sims)))
return(out)
}
Code:
stacks <- c(rep(1500,10))
prizes <- c(50, 30, 20, rep(0,7))
# Ex 1
SICM(stacks, prizes)
# Ex 2
SICM(stacks, prizes, sims=10000) # changing the sims for more precise results
# Ex 3
SICM(stacks=c(5000, 3000, 2000), prizes=c(50, 30, 20))
Code:
Example output:
> SICM(stacks, prizes)
Start.Stack ICM.EV
1 1500 10.76
2 1500 9.43
3 1500 10.38
4 1500 10.26
5 1500 9.28
6 1500 9.97
7 1500 10.88
8 1500 9.16
9 1500 10.28
10 1500 9.60
Warning message:
In SICM(stacks, prizes) : Errors are proportional to 0.0316227766016838
> SICM(stacks, prizes, sims=10000)
Start.Stack ICM.EV
1 1500 9.838
2 1500 9.976
3 1500 10.060
4 1500 10.212
5 1500 9.542
6 1500 9.923
7 1500 10.652
8 1500 9.593
9 1500 10.113
10 1500 10.091
Warning message:
In SICM(stacks, prizes, sims = 10000) : Errors are proportional to 0.01
> SICM(c(5000, 3000, 2000), c(50, 30, 20), sims=1000)
Start.Stack ICM.EV
1 5000 37.81
2 3000 32.85
3 2000 29.34
Warning message:
In SICM(c(5000, 3000, 2000), c(50, 30, 20), sims = 1000) :
Errors are proportional to 0.0316227766016838
Last edited by Sherman; 09-20-2011 at 01:47 PM.
Reason: added a fail-safe for improper user input.