library(ggplot2)
(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?
# The sensitivity of the test: the probability of correctly identifying a diseased individual
sensitivity <- 0.96
# The specificity of the test: the probability of correctly identifying a non-diseased individual
specificity <- 0.98
# The prevalence of the disease in the population
prevalence <- 0.001
# The probability of testing positive, combining true positives and false positives
prob_positive <- (sensitivity * prevalence) + ((1 - specificity) * (1 - prevalence))
# The probability that an individual actually has the disease given they test positive
prob_disease_given_positive <- (sensitivity * prevalence) / prob_positive
# The number of individuals to be tested
num_individuals <- 100000
# The cost of administering the test per individual
test_cost_per_individual <- 1000
# The median cost of treating a positive case
treatment_cost_per_case <- 100000
# The expected number of positive tests
expected_positives <- num_individuals * prob_positive
# The total cost of administering the tests to all individuals
total_testing_cost <- num_individuals * test_cost_per_individual
# The total cost of treating all expected positive cases
total_treatment_cost <- expected_positives * treatment_cost_per_case
# The total cost combining both testing and treatment
total_first_year_cost <- total_testing_cost + total_treatment_cost
cat("Probability that an individual actually has the disease given a positive test result = ", prob_disease_given_positive, "\n")
## Probability that an individual actually has the disease given a positive test result = 0.04584527
cat("Expected number of positive tests = ", expected_positives, "\n")
## Expected number of positive tests = 2094
cat("Total first-year cost = ", total_first_year_cost)
## Total first-year cost = 309400000
(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? What is the probability that, after 24 months, you received 2 or more inspections? What is the probability that your received fewer than 2 inspections? What is the expected number of inspections you should have received? What is the standard deviation?
# The probability of receiving an inspection in a given month
prob_inspection <- 0.05
# The total number of months
num_months <- 24
# The probability of exactly 2 inspections in 24 months
prob_exactly_two <- dbinom(2, size = num_months, prob = prob_inspection)
# The probability of 2 or more inspections can be calculated by subtracting the probability
# of fewer than 2 inspections from 1
prob_two_or_more <- 1 - pbinom(1, size = num_months, prob = prob_inspection)
# The probability of fewer than 2 inspections is the sum of the probabilities of 0 or 1 inspections
prob_less_than_two <- pbinom(1, size = num_months, prob = prob_inspection)
# The expected number of inspections over 24 months is the product of the number of trials
# and the probability of success
expected_inspections <- num_months * prob_inspection
# The standard deviation for a binomial distribution is the square root of np(1-p)
std_deviation <- sqrt(num_months * prob_inspection * (1 - prob_inspection))
# Output the calculated probabilities and statistics
cat("Probability of Exactly 2 Inspections = ", prob_exactly_two, "\n")
## Probability of Exactly 2 Inspections = 0.2232381
cat("Probability of 2 or More Inspections = ", prob_two_or_more, "\n")
## Probability of 2 or More Inspections = 0.3391827
cat("Probability of Fewer Than 2 Inspections = ", prob_less_than_two, "\n")
## Probability of Fewer Than 2 Inspections = 0.6608173
cat("Expected Number of Inspections = ", expected_inspections, "\n")
## Expected Number of Inspections = 1.2
cat("Standard Deviation of Inspections = ", std_deviation)
## Standard Deviation of Inspections = 1.067708
(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 distribution parameters
lambda = 10 # Average number of arrivals per hour
# Probability of exactly 3 arrivals in one hour
prob_exactly_three = dpois(3, lambda)
# Probability of more than 10 arrivals in one hour
prob_more_than_ten = 1 - ppois(10, lambda)
# Expected number of arrivals in 8 hours
expected_arrivals_8_hours = lambda * 8
# Standard deviation of the distribution
std_deviation = sqrt(lambda)
# Capacity of providers
providers = 3
patients_per_provider = 24
daily_capacity = providers * patients_per_provider
# Percent utilization
utilization = (lambda * 8) / daily_capacity
# Recommendations based on utilization
recommendations <- ifelse(utilization > 1, "Consider increasing capacity or optimizing scheduling.",
ifelse(utilization < 0.75, "Potential for reduced hours or staff to match demand.",
"Current staffing levels appear to meet demand."))
# Create a data frame for the results
cat("Probability of Exactly 3 Arrivals = ", prob_exactly_three, "\n")
## Probability of Exactly 3 Arrivals = 0.007566655
cat("Probability of More Than 10 Arrivals = ", prob_more_than_ten, "\n")
## Probability of More Than 10 Arrivals = 0.4169602
cat("Expected Number of Arrivals in 8 Hours = ", expected_arrivals_8_hours, "\n")
## Expected Number of Arrivals in 8 Hours = 80
cat("Standard Deviation = ", std_deviation, "\n")
## Standard Deviation = 3.162278
cat("Percent Utilization = ", utilization, "\n")
## Percent Utilization = 1.111111
cat("Recommendations = ", recommendations)
## Recommendations = Consider increasing capacity or optimizing scheduling.
(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
# Parameters
p <- 0.001 # Probability of being injured per hour
# Hours driven
hours_year <- 1200
hours_15_months <- hours_year + 300 # 25% more than a year
# Step 1: Probability of being injured within a year and within 15 months
prob_injury_year <- 1 - (1 - p)^hours_year
prob_injury_15_months <- 1 - (1 - p)^hours_15_months
# Step 2: Expected number of hours before being seriously injured
expected_hours_before_injury <- 1 / p
# Step 3: Probability of being injured in the next 100 hours after driving 1200 hours
prob_injury_next_100_hours <- 1 - (1 - p)^100
# Results
cat("Probability of Injury in a Year = ", prob_injury_year, "\n")
## Probability of Injury in a Year = 0.6989866
cat("Probability of Injury in 15 Months = ", prob_injury_15_months, "\n")
## Probability of Injury in 15 Months = 0.7770372
cat("Expected Hours Before Injury = ", expected_hours_before_injury, "\n")
## Expected Hours Before Injury = 1000
cat("Probability of Injury in Next 100 Hours = ", prob_injury_next_100_hours, "\n")
## Probability of Injury in Next 100 Hours = 0.09520785
(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?
# Parameters
p <- 0.001 # Probability of being injured per hour
# Hours driven
hours_year <- 1200
hours_15_months <- hours_year + 300 # 25% more than a year
# Step 1: Probability of being injured within a year and within 15 months
prob_injury_year <- 1 - (1 - p)^hours_year
prob_injury_15_months <- 1 - (1 - p)^hours_15_months
# Step 2: Expected number of hours before being seriously injured
expected_hours_before_injury <- 1 / p
# Step 3: Probability of being injured in the next 100 hours after driving 1200 hours
prob_injury_next_100_hours <- 1 - (1 - p)^100
# Results
cat("Probability of being injured within a year = ", prob_injury_year, "\n")
## Probability of being injured within a year = 0.6989866
cat("Probability of being injured within 15 months = ", prob_injury_15_months, "\n")
## Probability of being injured within 15 months = 0.7770372
cat("Expected number of hours before being seriously injured = ", expected_hours_before_injury, "\n")
## Expected number of hours before being seriously injured = 1000
cat("Probability of being injured in the next 100 hours = ", prob_injury_next_100_hours,"\n")
## Probability of being injured in the next 100 hours = 0.09520785
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?
# Load necessary library
library(stats)
# Define lambda (average rate of failure per 1000 hours)
lambda_rate <- 1
# Calculate the probability of more than two failures in 1000 hours
# Using 1 minus the cumulative probability of 0, 1, or 2 failures
prob_more_than_two <- 1 - ppois(2, lambda_rate)
# The expected value for a Poisson distribution is lambda
expected_value <- lambda_rate
# Display the results
cat("Probability of more than two failures in 1000 hours = ", prob_more_than_two, "\n")
## Probability of more than two failures in 1000 hours = 0.0803014
cat("Expected value (mean number of failures in 1000 hours) = ", expected_value, "\n")
## Expected value (mean number of failures in 1000 hours) = 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. 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?
# Load necessary library
library(stats)
# Step 1: Define the parameters of the uniform distribution
min_time <- 0 # Minimum waiting time
max_time <- 30 # Maximum waiting time
# Step 2: Probability of Waiting More Than 10 Minutes
# The distribution is uniform, so this is simply a ratio of the lengths of the intervals
prob_more_than_10 <- (max_time - 10) / (max_time - min_time)
# Step 3: Probability of Waiting at Least Another 5 Minutes After Already Waiting 10 Minutes
# Adjusting the interval since 10 minutes have already passed
prob_wait_another_5 <- (max_time - (10 + 5)) / (max_time - 10)
# Step 4: Expected Waiting Time
# The expected value for a uniform distribution is the midpoint of the distribution's interval
expected_waiting_time <- (min_time + max_time) / 2
# Display the results
cat("Probability of waiting more than 10 minutes = ", prob_more_than_10, "\n")
## Probability of waiting more than 10 minutes = 0.6666667
cat("Probability of waiting at least another 5 minutes after already waiting 10 minutes = ", prob_wait_another_5, "\n")
## Probability of waiting at least another 5 minutes after already waiting 10 minutes = 0.75
cat("Expected waiting time = ", expected_waiting_time, "minutes\n")
## Expected waiting time = 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? 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?
# Define the rate parameter based on the expected lifetime of 10 years
lambda <- 1 / 10 # per year
# The expected failure time and standard deviation for an exponential distribution
expected_failure_time <- 1 / lambda
std_deviation <- 1 / lambda
# Calculate the probability of failure after 8 years
prob_failure_after_8 <- exp(-lambda * 8)
# Calculate the probability of failure in the next two years, given the MRI is already 8 years old
prob_failure_next_2_years <- 1 - exp(-lambda * 2)
# Display the results
cat("Expected Failure Time = ", expected_failure_time, "years\n")
## Expected Failure Time = 10 years
cat("Standard Deviation = ", std_deviation, "years\n")
## Standard Deviation = 10 years
cat("Probability of Failure After 8 Years = ", prob_failure_after_8, "\n")
## Probability of Failure After 8 Years = 0.449329
cat("Probability of Failure in the Next Two Years After 8 Years = ", prob_failure_next_2_years, "\n")
## Probability of Failure in the Next Two Years After 8 Years = 0.1812692