#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?

a= having the disease b= testing positive We need to find probability of having the disease given that an individual has tested positive, ie, the probability of a given b.

p_a <- .001
p_b_given_a <- .96

#probability of testing positive is equal to probability of having a true positive plus the probability of having a false positive
p_b <- .001*.96+.999*.02

#use Bayes' theorem
p_a_given_b <- p_b_given_a*p_a/p_b
p_a_given_b
## [1] 0.04584527

#If the median cost (consider this the bestpoint 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?

size <- 100000
cost_per_positive <- 100000
cost_test <- 1000

#The total cost is the cost of administering tests to the population plus the cost of treating the expected number that test positive
total_cost <- size*cost_test + cost_per_positive*p_b*size
total_cost
## [1] 309400000

#2. (Binomial). The probability of your organization receiving a Joint Commission inspection in any given month is .05. What is the probability that, after 24 months, you received exactly 2 inspections?

p_two_inspections <- dbinom(2, size = 24, prob = 0.05)
p_two_inspections
## [1] 0.2232381

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

p_two_or_more <- 1-sum(dbinom(0:1, size= 24, prob = 0.05))
p_two_or_more
## [1] 0.3391827

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

p_fewer_than_two <- sum(dbinom(0:1, size= 24, prob = 0.05))
p_fewer_than_two
## [1] 0.6608173

#What is the expected number of inspections you should have received?

expected_inspections <- sum(0:24 * dbinom(0:24, size = 24, prob = 0.05))
expected_inspections
## [1] 1.2

#What is the standard deviation?

standard_deviation <- sqrt(24 * .05 * .95)
standard_deviation
## [1] 1.067708

#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?

lambda <- 10
x<- 3
p_three <- dpois(x,lambda)
p_three
## [1] 0.007566655

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

p_more_than_ten_patients <- ppois(10, 10, lower.tail = FALSE)
p_more_than_ten_patients
## [1] 0.4169602

#How many would you expect to arrive in 8 hours?

interval <- 8
expected_eight_hours <- interval * lambda
expected_eight_hours
## [1] 80

#What is the standard deviation of the appropriate probability distribution?

st_dev <- sqrt(lambda)
st_dev
## [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?

max_patients_per_day <- 3*24
percent_utilization <- expected_eight_hours/max_patients_per_day*100
percent_utilization
## [1] 111.1111

The clinic is currently operating beyond capacity. I would recommend either hiring another provider, or reducing the amount of time spent with each patient to increase the number of patients that can be seen by each provider.

#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?

population <- 30
sample <- 6
nurses_pop <- 15
non_nurses_pop <- 15
nurses_sample <- 5

p_five_nurses <- dhyper(nurses_sample,nurses_pop,non_nurses_pop,sample)
p_five_nurses
## [1] 0.07586207

The probability that this would happen if they had acted innocently is approximately 7.6%.

#How many nurses would we have expected your subordinate to send? How many non-nurses would we have expected your subordinate to send? We would expect the numbers of nurses and non-nurses in the sample to be proportional to the numbers in the population.

expected_nurses <- nurses_pop/population*sample
expected_non_nurses <- non_nurses_pop/population*sample
expected_nurses
## [1] 3
expected_non_nurses
## [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. What is the probability that the driver will be seriously injured during the course of the year?

#we find the cumulative probability that we have x trials before a success
prob_injured_year <- pgeom(1199,.001)
prob_injured_year
## [1] 0.6989866

#In the course of 15 months?

prob_injured_fifteen_months <- pgeom(1499, 0.001)
prob_injured_fifteen_months
## [1] 0.7770372

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

expected_hours_injury <- 1/.001
expected_hours_injury
## [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? This is the same as the probability that the driver will be injured in 100 hours of driving, regardless of the number of hours previously driven, since the events are assumed to be independent.

prob_injured_hundred_hours <- pgeom(99,.001)
prob_injured_hundred_hours
## [1] 0.09520785

#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?

This can be modeled by a Poisson distribution since it models an event occuring in a fixed interval of time.

p_more_than_two_failures <- ppois(2,1,lower.tail = FALSE)
p_more_than_two_failures
## [1] 0.0803014

#What is the expected value? The expected value is equal to lambda, 1 failure in 1000 hours, or 0.001 failures in one hour.

#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?

min_wait <- 0
max_wait <- 30
p_wait_more_than_ten <- 1 - punif(10, min_wait, max_wait)
p_wait_more_than_ten
## [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?

p_another_five <- 1 - punif(5, min = 0, max = 20)
p_another_five
## [1] 0.75

#What is the expected waiting time?

#average of min and max wait times
expected_wait <- (30+0)/2
expected_wait
## [1] 15

#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? The expected failure time is 10 years.

#What is the standard deviation? The standard deviation is equal to the mean in an exponential distribution, so the standard deviation is also 10.

#What is the probability that your MRI will fail after 8 years? We set the rate equal to 1 failure every 10 years, or 0.1.

p_fail_eight_years <- dexp(8,.1)
p_fail_eight_years
## [1] 0.0449329

#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?

#we use pexp to find the cumulative probability that it will fail between 8 and 10 years
p_next_two_years <- pexp(10,.1) - pexp(8, .1)
p_next_two_years
## [1] 0.08144952