#Question 1 1. (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. 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? If the median cost (consider this the best point estimate) is about $100,000 per positive case total and the test itself costs $1000 per administration, what is the total first-year cost for treating 100,000 individuals?
##Part 1:
Starting off with the Bayes rule: \[\begin{equation}\Pr(A|B)=\frac{\Pr(B|A)\Pr(A)}{\Pr(B|A)\Pr(A)+\Pr(B|\neg A)\Pr(\neg A)} \end{equation}\]
In the case of this problem the Bayes rule will look like this:
\[\begin{equation}P(A1|B)=\frac{P(B|A1)*P(A1)}{P(B|A1)*P(A1)+P(B|A2)*P(A2)} \end{equation}\]
We can now write out the inputs given the current problem
#I will be looking for P(A1 | B)
#A1 denotes HIV
#A2 denotes no HIV
#B denotes a positive test
#P(B | A1) = 0.96, This refers to those who have HIV and actually test positive
#P(A1) = 0.001
#P(B | A2) = 0.02, Refers to those without the disease being correctly tested as 'Negative'
#P(A2) = 0.999
Lets plug these numbers into the Bayes formula
PB_A1 <- 0.96
P_A1 <- 0.001
PB_A2 <- 0.02
P_A2 <- 0.999
B_A1 <- PB_A1*P_A1/((PB_A1*P_A1)+(PB_A2*P_A2))
B_A1
## [1] 0.04584527
##Part 2:
options(scipen = 999)
Cost_per <- 100000
Cost_admin <- 1000
patients <- 100000
first_year_cost <- (Cost_admin*patients) + Cost_per*((PB_A1*P_A1)+(PB_A2*P_A2))*B_A1*patients
first_year_cost
## [1] 109600000
print(paste0("The total cost for the first year of treatment is:$",first_year_cost))
## [1] "The total cost for the first year of treatment is:$109600000"
#Question 2
##Part 1 Binomial Distribution formula \[X \sim B(n,p) \\f(x)=\begin{pmatrix}n\\ x\end{pmatrix}p^{x}q^{n-x}=C^{k}_{n}p^{x}q^{n-x},q=1-p\\\text{Binominal Mean}\ \mu=np\\\text{Binominal Variance}\ \sigma^2=npq\] Probability for exactly 2 inspections in 24 months:
p <- 0.05
n <- 24
x <- 2
f_x <- choose(n, x)*(p^x)*((1-p)^(n-x))
print(paste0("The probablility of 2 inspections in 24 months is:", f_x))
## [1] "The probablility of 2 inspections in 24 months is:0.223238146031859"
##Part 2 Probability for two or more inspections in 24 months: Here you can also use the dbinom() function from base R, but I understand it better by plugging it into a formula
p <- 0.05
n <- 24
#inspection count vars
x0 <- 0
x1 <- 1
x2 <- 2
f_x1 <- choose(n, x1)*(p^x1)*((1-p)^(n-x1))
f_x0 <- choose(n, x0)*(p^x0)*((1-p)^(n-x0))
f_x2 <- 1 - (f_x1 + f_x0)
print(paste0("The probablility of 2 or more inspections in 24 months is:", f_x2))
## [1] "The probablility of 2 or more inspections in 24 months is:0.339182734391199"
##Part 3 Probability for fewer than 2 inspections:
few_x2 <- (f_x1+f_x0)
print(paste0("The probablility fewer than 2 inspections in 24 months is:", few_x2))
## [1] "The probablility fewer than 2 inspections in 24 months is:0.660817265608801"
##Part 4 What is the expected number of inspections you should have received? What is the standard deviation?
expected <- n*p
sd_x <- sqrt(expected*(1-p))
print(paste0("The expected number of visits for n is: ",expected," the sd(x) is : ",sd_x))
## [1] "The expected number of visits for n is: 1.2 the sd(x) is : 1.06770782520313"
#Question 3 3. (Poisson). You are modeling the family practice clinic and notice that patients arrive at a rate of 10 per hour. What is the probability that exactly 3 arrive in one hour? What is the probability that more than 10 arrive in one hour? How many would you expect to arrive in 8 hours? What is the standard deviation of the appropriate probability distribution? 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?
Poisson Distriburtion: \[X \sim \pi(\mu) \\f(x)=\frac{\mu^{x}}{x!}e^{-\mu}\\ \text{Poisson Mean} \mu \\ \text{Poisson Variance}\sigma^2=\mu\] ##Part 1 What is the probability that exactly 3 arrive in one hour?
dpois(3,10)
## [1] 0.007566655
##Part 2 What is the probability that more than 10 arrive in one hour?
1-sum(dpois(0:10, 10))
## [1] 0.4169602
##Part 3 How many would you expect to arrive in 8 hours? E(x) –> 80 people are expected to arrive within 8 hours
10*8
## [1] 80
##Part 4 What is the standard deviation of the appropriate probability distribution? sd = 3.16
sqrt(10)
## [1] 3.162278
##Part 5 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? Patients seen
3*24
## [1] 72
(80/72)*100
## [1] 111.1111
Recommendation: Having over 100% utilization means there are not enough family providers for the amount of patients expected. There are several things that they could do, adding another doctor or expanding the hours of operation would both help to alleviate this.
##Question 4 4. (Hypergeometric). 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. If your subordinate acted innocently, what was the probability he/she would have selected five nurses for the trips? How many nurses would we have expected your subordinate to send? How many non-nurses would we have expected your subordinate to send?
##Part 1
dhyper(5,15,15,6)
## [1] 0.07586207
##Part 2 How many nurses would we have expected your subordinate to send? E(X)=KM/N : Number of expected nurses
6*(15/30)
## [1] 3
##Part 3 How many non-nurses would we have expected your subordinate to send?
6*(15/30)
## [1] 3
#Question 5 5. (Geometric). The probability of being seriously injured in a car crash in an unspecified location is about .1% per hour. A driver is required to traverse this area for 1200 hours in the course of a year. What is the probability that the driver will be seriously injured during the course of the year? In the course of 15 months? What is the expected number of hours that a driver will drive before being seriously injured? Given that a driver has driven 1200 hours, what is the probability that he or she will be injured in the next 100 hours?
##Part 1 What is the probability that the driver will be seriously injured during the course of the year?
pgeom(1200,0.001)
## [1] 0.6992876
##Part 2 In the course of 15 months?
crash_15 <- pgeom(1200*(1500/1200), 0.001)
crash_15
## [1] 0.7772602
##Part 3 What is the expected number of hours that a driver will drive before being seriously injured?
1/0.001
## [1] 1000
##Part 4 Given that a driver has driven 1200 hours, what is the probability that he or she will be injured in the next 100 hours?
crash_100plus <- pgeom(100, 0.001)
crash_100plus
## [1] 0.09611265
#Question 6 6. You are working in a hospital that is running off of a primary generator which fails about once in 1000 hours. What is the probability that the generator will fail more than twice in 1000 hours? What is the expected value? What is the probability that the generator will fail more than twice in 1000 hours? ##Part 1
prob <- 1/1000
fail_plus2 <- 1-ppois(2, prob*1000)
fail_plus2
## [1] 0.0803014
##Part 2 What is the expected value?
1/(1/1000)
## [1] 1000
#Question 7 7. 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. What is the probability that this patient will wait more than 10 minutes? 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? What is the expected waiting time?
##Part 1 What is the probability that this patient will wait more than 10 minutes?
1-punif(10,0,30)
## [1] 0.6666667
##Part 2 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?
1-punif(15,0,30)
## [1] 0.5
##Part 3 What is the expected waiting time?
(0+30)/2
## [1] 15
#Question 8 8. Your hospital owns an old MRI, which has a manufacturer’s lifetime of about 10 years (expected value). Based on previous studies, we know that the failure of most MRIs obeys an exponential distribution. What is the expected failure time? What is the standard deviation? What is the probability that your MRI will fail after 8 years? 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?
##Part 1 What is the expected failure time? What is the standard deviation?
1/(1/10)
## [1] 10
##Part 2 What is the standard deviation?
1/(1/10)
## [1] 10
##Part 3 What is the probability that your MRI will fail after 8 years?
1- pexp(8, (1/10))
## [1] 0.449329
##Part 4 Given that you already owned the machine 8 years, what is the probability that it will fail in the next two years?
1-(1- pexp(2, (1/10)))
## [1] 0.1812692