SlidesCourse 21 Oct
SlidesCourse 21 Oct
https://bucloud.bogazici.edu.tr/s/WABgda87beMqDBQ
IE255 Course 21st October 2024 Part2
https://bucloud.bogazici.edu.tr/s/73zEik6LZ3AQ2ZF
5.8. A machine fills packages of flour. The exact quantity that is filled into the packages
follows a normal distribution with mean 1003 g and standard deviation 5g.
a) Calculate the probability that the filled quantity is less than 995g.
b) Calculate the approximate probability that the filled quantity is between
990.35 and 990.45g without using the R-command dnorm().
Compare the result with the exact result obtained with pnorm().
c) Find the filling quantity that is exceeded by 99% of all packages.
d) If a package is filled with less than 990g a fine of 10$ has to be paid.
For 500 filled packages find the expectation and the variance of the fine
and the probability that the fine is larger than 400$.
e) What is the probability that the fine is exactly 400$ ?
f) If a package is filled with less than 990g a fine of 10$ has to be paid.
Find the probability that for 10 packages at most 10$ fine must be paid. (f without R)
b) P(990.35< X <990.45) = integrate_990.35^990.45 f(x) dx =
Solutions:
a)
X ~ N(1003, sigma=5) P(X< 995) = pnorm((995-1003)/5)=pnorm(-8/5)=pnorm(-1.6)=0.0548
b) P(990.35<X<990.45) =
pnorm((990.45-1003)/5)- pnorm((990.35-1003)/5) [1] 0.0003334317
# approximate solution
dnorm(990.4,mean=1003,sd=5)*0.1 [1] 0.000333402
c) P(X < c) = 0.01 (ie. 1% quantile): mu+sigma*qnorm(0.01) = 1003+5*qnorm(0.01)
1003+5*qnorm(0.01) [1] 991.3683
d) Y ... # packages with less than 990 g out of the 500
Y~ binomial(n=500, p=pnorm((990-1003)/5) )
e) Fine = 10 Y P(Fine=400) = P(Y=40) = ... > 0
f) P(Y < = 1)
set.seed(123);runif(3)
[1] 0.2875775 0.7883051 0.4089769
> set.seed(123);runif(3)
[1] 0.2875775 0.7883051 0.4089769
> runif(3)
[1] 0.8830174 0.9404673 0.0455565
>
>
>
> myseed<- .Random.seed
> runif(4)
[1] 0.5281055 0.8924190 0.5514350 0.4566147
>
> .Random.seed <- myseed; runif(4)
[1] 0.5281055 0.8924190 0.5514350 0.4566147
Generating Continuous RVs:
Idea of “Inversion method” (book p53 it is called inverse transform method:)
X = F-1(U) = quantile(U)
For standard distributions and with R that is easy. Use qnorm(), qgamma() …
How can we find the quantile function (asked in Unit 5 questions)
….
We can use again inversion to generate from that random variate and can
use a simple sequential search to implement this idea in R.
b)
In R also the function “sample()” can be used
?sample
X<- sample(1:3,size=1.e6,replace=T,prob=c(0.5,0.3,0.2))
table(X)
X
1 2 3
500397 299699 199904
Of course the selection of the stock s of newspapers depends on the distribution of the
random demand D.
If D is deterministic and known the solution is clear. The newsboy has to take s=D papers.
If the demand is known to have the pmf f(10)=0.25, f(11)=0.5 and f(12)=0.25 things get
more interesting. We define the random variable: N ... Net Profit
Clear that a newsboy wants to select s such that he maximizes N.
Selecting swe can calculate the values of N = min(D,s)*p1 – s*p0
Note that it is not difficult to prove that s < 10 or s > 12 is never optimal !
s= 10 s=11 s=12
D = 10, 11, 12 D = 10, 11, 12 D = 10, 11, 12
N = 500 500 500 N = 450 550 500 N = 400 500 600
If we want to avoid risk s=10 is best as the Variance of N is 0.
Of course it is sensible to compare the expectations of N:
s=10: E(N) =500 s=11 E(N) = (450+500)*0.25 + 550*0.5 = 512.5
s=12 E(N) = (400+600)*0.25+ 0.5*500 = 500
for just one investment: important to also consider the size of the risk
risk = variance of the net profit.
our example: s=10 is better than s=12 as it has a smaller variance and the same expected
Net profit.
...
If we assume the general situation where the demand D is a discrete random variate with
known pmf f(x) it is not difficult to define the net profit and to find its distribution:
As notation we use:
s … the stock level for that day (it is the decision variable of the optimisation)
p0 … price the newsboy has to pay for the papers
p1 … price the newsboy gets for sold papers
D… daily demand; discrete random variable with pmf f(x) for x= 0,1,2,…
Sold … number of sold paper; it clear that we can never sell more than s or more than D.
Thus
Sold = min( s, D)
We define:
"net profit" = N = Sold*p1 – s*p0
The next step is that we have to find the pmf of “Sold” f_S. To do that we can rewrite
the definition of sold:
Sold = D for D<=s
s for D>=s
pmf of Sold = f_S(x) = P(Sold=x) = P(D=x) for x <s.
But for x = s we have f_S(x) =P(Sold=x) = P(D>=s) = 1-P(D<s) for x = s
So we can write:f_S(x) = f(x) for x < s
f_S(x) = 1-P(D<s) = 1- sum_(i = 0,1,2,…,s-1) f(i) for x=s
f_S(x) = 0 for x > s
So in words: for x <= s-1 the pmf of Sold is equal to the pmf of the demand.
for x = s the pmf of Sold is equal to Prob(D>=s) = 1 –Prob(D<s)
for x > s the pmf of Sold is 0