Library

library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.4.3
## -- Attaching packages ---------------------------------- tidyverse 1.2.1 --
## v ggplot2 2.2.1     v purrr   0.2.4
## v tibble  1.4.1     v dplyr   0.7.4
## v tidyr   0.7.2     v stringr 1.2.0
## v readr   1.1.1     v forcats 0.2.0
## Warning: package 'tibble' was built under R version 3.4.3
## Warning: package 'tidyr' was built under R version 3.4.3
## Warning: package 'readr' was built under R version 3.4.3
## Warning: package 'purrr' was built under R version 3.4.3
## Warning: package 'dplyr' was built under R version 3.4.2
## Warning: package 'forcats' was built under R version 3.4.3
## -- Conflicts ------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()

1) A box contains 54 red marbles, 9 white marbles, and 75 blue marbles. If a marble is randomly selected from the box, what is the probability that it is red or blue? Express your answer as a fraction or a decimal rounded to four decimal places.

R = 54
W = 9
B = 75
cat("Number of Marbles in the the Box","\n")
## Number of Marbles in the the Box
R + W + B
## [1] 138
cat("\n","Number of Red & Blue Marbles","\n")
## 
##  Number of Red & Blue Marbles
R + B
## [1] 129
cat("\n","Probability that a Red or Blue Marble will be Selected","\n")
## 
##  Probability that a Red or Blue Marble will be Selected
round(129/138, digits=4)
## [1] 0.9348

2) You are going to play mini golf. A ball machine that contains 19 green golf balls, 20 red golf balls, 24 blue golf balls, and 17 yellow golf balls, randomly gives you your ball. What is the probability that you end up with a red golf ball? Express your answer as a simplified fraction or a decimal rouded to four decimal places.

cat("Number of Mini Golf Balls","\n")
## Number of Mini Golf Balls
19 + 20 + 24 + 17
## [1] 80
cat("\n","Probability of Selecting a Red Golf Ball","\n")
## 
##  Probability of Selecting a Red Golf Ball
round(20/80, digits=4)
## [1] 0.25

3) A pizza delivery company classifies its customers by gender and location of residence. The reasearch department has gathered data from a random sample of 1399 customers. The data is summarized in the table below.

tb <- tibble(
    "Location of Residence" = c("Apartment","Dorm","With Parent(s)","Sorority/Fraternity House","Other"),
    "Males" = c(81,116,215,130,129),
    "Females" = c(228,79,252,97,72)
)
tb
## # A tibble: 5 x 3
##   `Location of Residence`   Males Females
##   <chr>                     <dbl>   <dbl>
## 1 Apartment                  81.0   228  
## 2 Dorm                      116      79.0
## 3 With Parent(s)            215     252  
## 4 Sorority/Fraternity House 130      97.0
## 5 Other                     129      72.0

What is the probability that a customer is not male or does not live with parents? Write you answer as a fraction or a decimal number rounded to four decimal places.

First find the probability of customers who are not males.

cat("Number of Non-Male Customers","\n")
## Number of Non-Male Customers
228 + 79 + 252 + 97 + 72
## [1] 728
cat("\n","Probability of Non-Male Customers","\n")
## 
##  Probability of Non-Male Customers
round(728/1399, digits = 4)
## [1] 0.5204

Secondly, we will find the probablity of customers who do not live with their parents.

cat("Number of Customers who Don't Live w/Parents","\n")
## Number of Customers who Don't Live w/Parents
215 + 253
## [1] 468
cat("\n","Probability of Customers who Don't Live w/Parents","\n")
## 
##  Probability of Customers who Don't Live w/Parents
round(468/1399, digits = 4)
## [1] 0.3345

Thirdly, we have to figure out the probability of customers who are females that don’t live with their parents.

cat("Probability of Female Customers That Don't Live w/Parents","\n")
## Probability of Female Customers That Don't Live w/Parents
round(252/1399, digits = 4)
## [1] 0.1801

Lastly we add the probabilities of non-male customers and those that don’t live with their parents and then subtract the female customers who don’t live with their parents.

0.5204 + 0.3345 - 0.1801
## [1] 0.6748

4) Determine is the following events are independent - Going to the gym. Losing Weight

These two events are independent, in some cases one can go to the gym gain weight. In another case, one can lose weight through bariatric surgery or by dieting.

5) A veggie wrap at City Subs is composed of 3 different vegetables and 3 different condiments wrapped up in a tortilla. If there are 8 vegatables, 7 condiments, and 3 types of tortilla available, how many different veggie wraps can be made?

In this instance, we will form the calculation by utilizing the choose() function which computes the combination \(_nC_r\)

v <- choose(8,3) #ways to calculate veggie combos
c <- choose(7,3) #ways to calculate condiments combos
t  <-choose(3,1) #ways to calculate tortilla combos
cat("Number of Different Veggie Wrap Combinations","\n")
## Number of Different Veggie Wrap Combinations
v * c * t
## [1] 5880

6) Determine is the following events are independent - Jeff runs out of gas on the way to work. Liz watches the evening news

These two events are independent, these two events are not directly linked at all.

7) The newly elected president needs to decide the remaining 8 spots available in the cabinet he/she is appointing. If there are 14 eligible candidates for these positions (where rank matters), how many different ways can the members of the cabinet be appointed?

