2.6 Dice rolls.

If you roll a pair of fair dice, what is the probability of

dice_sum <- c(2,3,4,5,6,7,8,9,10,11,12)
dice_roll_probability <- c(1,2,3,4,5,6,5,4,3,2,1)/36
df <- data.frame(dice_sum, dice_roll_probability)
names(df) <- c("Sums", "Probability")
df
##    Sums Probability
## 1     2  0.02777778
## 2     3  0.05555556
## 3     4  0.08333333
## 4     5  0.11111111
## 5     6  0.13888889
## 6     7  0.16666667
## 7     8  0.13888889
## 8     9  0.11111111
## 9    10  0.08333333
## 10   11  0.05555556
## 11   12  0.02777778
(a) getting a sum of 1?

Sum of 1 cannont happen in two dice. Minimum is 2. So the probability is 0

(b) getting a sum of 5?

p(5) is only possible with rolling p(1,4), p(2,3), p(3,2) and p(4,1), so probability is 4/36=1/9 => 0.1111.

(c) getting a sum of 12?

P(6,6) is 1/36 =>0.0278.

2.8 Poverty and language.

The American Community Survey is an ongoing survey that provides data every year to give communities the current information they need to plan investments and services. The 2010 American Community Survey estimates that 14.6% of Americans live below the poverty line, 20.7% speak a language other than English (foreign language) at home, and 4.2% fall into both categories.

Define following

B: Americans living below the poverty line.

F: Speak a language other than English (foreign language) at home.

P(B) = 14.6% = 0.146

P(F) = 20.7% = 0.207

P(B and F) = 4.2% = 0.042

(a) Are living below the poverty line and speaking a foreign language at home disjoint?

No. They are not disjoint because they have a union of 0.042

(b) Draw a Venn diagram summarizing the variables and their associated probabilities.

#install.packages(VennDiagram)
library("VennDiagram")
pov <- 14.6
forLang <- 20.7
both <- 4.2
povOnly <- pov - both
forLangOnly <- forLang - both

venn.plot <- draw.pairwise.venn(pov, 
                   forLang,
                   cross.area=both, 
                   c("Poverty", "Foreign Language"), 
                   fill=c("green", "yellow"),
                   cat.dist=-0.05,
                   ind=FALSE)
grid.draw(venn.plot)

(c) What percent of Americans live below the poverty line and only speak English at home?

P(A and Speak English at Home) => P(B) - P(A and F) = > 0.146 - 0.042 => 0.104 => 10.4%

(d) What percent of Americans live below the poverty line or speak a foreign language at home?

P(B or F) => P(B) + P(F) - P(B and F) => 0.146 + 0.207 - 0.042 => 0.311 = 31.1%

(e) What percent of Americans live above the poverty line and only speak English at home?

1-P(B or F) => 1-0.311 => 68.9%

(f) Is the event that someone lives below the poverty line independent of the event that the person speaks a foreign language at home?

P(poverty americans and foreign speaking) != P(poverty americans )x P(foreign speaking) => 0.146 * 0.207 => 0.030222 != 0.042 so the events dependent.

2.20 Assortative mating.

assortive_mating <- read.csv("https://raw.githubusercontent.com/jbryer/DATA606Spring2017/master/Data/Data%20from%20openintro.org/Ch%202%20Exercise%20Data/assortive_mating.csv")

table(assortive_mating)
##          partner_female
## self_male blue brown green
##     blue    78    23    13
##     brown   19    23    12
##     green   11     9    16
(a) What is the probability that a randomly chosen male respondent or his partner has blue eyes?

By applying the general addition rule:

P(M_Blue or F_Blue) = P(M_Blue) + P(F_Blue) - P(M_Blue and F_Blue)

P(M_Blue or F_Blue) = 108/204 + 114/204 - 78/204

P(M_Blue or F_Blue) = 0.7059

Answer: The probability that a randomly chosen male respondent or his partner has blue eyes is 70.59%.

(b) What is the probability that a randomly chosen male respondent with blue eyes has a partner with blue eyes?

P(F_Blue | M_Blue) = P(F_Blue and M_Blue) / P(M_Blue)

P(F_Blue | M_Blue) = (78/204) / (114 / 204)

P(F_Blue | M_Blue) = 0.6842

Answer: 68.42%

(c) What is the probability that a randomly chosen male respondent with brown eyes has a partner with blue eyes? What about the probability of a randomly chosen male respondent with green eyes having a partner with blue eyes?

P(F_Blue | M_Brown) = P(F_Blue and M_Brown) / P(M_Brown)

P(F_Blue | M_Brown) = (23/204) / (54/204)

P(F_Blue | M_Brown) = 0.4259

Answer: 42.59%

P(F_Blue | M_Green) = P(F_Blue and M_Green) / P(M_Green)

P(F_Blue | M_Green) = (13/204) / (36/204)

P(F_Blue | M_Green) = 0.3611

Answer: 36.11%

(d) Does it appear that the eye colors of male respondents and their partners are independent? Explain your reasoning.

Let’s build our independence condition:

P(M_Blue and F_Blue) = P(M_Blue) * P(F_Blue)

(78/204) = (114/204) * (108/204)

So 0.3824 != 0.2958 This shows that these events are not independent, since the independency multiplication rule is not satisfied.

2.30 Books on a bookshelf.

assortive_mating <- read.csv("https://raw.githubusercontent.com/jbryer/DATA606Spring2017/master/Data/Data%20from%20openintro.org/Ch%202%20Exercise%20Data/books.csv")

table(assortive_mating)
##             format
## type         hardcover paperback
##   fiction           13        59
##   nonfiction        15         8
(a) Find the probability of drawing a hardcover book first then a paperback fiction book second when drawing without replacement.

