1.
prevalence_rate <- 0.001
sensitivity <- 0.96
specificity <- 0.98
total_population <- 100000
cost_per_case <- 100000
test_cost <- 1000
positive_given_disease <- sensitivity
positive_given_no_disease <- 1 - specificity
disease_given_positive <- (positive_given_disease * prevalence_rate) / ((positive_given_disease * prevalence_rate) + (positive_given_no_disease * (1 - prevalence_rate)))
# Calculate total first-year cost
true_positive_cases <- disease_given_positive * total_population
total_cost <- (true_positive_cases * cost_per_case) + (total_population * test_cost)
# Display results
paste0("Probability that an individual who is reported as positive actually has the disease: ", round(disease_given_positive, 4))
## [1] "Probability that an individual who is reported as positive actually has the disease: 0.0458"
paste0("Total first-year cost for treating 100,000 individuals: ", round(total_cost, 2))
## [1] "Total first-year cost for treating 100,000 individuals: 558452722.06"
2.
n <- 24
p <- 0.05
choose <- function(n, k) {
factorial(n) / (factorial(k) * factorial(n - k))
}
binomial_pmf <- function(k, n, p) {
choose(n, k) * p^k * (1 - p)^(n - k)
}
prob_exactly_2 <- binomial_pmf(2, n, p)
prob_2_or_more <- sum(binomial_pmf(2:n, n, p))
prob_fewer_than_2 <- sum(binomial_pmf(0:1, n, p))
expected_inspections <- n * p
std_deviation <- sqrt(n * p * (1 - p))
paste0("Probability of exactly 2 inspections after 24 months:", round(prob_exactly_2, 4))
## [1] "Probability of exactly 2 inspections after 24 months:0.2232"
paste0("Probability of 2 or more inspections after 24 months:", round(prob_2_or_more, 4))
## [1] "Probability of 2 or more inspections after 24 months:0.3392"
paste0("Probability of fewer than 2 inspections after 24 months:", round(prob_fewer_than_2, 4))
## [1] "Probability of fewer than 2 inspections after 24 months:0.6608"
paste0("Expected number of inspections:", round(expected_inspections, 2))
## [1] "Expected number of inspections:1.2"
paste0("Standard deviation:", round(std_deviation, 2))
## [1] "Standard deviation:1.07"
3.
lambda <- 10
hours <- 8
providers <- 3
templated_patients_per_day <- 24
poisson_pmf <- function(k, lambda) {
exp(-lambda) * (lambda^k) / factorial(k)
}
prob_exactly_3 <- poisson_pmf(3, lambda)
prob_more_than_10 <- 1 - sum(poisson_pmf(0:10, lambda))
expected_arrivals_8_hours <- lambda * hours
std_deviation <- sqrt(lambda)
percent_utilization <- (providers * templated_patients_per_day) / expected_arrivals_8_hours
paste0("Probability of exactly 3 arrivals in one hour: ", round(prob_exactly_3, 4))
## [1] "Probability of exactly 3 arrivals in one hour: 0.0076"
paste0("Probability of more than 10 arrivals in one hour :", round(prob_more_than_10, 4))
## [1] "Probability of more than 10 arrivals in one hour :0.417"
paste0("Expected number of arrivals in 8 hours: ", round(expected_arrivals_8_hours, 2))
## [1] "Expected number of arrivals in 8 hours: 80"
paste0("Standard deviation: ", round(std_deviation, 2))
## [1] "Standard deviation: 3.16"
paste0("Percent utilization: ", round(percent_utilization * 100, 2), "%")
## [1] "Percent utilization: 90%"
4.
total_workers <- 30
nurses <- 15
non_nurses <- total_workers - nurses
trips_total <- 6
trips_nurses <- 5
choose <- function(n, k) {
factorial(n) / (factorial(k) * factorial(n - k))
}
prob_5_nurses <- (choose(nurses, trips_nurses) * choose(non_nurses, trips_total - trips_nurses)) / choose(total_workers, trips_total)
expected_nurses <- (trips_total / total_workers) * nurses
expected_non_nurses <- (trips_total / total_workers) * non_nurses
paste0("Probability of selecting 5 nurses for the trips: ", round(prob_5_nurses, 4))
## [1] "Probability of selecting 5 nurses for the trips: 0.0759"
paste0("Expected number of nurses selected: ", round(expected_nurses, 2))
## [1] "Expected number of nurses selected: 3"
paste0("Expected number of non-nurses selected: ", round(expected_non_nurses, 2))
## [1] "Expected number of non-nurses selected: 3"
5.
average_rate_per_hour <- 0.001 # 0.1%
hours_per_year <- 1200
hours_per_15_months <- 15 * 30 * 24
poisson_pmf <- function(k, lambda) {
exp(-lambda) * (lambda^k) / factorial(k)
}
prob_injured_year <- 1 - exp(-average_rate_per_hour * hours_per_year)
prob_injured_15_months <- 1 - exp(-average_rate_per_hour * hours_per_15_months)
expected_hours_before_injured <- 1 / average_rate_per_hour
hours_driven_so_far <- 1200
hours_in_next_100 <- 100
prob_injured_next_100_hours <- 1 - exp(-average_rate_per_hour * hours_in_next_100)
paste0("Probability of being seriously injured during the course of the year: ", round(prob_injured_year, 4))
## [1] "Probability of being seriously injured during the course of the year: 0.6988"
paste0("Probability of being seriously injured during the course of 15 months: ", round(prob_injured_15_months, 4))
## [1] "Probability of being seriously injured during the course of 15 months: 1"
paste0("Expected number of hours before being seriously injured: ", round(expected_hours_before_injured, 2))
## [1] "Expected number of hours before being seriously injured: 1000"
paste0("Probability of being injured in the next 100 hours (given 1200 hours already driven): ", round(prob_injured_next_100_hours, 4))
## [1] "Probability of being injured in the next 100 hours (given 1200 hours already driven): 0.0952"
6.
average_rate_generator_failure <- 1 / 1000
poisson_pmf <- function(k, lambda) {
exp(-lambda) * (lambda^k) / factorial(k)
}
prob_more_than_2_failures <- 1 - (poisson_pmf(0, average_rate_generator_failure) + poisson_pmf(1, average_rate_generator_failure) + poisson_pmf(2, average_rate_generator_failure))
expected_failures <- average_rate_generator_failure
paste0("Probability of more than two failures in 1000 hours: ", round(prob_more_than_2_failures, 4))
## [1] "Probability of more than two failures in 1000 hours: 0"
paste0("Expected number of failures: ", round(expected_failures, 4))
## [1] "Expected number of failures: 0.001"
7.
a <- 0
b <- 30
uniform_pdf <- function(x, a, b) {
ifelse(x >= a & x <= b, 1 / (b - a), 0)
}
uniform_cdf <- function(x, a, b) {
ifelse(x < a, 0, ifelse(x <= b, (x - a) / (b - a), 1))
}
prob_wait_more_than_10 <- 1 - uniform_cdf(10, a, b)
prob_wait_at_least_another_5_given_10 <- 1 - uniform_cdf(15, 10, b)
expected_waiting_time <- (a + b) / 2
paste0("Probability that the patient will wait more than 10 minutes: ", round(prob_wait_more_than_10, 4))
## [1] "Probability that the patient will wait more than 10 minutes: 0.6667"
paste0("Probability that the patient will wait at least another 5 minutes given 10 minutes have already passed: ", round(prob_wait_at_least_another_5_given_10, 4))
## [1] "Probability that the patient will wait at least another 5 minutes given 10 minutes have already passed: 0.75"
paste0("Expected waiting time: ", round(expected_waiting_time, 2))
## [1] "Expected waiting time: 15"
8.
expected_lifetime_years <- 10
years_owned <- 8
lambda_parameter <- 1 / expected_lifetime_years
exponential_pdf <- function(x, lambda) {
lambda * exp(-lambda * x)
}
exponential_cdf <- function(x, lambda) {
1 - exp(-lambda * x)
}
expected_failure_time <- 1 / lambda_parameter
standard_deviation <- 1 / lambda_parameter
prob_fail_after_8_years <- 1 - exponential_cdf(8, lambda_parameter)
prob_fail_in_next_2_years_given_8 <- (exponential_cdf(10, lambda_parameter) - exponential_cdf(8, lambda_parameter)) / prob_fail_after_8_years
paste0("Expected failure time:", round(expected_failure_time, 2), " years")
## [1] "Expected failure time:10 years"
paste0("Standard deviation:", round(standard_deviation, 2), " years")
## [1] "Standard deviation:10 years"
paste0("Probability that the MRI will fail after 8 years: ", round(prob_fail_after_8_years, 4))
## [1] "Probability that the MRI will fail after 8 years: 0.4493"
paste0("Probability that the MRI will fail in the next two years given it has already been owned for 8 years: ", round(prob_fail_in_next_2_years_given_8, 4))
## [1] "Probability that the MRI will fail in the next two years given it has already been owned for 8 years: 0.1813"