In this particular case we would use combinatorics so we would calculate the facotorial for the 14 eligible candidates and divide that by the factorial of the 8 available slots against the number of eligible candidates.

factorial(14) / factorial(14-8)
## [1] 121080960

8) A bag contains 9 red, 4 orange, and 9 green jellybeans. What is the probability of reaching into the bag and randomly withdrawing 4 jellybeans such that the number of red ones is 0, the number of oranges ones is 1, and the number of green ones is 3? Write your answer as a fraction or a decimal number rounded to four decimal places.

Again, we will utilize the choose function according to the rules of combinatorics

cat("Number of Jellybeans in the Bag","\n")
## Number of Jellybeans in the Bag
9 + 4 + 9
## [1] 22
R <- choose(9,0) #randomly selecting red jellybean
O <- choose(4,1) #randomly selecting orange jellybean
G <- choose(9,3) #randomly selecting green jellybean
cat("\n","Probability of Selecting Jellybeans Combination","\n")
## 
##  Probability of Selecting Jellybeans Combination
round(R * O * G/choose(22,4), digits = 4) #multiplyting the outcome and dividing by the 22 jellybeans and the withdrawal of 4
## [1] 0.0459

9) Evaluate the expression \[\frac{11!}{7!}\] For this question I decided to conduct the calculation two ways, one by the previous method.

factorial(11) / factorial(7)
## [1] 7920

Secondly, we implement a function and calculate the answer the long way.

fact_calc <- function(n){
    if(n <= 1) {
        return(1)
    } else {
        return(n * fact_calc(n-1))
    }
}
fact_calc(11)
## [1] 39916800
fact_calc(7)
## [1] 5040

Lastly we will divide the output

39916800 / 5040
## [1] 7920

The answer is 7,920

10) Describe the complement of the given event. 67% of subscribers to a fitness magazine are over the age of 34

1 - 0.67
## [1] 0.33

The complement would be 33% of subscribers to a fitness magazine are under the age of 34.

11) If you throw exactly three heads in four tosses of a coin you win $97. If not, you pay me $30.

Step 1 - Find the expected value of the proposition.Round your answer to two decimal places

Step 2 - If you played this game 559 times how much would you expect to win or lose? (Losses must be entered as negative).

Using the pbinom function we can enter a number against the size and add the probability.

cat("Step 1: Probability of 3 Heads (For/Against)","\n")
## Step 1: Probability of 3 Heads (For/Against)
ct <- pbinom(3,size=4, prob=0.5) - pbinom(2,size=4,prob=0.5)
nct <- 1 - ct
out <- ct * 97 - nct * 30
out
## [1] 1.75
cat("\n","Step 2: Probability of 3 Heads (559 Trials)","\n")
## 
##  Step 2: Probability of 3 Heads (559 Trials)
out * 559
## [1] 978.25

12) Flip a coin 9 times. If you get 4 tails or less, I will pay you $23. Otherwise you pay me $26.

Step 1 - Find the expected value of the proposition.Round your answer to two decimal places

Step 2 - If you played this game 994 times how much would you expect to win or lose? (Losses must be entered as negative).

cat("Step 1: Probability of 3 Heads (For/Against)","\n")
## Step 1: Probability of 3 Heads (For/Against)
ct <- pbinom(4,size=9, prob=0.5) - pbinom(3,size=9,prob=0.5)
nct <- 1 - ct
out <- ct * 23 - nct * 26
out
## [1] -13.94141
cat("\n","Step 2: Probability of 3 Heads (559 Trials)","\n")
## 
##  Step 2: Probability of 3 Heads (559 Trials)
out * 994
## [1] -13857.76

13) The sensitivity and specificity of the polygraph has been a subject of study and debate for years. A 2001 study of the use of polygraph for screening purposes suggested that the probability of detecting a liar was .59(sensitivity) and that the probability of detecting a “truth teller” was .90 (specificity). We estimate that about 20% of individuals selected for the screening polygraph will lie

A) What is the probability that an individual is actually a liar given that the polygraph detected him/her as such? (Show me the table or the formulaic solution or both.)

In this scenario we know the probability for lying is 20% and 59% of the time the polygraph detected a liar, therefore we will multiply the two outcomes. Decision based to calculate findings were showcased on Khan Academy - Conditional Probability

cat("Probability Individual Liar | Polygraph Detected","\n")
## Probability Individual Liar | Polygraph Detected
L <- 0.2
D <- 0.59
L * D
## [1] 0.118

B) What is the probability that an individual is actually a truth-teller given that the polygraph detected him/her as such?(Show me the table or the formulaic solution or both.)

Using the complement, we can calculate that since the polygraph detected a lie at 20% then it detected truth at 80%.

cat("Probability Individual Truth | Polygraph Detected","\n")
## Probability Individual Truth | Polygraph Detected
T <- 0.8
D <- 0.9
T * D
## [1] 0.72

C) What is the probability that a randomly selected individual is either a liar or was identified as a liar by the polygraph?(Show me the table or the formulaic solution or both.)

L <- 0.2
D <- 0.59
1 - L * D
## [1] 0.882