P(First H and Second F) = P(First H) * P(Second F)

P(First H and Second F) = (28/95) * (59/94)

P(First H and SecondF) = = 0.185

Answer: is 18.5%

(b) Determine the probability of drawing a fiction book first and then a hardcover book second, when drawing without replacement.

P(F and second H) = P(F) * P(second H)

P(F and second H) = (72/95) * (28/94)

P(F and second H) = 0.2258

Answer: 22.58%

(c) Calculate the probability of the scenario in part (b), except this time complete the calculations under the scenario where the first book is placed back on the bookcase before randomly drawing the second book.

P(F and second being H) = P(Fiction) * P(second being H)

P(F and second being H) = (72/95) * (28/95)

P(F and second being H) = 0.2234

Answer: 22.34%

(d) The final answers to parts (b) and (c) are very similar. Explain why this is the case.

Answer: When drawing books without replacement two events were dependent. Result of the first draw will impact second draw. Where as drawing with replacement two events are independent. Results of the first draw will not have any effect on second draw. Hence probabilities are slightly different.

2.38 Baggage fees.

(a) Build a probability model, compute the average revenue per passenger, and compute the corresponding standard deviation.

prob <- c(0.54, 0.34, 0.12)
bags <- c(0, 1, 2)
fees <- c(0, 25, 25 + 35)
df38 <- data.frame(prob, bags, fees)
df38$weightRev <- df38$prob * df38$fees
df38
##   prob bags fees weightRev
## 1 0.54    0    0       0.0
## 2 0.34    1   25       8.5
## 3 0.12    2   60       7.2
Compute the average revenue per passenger

avgRevPerPax <- sum(df38$weightRev)
avgRevPerPax
## [1] 15.7
Compute Variance

df38$DiffMean <- df38$weightRev - avgRevPerPax
df38$DiffMeanSqrd <- df38$DiffMean ^ 2
df38$DiffMeanSqrdTimesProb <- df38$DiffMeanSqrd * df38$prob
df38
##   prob bags fees weightRev DiffMean DiffMeanSqrd DiffMeanSqrdTimesProb
## 1 0.54    0    0       0.0    -15.7       246.49              133.1046
## 2 0.34    1   25       8.5     -7.2        51.84               17.6256
## 3 0.12    2   60       7.2     -8.5        72.25                8.6700
Compute standard deviation

varRevPerPax <- sum(df38$DiffMeanSqrdTimesProb)
sdRevPerPax <- sqrt(varRevPerPax)
sdRevPerPax
## [1] 12.62538
(b). About how much revenue should the airline expect for a flight of 120 passengers? With what standard deviation? Note any assumptions you make and if you think they are justified. The following R code computes the revenue for a flight of 120 passengers:

pax <- 120
avgFlightRev <- avgRevPerPax * pax
avgFlightRev
## [1] 1884
## [1] 1884
Standard Deviation of revenue

varFlightRev <- (pax ^ 2) * varRevPerPax
sdFlightRev <- sqrt(varFlightRev)
sdFlightRev
## [1] 1515.046
The standard deviation of the average revenue for the flight is valid only if the average revenue per passenger is independent of other random variables. Given that this is the only random variable, independence is not an issue.

2.44 Income and gender.

59% males, 41% females

income <- c("$1 - $9,999 or loss",
"$10,000 to $14,999",
"$15,000 to $24,999",
"$25,000 to $34,999",
"$35,000 to $49,999",
"$50,000 to $64,000",
"$65,000 to $74,999",
"$75,000 to $99,999",
"$100,000 or more")
bounds <- c(1, 10000, 15000, 25000, 35000, 50000, 65000, 75000, 100000)
size <- c(9999, 4999, 9999, 9999, 14999, 14999, 9999, 24999, 99999)
center <- bounds + (size / 2)
total <- c(0.022, 0.047, 0.158, 0.183, 0.212, 0.139, 0.058, 0.084, 0.097)
df44 <- data.frame(income, center, total)
df44
##                income   center total
## 1 $1 - $9,999 or loss   5000.5 0.022
## 2  $10,000 to $14,999  12499.5 0.047
## 3  $15,000 to $24,999  19999.5 0.158
## 4  $25,000 to $34,999  29999.5 0.183
## 5  $35,000 to $49,999  42499.5 0.212
## 6  $50,000 to $64,000  57499.5 0.139
## 7  $65,000 to $74,999  69999.5 0.058
## 8  $75,000 to $99,999  87499.5 0.084
## 9    $100,000 or more 149999.5 0.097
barplot(df44$total, names.arg=income)
(b). What is the probability that a randomly chosen US resident makes less than $50,000 per year? By summing the percentages from the data for the disjoint, mutually exclusive outcomes of each income level, we can determine the total probability:

pr50K <- sum(df44[1:5,]$total)
pr50K
## [1] 0.622
(c). What is the probability that a randomly chosen US resident makes less than $50,000 per year and is female? Note any assumptions you make. We don’t know the relationship between the probability of an income of less than $50,000 and being female. Assuming they are independent events then P(A and B) = P(A) x P(B).

P_female <- 0.41
P_50K <- pr50K
# Compute
P_female_50K <- P_female * P_50K
# Show the result
P_female_50K
## [1] 0.25502
(d). The same data source indicates that 71.8% of females make less than $50,000 per year. Use this value to determine whether or not the assumption you made in part (c) is valid.

What percent of population is female and makes less than $50K?

actualFemale50K <- 0.718 * P_female
actualFemale50K
## [1] 0.29438
While 0.29438 is close to 0.25502, they are not equal. Therefore I conclude that making less than $50K and being female are not independent events.