R Libraries:

Load necessary libraries -

library(VennDiagram)
library(ggplot2)

Exercise 2.6 Dice rolls:

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

Part (a): getting a sum of 1?

Ans: The probablibility of getting a sum of 1 after rolling two fair dice is 0, since the minimum sum possible is 2.

Part (b): getting a sum of 5?

Ans: The probability of getting a sum of 5 is possible under following scenarios -

Dice 1 X 2 1. 1 X 4 2. 4 X 1 3. 2 X 3 4. 3 X 2

Since the dice are fair and the rolling of dice1 & 2 are two independent events, so the chances of any number for a given roll is equal with a probablility of 1/6.

P(5) = 1/6x1/6 + 1/6x1/6 + 1/6x1/6 + 1/6x1/6 = 4/36

Part (c): getting a sum of 12?

Ans: The sum of the two fair dice will be 12 only when both the dice roll into 6.

P(12) = 1/6x1/6 = 1/36

Exercise 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.

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

Ans: Living below the poverty line and speaking a foreign language are not disjoint since there are 4.2% of the population which fall into both the categories.

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

Ans: Below are the variables -

Variable A : Americans Speaking foreign language and living above poverty line

Variable B : Americans Speaking foreign language and living below poverty line

Variable C : English Speaking Americans living below poverty line

P(A) = 16.5/(16.5 + 4.2 + 10.4) = 16.5/31.1 = 0.530

P(B) = 4.2/(16.5 + 4.2 + 10.4) = 4.2/31.1 = 0.135

P(C) = 10.4/(16.5 + 4.2 + 10.4) = 10.4/31.1 = 0.334

grid.newpage()
draw.pairwise.venn(14.6, 20.7, 4.2, category = c("Americans Below Poverty Line", "Americans Speaking Foreign Language"), lty = rep("blank", 
    2), fill = c("light blue", "pink"), alpha = rep(0.5, 2), cat.pos = c(0, 
    0), cat.dist = rep(0.025, 2))

## (polygon[GRID.polygon.1], polygon[GRID.polygon.2], polygon[GRID.polygon.3], polygon[GRID.polygon.4], text[GRID.text.5], text[GRID.text.6], text[GRID.text.7], text[GRID.text.8], text[GRID.text.9])

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

Ans: 10.4% Americans living below the poverty line and only speak English at home.

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

Ans:

P(Below Poverty or Speaking Foreign Lang) = P(Below Poverty) + P(Speaking Foreign Lang) - P(Below Poverty and Speaking Foreign Lang) = 14.6% + 20.7% - 4.2% = 31.1%

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

Ans:

P(Above Poverty and Speaking English) = P(Above Poverty)P(Speaking English) = (1 - P(Below Poverty))(1 - P(Speaking Foreign Lang)) = (1 - 0.146)(1 - 0.207) = 0.854 0.793 = 0.677 = 67.7%

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

Ans:

P(Below Poverty and Speaking Foreign Lang) = P(Below Poverty)P(Speaking Foreign Lang) = (0.146)(0.207) = 0.03 = 3%

The fact that above calculated 3% is not the same as 4.2% indicated in the problem statement concludes that someone living below the poverty line and the person speaking a foreign language at home are NOT independent variables since simple rule of multiplication for independent variables is not applicable in this case..

Exercide 2.20 Assortative mating:

Assortative mating is a nonrandom mating pattern where individuals with similar genotypes and/or phenotypes mate with one another more frequently than what would be expected under a random mating pattern. Researchers studying this topic collected data on eye colors of 204 Scandinavian men and their female partners. The table below summarizes the results. For simplicity, we only include heterosexual relationships in this exercise.

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

Ans: P(male with blue eyes OR female with blue eyes) = P(male with blue eyes) + P(female with blue eyes) - P(both male female with blue eyes) = 114/204 + 108/204 - 78/204 = 0.7059

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

Ans:

P(female with blue eyes|male with blue eyes) = P(female with blue eyes AND male with blue eyes)/P(male with blue eyes) = 78/114 = 0.6842

(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?

Ans: P(female with blue eyes|male with brown eyes) = P(female with blue eyes AND male with brown eyes)/P(male with brown eyes) = 19/54 = 0.3518

P(female with blue eyes|male with green eyes) = P(female with blue eyes AND male with green eyes)/P(male with green eyes) = 11/36 = 0.3055

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

Ans: According to Multiplication rule, if A and B are two independent events then, P(A AND B) = P(A)*P(B)

Blue eyes P(Both male and female with blue eyes) = 78/204 = 0.3824

P(male with blye eyes) = 114/204 = 0.5588 P(female with blue eyes) = 108/204 = 0.5294

P(male with blye eyes) x P(female with blye eyes) = 0.5588 * 0.5294 = 0.2958

Note, 0.3824 <> 0.258

Green eyes P(Both male and female with green eyes) = 16/204 = 0.0784

P(male with green eyes) = 36/204 = 0.1765 P(female with green eyes) = 41/204 = 0.2010

P(male with blye eyes) x P(female with blye eyes) = 0.1765 * 0.2010 = 0.0355

Note, 0.0784 <> 0.0355

Hence it can be be conculded that eye colors of randomly chosen male and female partners are not independent.

Exercise 2.30 Books on a bookshelf:

The table below shows the distribution of books on a bookcase based on whether they are nonfiction or fiction and hardcover or paperback.

(a) Find the probability of drawing a hardcover book first then a paperback fiction book second when drawing without replacement.

Ans: 1st Draw: P(Hard Cover Book) = 28/95 = 0.2947 2nd Draw w/o replacement: P(Paper Back Fiction) = 59/94 = 0.6277

Joint Probability = 0.2947 * 0.6277 = 0.1849

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

Ans: 1st Draw: P(Fiction Book) = 72/95 = 0.7579 2nd Draw w/o replacement: P(Hard Cover Book) = 28/94 = 0.2979

Joint Probability = 0.7579 * 0.2979 = 0.2258

(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.

Ans:

1st Draw: P(Fiction Book) = 72/95 = 0.7579 2nd Draw with replacement: P(Hard Cover Book) = 28/95 = 0.2947

Joint Probability = 0.7579 * 0.2947 = 0.2234

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

Ans: Since there are a lot of books (94 vs. 95), a one book difference will not impact the probability as much as if there were a lot less books (smaller population).

Exercise 2.38 Baggage fees:

An airline charges the following baggage fees: $25 for the first bag and $35 for the second. Suppose 54% of passengers have no checked luggage, 34% have one piece of checked luggage and 12% have two pieces. We suppose a negligible portion of people check more than two bags.

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

Ans:

luggageCost <- c(0,25,60)

luggageProb <- c(0.54,0.34,0.12)

luggageRev <- luggageCost * luggageProb

Ex <- sum(luggageRev)

cat("The Expected Value is:", Ex,"\n")
## The Expected Value is: 15.7
luggageCostMinusEx <- (luggageCost - Ex)

SqrLuggageCostMinusEx <- luggageCostMinusEx * luggageCostMinusEx

variance <- SqrLuggageCostMinusEx * luggageProb

stdDev <- sqrt(sum(variance))

cat("The Standard Deviation is:", stdDev,"\n")
## The Standard Deviation is: 19.95019

(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.

Ans: Expected Revenue with 120 passengers

passengers <- 120
revenue <- Ex * 120 

cat("The Revenue is ", revenue,"\n")
## The Revenue is  1884
luggageCost <- c(0,25,60)

luggageProb <- c(0.54,0.34,0.12)

luggageCostMinusEx <- (luggageCost - Ex)

SqrLuggageCostMinusEx <- luggageCostMinusEx * luggageCostMinusEx 

variance <- SqrLuggageCostMinusEx * luggageProb * passengers

stdDev <- sqrt(sum(variance))

cat("The Standard Deviation is:", stdDev,"\n")
## The Standard Deviation is: 218.5434

Exercise 2.44 Income and gender:

The relative frequency table below displays the distribution of annual total personal income (in 2009 inflation-adjusted dollars) for a representative sample of 96,420,486 Americans. These data come from the American Community Survey for 2005-2009. This sample is comprised of 59% males and 41% females.

(a) Describe the distribution of total personal income.

Ans: The distribution is Unimodal.

sortOrder <- c(1:9)
Income <- c("<$10K","$10K-$15K","$15K-$25K","$25K-$35K","$35K-$50K","$50K-$65K","$65K-$75K","$75K-$100K",">$100K")

percentage <- c(0.022,0.047,0.158,0.183,0.212,0.139,0.058,0.084,0.097)

IncomeDF <- data.frame(sortOrder,Income,percentage,stringsAsFactors = FALSE)
colnames(IncomeDF) <- c("Sort Order","Income Range","Distribution Perc")

ggplot(IncomeDF, aes(x =reorder(`Income Range`,`Sort Order`) ,y= `Distribution Perc`)) +
  geom_bar( stat = "identity", position = "dodge") +
  theme(axis.text.x=element_text(angle = 45, vjust = 0.5)) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Income Distrbution") +
  labs(x = "Income Range",y = "% of Distribution")

(b) What is the probability that a randomly chosen US resident makes less than $50,000 per year?

Ans:

### Probability of random chosen person earning less than $50K = P(<$10K)+P($10K-$15K)+P($15K-$25K)+P($25K-$35K)+P($35K-$50K)+P(35K-$50K)

probLess50K <- sum(0.022,0.047,0.158,0.183,0.212)

cat("Probability of randomly chosen person to earn <$50K :",probLess50K)
## Probability of randomly chosen person to earn <$50K : 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.

Ans:

FemalePerc <- 0.41
probLess50KFemale <- probLess50K*FemalePerc

cat("Probability of randomly chosen female to earn <$50K :",probLess50KFemale)
## Probability of randomly chosen female to earn <$50K : 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.

Ans: The fact that the data shows 71.8% of the female earns <$50K as opposed to 25.5% derived in section (c) indicates that the assumption of Income and Gender are independent variables is NOT TRUE. Hence simple rule of multiplication can not be applied to derive this probability. So Income and Gender are dependent variables based on this observation.