# x "has the disease"
# y "tests positive"
# p(x) i.e. prior
HIV_prevalence <- .001
# p(y | x) i.e. likelihood
HIVtest_sensitivity <- 0.96
# p(bar_y | bar_x) i.e. specificity
HIVtest_specificity <- 0.98
# p(y) i.e. evidence
# p(y) = p(y | x)*p(x) + p(y |bar_x)*p(bar_x)
HIVtest_evidence <- (HIVtest_sensitivity * HIV_prevalence) + ((1 - HIVtest_specificity)*(1 - HIV_prevalence))
# p(x | y) i.e. posterior
HIVtest_posterior <- (HIVtest_sensitivity * HIV_prevalence) / HIVtest_evidence
print(paste0("The probability of actually having HIV given a positive test is: ", HIVtest_posterior))
## [1] "The probability of actually having HIV given a positive test is: 0.0458452722063037"
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?
treatment_cost <- 100000
testcost <- 1000
patients <- 100000
firstyear_cost <- (testcost*patients)+treatment_cost*HIVtest_posterior*HIVtest_evidence*patients
print(paste0("The total first-year cost is $", firstyear_cost))
## [1] "The total first-year cost is $109600000"
(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?
#prob. for any given month
mu <- .05
#no of months
N <- 24
#no of inspections
m2 <- 2
p_m2_N_mu <- choose(N, m2)*(mu^m2)*((1-mu)^(N-m2))
print(paste0("The probability of exactly 2 inspections in 24 months is: ", p_m2_N_mu))
## [1] "The probability of exactly 2 inspections in 24 months is: 0.223238146031859"
What is the probability that, after 24 months, you received 2 or more inspections?
#prob. for any given month
mu <- .05
#no of months
N <- 24
#no of inspections
m0 <- 0
m1 <- 1
m2 <- 2
p_m1_N_mu <- choose(N, m1)*(mu^m1)*((1-mu)^(N-m1))
p_m0_N_mu <- choose(N, m0)*(mu^m0)*((1-mu)^(N-m0))
p_ge2_N_mu <- 1 - (p_m1_N_mu + p_m0_N_mu)
print(paste0("The probability of 2 or more inspections in 24 months is: ", p_ge2_N_mu))
## [1] "The probability of 2 or more inspections in 24 months is: 0.339182734391199"
What is the probability that your received fewer than 2 inspections?
p_l2_N_mu <- (p_m1_N_mu + p_m0_N_mu)
print(paste0("The probability of fewer than 2 inspections in 24 months is: ", p_l2_N_mu))
## [1] "The probability of fewer than 2 inspections in 24 months is: 0.660817265608801"
What is the expected number of inspections you should have received? What is the standard deviation?
E_mu <- N*mu
Sd_mu <- sqrt(E_mu*(1-mu))
print(paste0("The expected number of visits in 24 months is: ", E_mu, " and the standard deviation is: ", Sd_mu))
## [1] "The expected number of visits in 24 months is: 1.2 and the standard deviation is: 1.06770782520313"
lambda <- 10
k1 <- 3
p_3 <- ((lambda^k1)*exp(-lambda))/factorial(k1)
print(paste0("The probability of exactly 3 patients arriving in one hour is: ", p_3))
## [1] "The probability of exactly 3 patients arriving in one hour is: 0.00756665496041414"
What is the probability that more than 10 arrive in one hour?
lambda <- 10
kvec <- c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
jvec <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
for (i in kvec){jvec[i] <- ((lambda^kvec[i])*exp(-lambda))/factorial(kvec[i])}
p_le10 <- sum(jvec[1:11])
p_ge10 <- 1 - p_le10
print(paste0("The probability of 10 or more patients arriving in one hour is: ", p_ge10))
## [1] "The probability of 10 or more patients arriving in one hour is: 0.542070285528148"
How many would you expect to arrive in 8 hours?
Since we expect 10 patients to arrive in one hour, we expect 80 to arrive in 8 hours
What is the standard deviation of the appropriate probability distribution?
Since the variance of a poisson distribution is equal to its expected value, the standard deviation is equal to the square root of 10…
print(sqrt(10))
## [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?
I recommend the practice hire an additional provider to accommodate hours and days with patient loads greater than expected value. The utilizaiton rate based on expected number of daily patients will fall to 83.3%, which will allow the providers an acceptable level of admin time and personal time off to prevent burnout, while increasing the revenue the clinic can bring in from patient demand.
utilization <- 80/72
print(paste0("The utilization rate is: ", round(utilization*100, 2), "%"))
## [1] "The utilization rate is: 111.11%"
(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?
N <- 30
k <- 15
N_minus_k <- 15
n <- 6
x <- 5
h <- (choose(k, x))*(choose(N_minus_k, (n - x)))/(choose(N, n))
print(h)
## [1] 0.07586207
How many nurses would we have expected your subordinate to send?
3
How many non-nurses would we have expected your subordinate to send?
3
(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?
p <- .001
q <- 1 - p
k <- 1200
j12 <- 1200
j15 <- 1500
#probability we don't crash in the next year
P_year_nocrash <- q^(k)
P_yearcrash <- 1 - P_year_nocrash
print(P_yearcrash)
## [1] 0.6989866
#probability we don't crash in the next 15 months
P_15mo_nocrash <- q^(j15)
P_15mo_crash <- 1 - q^j15
What is the expected number of hours that a driver will drive before being seriously injured?
E_T <- 1/p
print(E_T)
## [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?
p_next100 <- 1 - q^100
print(p_next100)
## [1] 0.09520785
p <- 1/1000
k <- 3
x <- 1000
p_3in1k <- (choose(x-1, k-1))*(p^k)*(q^(x-k))
print(p_3in1k)
## [1] 0.0001838475
E_3in1k <- k/p
print(paste0("The number of hours before the generator fails 3 times is expected to be ", E_3in1k))
## [1] "The number of hours before the generator fails 3 times is expected to be 3000"
y <- 1/30
x <- 20
prob_g10 <- x*y
print(paste0("The probability the patient will wait more than 10 minutes is ", round(prob_g10, 5)))
## [1] "The probability the patient will wait more than 10 minutes is 0.66667"
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?
y <- 1/30
x <- 15
prob_g5 <- x*y
print(paste0("The probability the patient will wait at least 5 more minutes is ", round(prob_g5, 5)))
## [1] "The probability the patient will wait at least 5 more minutes is 0.5"
What is the expected waiting time?
The expected waiting time is 15 minutes.
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?
Since in the exponetial distribution, the standard deviation is equal to the mean or expected value, the standard deviation is also 10 years.
What is the probability that your MRI will fail after 8 years?
mu <- 10
k <- 8
lambda <- k/ mu
p_8years <- exp(-lambda)
print(paste0("The probability our machine will fail after 8 years is ", round(p_8years, 5)))
## [1] "The probability our machine will fail after 8 years is 0.44933"
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?
mu <- 10
k <- 2
lambda <- k/ mu
p_2years <- 1 - exp(-lambda)
print(paste0("The probability our machine will fail in the next 2 years is ", round(p_2years, 5)))
## [1] "The probability our machine will fail in the next 2 years is 0.18127"