Last active
June 20, 2019 15:14
-
-
Save AkselA/42aa4067ffce2cf630ae9560620e6563 to your computer and use it in GitHub Desktop.
This file contains 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
sides <- 8 | |
lim <- 6 | |
n <- 20 | |
lb <- 12 | |
ub <- 16 | |
pbinom(ub, n, (sides-lim)/sides) - pbinom(lb-1, n, (sides-lim)/sides) | |
# 0.000935362 |
This file contains 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
fc <- function(x) { # Factorial | |
x[x == 0] <- 1 | |
vapply(x, function(y) prod(1:y), numeric(1)) | |
} | |
ch <- function(n, k) fc(n)/(fc(k)*fc(n-k)) # Binomial coefficient | |
db <- function(x, n, p) ch(n, x) * p^x * (1-p)^(n-x) # PMF | |
pb <- function(q, n, p) sum(db(0:floor(q), n, p)) # CDF | |
pb(ub, n, (sides-lim)/sides) - pb(lb-1, n, (sides-lim)/sides) | |
# 0.000935362 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment