Environment Setup
## -- Attaching packages ---------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 2.2.1 v purrr 0.2.4
## v tibble 1.4.2 v dplyr 0.7.4
## v tidyr 0.8.0 v stringr 1.2.0
## v readr 1.1.1 v forcats 0.2.0
## -- Conflicts ------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
##
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
##
## set_names
## The following object is masked from 'package:tidyr':
##
## extract
## Loading required package: combinat
##
## Attaching package: 'combinat'
## The following object is masked from 'package:utils':
##
## combn
##
## Attaching package: 'prob'
## The following objects are masked from 'package:dplyr':
##
## intersect, setdiff, union
## The following objects are masked from 'package:base':
##
## intersect, setdiff, union
## Loading required package: grid
## Loading required package: futile.logger
2.6 Dice rolls. If you roll a pair of fair dice, what is the probability of
# get sample space of rolling die possibilites
# add sum column
ss <- rolldie(2) %>%
mutate(sum = X1 + X2)
poss <- nrow(ss)
sumof1 <- ss %>%
filter(sum == 1) %>%
count
sumof1/poss %>%
print
## [1] 36
## n
## 1 0
sumof5 <- ss %>%
filter(sum == 5) %>%
count
sumof5/poss %>%
print
## [1] 36
## n
## 1 0.1111111
sumof12 <- ss %>%
filter(sum == 12) %>%
count
sumof12/poss %>%
print
## [1] 36
## n
## 1 0.02777778
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.
pov <- .146
lote <- .207
both <- .042
- Are living below the poverty line and speaking a foreign language at home disjoint? They are not disjoint since there are individuals who belong t both groups.
- Draw a Venn diagram summarizing the variables and their associated probabilities.
grid.newpage()
draw.pairwise.venn(area1 = .146, area2 = .207, cross.area = .042,
category = c("Below Poverty", "LOTE"))

## (polygon[GRID.polygon.11], polygon[GRID.polygon.12], polygon[GRID.polygon.13], polygon[GRID.polygon.14], text[GRID.text.15], text[GRID.text.16], text[GRID.text.17], text[GRID.text.18], text[GRID.text.19])
- What percent of Americans live below the poverty line and only speak English at home?
pov - both
## [1] 0.104
- What percent of Americans live below the poverty line or speak a foreign language at home?
pov + lote - both
## [1] 0.311
- What percent of Americans live above the poverty line and only speak English at home?
1 - (pov + lote - both)
## [1] 0.689
- Is the event that someone lives below the poverty line independent of the event that the person speaks a foreign language at home Someone living below the poverty line does not indicate the language they speak at home because there are people that live below the poverty line yet speak English.
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.
- What is the probability that a randomly chosen male respondent or his partner has blue eyes?
(108 + 114 - 78)/204
## [1] 0.7058824
- What is the probability that a randomly chosen male respondent with blue eyes has a partner with blue eyes?
78/204
## [1] 0.3823529
- 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?
BrBl <- (19/204) %>%
print
## [1] 0.09313725
GrBl <- (13/204) %>%
print
## [1] 0.06372549
- Does it appear that the eye colors of male respondents and their partners are independent? Explain your reasoning. It does appear that there is a correlation between matching partner eye colors however I still believe that these are independent events. The relationship does not explain causality and as such there is no dependency. A significance test would need to be performed to determine causality.
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.
books <- matrix(c(13, 59, 15, 8), nrow = 2, ncol = 2, byrow = TRUE)
- Find the probability of drawing a hardcover book first then a paperback fiction book second when drawing without replacement.
sum(books[,1])/sum(books) * books[1,2]/(sum(books) -1)
## [1] 0.1849944
- Determine the probability of drawing a fiction book first and then a hardcover book second, when drawing without replacement.
sum(books[1,])/sum(books) * sum(books[,1])/(sum(books) - 1)
## [1] 0.2257559
- 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.
sum(books[1,])/sum(books) * sum(books[,1])/(sum(books))
## [1] 0.2233795
- The final answers to parts (b) and (c) are very similar. Explain why this is the case. The probabilities are similar because the denominator is only changing very slightly. In the case of replacement, adding that extra book back the pool of books lowers the probability of achieving the condition by a very slight amount.
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 bag.
bags <- c(0,1,2)
fees <- c(0,25,25+35)
prob <- c(.52, .34, .12)
model <- data_frame(bags, fees, prob)
- Build a probability model, compute the average revenue per passenger, and compute the corresponding standard deviation.
avgrev <- sum(fees * prob) %>%
print
## [1] 15.7
sd <- (((fees - avgrev)^2) * prob) %>%
sum %>%
sqrt %>%
print
## [1] 19.82625
- 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.
rev120 <- (avgrev * 120) %>%
print
## [1] 1884
sd120 <- (sd^2 * 120) %>%
sqrt %>%
print
## [1] 217.1857
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.
inc <- c("1 to 9,999", "10,000 to 14,999", "15,000 to 24,999", "25,000 to 34,999",
"35,000 to 49,999", "50,000 to 64,999", "65,000 to 74,999",
"75,000 to 99,999", "100,000 or more")
total <- c(.022, .047, .158, .183, .212, .139, .058, .084, .097)
dis <- data_frame(inc, total)
male <- .59
female <- .41
- Describe the distribution of total personal income.
barplot(dis$total, names.arg = inc, xlab = "Income", ylab = "Total")
The distribution is unimodal, skewed left, and asymmetrical. * (b) What is the probability that a randomly chosen US resident makes less than $50,000 per year?
lt50k <- sum(dis$total[1:5]) %>%
print
## [1] 0.622
- 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.
flt50k <- (lt50k * female) %>%
print
## [1] 0.25502
- 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. The assumption made in part c is that the percentage of men and women is equally distributed amongst the different income brackets. If 71.8% of females make less then $50K per year, then that means most of the female population within this distribution are within the lower income brackets. This makes the equality assumption false.