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).
bb<-2
bw<-1
ww<-0
#Since one side of the card is black, for the other side to be black, there are only two options out of three total possible options. Hence the probability is
bb/(bb+bw)
## [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.
bb<-2
bw<-1
ww<-0
bb2<-2
#In this case, there are four options out of five for the other card to be black. Hence the probability is
(bb+bb2)/(bb+bb2+bw)
## [1] 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.
bb<-2*1
bw<-1*2
ww<-0*3
#In this case there are two ways black shows up on both the sides and there is ideally only one way black shows up on one side. Due the weightage, this one gets multiplied by two and becomes two. Since, in two out of four options this is possible, the probability is
bb/(bb+bw)
## [1] 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.
first_bb<-2*3 #2 options for the first card, 3 options for the second card
first_wb<-1*2 #1 option for the first card, 2 options for the second card
first_ww<-0
#The probability of first card showing black for the other side is
first_bb/(first_bb+first_wb)
## [1] 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?
P_A <- 0.5
P_TA <- 0.1
P_TB <- 0.2
P_T <- P_A*P_TA + (1-P_A)*P_TB
#Give the first birth is twins, the probability of the unknown panda is species A:
P_AT <- P_TA*P_A/P_T
P_AT
## [1] 0.3333333
#Give the first birth is twins, the probability of the unknown panda is species B:
P_BT <- P_TB*(1-P_A)/P_T
P_BT
## [1] 0.6666667
P_T2 <- P_AT*P_TA + P_BT*P_TB
P_T2
## [1] 0.1666667