I am having a problem writing an income function. The information I have been given is: " Charles has taken over a market stall where he sells fresh fish. Each morning he buys fish from the wholesaler at a cost of £4 per kg up to the first 100 kg and £2.5 per kg for anything above 100 kg. He sells the fish at £8 per kg. If any fish remains unsold at the end of the day, he sells it to the cat food factory for £1 per kg. Charles would like to know how much fish to buy each day in order to maximise his average daily profit."
So far I modelled given data for the daily sales figures for the last 150 as a gamma function and used the Method of moments to find the parameters, below is the code I used:
First_moment_Xbar = sum(nfsold)/150
Second_moment = sum((nfsold)^2)/150\
estimator_of_lambda = (First_moment_Xbar)/(Second_moment - (First_moment_Xbar)^2)
estimator_of_k = (First_moment_Xbar)^2 / (Second_moment - (First_moment_Xbar)^2 )
estimator_of_k
estimator_of_lambda
and I got:
> estimator_of_k
[1] 4.992957
> estimator_of_lambda
[1] 0.05733275
I wrote a cost function of buying n kg of fish as:
cost=function(n)
{
total = 0
if(n<=100)
{
total = n*4
}
else{
total = 100*4 + (n-100)*2.5
}
return(total)
}
Now, I have to write an income function, income(n,d) when there are potential sales of d kg and Charles has bought n kg of fish.
I think potential sales will be modelled around:
round(rgamma(1, estimator_of_k, estimator_of_lambda), digits = 0)
as I know the sales for fish prior to cat food will be modelled around the Gamma I found.
Please may I have some help as to how to find the income function, thank you.