Instructions: Solve these problems using RStudio, writing code in one script file, and compiling it into an HTML file. Upload one HTML file to Canvas. Please do not email your file to the professor.
x <- seq(-5, 7, length = 200)
y <- dnorm(x)
plot(x, y, type = "l", main = "Normal Density Curve", xlab = "x", ylab = "Density")
q_975 <- qnorm(0.975)
q_975
## [1] 1.959964
p_interval <- pnorm(5) - pnorm(-3)
p_interval
## [1] 0.9986498
p_greater_than_7 <- 1 - pnorm(7)
p_greater_than_7
## [1] 1.279865e-12
Examine the binomial distribution using n = 12, p = 0.3
x_binom <- 0:12
prob_binom <- dbinom(x_binom, size = 12, prob = 0.3)
plot(x_binom, prob_binom, type = "h", lwd = 2, col = "blue", main = "Binomial Density (n=12, p=0.5)", xlab = "x", ylab = "Probability")
q_99_binom <- qbinom(0.99, size = 12, prob = 0.3)
q_99_binom
## [1] 7
p_0_4 <- pbinom(4, size = 12, prob = 0.3)
p_0_4
## [1] 0.7236555
p_greater_3 <- 1 - pbinom(3, size = 12, prob = 0.3)
p_greater_3
## [1] 0.5074842
Strategy A: She gets bids from 12 dealers for purchasing one three-year-old truck, assuming she will take the three lowest bids. Assuming the delivery costs are zero, and the sold-truck price is normally distributed with a mean of 156818 and a standard deviation of 8000, what is the probability she will be able to purchase the three trucks within the budget?
set.seed(123)
n_sim <- 10000
mean_price <- 156818
sd_price <- 8000
budget <- 450000
num_dealers <- 12
num_trucks <- 3
within_budget_A <- replicate(n_sim, {
bids <- rnorm(num_dealers, mean = mean_price, sd = sd_price)
total_cost <- sum(sort(bids)[1:num_trucks])
total_cost <= budget
})
prob_A <- mean(within_budget_A)
prob_A
## [1] 0.7853
Strategy B: The purchasing manager found out that all the dealers give a discount for purchasing multiple trucks, In fact, the discount is 1% for purchasing three trucks. Same as Strategy A, except she will get bids for three trucks from each of the 12 dealers, applies the discount, and takes the lowest bid for three trucks.
set.seed(123)
n_sim <- 10000
mean_price <- 156818
sd_price <- 8000
budget <- 450000
num_dealers <- 12
num_trucks <- 3
within_budget_B <- replicate(n_sim, {
bids <- rnorm(num_dealers, mean = mean_price, sd = sd_price)
total_costs <- 3 * bids * 0.99
min_total <- min(total_costs)
min_total <= budget
})
prob_B <- mean(within_budget_B)
prob_B
## [1] 0.9684
Which one of these strategies produces the highest probability of purchasing the three trucks within the budget?
#Strategy B results in the highest probability of purchasing the 3 trucks under budget with a 96.84% chance vs. a 78.53% chance in Strategy A