Skip to content

Instantly share code, notes, and snippets.

@yuugit
Last active December 18, 2015 13:59
Show Gist options
  • Save yuugit/5793984 to your computer and use it in GitHub Desktop.
Save yuugit/5793984 to your computer and use it in GitHub Desktop.
probability
expected.x <- function(d, a, h) {
sum(sapply(0:h, function(y) prob.justy(d, a, h, y)) * 0:h)
}
prob.xormore <- function(d, a, h, x) {
if (d >= h && min(a, h) >= x)
sum(prob.justy.nocheck(d, a, h, x:min(a, h)))
else {
0
}
}
prob.justy <- function(d, a, h, y) {
if (d >= h)
prob.justy.nocheck(d, a, h, y)
else
0
}
prob.justy.nocheck <- function(d, a, h, y) {
choose(a, y) * choose(d-a, h-y) / choose(d, h)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment