Exercise 2.6 Dice Rolls If you roll a pair of fair dice, what is the probability of…
#Create a vector entitled fair dice
#There are 36 different outcomes
fair_dice <- c(1,2,3,4,5,6,5,4,3,2,1)/36
#Display findings
fair_dice
## [1] 0.02777778 0.05555556 0.08333333 0.11111111 0.13888889 0.16666667
## [7] 0.13888889 0.11111111 0.08333333 0.05555556 0.02777778
(A)Getting a sum of 1? 0 (B)Getting a sum of 5? Occurs with 1:4, 2:3, 3:2, and 4:1 the outcome is 0.11111111 (C)Getting a sum of 12? Occurs once with two sixes the outcome is 0.02777778
Exercise 2.8 Poverty and Language (A)Are living below the poverty line and speaking a foreign language at home disjoint? Disjoint outcomes cannot happen at the same time, therefore the answer is no since both outcomes are independent of each other.
(B)Draw a Venn diagram summarizing the variables and their associated problems?
#Incomplete (Having difficulties loading package)
(C)What percent of Americans live below the poverty line and only speak English at home?
#Create variables
Below_PovLine <- c(0.146)
Other_English <- c(0.207)
Both <- c(0.042)
Below_PovLine_Only <- Below_PovLine - Both
#Display results
Below_PovLine_Only
## [1] 0.104
#Use the General Addition Rule
(Below_PovLine + Other_English) - Both
## [1] 0.311
(100 - (0.104+0.042+0.165))/100
## [1] 0.99689
Exercise 2.20 Assortative Mating Import data into R
am<-read.csv(url("https://raw.githubusercontent.com/jbryer/DATA606Fall2017/master/Data/Data%20from%20openintro.org/Ch%202%20Exercise%20Data/assortive_mating.csv"))
#Use Table function to display total of am
table(am)
## partner_female
## self_male blue brown green
## blue 78 23 13
## brown 19 23 12
## green 11 9 16
#Obtain total of partner_female
(sum(am$partner_female=="blue"))
## [1] 108
(sum(am$partner_female=="brown"))
## [1] 55
(sum(am$partner_female=="green"))
## [1] 41
#Obtain total of self_male
(sum(am$self_male=="blue"))
## [1] 114
(sum(am$self_male=="brown"))
## [1] 54
(sum(am$self_male=="green"))
## [1] 36
((sum(am$self_male =="blue")/nrow(am)) +
(sum(am$partner_female =="blue")/nrow(am)))- (sum(am$self_male =="blue" & am$partner_female=="blue")/nrow(am))
## [1] 0.7058824
(sum(am$self_male =="blue" & am$partner_female=="blue")/nrow(am))
## [1] 0.3823529
#Brown Eye Male Blue Eye Partner
(sum(am$self_male =="blue" & am$partner_female=="blue")/nrow(am))/(sum(am$self_male=="blue")/nrow(am))
## [1] 0.6842105
(sum(am$self_male =="green" & am$partner_female=="blue")/nrow(am))/(sum(am$self_male=="green")/nrow(am))
## [1] 0.3055556
They are not independent because their outcomes are not equivalent
Exercise 2.30 Books on a Bookshelf
books<-read.csv(url("https://raw.githubusercontent.com/jbryer/DATA606Fall2017/master/Data/Data%20from%20openintro.org/Ch%202%20Exercise%20Data/books.csv"))
#Use Table function to display total of books
table(books)
## format
## type hardcover paperback
## fiction 13 59
## nonfiction 15 8
#Find the sum of hardcover
sum(books$format=="hardcover")
## [1] 28
#Find the sum of paperback
sum(books$format=="paperback")
## [1] 67
#Find the sum of fiction
sum(books$type=="fiction")
## [1] 72
#Find the sum of nonfiction
sum(books$type=="nonfiction")
## [1] 23
#Obtain the total of hardcover books and divide by the total of books
#Multiply the total of paperback boks which are divided by the total of books minus 1 since drawings are conducted without replacement
(sum(books$format=="hardcover"))/sum(table(books))*
(sum(books$format=="paperback"))/(sum(table(books))-1)
## [1] 0.2100784
#As in the first example drawings are conducted without replacement
(sum(books$type=="fiction"))/sum(table(books))*
(sum(books$format=="hardcover"))/(sum(table(books))-1)
## [1] 0.2257559
#In this example drawings are being replaced
(sum(books$type=="fiction"))/sum(table(books))*
(sum(books$format=="hardcover"))/sum(table(books))
## [1] 0.2233795
There is not much difference because the denominator changed by 1 only. If there was an exponential change then the disparity would be greater.
Exercise 2.38 Baggage Fees
Build a probability model, compute the average revenue per passenger, and compute the corresponding standard deviation.
About how much revenue should the airline expect for a ???ight of 120 passengers? With what standard deviation? Note any assumptions you make and if you think they are justi???ed.
Exercise 2.44 Income and Gender
#Create vectors to mirror exercise 2.44
income <-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(2.2,4.7,15.8,18.3,21.2,13.9,5.8,8.4,9.7)
layout <- data.frame(income,total)
layout
## income total
## 1 $1 to $9,999 2.2
## 2 $10,000 to $14,999 4.7
## 3 $15,000 to $24,999 15.8
## 4 $25,000 to $34,999 18.3
## 5 $35,000 to $49,999 21.2
## 6 $50,000 to $64,999 13.9
## 7 $65,000 to $74,999 5.8
## 8 $75,000 to $99,999 8.4
## 9 $100,000 or more 9.7
barplot(layout$total, horiz=T)
prob_50less <-sum(layout[1:5,]$total)
prob_50less
## [1] 62.2
#Sample is comprised of 59% males and 41% females
prob_fem <-0.41 * prob_50less
prob_fem
## [1] 25.502
fem50 <- 0.718 * 0.41
fem50
## [1] 0.29438