# Load packages
library(tidyverse)
# Define n
n <- 1000
# Empty data frame for 1000 simulated days
data <- data.frame(day = seq(1:n),
demand = NA, # demand in Rockport
quantity = NA, # quantity sold
price = NA, # price per pound
cost = 10000, # cost of daily operations
earnings = NA)
head(data)
## day demand quantity price cost earnings
## 1 1 NA NA NA 10000 NA
## 2 2 NA NA NA 10000 NA
## 3 3 NA NA NA 10000 NA
## 4 4 NA NA NA 10000 NA
## 5 5 NA NA NA 10000 NA
## 6 6 NA NA NA 10000 NA
Your goal in this project is to:
Fill in the dataset with random numbers drawn from the probability distributions defined in the case description—distributions for demand, quantity and price.
Use those numbers to compute earnings.
Summarize the earnings distribution to inform a business recommendation.
Note:
This case is slightly different from the one in the tutorial in
that quantity sold is a function of demand: if demand is greater than
3500 then quantity is 3500 otherwise it equals demand. The mathematical
notation used for this relationship in the case description—min(3500,
D)—is NOT R code. There are various ways of creating the quantity
variable but ifelse() works well.
Use set.seed(123) once before doing any simulation. Why 123? This is an arbitrary seed that controls a random process, making the results comparable. People who share the seed will get the same results. However, R will increment the seed in a deterministic fashion every time you run a random process. So if you simulate your random variables in a different order than the one stipulated in the empty dataframe that has been provided, you will get a different answer. Is it wrong? No, but your results will not be identical to those of your classmates. For example:
set.seed(123)
rnorm(1000) %>% mean()
## [1] 0.01612787
rnorm(1000) %>% mean()
## [1] 0.04246525
The means of the two samples are different (.016 vs. .042) because R has incremented the seed for the second sample.
Compare to:
set.seed(123)
rnorm(1000) %>% mean()
## [1] 0.01612787
set.seed(123)
rnorm(1000) %>% mean()
## [1] 0.01612787
Lightly comment your code and use pipes for readability.
Most of the questions require some writing. Please place your text immediately after the “>” in each question, which will make it into a block quote.
Use this code chunk to simulate demand, quantity and price, and then compute earnings. Make sure to use set.seed(123) before running any random process to ensure that your results are reproducible!
set.seed(123)
sim <- data %>%
mutate(demand = sample(x = c(0, 1000, 2000, 3000, 4000, 5000, 6000),
size = 1000,
replace = T,
prob = c(.02, .03, .05, .08, .33, .29, .2)),
price = rnorm(n = n, mean = 3.65, sd = .2),
quantity = ifelse(demand >= 3500, 3500, demand),
cost = 10000,
earnings = quantity * price - cost)
head(sim)
## day demand quantity price cost earnings
## 1 1 4000 3500 3.529621 10000 2353.675
## 2 2 6000 3500 3.451260 10000 2079.411
## 3 3 5000 3500 3.855357 10000 3493.750
## 4 4 3000 3000 3.800212 10000 1400.637
## 5 5 2000 2000 3.348167 10000 -3303.667
## 6 6 4000 3500 3.630971 10000 2708.397
Plot simulated earnings.
library(ggplot2)
ggplot(sim, aes(earnings)) +
geom_density() +
geom_vline(xintercept = 1375, col = 2) +
geom_vline(xintercept = 0, col = 2, lty = 2) +
theme_minimal()+
labs(title = "Distribution of earnings",
subtitle = "solid = 1375, dashed = 0")
What is P(F > 1375)?
(sim$earnings > 1375) %>%
mean
## [1] 0.826
The probability of having daily earning over $1375 in Rockport market is 0.826. Simply put as there is 82.6% chance to earn over $1375 (the daily earning in Gloucerter) each day in the Rockport market.
What is P(F < 0)
(sim$earnings < 0) %>%
mean
## [1] 0.099
The probability of having negative daily earning in Rockport market is 0.099. Simply put as there is 9.9% chance to not earn any profit in a day if Clint is selling in the Rockport market.
What is the expected value (mean) of F?
mean(sim$earnings)
## [1] 1879.699
Clint is likely to earn the average of $1879 selling codfish in Rockport market, which is $504.699 more than what he would earn if selling in Gloucester market.
What is your advice to Mr. Conley? Write one paragraph in which you argue a position. In your answer please incorporate the quantitative details from your simulation, and consider in particular the trade-off between risk and reward.
My advice to Mr. Conley is to sell in Rockport market rather in Gloucester market. According to the simulation model, the average earning in Rockport market is $1879.699, which is $500 more than that in Gloucester market. The demand and market price in Gloucester market are stable. This puts a cap on the daily earning Mr. Conley can have. In the flip side, Mr. Conley would be a 82.6% chance to earn more in Rockport market. In simplier words, around 83 out of 100 days/times, Mr. Conley will be over $1375 per boat in Rockport market. However, it is important to know the risk of not earning in Rockport market, which is equals to the probability of not earning is 0.099. In other words, there is 10% chance of Mr. Conley not earning selling in Rockport market. However, comparing the reward risk and the reward, the risk is minimal (82.6% vs 9.9%). Therefore, Mr. Conley should tell in Rockport market if he would like to maximize his profits.
This question is optional and not graded!
The cod population off the coast of New England has been declining for decades (down 95% in the early 90s) due to overfishing and destructive fishing practices, such as bottom trawling. Most recently, a 10-year rebuilding plan was implemented for this stock in 2014, which is now managed under the Northeast Multispecies (Groundfish) Fishery Management Plan. The catch has been restricted as follows:
While Clint Conley supports these measures, which he understands as necessary to create a sustainable cod fishery, they had devastating impacts on his business. Particularly in the area north of Cape Cod, where Gloucester and Rockport are located, the catch was limited dramatically: 200 pounds per boat per day during the season.
Cod prices have gone up dramatically. Gloucester is still a reliable market (he can always sell his limit, 200 lbs), but Conley is sometimes unable to sell at Rockport at all. When he can sell at Rockport, the prices are variable, but usually quite a bit higher than at Gloucester.
Update your simulation with this new information:
He has managed to reduce his cost per boat to $2000.
His fleet now consists in 10 boats.
Prices (in dollars) at Gloucester are fixed:
Prices (in dollars) at Rockport are normally distributed: N(mean, sd).
Moreover, the probability mass function for demand at Rockport, in both selling seasons, based on recent data, is now as follows:
sim_fish <- data.frame(demand = c(0, 50, 100, 150, 200),
probability = c(.02, .1, .3, .3, .28))
head(sim_fish)
## demand probability
## 1 0 0.02
## 2 50 0.10
## 3 100 0.30
## 4 150 0.30
## 5 200 0.28
What is your recommendation to Mr. Conley based on your new simulation?