library(stats)
(Bayesian). A new test for multinucleoside-resistant (MNR) human immunodeficiency virus type 1 (HIV-1) variants was recently developed. The test maintains 96% sensitivity, meaning that, for those with the disease, it will correctly report “positive” for 96% of them. The test is also 98% specific, meaning that, for those without the disease, 98% will be correctly reported as “negative.”
MNR HIV-1 is considered to be rare (albeit emerging), with about a .1% or .001 prevalence rate.
a. Given the prevalence rate, sensitivity, and specificity estimates, what is the probability that an individual who is reported as positive by the new test actually has the disease?
We want to find p(has disease | + test) A1 = Has the disease B = + test
\(p(A1 | B) = P(B | A1) * P(A1) / P(B | A1) * P(A1) + P(B | A2) * P(A2)\)
(.96 * 0.001) / (.96 * 0.001) + (0.02 + 0.999)
round((.96 * 0.001) / (.999 * 0.02) + (.96 * 0.001), 4)
## [1] 0.049
The probability of that an individual who has the disease given a positive test = 0.049 or 4.9%
b. If the median cost (consider this the best point estimate) is about 100,000 dollars per positive case total and the test itself costs 1000 dollars per administration, what is the total first-year cost for treating 100,000 individuals?
Total First Year Cost = Total Cost of Administering the Test + (Number of Positive Cases × Median Cost per Positive Case)
$ = (1000 x 100,000) + (100,000 * 100,000)$
total_firstyearcost <- (1000 * 100000) + (100000 * 100000)
total_firstyearcost
## [1] 1.01e+10
Total First Year Cost = 1.01 x 10^10 - $101 million
The probability of your organization receiving a Joint Commission inspection in any given month is 0.05.
X = {inspection, no inspection} p(inspection) = 0.05 p(no inspection) = 0.95
a. What is the probability that, after 24 months, you received exactly 2 inspections?
Using the formula: p(X = x | N, p) = \(N_C_x\) * \(p^x\) * \((1 - p)^N^-^x\)
p(X = 2 | N = 24, p = 1/20)
scenarios <- factorial(24) / (factorial(2) * factorial(22))
a <- ((1/20) ** 2) * ((19/20) ** 22)
scenarios * a
## [1] 0.2232381
p(X = 2 | N = 24, p = 1/20) = 0.2232 - 22.32%
b. What is the probability that, after 24 months, you received 2 or more inspections?
For this problem we can find the compliment of the probabilities of 0 and 1 inspections
p(0 inspections) = (0.95)^24
p(1 inspection) = (24! / 23!) * (0.5^1 * .95^23)
p0 <- 0.95 ** 24
p1 <- (factorial(24) / factorial(23)) * (.05 * (.95 ** 23))
1 - (p0 + p1)
## [1] 0.3391827
p(X >= 2) = 0.3391
c. What is the probability that you received fewer than 2 inspections?
For this problem we can find the probabilities of 0 and 1 inspections as above
p0 <- 0.95 ** 24
p1 <- (factorial(24) / factorial(23)) * (.05 * (.95 ** 23))
p0 + p1
## [1] 0.6608173
p(X < 2) = 0.6608
d. What is the expected number of inspections you should have received?
expected number of inspections = 0.05 x 24 = 1.2
e. What is the standard deviation?
the square root of Np * (1 - p)
24 * 0.5 / 0.95
The standard deviation = 1.067708
sqrt((24 * 0.05) * 0.95)
## [1] 1.067708
You are modeling the family practice clinic and notice that patients arrive at a rate of 10 per hour.
a. What is the probability that exactly 3 arrive in one hour? p(X = 3) \(\lambda^k\) * \(e^-k\) / \(k!\)
\(\lambda\) = 10 \(k = 3\)
(10 ** 3) * (exp(1)**(-10)) / factorial(3)
## [1] 0.007566655
p(X = 3) = 0.007566 - .7566%
b What is the probability that more than 10 arrive in one hour? p(k > 10) - find the complimentary 1 - p(k <= 10) - sum up all of the probabilities <= 10 then subtract from 1
x <- c()
for(i in 0:10){
prob_i <- (10 ** i) * (exp(1)**(-10)) / factorial(i)
x <- append(x, prob_i)
}
1 - sum(x)
## [1] 0.4169602
p(k > 10) = 0.417 - 41.7%
c. How many would you expect to arrive in 8 hours?
Expected visits in 8 hours
arrival rate = 10/hr * 8 hours = 80 patients
d. What is the standard deviation of the appropriate probability distribution?
sd = sqrt(10) = 3.162
sqrt(10)
## [1] 3.162278
e. If there are three family practice providers that can see 24 templated patients each day, what is the percent utilization and what are your recommendations?
With 3 providers that can see 24 patients each/day the capacity = 72
patients The expected number of patients in 8 hours is 80
Percent utilization is the expected number * total capacity
(80/72) * 100
## [1] 111.1111
Since we are over capacity, potentially hiring another provider or part time provider to handle over flow might be needed.
Your subordinate with 30 supervisors was recently accused of favoring nurses. 15 of the subordinate’s workers are nurses and 15 are other than nurses. As evidence of malfeasance, the accuser stated that there were 6 company-paid trips to Disney World for which everyone was eligible. The supervisor sent 5 nurses and 1 non-nurse.
a. If your subordinate acted innocently, what was the probability he/she would have selected five nurses for the trips?
N = population size = 30 K = Success stats in population - 15 (nurses) n = number of draws = 6 k = number of observed success = 5
p(5 nurses selected) = \(K_ck\) * \(N-K_cn-k\) / \(N_cn\) = \(15_c5\) * \(15_c1\) / \(30_c6\)
p(5 nurses selected) = 0.0757 - 7.57%
# 15c5
a <- factorial(15) / (factorial(5) * factorial(10))
# 15c1
b <- factorial(15) / (factorial(1) * factorial(14))
# 30c6
c <- factorial(30) / (factorial(6) * factorial(24))
(a * b) / c
## [1] 0.07586207
b. How many nurses would we have expected your subordinate to send?
We would have expected there to be 3 nurses chosen
c. How many non-nurses would we have expected your subordinate to send?
We would have expected there to be 3 nurses chosen
Explanation for b and c expected value = n * K/N
expected_value <- 6 * (15/30)
expected_value
## [1] 3
The probability of being seriously injured in a car crash in an unspecified location is about 0.1% per hour. A driver is required to traverse this area for 1200 hours in the course of a year.
X = injuries
a. What is the probability that the driver will be seriously injured during the course of the year?
p(injury in a given year) We can use the compliment of p(X = 0)
p(X > 0) = 1 - \(e^-_\lambda\) * \(\lambda^k\) / \(k!\)
lambda <- 0.001 * 1200
p0 <- (exp(1) ** (-1 * lambda)) * (lambda ** 0) / factorial(0)
1 - p0
## [1] 0.6988058
p(X > 0) = 0.6988 - 69.88%
b. In the course of 15 months? Can use the same logic as above but our lambda is now the rate x the amount of hours in 15 months
# hours in a 15 months
hours <- 13 * 30 * 24
lambda <- 0.001 * hours
p0 <- (exp(1) ** (-1 * lambda)) * (lambda ** 0) / factorial(0)
1 - p0
## [1] 0.9999139
p(X > 0 in 15 months) = 0.99998 - 99.98%
c. What is the expected number of hours that a driver will drive before being seriously injured?
The expected number of hours that a driver will drive before being injured is 1/p = 1000 hours
expected_number_hours <- 1 / 0.001
expected_number_hours
## [1] 1000
d. Given that a driver has driven 1200 hours, what is the probability that he or she will be injured in the next 100 hours?
remaining_time_hrs = 100
lambda_per_hour = 0.001
probability_injured_next_100_hours <- ppois(0, lambda_per_hour * remaining_time_hrs)
probability_injured_next_100_hours
## [1] 0.9048374
p(X > 0 in the next 100 | 1200) = 0.9048374 - 90.48
You are working in a hospital that is running off of a primary generator which fails about once in 1000 hours.
failure_rate_hrs = 1/1000
a. What is the probability that the generator will fail more than twice in 1000 hours? p(k > 2) = 1 - p(k <= 2) = 0.0803 - 8.03%
z <- c()
for(i in 0:2){
prob_i <- (1 ** i) * (exp(1)**(-1)) / factorial(i)
z <- append(z, prob_i)
}
1 - sum(z)
## [1] 0.0803014
b. What is the expected value?
Expected value = 1
A surgical patient arrives for surgery precisely at a given time. Based on previous analysis (or a lack of knowledge assumption), you know that the waiting time is uniformly distributed from 0 to 30 minutes.
a. What is the probability that this patient will wait more than 10 minutes?
p(X > 10 minutes) = 1 - p(X <= 10) p(X > 10 minutes) = 0.667 - 66.7%
a <- 0
b <- 30
1 - (10 * (1/30))
## [1] 0.6666667
b. If the patient has already waited 10 minutes, what is the probability that he/she will wait at least another 5 minutes prior to being seen?
p(X >= 5 minutes | X = 10) p(X >= 5 minutes | X = 10) = 0.75 - 75%
15 * (1/(30 - 10))
## [1] 0.75
c. What is the expected waiting time?
mean or expected waiting time = 1/2 (a + b) expected waiting time = 15 minutes
expected_waittime <- 0.5 * (a + b)
expected_waittime
## [1] 15
Your hospital owns an old MRI, which has a manufacturers lifetime of about 10 years (expected value). Based on previous studies, we know that the failure of most MRI’s obeys an exponential distribution.
a. What is the expected failure time?
expected_failuretime = 0.1
The expected failure time is 0.1
b. What is the standard deviation? The standard deviation (sd) of an exponential distribution is also the inverse of the failure rate.
sd = 0.1
c. What is the probability that your MRI will fail after 8 years? F(x) = 1 - \(e^-\lambda x\) p(X > 8 years) = 1 - F(8)
1 - (1 - (exp(1) ** (-0.1 * 8)))
## [1] 0.449329
p(X > 8 years) = 0.4493 - 44.93%
d. Now assume that you have owned the machine for 8 years. Given that you already owned the machine 8 years, what is the probability that it will fail in the next two years?
p(8 < X ≤ 10) = F(10) − F(8)
(1 - (exp(1) ** (-0.1 * 10))) - (1 - (exp(1) ** (-0.1 * 8)))
## [1] 0.08144952
p(8 < X ≤ 10) = 0.0814 - 8.14%