The objectives of this problem set is to work with the conceptual mechanics of Bayesian data analysis. The target of inference in Bayesian inference is a posterior probability distribution. Posterior probabilities state the relative numbers of ways each conjectured cause of the data could have produced the data. These relative numbers indicate plausibilities of the different conjectures. These plausibilities are updated in light of observations through Bayesian updating.
Place each answer inside the code chunk (grey box). The code chunks should contain a text response or a code that completes/answers the question or activity requested. Make sure to include plots if the question requests them.
Finally, upon completion, name your final output .html file as: YourName_ANLY505-Year-Semester.html and publish the assignment to your R Pubs account and submit the link to Canvas. Each question is worth 5 points
2-1. Suppose you have a deck with only three cards. Each card has two sides, and each side is either black or white. One card has two black sides. The second card has one black and one white side. The third card has two white sides. Now suppose all three cards are placed in a bag and shuffled. Someone reaches into the bag and pulls out a card and places it flat on a table. A black side is shown facing up, but you don’t know the color of the side facing down. Show that the probability that the other side is also black is 2/3. Use the counting method (Section 2 of the chapter) to approach this problem. This means counting up the ways that each card could produce the observed data (a black side facing up on the table).
# Total deck of three cards specification:
## Card_A_BB: Suppose first card A has Two black sides.
## Card_B_WB: Suppose second card B has one white and one black sides.
## Card_C_WW: Suppose third card C has both White sides.
## As per the condition, because the pulled up card from the bag has one black side, so only two possible combination's of either "Card_A_BB", or "Card_B_WB", would be feasible for this scenario, and the third option of "Card_C_WW" would be eliminated because one of the already depicted card size is black, hence this option will be dropped.
# Total ways of producing card of each sides as black sides will be 2 Ways.
# Total ways of producing card of one black and one white side will be 1 Way.
# Total ways of producing card of each sides as white sides for the third eliminated scenario will be 0 Ways, because one of the already depicted card size is black, hence eliminating this possible option.
## Determination for the probability of the card to be of color black on the other side as well:
# According to Bayes Theory:
# Pr(A\B) = (P(B\A)* P(A))/P(B)
# Pr(A) = Pr (Card_A_BB) = 1/3 # Probability of two side black.
# Pr(B) = Pr (Card_B_WB) = 1/2 # Probability of one side black.
# Pr(B\A) = P(Card_B_WB)\ Card_A_BB) = 1
# Pr(A\B) = P(Card_A_BB)\ (Card_B_WB) = (1 * 1/3)/ (1/2) = 2/3
# Therefore, probability that the other side is also black would be 2/3 or 0.667.
## Hence the probability that the other side is also black would be 2/3.
# Calculation by computing these plausibilities in R.
ways <- c(2, 1, 0)
sum(ways)
## [1] 3
Probability <- 2 / sum(ways) # Probability of the card to be of color black on the other side as well
Probability # Probability will be 2/3 or 0.667.
## [1] 0.6666667
2-2. Now suppose there are four cards: B/B, B/W, W/W, and another B/B. Again suppose a card is drawn from the bag and a black side appears face up. Again calculate the probability that the other side is black.
## Provided an additional card of each side is added in our prior sample deck of cards to provide different below possible options.
## Card_A_BB_1: First card A having Two black sides.
## Card_B_WB: Second card B having one white and one black sides.
## Card_C_WW: Third card C having both White sides.
## Card_D_BB_2: Additional new card A having Two black sides.
## As per the condition, because the pulled up card from the bag has one black side, so only three possible combination's of either "Card_A_BB_1", or "Card_B_WB", or "Card_D_BB_2" would be feasible for this scenario, and the third option of "Card_C_WW" would again be eliminated, because one of the already depicted card size is black, hence this option of Card_C will be dropped.
# Total Ways of producing four cards.
# Total ways of producing first "Card_A_BB_1" of each sides as black sides will be 2 Ways.
# Total ways of producing second "Card_B_WB" of one side as black and other black side will be 1 Ways.
# Total ways of producing third "Card_C_WW" of both sides as white will be 0 Ways.
# Total ways of producing fourth "Card_D_BB_2" of each sides as black sides will be again 2 Ways.
## Determination for the probability of the card to be of color black on the other side as well:
## Pr (Both sides black) = Total ways of producing card of each sides as black sides / Total ways of sample size of the event
## Pr (Both sides black) = 2 + 2/ 2 + 1 + 0 + 2 = 4/5 or 0.8
## Hence the probability that the other side is also black would be 0.8.
# Calculation by Bayes theory for this scenario..
# Pr(A\B) = (P(B\A)* P(A))/P(B)
# Pr(A) = Pr (Card_A_BB) = 2/4 # Probability of two side black.
# Pr(B) = Pr (Card_B_WB) = 5/8 # Probability of one side black.
# Pr(B\A) = P(Card_B_WB)\ Card_A_BB) = 1
# Pr(A\B) = Pr(Card_A_BB)\ (Card_B_WB) = (1*1/2)/(5/8) = 8/10 = 4/5 or 0.8.
## Thus, the probability that the other side is also black would be 0.8.
2-3. Imagine that black ink is heavy, and so cards with black sides are heavier than cards with white sides. As a result, it’s less likely that a card with black sides is pulled from the bag. So again assume there are three cards: B/B, B/W, and W/W. After experimenting a number of times, you conclude that for every way to pull the B/B card from the bag, there are 2 ways to pull the B/W card and 3 ways to pull the W/W card. Again suppose that a card is pulled and a black side appears face up. Show that the probability the other side is black is now 0.5. Use the counting method, as before.
# Additional condition: Blank ink is heavy, and under this new condition it's assumed that the likelihood of pulling up the black card from the bag is lesser comapritively.
## Determination of the likelihood by taking into consideration the prior counting of ways methos.
# Card_A_BB: Card with both side as black
# Card_B_WB: Card with one side as black and other white.
# Card_C_WW: Card with both sides as white.
## Card Specification Prior Revised Ways Likelihood
# Card_A_BB 2 1 2
# Card_B_WB 1 2 2 # Since now there are two ways to pull B/W card.
# Card_C_WW 0 3 0 # Since now there are 3 ways to pull W/W card.
## Therefore, under this new condition the probability of pulling up the card of other side as black as well would be:
# Pr (Card_A_BB) = 2 / 2 + 2 + 0 = 2 / 4 = 0.5
# Hence the probability the other side is black would be 0.5.
## Calculation per Bayes Theorem of this scenario:
# Pr(A\B) = (P(B\A)* P(A))/P(B)
# Pr(A) = Pr (Card_A_BB) = 1/6 # Probability of two side black.
# Pr(B) = Pr (Card_B_WB) = 4/12 = 1/3 # Probability of one side black.
# Pr(B\A) = P(Card_B_WB)\ Card_A_BB) = 1
# Pr(A\B) = Pr(Card_A_BB)\ (Card_B_WB) = (1 * 1/6)/ 1/3 = 1/2 0r 0.5.
# Therefore according to Bayes Theory calculation the probability the other side is black would also be 0.5.
2-4. Assume again the original card problem, with a single card showing a black side face up. Before looking at the other side, we draw another card from the bag and lay it face up on the table. The face that is shown on the new card is white. Show that the probability that the first card, the one showing a black side, has black on its other side is now 0.75. Use the counting method, if you can. Hint: Treat this like the sequence of globe tosses, counting all the ways to see each observation, for each possible first card.
## As per Bayes Theory
# Pr(A\B) = (P(B\A)* P(A))/P(B)
# Consider condition #1 as C-a having one side of card as black and other white.
# Consider condition #2 as C-b having both side of card as black.
# Consider condition #3 as C-c having both side of card as white.
# Provided if the first card is C-b, on face one, then we have three ways to get second white faced card, and similarly, again three ways to get a white with second black face and totaling six (6) ways, Therefore total possible ways for first card to be BB = 6 ways
# Also, if the first card is C-a, then we would have total two (2) ways to obtain the outcome, or total ways the second card would be white will be 2 ways.
# And for the other condition C-c, if the first card is C-c, then we would have zero outcome.
# Thus as per these conditions, we could only obtain second face of the first card as black, provided we have the first card as C-b.
# Therefore probability will become: 6 / ( 6 + 2 + 0) = 6/8 = 3/4 = 0.75.
# Hence the probability that the first card, the one showing black side, has black on its other side is now 0.75.
2-5. Suppose there are two species of panda bear. Both are equally common in the wild and live in the same places. They look exactly alike and eat the same food, and there is yet no genetic assay capable of telling them apart. They differ however in their family sizes. Species A gives birth to twins 10% of the time, otherwise birthing a single infant. Species B births twins 20% of the time, otherwise birthing singleton infants. Assume these numbers are known with certainty, from many years of field research. Now suppose you are managing a captive panda breeding program. You have a new female panda of unknown species, and she has just given birth to twins. What is the probability that her next birth will also be twins?
## Probability of Species A of panda giving birth to twins is 10 % or 0.1.
# Pr (Twins\Panda_Species_A) = 0.1
## Probability of Species B of panda giving birth to twins is 20 % or 0.2.
# Pr (Twins\Panda_Species_B) = 0.2
# Probability of Panda species A found in wild environment:
# Pr (Panda_Species_A) = 0.5
# Probability of Panda species B found in wild environment:
# Pr (Panda_Species_B) = 0.5
# Therefore MarginaL Probability of Twins would be:
# Pr(Twins) = Pr(Twins\Panda_Species_A) * Pr(Panda_Species_A) + Pr(Twins\Panda_Species_B) * Pr (Panda_Species_B) = 0.1 * 0.5 + 0.2 * 0.5 = 0.15
# Pr(Panda_Species_A\Twins) = Pr (Twins\Panda_Species_A) * Pr(Panda_Species_A)/Pr(Twins) = 0.1 * 0.5/0.15 = 1/3
# Pr(Panda_Species_B\Twins) = Pr (Twins\Panda_Species_B) * Pr(Panda_Species_B)/Pr(Twins) = 0.2 * 0.5/0.15 = 2/3
### According to Bayes theorem, probability calculation of unknown Panda species to have twins again in her second birth:
# Pr (Second Twins) = Pr(Twins\Panda_Species_A) * Pr(Panda_Species_A\Twins) + Pr (Twins\Panda_Species_B) * Pr(Panda_Species_B\Twins) = 0.1 * 1/3 + 0.2 * 2/3 = 1/6 = 0.167
## Hence the probability for the unknown Panda species to have twins again in her second birth would be 0.1664 or 0.167.