Laboratory Exercise No. 1

Problem 1

library(gt)
library(dplyr)
p <- seq(0.20, 0.80, by= 0.2)
prior <- c(0.25,0.25,0.25,0.25)
likelihood <- p^{7}*(1-p)^{3}
PL <- prior*likelihood
posterior <- PL/sum(PL)
posteriordist <- as.data.frame(cbind(p,prior,likelihood,posterior))
posteriordist %>%
  gt() %>% 
  cols_align(align="center", columns = everything())
p prior likelihood posterior
0.2 0.25 0.0000065536 0.00171123
0.4 0.25 0.0003538944 0.09240642
0.6 0.25 0.0017915904 0.46780749
0.8 0.25 0.0016777216 0.43807487

Problem 2

prior <- posterior
likelihood <- p^{2}*(1-p)^{3}
PL <- prior*likelihood
posterior <- PL/sum(PL)
posteriordist <- as.data.frame(cbind(p,prior,likelihood,posterior))
posteriordist %>%
  gt() %>% 
  cols_align(align="center", columns = everything())
p prior likelihood posterior
0.2 0.00171123 0.02048 0.002156698
0.4 0.09240642 0.03456 0.196529065
0.6 0.46780749 0.02304 0.663285594
0.8 0.43807487 0.00512 0.138028644

Problem 3

p <- seq(0.20, 0.80, by= 0.2)
prior <- c(0.25,0.25,0.25,0.25)
likelihood <- p^{9}*(1-p)^{6}
PL <- prior*likelihood
posterior <- PL/sum(PL)
posteriordist <- as.data.frame(cbind(p,prior,likelihood,posterior))
posteriordist %>%
  gt() %>% 
  cols_align(align="center", columns = everything())
p prior likelihood posterior
0.2 0.25 1.342177e-07 0.002156698
0.4 0.25 1.223059e-05 0.196529065
0.6 0.25 4.127824e-05 0.663285594
0.8 0.25 8.589935e-06 0.138028644
  1. The results from Problem 1 to Problem 3 show how the assigned probabilities on the prior distribution for each possible value of p affects the Posterior distribution. Problem 1 and 3 have prior distributions which assign equal probability for each value of p while problem 2 uses the posterior distribution from problem 1 as a prior distribution for p. Consequently, Problem 1 and 3 exemplifies a posterior distribution which are dominated by the likelihood while Problem 2 is a combination of the varied prior probabilities and the likelihood.Accordingly, this difference and how prior distribution affects the posterior probabilities is best exemplified in Problem 2 and 3 as they have identical posterior distribution despite having different proportions of success based on their corresponding experiments with p=2/5 and p=9/15=3/5, respectively. The probable reason behind the similarity of the posterior distributions of Problem 2 and 3 is the fact that Problem 2 uses the Posterior distribution from Problem 1 as a Prior, and the prior of problem 3 is based from the prior of problem 1.

  2. H\(_0\): p \(\ge\) 0.60 vs. H\(_1\): p < 0.60

P(H\(_0\)) = P(p \(\ge\) 0.60) = P(p=0.60) + P(p=0.80) = 0.8013

Therefore, there is a strong evidence supporting the claim that p is at least 0.60.