Chapter 2 - Probability

Defining Probability

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

There is 36 posible combianations when rolling a pair of fair dice
  1. getting a sum of 1? Ther is not possible combination to get a sum of on rolling a pair of dice

  2. getting a sum of 5?

    Please see the following ways: 1,4; 2,3; 3,2; 4,1 so the changes are 4 times in 36 posible combinations which is 4/36

    The probability of getting a sum of 5 is 4/36

  3. getting a sum of 12

    There is only one posible combination 6,6 out of the 36

    The probabilty of getting a sum of 12 is 1/36

2.8 Poverty and Language: The American Community Survey is an ongoing survey that provides data every year to give communities the current 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 (foreing language) at home, and 4.2% fall into both categories.

  1. Are living below the poverty line and speaking a foreing language at home disjoint?

    Because the living below the poverty line and language spoken in the America community are events that have elements in common, one variable falls in the other one. they are not disjoint events.

  2. Draw a Venn diagram summarizing the variables and their associated probabilities?

library(VennDiagram)
## Loading required package: grid
## Loading required package: futile.logger
library(grid)
venn_sample <- draw.pairwise.venn(14.6, 20.7, 4.2, c("Foreing Language spoken", "Below poverty Line"),  scale = FALSE, fill = c("blue", "red"));
grid.draw(venn_sample);

#grid.newpage()
  1. What percentage of Americans live below the poverty line and only speaks English at home?

    According to the Venn diagram for the two variables give ; 10.4 percent of Americans live below the poverty line and they are english speakers at home.

  2. What percentage of Americans live below the poverty line or speaks a foreign language at home?

    It would be 14.6 of Americans live below poverty leve plus 20.7 speaks foreing language minus 4.2 that meet both criteria, it means ( 14.6 + 20.7) - 4.2 = 31.1 percent of Americans live below the poverty or speak a foreing language.

  3. What percentage of Americans live above the poverty line and only speaks English at home?

    The percente of Americans live above the poverty line and only speaks English would be from 100 % - 31.1% = 68.9 %

  4. Is the event that someones lives below the poverty line independent of the event that a person speaks a foreing language at home?

    No, Those events are not independent, there is many possibilities that one variable falls in the other one.

Conditional Probability

2.20 Assortative mating.Assortative mating is a nonramdom 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.

ass_mating <- read.csv('https://raw.githubusercontent.com/jbryer/DATA606Fall2017/master/Data/Data%20from%20openintro.org/Ch%202%20Exercise%20Data/assortive_mating.csv')
sampleblue = subset(ass_mating, partner_female == "blue")

count1 = table(ass_mating$self_male, ass_mating$partner_female)
t = as.data.frame(count1)
names(t)[1] = 'Self Male'
names(t)[2] = 'Partner Female'
t
##   Self Male Partner Female Freq
## 1      blue           blue   78
## 2     brown           blue   19
## 3     green           blue   11
## 4      blue          brown   23
## 5     brown          brown   23
## 6     green          brown    9
## 7      blue          green   13
## 8     brown          green   12
## 9     green          green   16
  1. What is the probabilty that a randomly chosen male respondent or his partner has blue eyes?
library(gmodels)
# The gmodels packages has a function CrossTable with Tests for Factor Independece
# prop.r    If TRUE, row proportions will be included
with(warpbreaks, CrossTable(ass_mating$self_male, ass_mating$partner_female, prop.r = TRUE, prop.c = FALSE, prop.t = FALSE, prop.chisq = FALSE))
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## |           N / Row Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  204 
## 
##  
##                      | ass_mating$partner_female 
## ass_mating$self_male |      blue |     brown |     green | Row Total | 
## ---------------------|-----------|-----------|-----------|-----------|
##                 blue |        78 |        23 |        13 |       114 | 
##                      |     0.684 |     0.202 |     0.114 |     0.559 | 
## ---------------------|-----------|-----------|-----------|-----------|
##                brown |        19 |        23 |        12 |        54 | 
##                      |     0.352 |     0.426 |     0.222 |     0.265 | 
## ---------------------|-----------|-----------|-----------|-----------|
##                green |        11 |         9 |        16 |        36 | 
##                      |     0.306 |     0.250 |     0.444 |     0.176 | 
## ---------------------|-----------|-----------|-----------|-----------|
##         Column Total |       108 |        55 |        41 |       204 | 
## ---------------------|-----------|-----------|-----------|-----------|
## 
## 

