Assignment 5

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?

Given by Bayesian: \[ P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)} \]

# define variables & add true positives with false positives
sensitivity <- .96 # P(B|A)
specificity <- .98
prevalence <- .001 # P(A)

total_positives <- (sensitivity * prevalence) + ((1-specificity)*(1-prevalence)) #looking for P(B)

answer <- (sensitivity * prevalence) / total_positives
answer
## [1] 0.04584527
#The probability that an individual who is reported as positive by the new test actually has the disease is ~ 4.58%

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?

median_cost <- 100000
test_cost <- 1000
individuals <- 100000
#have to use first part
total_cost <- (answer * median_cost + (1 - answer) * test_cost) * individuals

total_cost
## [1] 553868195

2.(Binomial)

The probability of your organization receiving a Joint Commission inspection in any given month is .05.

P^K (1-p)^n-k

What is the probability that, after 24 months, you received exactly 2 inspections? 22.3%

n = 24
k = 2
p = .05
P_2 <- dbinom(k, n, p)
P_2
## [1] 0.2232381

What is the probability that, after 24 months, you received 2 or more inspections? 33.92%

  # P(2 or more) = 1 - P(1)- P(0)
p2more <- 1- (dbinom(1, n, p) + dbinom(0, n, p))
p2more
## [1] 0.3391827

What is the probability that your received fewer than 2 inspections? 66.08%

p2less <- dbinom(0,n,p) + dbinom(1,n,p)
p2less
## [1] 0.6608173

What is the expected number of inspections you should have received? 1.2 or 1 to 2 inspections

expected_inspection <-n*p # number of months * probability 
expected_inspection
## [1] 1.2

What is the standard deviation? 1.068

#the square root (or to the half power) of the answer above is the sd
sd <- sqrt(expected_inspection*(1-p))
sd
## [1] 1.067708

3.(Poisson)

You are modeling the family practice clinic and notice that patients arrive at a rate of 10 per hour.

\[ P(X=k) = \frac{e^{-\lambda} \lambda^k}{k!} \]

What is the probability that exactly 3 arrive in one hour? 0.76%

r <- 10    #rate per hour

(dpois(3, r))
## [1] 0.007566655

What is the probability that more than 10 arrive in one hour? 41.7%

1-(ppois(10, r))
## [1] 0.4169602

How many would you expect to arrive in 8 hours?

expected_pt <- r*8
expected_pt
## [1] 80

What is the standard deviation of the appropriate probability distribution? 3.16; 3 people

sqrt (r)
## [1] 3.162278

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? 111%

They have more patients expected than the 3 providers can handle. I recommend they set up an appointment system, extend their hours or hire a part time provider to meet the needs of these folks. Ideally you would not want 100% or more utilization.

providers <- 3
patients_each <- 24
capacity <- providers*patients_each
utilization <- expected_pt/ capacity #decimal
utilization*100
## [1] 111.1111

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.

PMF for hypergeometric distribution is given by:

\[ P(X = k) = \frac{\binom{K}{k} \cdot \binom{N - K}{n - k}}{\binom{N}{n}} \]

If your subordinate acted innocently, what was the probability he/she would have selected five nurses for the trips? 7.59%

N = 30
n = 6
k = 15
x = 5

dhyper(x,k, N-k,n) 
## [1] 0.07586207

How many nurses would we have expected your subordinate to send? 3 nurses

n*(k/N)
## [1] 3

How many non-nurses would we have expected your subordinate to send? 3

#How many non-nurses would we have expected your subordinate to send? 
n-3
## [1] 3

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.

the geometric distribution is given by:

\[ P(X \leq x) = 1 - (1 - p)^x \]

What is the probability that the driver will be seriously injured during the course of the year? 69.9%

p <- .001 #1%
t <- 1200
pgeom(t,p)
## [1] 0.6992876

What is the probability that the driver will be seriously injured during the course of of 15 months? 77.73%

hrs15<- t*15/12
pgeom(hrs15, p)
## [1] 0.7772602

What is the expected number of hours that a driver will drive before being seriously injured? 1000hrs

1/p
## [1] 1000

Given that a driver has driven 1200 hours, what is the probability that he or she will be injured in the next 100 hours? 9.52%

1-((1-p)^100)
## [1] 0.09520785

6. Poisson

You are working in a hospital that is running off of a primary generator which fails about once in 1000 hours.

\[ P(X=k) = \frac{e^{-\lambda} \lambda^k}{k!} \]

What is the probability that the generator will fail more than twice in 1000 hours? 8%

1 - ppois(2,1)
## [1] 0.0803014

What is the expected value? 1 by definition

7. continuous uniform distribution

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.

1/ (b-a)

What is the probability that this patient will wait more than 10 minutes? 66.67%

(1 - punif(10, 0, 30)) #min & max
## [1] 0.6666667

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? 75%

#update mins
p10 <- 1 - punif(10, 10, 30) #10 mins
p15 <-1 - punif(15, 10, 30) #another 5 = 15mins
p15/p10
## [1] 0.75

What is the expected waiting time? 15 minw

#(1/2)ab
.5*30
## [1] 15

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

\[ f_X(x) = \lambda e^{-\lambda x} \]

What is the expected failure time? 10 years (stated in problem)

What is the standard deviation? 10 yrs, same as expected in exponential distribution

What is the probability that your MRI will fail after 8 years? (years, fail rate); 44.93%

1 - pexp(8,.1) # lamda is 1/10; 
## [1] 0.449329

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? 18.12%

pexp(2,.1) #10-8 
## [1] 0.1812692

This also means that the probability it will fail before the 10 year manufacturer warranty is 63.2%

pexp(10,.1) 
## [1] 0.6321206