Skip to content

Instantly share code, notes, and snippets.

@fdavidcl
Last active September 29, 2015 21:02
Show Gist options
  • Save fdavidcl/2ed9d74cc09958234d3c to your computer and use it in GitHub Desktop.
Save fdavidcl/2ed9d74cc09958234d3c to your computer and use it in GitHub Desktop.
Teorema Central del Límite: lanzando dados
# Guion para comprobación del Teorema Central del Límite:
#
# The central limit theorem (CLT) states that, given certain conditions,
# the arithmetic mean of a sufficiently large number of iterates of
# independent random variables, each with a well-defined expected value
# and well-defined variance, will be approximately normally distributed,
# regardless of the underlying distribution -- Wikipedia (https://en.wikipedia.org/wiki/Central_limit_theorem)
#
simular <- function(dados = 20, caras = 6, muestras = 1000) {
throwDice <- function(n)
sum(sample(1:caras, n, replace = TRUE))
diceNum <- rep(dados, muestras)
hist(sapply(diceNum, throwDice), breaks = 100)
}
# Ejemplos:
simular()
simular(100, 20, 100000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment