library(tidyverse)
single_trial_prob <- .5
num_trials <- 2
0:num_trials ->
possible_outcomes
dbinom(x = possible_outcomes,
size = 2,
prob = single_trial_prob) ->
probs
tibble(possible_outcomes, probs) %>%
ggplot() +
aes(x = possible_outcomes) +
scale_x_continuous(breaks = possible_outcomes) +
aes(y = probs) +
geom_point() +
aes(xend = possible_outcomes,
yend = 0) +
geom_segment(lty = "dotted") +
labs(title = "Binomial Distribution of for ten events where probability of success for each event is .85 (success/failure probability is independent)" %>%
str_wrap()) +
geom_text(aes(label = probs %>% round(4)),
nudge_y = .01) +
annotate(geom = "text",
x = 1.5,
y = .2,
label = "nCk(pi^k)*(1-pi)^(n-k)",
parse = TRUE,
size = 5)
Board Problems for Lesson 27: Binomial, Geometric, and Normal Distributions
library(tidyverse)
single_trial_prob <- .85
num_trials <- 10
0:num_trials ->
possible_outcomes
dbinom(x = possible_outcomes,
size = 10,
prob = single_trial_prob) ->
probs
tibble(possible_outcomes, probs) %>%
ggplot() +
aes(x = possible_outcomes) +
scale_x_continuous(breaks = possible_outcomes) +
aes(y = probs) +
geom_point() +
aes(xend = possible_outcomes,
yend = 0) +
geom_segment(lty = "dotted") +
labs(title = "Binomial Distribution of for ten events where probability of success for each event is .85 (success/failure probability is independent)" %>%
str_wrap()) +
geom_text(aes(label = probs %>% round(4)),
nudge_y = .01) +
annotate(geom = "text",
x = 1.5,
y = .2,
label = "nCk(pi^k)*(1-pi)^(n-k)",
parse = TRUE,
size = 5)
# what is the probability of at least eight successes in ten trials
# when each trial is chance event with probability of .8
8:10 %>%
dbinom(x = .,
size = 10,
prob = .8) %>%
sum()
## [1] 0.6777995
# or probabilities associated with single outcome
dbinom(x = 8, size = 10, .8) +
dbinom(9, 10, .8) +
dbinom(10, 10, .8)
## [1] 0.6777995
# what is the probability of exactly 5 successes in 10 trials
# when each trial is chance event with probability .5 success
dbinom(5, 10, .5)
## [1] 0.2460938
\[\binom{n}k(\pi^k)(1-\pi)^{n-k}\]
–
Where n choose k (first part)
\[\frac{n!}{(n-k)!k!} \]
choose(5,2) *
.341^2 *
(1 - .341)^3
## [1] 0.332786
dbinom(2, 5, .341)
## [1] 0.332786
library(tidyverse)
single_trial_prob <- .8
num_trials <- 10
0:num_trials ->
possible_outcomes
dgeom(x = possible_outcomes,
prob = single_trial_prob) ->
probs
tibble(possible_outcomes, probs) %>%
ggplot() +
aes(x = possible_outcomes) +
scale_x_continuous(breaks = possible_outcomes) +
aes(y = probs) +
geom_point() +
aes(xend = possible_outcomes,
yend = 0) +
geom_segment(lty = "dotted") +
labs(title = "Geometric Distribution success by events where probability of success for each event is .8 (success/failure probability is independent)" %>%
str_wrap()) +
geom_text(aes(label = probs %>% round(4)),
nudge_y = .01) +
annotate(geom = "text",
x = 1.5,
y = 1,
label = "(pi^k)*(1-pi)^(n-k)",
parse = TRUE,
size = 5)
library(ggxmean)
ggxmean:::stamp_space() +
stamp_normal_dist(sd = 400^.5, mean = 400) +
stamp_normal_dist_zlines(sd = 400^.5, # sd = 20
mean = 400,
height = 20) ->
basenormal
## Warning: Ignoring unknown parameters: outline.type
basenormal
basenormal +
geom_vline(xintercept = 420, color = "green")
basenormal +
geom_vline(xintercept = 450, color = "blue")
basenormal +
geom_vline(xintercept = c(390, 425),
linetype = "dotted",
color = "red")