In: Statistics and Probability
***Please only reply with answers using R. Please leave for other experts if not able to help with R programming.
I need help trying to figure out how to set up a simulation to the below question using R.
The annual demand for Prizdol, a prescription drug manufactured
and marketed by the NuFeel Company, is normally distributed with
mean 50,000 and standard deviation 12,000. We assume that demand
during each of the next 10 years is an independent random draw from
this distribution. NuFeel needs to determine how large they should
build the Prizdol plant to maximize its expected profit over the
next 10 years. If the company builds a plant that can produce x
units of Prizdol per year, it will incur a one-time cost of $16 for
each of these x units. NuFeel will produce only the amount demanded
each year, and each unit of Prizdol produced will sell for $3.70.
Each unit of Prizdol produced incurs a variable production cost of
$0.20. It costs $0.40 per year to operate a unit of capacity.
1. Among the capacity levels of 30K, 35K, 40K, 45K, 50K, 55K, and
60K units per year, which level maximizes expected profit? Use
simulation to answer the question.
2. Using the capacity from your answer to the previous question, NuFeel can be 95% certain that expected profit for the 10-year period will be between what two values?
1) R code with comments
----
#function to calculate the Net profit
#x is the capacity of plant
NProfit<-function(x){
#set the number of simulations
R<-10000
#get R simulations of 10 annual demands
d<-rnorm(R*10,mean=50000,sd=12000)
#convert this into a matrix of 10xR
d<-matrix(d,nrow=10)
#get the amount sold (cannot sell more than the
capacity)
qs<-pmin(d,x)
#revenue from selling s
r<-qs*3.70
#get the annual cost of producing qs using capacity
x
#cannot produce more than the capacity x and hence
produced=sold
ac<-qs*0.20+x*0.40
#get the annual profit (without the fixed cost)
ap<-r-ac
#get the fixed cost for capacity x
fc<-x*16
#get R number of net profit for 10 years
netp<-apply(ap,2,sum)-fc
return(netp)
}
#set the random seed for repetability
set.seed(123)
#initialize the max profit
MaxP<-0;
for (x in seq(30000,60000,by=5000)) {
#get R net profits
NP<-NProfit(x)
#get the expected Profit
MeanP<-mean(NP)
#get the maximum expected profit
if (MaxP<MeanP){
MaxP<-MeanP
MaxX<-x
}
}
sprintf('The capcacity which maximizes the expected profit is %g
units/year',MaxX)
sprintf('The maximum expected profit is $%.2f',MaxP)
----
#get this
2) get 95% interval using x=50000
R code
---
#part 2)
#get the net profits for x=50000
NP<-NProfit(50000)
#get 2.5 and 97.5 percentiles
ci<-quantile(NP,c(0.25,0.975))
sprintf('NuFeel can be 95%% certain that expected profit for the
10-year period will be between $%.2f and $%.2f',ci[1],ci[2])
----
#get this
All code together
--------
#function to calculate the Net profit
#x is the capacity of plant
NProfit<-function(x){
#set the number of simulations
R<-10000
#get R simulations of 10 annual demands
d<-rnorm(R*10,mean=50000,sd=12000)
#convert this into a matrix of 10xR
d<-matrix(d,nrow=10)
#get the amount sold (cannot sell more than the
capacity)
qs<-pmin(d,x)
#revenue from selling s
r<-qs*3.70
#get the annual cost of producing qs using capacity
x
#cannot produce more than the capacity x and hence
produced=sold
ac<-qs*0.20+x*0.40
#get the annual profit (without the fixed cost)
ap<-r-ac
#get the fixed cost for capacity x
fc<-x*16
#get R number of net profit for 10 years
netp<-apply(ap,2,sum)-fc
return(netp)
}
#set the random seed for repetability
set.seed(123)
#initialize the max profit
MaxP<-0;
for (x in seq(30000,60000,by=5000)) {
#get R net profits
NP<-NProfit(x)
#get the expected Profit
MeanP<-mean(NP)
#get the maximum expected profit
if (MaxP<MeanP){
MaxP<-MeanP
MaxX<-x
}
}
sprintf('The capcacity which maximizes the expected profit is %g
units/year',MaxX)
sprintf('The maximum expected profit is $%.2f',MaxP)
#part 2)
#get the net profits for x=50000
NP<-NProfit(50000)
#get 2.5 and 97.5 percentiles
ci<-quantile(NP,c(0.25,0.975))
sprintf('NuFeel can be 95%% certain that expected profit for the
10-year period will be between $%.2f and $%.2f',ci[1],ci[2])
--------