knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)

Q1

library(tidyverse)

set.seed(123)  # reproducibility

#Simulation parameters
n <- 1000 # number of simulated days
catch <- 3500 # pounds each boat can carry
cost  <- 10000 # daily operating cost

#Define Rockport demand and price distributions
demand_levels <- c(0, 1000, 2000, 3000, 4000, 5000, 6000)
prob_levels   <- c(0.02, 0.03, 0.05, 0.08, 0.33, 0.29, 0.20)

#Simulate 1000 random days
data <- tibble(day = 1:n) %>%
  mutate(
    demand   = sample(demand_levels, size = n, replace = TRUE, prob = prob_levels), # Rockport demand
    price    = rnorm(n, mean = 3.65, sd = 0.2),                                     # Rockport price
    quantity = ifelse(demand >= catch, catch, demand),                             
    earnings = price * quantity - cost                                              
  )

#Plot simulated earnings
data %>%
  ggplot(aes(x = earnings)) +
  geom_histogram(fill = "lightblue", color = "white", bins = 30) +
  geom_vline(xintercept = 1375, color = "red", linetype = "dashed", size = 1) +
  labs(
    title = "Simulated Daily Earnings at Rockport",
    subtitle = "Red dashed line = Gloucester daily earnings ($1,375)",
    x = "Daily Earnings ($)",
    y = "Frequency"
  ) +
  theme_minimal()

Q2

#Compute P(F > 1375) for Rockport
# Gloucester fixed daily earnings
gloucester_earnings <- 1375

# Probability Rockport earnings exceed Gloucester
PF_greater_1375 <- data %>%
  summarise(prob = mean(earnings > gloucester_earnings)) %>%
  pull(prob)

#The answer is 
PF_greater_1375 #Rounded is 0.83
## [1] 0.826
# Rockports daily earnings exceeds Gloucester's fixed profits of $1375 about 83% of the time.

Q3

#Compute P(F < 0) for Rockport
PF_less_0 <- data %>%
  summarise(prob = mean(earnings < 0)) %>%
  pull(prob)

# Print result
PF_less_0
## [1] 0.099
#The anticipated proberlity that Mr Colney would lose money by selling to Rockport instead of Gloucester port is 10%. 

Q4

#Compute mean (expected) earnings at Rockport
mean_F <- data %>%
  summarise(mean_earnings = mean(earnings)) %>%
  pull(mean_earnings)

# Print result
mean_F
## [1] 1879.699
#The mean of F is approximately $1879.70 per boat

Q5

#Mr Conley, I would strongly recommend that you move your operation to Rockport as your first option, the risk of 11% for not making a profit is far too low to ignore. Rockport is expected to geerate a profit of around $1820 against Gloucester's standard $1375 a difference of $445. In this line of business some risk must be adapted, Rockport has a given probability of a 83% chance that you will make a profit when you offload your catch everyday if possible. Given these numbers you will at times if moved over to Rockport there is a low chance that you will lose money occasionally but that is just part of the risk you will be taking on but in the long run overall you will be making a profit, in closing my recommendation is to have Rockport as your central location of offloading your fish to make a bigger profit.