Acording to the table above we can summarize the assorting mating data set using the contingency table that contains a sample of 204 cases with two variables, A = self_male and B = partner_female

Total of self male with blue eyes = 114 Total of self male with brown eyes = 54 Total of self male with green eyes = 36

Total of partner female with blue eyes = 108 Total of partner female with brown eyes = 55 Total of partner female with green eyes = 41

P(A or B) = P(A)+P(B)-P(A and B)

      = (114/204)+(108/204)-(78/204)= .7059 =70.59%   
      
((sum(ass_mating$self_male =="blue")/nrow(ass_mating)) +
 (sum(ass_mating$partner_female =="blue")/nrow(ass_mating)))- (sum(ass_mating$self_male =="blue" & ass_mating$partner_female=="blue")/nrow(ass_mating))
## [1] 0.7058824
  1. What is the probability that a randomly chosen male respondent with blue eyes has a partner with blue eyes?

    I selected the number that correspondents in the table above to the self_male blue/partner blue = 78 divided by the total of self_male with blue eyes = 114

    P(A|B) = p(A and B)/P(B)

       = 78/114 = .6842 = 68.42%
(sum(ass_mating$self_male =="blue" & ass_mating$partner_female=="blue")/nrow(ass_mating))/(sum(ass_mating$self_male=="blue")/nrow(ass_mating))
## [1] 0.6842105
  1. What is the probability that a randomly chose male respondent with brown eyes has a partner with blue eyes?

    I selected the number that correspondents in the table above to the self_male brown/partner blue = 19 divide by the Total of self male with brown eyes = 54

    = 19/54 = .352 = 35.2%

(sum(ass_mating$self_male =="brown" & ass_mating$partner_female=="blue")/nrow(ass_mating))/(sum(ass_mating$self_male=="brown")/nrow(ass_mating))
## [1] 0.3518519

What about the probability of a randomly chosen male respondent with green eyes having a partner with blue eyes?

I selected the number that correspondents in the table above the self_male green/ partners blue = 11, divide by the Total of self male with green eyes = 36

= 11/36 = .306 = 30.6%

(sum(ass_mating$self_male =="green" & ass_mating$partner_female=="blue")/nrow(ass_mating))/(sum(ass_mating$self_male=="green")/nrow(ass_mating))
## [1] 0.3055556

Does it appears that the eye colors of male respondents and their partners are independent? Explain you reasoning.

The probability that a random self male from the study has a blue eyes     is 56% and the probability of randomly select a partner female with        blue eyes is 52.4% . Both variables are dependent.

Sampling from a Small population

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.

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

with(warpbreaks, CrossTable(book_class$type, book_class$format, prop.r = TRUE, prop.c = FALSE, prop.t = FALSE, prop.chisq = FALSE))
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## |           N / Row Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  95 
## 
##  
##                 | book_class$format 
## book_class$type | hardcover | paperback | Row Total | 
## ----------------|-----------|-----------|-----------|
##         fiction |        13 |        59 |        72 | 
##                 |     0.181 |     0.819 |     0.758 | 
## ----------------|-----------|-----------|-----------|
##      nonfiction |        15 |         8 |        23 | 
##                 |     0.652 |     0.348 |     0.242 | 
## ----------------|-----------|-----------|-----------|
##    Column Total |        28 |        67 |        95 | 
## ----------------|-----------|-----------|-----------|
## 
## 
  1. Find the probability of drawing a hardcover book first then a paperback fiction the second time without replacement?

General multiplication Rule

The probability of drawing a hardcover book = 28/95 = .2947 = 29.47% the probability of drawing a paperback book fiction = 59/94 = .6276 = 62.76%

The probability of the second time without replacement = .2947 X .6276 = .1849 = 18.49%

