library(likelihoodExplore)


tidy_likbinom <- function(x = 8, size = 10){
probs <- 0:1000/1000

likelihood <- likbinom(8, 10, prob = probs, log = F)

log_likelihood <- likbinom(8, 10, prob = probs, log = T)

tibble::tibble(probs, likelihood, log_likelihood, num_successes = 8, num_trials = 10) 

}

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.6     ✓ dplyr   1.0.8
## ✓ tidyr   1.0.2     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.5.0
## Warning: package 'ggplot2' was built under R version 3.6.2
## Warning: package 'tibble' was built under R version 3.6.2
## Warning: package 'purrr' was built under R version 3.6.2
## Warning: package 'dplyr' was built under R version 3.6.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(patchwork)
(ggplot(tidy_likbinom(8,10)) + 
  aes(probs, likelihood) + 
  geom_area() + 
  geom_vline(xintercept = .5,
             linetype = "dashed"))/
ggplot(tidy_likbinom(8,10)) + 
  aes(probs, log_likelihood) + 
  geom_line() + 
  geom_vline(xintercept = .5,
             linetype = "dashed") + 
  patchwork::plot_annotation(title = "Likelihood and log likelihood of observing given 8 successes observed in 10 Bernoulli trails" %>% str_wrap(50))