class: center, middle, inverse, title-slide # Exploded code ## Using flipbookr and xaringan ### Me --- <style type="text/css"> .remark-code{line-height: 1.5; font-size: 70%} @media print { .has-continuation { display: block; } } code.r.hljs.remark-code{ position: relative; overflow-x: hidden; } code.r.hljs.remark-code:hover{ overflow-x:visible; width: 500px; border-style: solid; } </style> --- count: false .panel1-base-auto[ ```r *library(tidyverse) ``` ] .panel2-base-auto[ ] --- count: false .panel1-base-auto[ ```r library(tidyverse) *single_trial_prob <- .5 ``` ] .panel2-base-auto[ ] --- count: false .panel1-base-auto[ ```r library(tidyverse) single_trial_prob <- .5 *num_trials <- 10 ``` ] .panel2-base-auto[ ] --- count: false .panel1-base-auto[ ```r library(tidyverse) single_trial_prob <- .5 num_trials <- 10 *0:num_trials ``` ] .panel2-base-auto[ ``` [1] 0 1 2 3 4 5 6 7 8 9 10 ``` ] --- count: false .panel1-base-auto[ ```r library(tidyverse) single_trial_prob <- .5 num_trials <- 10 0:num_trials -> * possible_outcomes ``` ] .panel2-base-auto[ ] --- count: false .panel1-base-auto[ ```r library(tidyverse) single_trial_prob <- .5 num_trials <- 10 0:num_trials -> possible_outcomes *dbinom(x = possible_outcomes, * size = 10, * prob = single_trial_prob) ``` ] .panel2-base-auto[ ``` [1] 0.0009765625 0.0097656250 0.0439453125 0.1171875000 0.2050781250 0.2460937500 0.2050781250 0.1171875000 0.0439453125 0.0097656250 0.0009765625 ``` ] --- count: false .panel1-base-auto[ ```r library(tidyverse) single_trial_prob <- .5 num_trials <- 10 0:num_trials -> possible_outcomes dbinom(x = possible_outcomes, size = 10, prob = single_trial_prob) -> * probs ``` ] .panel2-base-auto[ ] --- count: false .panel1-base-auto[ ```r library(tidyverse) single_trial_prob <- .5 num_trials <- 10 0:num_trials -> possible_outcomes dbinom(x = possible_outcomes, size = 10, prob = single_trial_prob) -> probs *tibble(possible_outcomes, probs) ``` ] .panel2-base-auto[ ``` # A tibble: 11 × 2 possible_outcomes probs <int> <dbl> 1 0 0.000977 2 1 0.00977 3 2 0.0439 4 3 0.117 5 4 0.205 6 5 0.246 7 6 0.205 8 7 0.117 9 8 0.0439 10 9 0.00977 11 10 0.000977 ``` ] --- count: false .panel1-base-auto[ ```r library(tidyverse) single_trial_prob <- .5 num_trials <- 10 0:num_trials -> possible_outcomes dbinom(x = possible_outcomes, size = 10, prob = single_trial_prob) -> probs tibble(possible_outcomes, probs) %>% * ggplot() ``` ] .panel2-base-auto[ ![](dbinom_dgeom_flipbook_files/figure-html/base_auto_09_output-1.png)<!-- --> ] --- count: false .panel1-base-auto[ ```r library(tidyverse) single_trial_prob <- .5 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) ``` ] .panel2-base-auto[ ![](dbinom_dgeom_flipbook_files/figure-html/base_auto_10_output-1.png)<!-- --> ] --- count: false .panel1-base-auto[ ```r library(tidyverse) single_trial_prob <- .5 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) ``` ] .panel2-base-auto[ ![](dbinom_dgeom_flipbook_files/figure-html/base_auto_11_output-1.png)<!-- --> ] --- count: false .panel1-base-auto[ ```r library(tidyverse) single_trial_prob <- .5 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) ``` ] .panel2-base-auto[ ![](dbinom_dgeom_flipbook_files/figure-html/base_auto_12_output-1.png)<!-- --> ] --- count: false .panel1-base-auto[ ```r library(tidyverse) single_trial_prob <- .5 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() ``` ] .panel2-base-auto[ ![](dbinom_dgeom_flipbook_files/figure-html/base_auto_13_output-1.png)<!-- --> ] --- count: false .panel1-base-auto[ ```r library(tidyverse) single_trial_prob <- .5 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) ``` ] .panel2-base-auto[ ![](dbinom_dgeom_flipbook_files/figure-html/base_auto_14_output-1.png)<!-- --> ] --- count: false .panel1-base-auto[ ```r library(tidyverse) single_trial_prob <- .5 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") ``` ] .panel2-base-auto[ ![](dbinom_dgeom_flipbook_files/figure-html/base_auto_15_output-1.png)<!-- --> ] --- count: false .panel1-base-auto[ ```r library(tidyverse) single_trial_prob <- .5 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 .5 (success/failure probability is independent)" %>% * str_wrap()) ``` ] .panel2-base-auto[ ![](dbinom_dgeom_flipbook_files/figure-html/base_auto_16_output-1.png)<!-- --> ] --- count: false .panel1-base-auto[ ```r library(tidyverse) single_trial_prob <- .5 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 .5 (success/failure probability is independent)" %>% str_wrap()) + * geom_text(aes(label = probs %>% round(4)), * nudge_y = .01) ``` ] .panel2-base-auto[ ![](dbinom_dgeom_flipbook_files/figure-html/base_auto_17_output-1.png)<!-- --> ] --- count: false .panel1-base-auto[ ```r library(tidyverse) single_trial_prob <- .5 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 .5 (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 = "P(n==k) == {Pi}", * parse = TRUE, * size = 5) ``` ] .panel2-base-auto[ ![](dbinom_dgeom_flipbook_files/figure-html/base_auto_18_output-1.png)<!-- --> ] <style> .panel1-base-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-base-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-base-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false .panel1-more-auto[ ```r # what is the probability of at least eight successes in ten trials # when each trial is chance event with probability of .8 *8:10 ``` ] .panel2-more-auto[ ``` [1] 8 9 10 ``` ] --- count: false .panel1-more-auto[ ```r # 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) ``` ] .panel2-more-auto[ ``` [1] 0.3019899 0.2684355 0.1073742 ``` ] --- count: false .panel1-more-auto[ ```r # 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() ``` ] .panel2-more-auto[ ``` [1] 0.6777995 ``` ] --- count: false .panel1-more-auto[ ```r # 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() # or *dbinom(8, 10, .8) ``` ] .panel2-more-auto[ ``` [1] 0.6777995 ``` ``` [1] 0.3019899 ``` ] --- count: false .panel1-more-auto[ ```r # 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() # or dbinom(8, 10, .8) + * dbinom(9, 10, .8) ``` ] .panel2-more-auto[ ``` [1] 0.6777995 ``` ``` [1] 0.5704253 ``` ] --- count: false .panel1-more-auto[ ```r # 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() # or dbinom(8, 10, .8) + dbinom(9, 10, .8) + * dbinom(10, 10, .8) ``` ] .panel2-more-auto[ ``` [1] 0.6777995 ``` ``` [1] 0.6777995 ``` ] <style> .panel1-more-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-more-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-more-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false .panel1-more2-auto[ ```r # what is the probability of exactly 5 successes in 10 trials # when each trial is chance event with probility .5 success *dbinom(5, 10, .5) ``` ] .panel2-more2-auto[ ``` [1] 0.2460938 ``` ] --- count: false .panel1-more2-auto[ ```r # what is the probability of exactly 5 successes in 10 trials # when each trial is chance event with probility .5 success dbinom(5, 10, .5) ``` ] .panel2-more2-auto[ ``` [1] 0.2460938 ``` ] <style> .panel1-more2-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-more2-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-more2-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style>