(sum(book_class$format=="hardcover"))/sum(table(book_class)) *
(sum(book_class$format=="paperback" & book_class$type == "fiction"))/(sum(table(book_class))-1)
## [1] 0.1849944
  1. Determine the probability of drawing a fiction book first and then a hardcover book second, when drawing without replacement.

The probability of drawing a fiction book 72/95 = .7578 = 75.78% the probability of dawing a hardbook = 28/94 = .2978= 29.78% the probability of drawing a fiction book then hardcover NO replacement is .7578 x .2978 = .2256 = 22.56%

(sum(book_class$type=="fiction"))/sum(table(book_class)) *
(sum(book_class$format=="hardcover"))/(sum(table(book_class))-1)
## [1] 0.2257559
  1. Calculate the probability of the scenario in part(b), except this time complete the calculaltions under the scenario where the first book is placed back on the bookcase before randomly drawing a second book.

The probability of drawing a fiction book 72/95 = .7578 = 75.78% the probability of dawing a hardbook = 28/95 = .2947 = 29.47% the probability of drawing a fiction book then hardcover WITH replacement is .7578 x .2947 = .2233 = 22.33%

(sum(book_class$type=="fiction"))/sum(table(book_class)) *
(sum(book_class$format=="hardcover"))/(sum(table(book_class)))
## [1] 0.2233795
  1. The final answers to parts b and c are very similar. Explain why this is the case.

the larger the samples the smaller the difference.

Random Variables

2.38 Baggages 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.

  1. Build a probability model, compute the average revenue per passenger, and compute the corresponding standard deviation.
num_bags <- c('no-bags', 'one-bags', 'two-bags')
bag_fee <- c(0,25,35)
pass <- c(.54, .34, .12)
sample <- data.frame(num_bags, pass, bag_fee)
average_revenue <- (sum((sample$pass*sample$bag_fee))/sum(sample$pass))
average_revenue
## [1] 12.7
sqrt(0.54*(0-average_revenue)^2 + 0.34*(25-average_revenue)^2 + 0.12*(35-average_revenue)^2)
## [1] 14.07871
  1. About how much revenue should the airline expect for a flight of 120 passengers? With what standar deviation? Note any assumption you make and if you think they are justified.

    Total passengers 120 Assuming that 54% of passengers have no checked luggage, 34% have one piece of checked luggage and 12% have two pieces

    65 passengers have no checked bag 41 passengers have one checked bag 14 passengers have two checked bag

avg120flight <- (65*0 + 41*25 + 14 *25 + 14 * 35)
avg120flight
## [1] 1865
x <- c(0, 1025,840)
# Standar deviation of the revunue for a flight of 120 passengers
sqrt(sum((x-mean(x))^2/(length(x)-1)))
## [1] 546.2676
sd(x)
## [1] 546.2676

Continuos Distribution 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.

  1. Describe the distribution of total personal income.
Income_range <- c("1 to $9999 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,999", "65,000 to 74,999",
                  "75,000 to 99,999", "100,000 or more")
total <- c(.022, .047, 0.158, 0.183, 0.212, 0.139, 0.058, 0.084, 0.097)
x <- data.frame (Income_range, total)
x
##         Income_range total
## 1 1 to $9999 or loss 0.022
## 2   10,000 to 14,999 0.047
## 3  15, 000 to 24,999 0.158
## 4   25,000 to 34,999 0.183
## 5   35,000 to 49,999 0.212
## 6   50,000 to 64,999 0.139
## 7   65,000 to 74,999 0.058
## 8   75,000 to 99,999 0.084
## 9    100,000 or more 0.097
barplot(total)

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

    P(less than 50,000) = 2.2 + 4.7 + 15.8 + 18.3 + 21.2 = 62.2 %

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

    P(less than 50,000 and gender = female) = P(less than $50,000) * P(gender= female) = 0.622 x 0.410 = 0.255 = 25.5%

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

    Gender and income are dependent variables,I am not able to calculate the probability of 71.8% of females making less than $50,000 because the total population making less than 50,000 (C) is 62.2%.