red <- 54
white <- 9
blue <- 75
box.of.marbles <- vector()
box.of.marbles[1:54] <-"red"
box.of.marbles[55:63] <- "white"
box.of.marbles[64:138] <- "blue"
count.marble <- 0
for (i in 1:1000000) {
selected <- sample(box.of.marbles,1,replace=TRUE)
if (selected == "red" | selected == "blue") {
count.marble <- count.marble + 1
}
}
round(count.marble/1000000,4)
## [1] 0.9345
\(P(Red\quad or\quad Blue)=\frac { red\quad marbles\quad +\quad blue\quad marbles }{ total\quad marbles } =\frac { 54+75 }{ 138 }\)
round(sum(red,blue)/sum(red,white,blue),4)
## [1] 0.9348
green <- 19
red <- 20
blue <- 24
yellow <- 17
mini.golf <- vector()
mini.golf[1:19] <-"green"
mini.golf[20:39] <- "red"
mini.golf[40:63] <- "blue"
mini.golf[64:80] <- "yellow"
count.golf <- 0
for (i in 1:1000000) {
selected.golf <- sample(mini.golf,1,replace=TRUE)
if (selected.golf == "red") {
count.golf <- count.golf + 1
}
}
round(count.golf/1000000,4)
## [1] 0.25
\(P(red)=\frac{number\quad of\quad red}{total\quad balls}\)
round(sum(red)/sum(green,red,blue,yellow),4)
## [1] 0.25
knitr::include_graphics("C:\\Users\\sergioor\\Desktop\\Old PC\\CUNY\\DATA605\\hw6eq1.png")
What is the probability that a customer is not male or does not live with parents? Write your answer as a fraction or a decimal number rounded to four decimal places.
\({ M }^{ c }\) represents the event that a customer is not male \({ P }^{ c }\) represents the event that customer doesn’t live with parents \({ P(M }^{ c }\cup { P }^{ c })={ P(M }^{ c }\cap { P }^{ c })\\ =\quad 1-(\frac { 215 }{ 1399 } +\frac { 1184 }{ 1399 } )\)
Going to the gym. Losing weight. A) Dependent B) Independent
Two events are indepedent if either:
In other words, given the existence of one event, if the probability of the other event doesn’t change and vice versa, we can conclude that these two events are independent.
In this situation, given the fact of going to the gym, the probability of losing weight will be different, and therefore these two events are A) dependent.
veg.type <- 8
cdm.type <- 7
tor.type <- 3
veg.need <- 3
cdm.need <- 3
tor.need <- 1
n.type <- choose(veg.type,veg.need)*choose(cdm.type,cdm.need)*choose(tor.type,tor.need)
n.type #use nCr because order doesn't matter
## [1] 5880
Jeff runs out of gas on the way to work. Liz watches the evening news. A) Dependent B) Independent
Assuming there is no exceptional connections between Jeff and Liz and/or between the two events, these two events should be B) independent since given the fact that Jeff runs out of gas on the way to work, Liz should watch or not watch evening news regardless.
permutation <- function(n,r){gamma(n + 1)/gamma(n - r + 1)}
permutation(14,8) #use nPr because order is taken into consideration
## [1] 121080960
\(P(nored,1orange,3green)=\frac { \begin{pmatrix} 9 \\ 0 \end{pmatrix}\begin{pmatrix} 4 \\ 1 \end{pmatrix}\begin{pmatrix} 9 \\ 3 \end{pmatrix} }{ \left( \frac { 9+4+9 }{ 4 } \right) } =\frac { 336 }{ 7315 }\)
red.contain <- 9
orange.contain <- 4
green.contain <- 9
red.withdraw <- 0
orange.withdraw <- 1
green.withdraw <- 3
choices <- choose(red.contain + orange.contain + green.contain, 4)
withdrwal <- choose(red.contain,red.withdraw)*choose(orange.contain,orange.withdraw)*choose(green.contain,green.withdraw)
withdrwal/choices
## [1] 0.04593301
\(\frac { 11! }{ 7! }\)
gamma(11+1)/gamma(7+1)
## [1] 7920
67% of subscribers to a fitness magazine are over the age of 34.
P(subscribers > age of 34) = 67% P(subscribers ≤ age of 34) = 1 - P(> 34) = 33%
Step 1. Find the expected value of the proposition. Round your answer to two decimal places.
\(E\left[ X \right] =\sum _{ i=1 }^{ \infty }{ { x }_{ i } } p({ x }_{ i })\)
win <- 97
p.win <- choose(4,3)/2^4
lose <- -30
p.lose <- 1 - p.win
expected.toss <- win*p.win + lose*p.lose
round(expected.toss,2)
## [1] 1.75
expected.559times <- expected.toss*559
expected.559times
## [1] 978.25
\(E\left[ X \right] =\sum _{ i=1 }^{ \infty }{ { x }_{ i } } p({ x }_{ i })\)
win <- 23 #calculate
p.win <- sum(choose(9,4),choose(9,3),choose(9,2),choose(9,1),choose(9,0))/2^9
lose <- -26
p.lose <- 1 - p.win
expected.flip <- win*p.win + lose*p.lose
round(expected.flip,2)
## [1] -1.5
Step 2. If you played this game 994 times how much would you expect to win or lose? (Losses must be entered as negative.)
expected.994times <- expected.flip*994
expected.994times
## [1] -1491
Based on sensitivity = 0.59, specificity = 0.9, and P(liar) = 0.2, we can generate:
knitr::include_graphics("C:\\Users\\sergioor\\Desktop\\Old PC\\CUNY\\DATA605\\hw6eq2.png")
\(sensitivity\quad =\frac { a }{ a+c } =0.59\\ Specificity\quad =\quad \frac { d }{ b+d } =0.90\\ P(liar)\quad =\quad \frac { a+c }{ a+b+c+d } =0.20\)
p.liar <- 0.2 #a + c in the table
p.truth_teller <- 1 - p.liar #b + d in the table
p.detected_liar <- 0.118 #a in the table, true positives, P(L and D)
p.undetected_liar <- 0.082 #c in the table, false negatives, P(L and D^c)
p.undetected_truth <- 0.08 #b in the table,false positives, P(L^c and D)
p.detected_truth <- 0.72 #d in the table, true negative, P(L^c and D^c)
sum(p.detected_liar,p.undetected_liar,p.undetected_truth,p.detected_truth)
## [1] 1
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.)
\(P(A\cap B)=P(A|B)P(B)P(Liar|Detected)=\frac { P(L\cap D) }{ P(D) } =\frac { 0.118 }{ 0.118+.08 }\)
p.detected_liar/(p.detected_liar + p.undetected_truth)
## [1] 0.5959596
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.)
\(P(Truth|notdetected)=\frac { P({ L }^{ c }\cap { D }^{ c }) }{ P({ D }^{ c }) } =\frac { 0.72 }{ 0.082+0.72 }\)
p.detected_truth/(p.undetected_liar + p.detected_truth)
## [1] 0.8977556
What is the probability that a randomly selected individual is either a liar or was identified as a liar by the polygraph? Be sure to write the probability statement.
\(P(A\cup B)=P(A)+P(B)-P(A\cap B)\\ P(Liar\quad \cup \quad Detected)\quad =\quad P(L)+P(D)-P(L\cap D)=0.2+(0.118+0.08)-0.118\)
p.liar + (p.detected_liar + p.undetected_truth) - p.detected_liar
## [1] 0.28