Solutions-3, 3. oktober 212; s. 1 STA51. Solutions to eercises. 3, fall 212 See R script le 'problem-set-3-h-12.r'. Problem 1 Histogram of y.non.risk The histograms to the right show the simulated distributions (1 replications) of resources riskand non risk weighted...4.8.12..2.4 1 2 3 4 5 6 7 y.non.risk Histogram of y.risk 1 2 3 4 5 6 7 y.risk Histogram of y.c c) The histogram to the right shows the simulated distribution of resources. P (Y 62) is estimated to.78 (1 replications)...5.1.15.2 5 55 6 y.c Simulation of Poisson processes In for eample problem 2, we are asked to simulate a (homogenous) Poisson process N(t) with intensity λ = 2. A recommended way to do this is to start with simulating the inter arrival times T 1, T 2, T 3,.... The T j 's are independent Ep(λ) (E(T j ) = 1, λ is called the rate of the process): λ T < rep(n = n.interarr, lambda = 2) Then the time points at which N(t) jumps, is found with: S.t < cumsum(t) ( S.t is assigned the numbers: S 1 = T 1, S 2 = T 1 +T 2, S 3 = T 1 +T 2 +T 3,..., i.e. the time points at which the process makes a one unit jump; called the arrival times.) Undervisning\STA51, Statistical modeling and simulation\eercises\1213-solutions-3.te
Solutions-3, 3. oktober 212; s. 2 The process N(t) is zero for t < t 1, and t 1 is the rst time point in S.t, i.e. S.t[1]. Then the process is one for t 1 t < t 2 and so on. Therefore we can plot a simulated realization of N(t) by Nt < : length( S.t ) plot( = c(, S.t ), y = Nt, type = s ) (The type = s produces a step function plot.) The value of N(t) (at time t) in the simulation is: n < min( which( S.t > t ) ) 1 See R script le 'problem-set-3-h-12.r Problem 2 Non homogenous Poisson processes In N(t) is a non homogenous Poisson processes with intensity λ(t) which we are going to simulate on the interval [, t ], we have to nd an upper limit for the intensity λ(t); nd a value λ such that λ(t) λ for t t. Simulate inter arrival times T 1, T 2, T 3,... where T j 's are independent Ep(λ ) (these are inter arrival times of a homogenous processes with rate λ.) The T 1, T 2, T 3,... form the arrival times S 1 = T 1, S 2 = T 1 + T 2, S 3 = T 1 + T 2 + T 3,... of the homogenous processes with rate λ, and only a subset of these events at the times S 1, S 2, S 3,... corresponds to the non homogenous processes. At time S j = t an event should be regarded an event of the non homogenous processes with probability λ(t)/λ. Thus: collect arrival times S j with probability λ(s j )/λ ; disregard the other events. The the resulting (sub) set of arrival times constitutes the the ones of the non homogenous processes. The number of inter arrival times One question is how large n.interarr, the number of inter arrival times, has to be. This depends on the time point t we want to study the process, N(t ), and it depends on the rate λ. The epected number of arrivals at time t is E{N(t )} = λt. But there is a considerable probability that the number eceeds λt, and n.interarr should be larger than this. If λt is not small (larger than 9 is sucient), N(t ) is approimately normally distributed with mean λt and standard deviation λt. Thus the probability that N(t ) eceeds λt + 3 λt, e.g., can be calculated approimately. This is: P (N(t ) > λt + 3 λt ) P (Z > 3) =.135, Undervisning\STA51, Statistical modeling and simulation\eercises\1213-solutions-3.te
Solutions-3, 3. oktober 212; s. 3 where Z N(, 1). Therefore, if we choose n.interarr < ceiling( lambda t.star + 3 sqrt( lambda t.star ) ) only in approimately 14 out of 1 times we would simulate too few inter arrival times. (Here t.star is t.) This method for computing the number of needed T j 's is not used in problems 2 and 3. But it is used in problem 3.21 from the book. It could of course as well have been used in 2 and 3. See R script le 'problem-set-3-h-12.r Problem 3 Plot of realization of N 1 (t) and N 2 (t). Nt 2 4 6 8 1 12 N1 N2 5 1 15 2 t Problem 4 {, with probability 1 pj For i = 1,..., 1 let I j =, where I 1, with probability p j = 1 means that component j j works. Then i) P (I 1 = 1 I 2 = 1) = P (I 1 = 1)P (I 2 = 1) = p 1 p 2 =.7.95 =.665 ii) P (I 1 = 1 I 2 = 1) = P (I 1 = 1) + P (I 2 = 1) P (I 1 = 1)P (I 2 = 1) = p 1 + p 2 p 1 p 2 iii) P { (I 1 = 1 I 2 = 1) (I 3 = 1 I 4 = 1) } = P { (I 1 = 1 I 2 = 1 I 3 = 1) (I 1 = 1 I 2 = 1 I 4 = 1) } = p 1 p 2 p 3 + p 1 p 2 p 4 p 1 p 2 p 3 p 4 =.6633 iv) P (I 1 + + I 1 7) =... may be found in principle, but it is much more easy to nd this probability by simulation! Cf. R script le. Undervisning\STA51, Statistical modeling and simulation\eercises\1213-solutions-3.te
Solutions-3, 3. oktober 212; s. 4 Problem 5 X, Y and Z are normal random variables, where E(X) = µ X ; Var(X) = σ 2 X E(Y ) = µ Y ; Var(Y ) = σ 2 Y Corr(X, Y ) = Cov(X,Y ) σ X σ Y = ρ, and if Y = ax + Z, (Z independent of X) we get: Cov(X, Y ) = avar(x) ρ = Corr(X, Y ) = Cov(X, Y ) σ X σ Y E(Y ) = ae(x) + E(Z) E(Z) = E(Y ) ae(x) = a σ X σ Y a = ρ σ Y σ X Var(Y ) = a 2 Var(X) + Var(Z) Var(Z) = Var(Y ) a 2 Var(X) Problem 6 The a 1, a 2 and a 3 should be chosen as the epectations of X 1, X 2 and X 3 resp. The matri A should be chosen as the cholesky decomposition of the covariance matri of [X 1, X 2, X 3 ] : Σ = Cov(X 1, X 1 ) Cov(X 1, X 2 ) Cov(X 1, X 3 ) Cov(X 2, X 1 ) Cov(X 2, X 2 ) Cov(X 2, X 3 ) Cov(X 3, X 1 ) Cov(X 3, X 2 ) Cov(X 3, X 3 )... This is how it should be done. But why does this work? Simulation estimate of P (X 1 + X 2 + X 3 3):.465 (1 replications). Problem 3.11 (Rizzo) p1=.1 p1=.2 p1=.3 p1=.4 p1=.5 p1=.6 p1=.7 p1=.8 p1=.9 Undervisning\STA51, Statistical modeling and simulation\eercises\1213-solutions-3.te
Solutions-3, 3. oktober 212; s. 5 Problem 3.14 (Rizzo) 1 1 2 3 4 X 1 3 2 1 1 2 1 1 2 3 4 X 2 X 3 1 2 3 4 5 3 2 1 1 2 1 2 3 4 5 Problem 3.21 (Rizzo) Inhomogeneous Poisson process N(t) is an inhomogeneous Poisson process with mean value function m(t) = t 2 + 2t. That is the rate (intensity) λ(t) is determined by m(t) = t λ()d. This means that λ(t) = m (t) = 2t + 2. To simulate N(t) on the interval [4, 5], we could eploit that N(4) is Poisson with mean m(4) = 4 2 + 2 4 = 24. So if Y P oiss(24), N(t) = Y + N (t 4), t 4, where N (t) is an inhomogeneous Poisson process with mean value function m (t) = m(t + 4) (intensity: λ (t) = λ(t + 4) = 2(t + 4) + 2 = 2t + 1). We will simulate N(t) for t < 6, to cover the interval [4, 5]. That is, we have to simulate N (t) for t < 2. In this period the intensity has the maimal value: λ (t) λ (2) = 2 2 + 1 = 14 (since λ (t) increases with t) The number of inter arrival times: When the intensity is not constant, we can try to use the average intensity in the period considered, for the calculations of number of needed inter arrival times. Generally, the average Undervisning\STA51, Statistical modeling and simulation\eercises\1213-solutions-3.te
Solutions-3, 3. oktober 212; s. 6 1 b m(b) m(a) intensity in the interval [a, b] is: λ(t)dt =. a b a b a The average intensity of N (t) in [, 2] is m (2) m () 48 24 = 2 2 12 2 + 3 12 2 = 38.7 39 T j 's are needed. = 12. This implies that If we do not eploit that N(4) is Poisson with mean m(4) = 4 2 + 2 4 = 24 we can proceed as follows: We will simulate N(t) for t < 6, to cover the interval [4, 5]. In this period the intensity has the maimal value: λ(t) λ(6) = 2 6 + 2 = 14 (since λ(t) increases with t) The number of inter arrival times: The average intensity of N(t) in [, 6] is 3 8 6 = 68.8 69 T j 's are needed. m(6) m() 6 = 48 6 = 8. This implies that 8 6 + Problem 6.4 (Rizzo) X 1,..., X n : i.i.d., lognormal(µ, σ 2 ). I.e. X i = e Y i, where Y i N(µ, σ 2 ). E(Y i ) = E{ln(X i )} = µ. E(X i ) = e µ+σ2 /2 ; Var(X i ) = e 2µ+σ2 (e σ2 1). (Y i Y ) 2 (ordi- Y µ For n large, we have approimately: SY 2 /n N(, 1), where S2 Y = 1 n 1 nary variance estimator, estimates σ 2 = Var(Y i )). On this background if n is large: n i=1 P ( z α/2 < Y µ S 2 Y /n < z α/2) 1 α P (Y z α/2 SY 2 /n < µ < Y + z α/2 SY 2 /n) 1 α Therefore, ( Y z α/2 S 2 Y /n, Y + z α/2 S 2 Y /n ) is a condence interval for µ with approimate condence level 1 α. Actually, since the Y i 's are i.i.d. N(µ, σ 2 ), we have that S Y µ Y 2 /n P ( t α/2,n 1 < Y µ < t S 2 α/2,n 1) = 1 α and that ( Y t α/2,n 1 S 2 Y /n Y /n, t(n 1), Y + t α/2,n 1 S 2 Y /n ) Undervisning\STA51, Statistical modeling and simulation\eercises\1213-solutions-3.te
Solutions-3, 3. oktober 212; s. 7 is a condence interval for µ with (eact) condence level 1 α. We are asked to use a Monte Carlo method to obtain an empirical estimate of the condence level of the interval. C.f. book at pages 16 162 and check R script le. For dierent n (2, 4, 1, 2), this gave estimated condence levels very close to 95% (1 replications used). Problem 6.5 (Rizzo) X 1,..., X 2 : i.i.d., χ 2 (2) (chi square distributed with 2 degrees of freedom.) We are supposed to (erroneously) use the t-interval: ( Y t α/2,n 1 SY 2 /n, Y + t α/2,n 1 SY 2 /n ) as a condence interval for E(X i ) = µ = 2 (=d.f.) in this situation. (Erroneous, because this t-interval assumes that the X i 's are i.i.d. N(µ, σ 2 ).) This mean that the condence interval does not necessarily have condence 1 α. C.f. book at pages 16 162 and check R script le. With 1 replications used, this gave an estimated condence level 92.7% which is very close to 95%. π/3 sin(t)dt = cos(t) Problem 5.1 (Rizzo) π/3 π/3 = cos(π/3) + 1 =.5 If U U[, π/3], then E{sin(U)} = sin(t) 1 π/3 dt = 3 sin(t)dt. So, for n U[, π/3] distributed U 1,..., U n, we have that the average of sin(u 1 ),..., sin(u n ) times ( 3 π ) 1 will π estimate the quantity π/3 π/3 sin(t)dt. The Monte Carlo estimate is then: v ( 3 π ) 1, (with v i = sin(u i )). We want to estimate (assume < ) The term Φ() = Problem 5.2 (Rizzo) 1 e 1 1 2 y2 dy =.5 + e 1 2 y2 dy 2π 2π 1 2π e 1 2 y2 dy can be estimated by Monte Carlo simulation by using U U[, ]. Then we have: E{e 1 2 U 2 } = e 1 1 2π 2 y2 dy = 1 e 1 2 y2 dy. 2π Undervisning\STA51, Statistical modeling and simulation\eercises\1213-solutions-3.te
Solutions-3, 3. oktober 212; s. 8 Thus if U 1,..., U n are i.i.d. U[, ] and V i = e 1 2 U 2 i, then Here V = 1 n ni=1 V i. 1 V estimates e 1 2 y2 dy. 2π 2π Remark: The gure below shows a histogram of n = 1 simulated values of Φ() =.5 + V for 2π = 2. As may be seen, it is possible that a simulated value may larger that 1., but we know that Φ() 1 for all. Histogram of fi..vec 1 2 3 4 For these simulated values: Maimum value: 1.572 Variance: 6.36116e-5 The condence interval, 1: (.9631,.9929) The condence interval, 2: (.9615,.992) Theoretical value:.9772.96.97.98.99 1. 1.1 fi..vec Undervisning\STA51, Statistical modeling and simulation\eercises\1213-solutions-3.te