Skip to content

Instantly share code, notes, and snippets.

@duarteguilherme
Created September 18, 2018 19:08
Show Gist options
  • Save duarteguilherme/15891e272878e68a1b62ca5dfa210c45 to your computer and use it in GitHub Desktop.
Save duarteguilherme/15891e272878e68a1b62ca5dfa210c45 to your computer and use it in GitHub Desktop.
# Simulando probabilidades
# Teste
simula_eleicoes <- function(sd) {
ns <- seq(0.25, 0.75, 0.001)
v <- purrr::map_dbl(ns, ~ mean(
ifelse(
rnorm(n = 100000, mean = .x, sd = sd) > .5
, 1, 0 )
)
)
tibble(ns = ns, v = v)
}
ggplot2::qplot(data = simula_eleicoes(0.01), ns, v, geom = "line") + ggplot2::theme_bw() + scale_x_continuous(breaks = seq(0, 1,0.02)) +
labs(x = "porcentagem", y = "probabilidade_vitoria")
ggplot2::qplot(data = simula_eleicoes(0.03), ns, v, geom = "line") + ggplot2::theme_bw() + scale_x_continuous(breaks = seq(0, 1,0.02)) +
labs(x = "porcentagem", y = "probabilidade_vitoria")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment