2024-25 (First Semester) HOFERT Marius, HKU
STAT3902 Statistical models
Solution Assignment 2
Solution 10
a) By the law of total probability,
E(X) = 0 · P(X = 0) + 1 · P(X = 1) + 2 · P(X = 2)
1 1
1 1 1 1
X X
tot.
=0+1· P(X = 1, Y = i) + 2 · P(X = 2, Y = i) = + + +2 3·
prob.
i=−1 i=−1
5 10 30 15
22 11
= = .
30 15
b) Note that Z = XY ∈ ¶−2, −1, 0, 1, 2♢ with XY = −2 iff X = 2 and Y = −1, XY = −1 iff
X = 1 and Y = −1, XY = 1 iff X = 1 and Y = 1, and XY = 2 iff X = 2 and Y = 1. Therefore
E(Z) = −2 · P(XY = −2) − 1 · P(XY = −1) + 0 + 1 · P(XY = 1) + 2 · P(XY = 2)
= −2P(X = 2, Y = −1) − P(X = 1, Y = −1) + P(X = 1, Y = 1) + 2P(X = 2, Y = 1)
1 1 1 1 1
= −2 − + +2 =− .
15 5 30 15 6
Furthermore, Z 2 ∈ ¶0, 1, 4♢, so E(Z 2 ) = 1 · P(XY ∈ ¶−1, 1♢) + 4 · P(XY ∈ ¶−2, 2♢) = 1 · (1/5 +
1/30) + 4(1/15 + 1/5) = 23/30 and thus var(Z) = E(Z 2 ) − E(Z)2 = 23/30 − (−1/6)2 = 133/180.
c) −2/45 = cov(X, Y ) = E(XY ) − E(X)E(Y ) b),a)
= −1/6 − (11/15)E(Y ) and thus E(Y ) = −1/6.
This implies that
1
− = E(Y ) = −1 · P(Y = −1) + 0 · P(Y = 0) + 1 · P(Y = 1)
6
1 1 1 1 1
= −1 · + + + 0 + 1 · P(Y = 1, X = 0) + + .
5 5 15 30 15
Therefore, P(Y = 1, X = 0) = −1/6 + 7/15 − 1/10 = 1/5 and thus
P(Y = 0, X = 0) = P(X = 0) − P(Y = −1, X = 0) − P(Y = 1, X = 0)
= (1 − P(X = 1) − P(X = 2)) − P(Y = −1, X = 0) − P(Y = 1, X = 0)
1 1 1 1 1 1 1
= 1− + + − 3 − − = .
5 10 30 15 5 5 15
Since cov(X, Y ) = −2/45 ̸= 0, X and Y are correlated and thus cannot be independent (as
independence implies uncorrelatedness).
Solution 11
a) f is nonnegative, integrable (by TonelliŠs theorem, the double-integral of a non-negative function
can be computed as an iterated integral in any of the two orders of integration), and we have
the value
© 2024-25, HOFERT Marius, HKU
Z Z Z ∞ Z ∞
f (x) dx = 2 exp(−(x1 + x2 )) dx Tonelli
= 2 exp(−x2 ) exp(−x1 ) dx1 dx2
R2 {(x1 ,x2 ):0≤x2 ≤x1 <∞} 0 x2
Z ∞
1
=2 exp(−2x2 ) dx2 = 2 ·
= 1.
0 2
Therefore, f satisĄes all three deĄning properties of being a density.
b) For the Ąrst margin,
(R x
2e−(x1 +x2 ) dx2 = 2e−x1 (1 − e−x1 ), x1 > 0,
Z ∞ 1
0
f1 (x1 ) = f (x1 , x2 ) dx2 =
−∞ 0, x1 ≤ 0,
= 2e−x1 (1 − e−x1 )✶(0,∞) (x1 ), x1 ∈ R.
For the second margin,
Z ∞ Z ∞
f2 (x2 ) = f (x1 , x2 ) dx1 = 2e−(x1 +x2 ) dx1 ✶(0,∞) (x2 )
−∞ x2
= 2e−2x2 ✶(0,∞) (x2 ), x2 ∈ R,
which is the density of the Exp(2) distribution.
c) Let fExp(λ) (x) = λe−λx , x > 0, denote the density of Exp(λ) with mean 1/λ and second moment
2/λ2 (which we use to compute the appearing integrals in what follows). We have
Z ∞ Z ∞ Z ∞
−x1 −x1 −x1 −2x1
E(X1 ) = x1 · 2e (1 − e ) dx1 lin.
=2 x1 e dx1 − x1 e dx1
0 0 0
Z ∞ Z ∞
1 1 1 3
=2 x1 fExp(1) (x1 ) dx1 − x1 fExp(2) (x1 ) dx1 = 2 1 − · =
0 2 0 2 2 2
and
Z ∞ Z ∞ Z ∞
E(X12 ) = x21 · 2e−x1
(1 − e −x1
) dx1 lin.
= x21 e−x1 dx1 − x21 e−2x1 dx1
0 0 0
Z ∞ Z ∞
1 2 1 2 7
=2 x21 fExp(1) (x1 ) dx1 − x21 fExp(2) (x1 ) dx1 = 2 2
− · 2 = .
0 2 0 1 2 2 2
Therefore, var(X1 ) = E(X12 ) − E(X1 )2 = 7/2 − (3/2)2 = 5/4. Since X2 ∼ Exp(2), we have
E(X2 ) = 1/2, E(X22 ) = 2/22 = 1/2 and thus var(X2 ) = E(X22 ) − E(X2 )2 = 1/4. Furthermore,
Z ∞ Z ∞ Z ∞Z ∞
E(X1 X2 ) = x1 x2 f (x1 , x2 ) dx1 dx2 = 2 x1 x2 e−(x1 +x2 ) dx1 dx2
−∞ −∞ 0 x2
Z ∞ Z ∞ Z ∞
=2 x2 e−x2 x1 e−x1 dx1 dx2 = 2
by parts
x2 e−x2 ((1 + x2 )e−x2 ) dx2
0 x2 0
Z ∞ Z ∞
1 2
= x2 · 2e−2x2 dx2 + x22 · 2e−2x2 dx2 = + 2 =1
0 0 2 2
and thus
3 1 1
cov(X1 , X2 ) = E(X1 X2 ) − E(X1 )E(X2 ) = 1 − · = .
2 2 4
Therefore,
cov(X1 , X2 ) 1/4 1
cor(X1 , X2 ) = p =p =√ .
var(X1 ) var(X2 ) (5/4)(1/4) 5
© 2024-25, HOFERT Marius, HKU
d) As just seen, X1 , X2 are correlated.
e) As X1 , X2 are correlated, they are not independent.
f) E(X1 − X2 ) = E(X1 ) − E(X2 ) = 3/2 − 1/2 = 1 and var(X1 − X2 ) = var(X1 ) + var(−X2 ) +
2 cov(X1 , −X2 ) = var(X1 ) + var(X2 ) − 2 cov(X1 , X2 ) = 5/4 + 1/4 − 2 · 1/4 = 1.
Solution 12
By the law of total probability,
∞
X k
X
tot.
P(X1 + X2 = k) prob.
= P(X1 + X2 = k, X2 = l) = P(X1 + X2 = k, X2 = l)
l=0 l=0
k
X k
X
= P(X1 = k − l, X2 = l) ind.
= P(X1 = k − l)P(X2 = l)
l=0 l=0
k k
λ1k−l −λ1 λl2 −λ2 1 X k!
= e−(λ1 +λ2 ) λl λk−l
X
= e · e
l=0
(k − l)! l! k! l=0 l!(k − l)! 2 1
k
−(λ1 +λ2 ) 1 X k l k−l (λ1 + λ2 )k
= e−(λ1 +λ2 )
binomial
=e λ λ , k ∈ N0 ,
k! l=0 l 2 1 theorem
k!
which is the probability mass function of the Poi(λ1 + λ2 ) distribution, so X1 + X2 ∼ Poi(λ1 + λ2 ).
Solution 13
linearity
a) E(aX + bZ ♣ Y ) =
factorization
E(aX + bZ ♣ Y = y)♣y=Y = (aE(X ♣ Y = y) + bE(Z ♣ Y = y))♣y=Y
of E(·)
=
factorization
aE(X ♣ Y ) + bE(Z ♣ Y ).
b) By factorization, let h(y) = E(X ♣ Y = y), so that h(Y ) = E(X ♣ Y = y)♣y=Y = E(X ♣ Y ). Then
E(E(X ♣ Y ) ♣ (Y , Z)) = E(h(Y ) ♣ (Y , Z)) factorization
= E(h(Y ) ♣ (Y , Z) = (y, z))♣(y,z)=(Y ,Z)
= E(h(y) ♣ (Y , Z) = (y, z))♣(y,z)=(Y ,Z)
Y =y
=
TOWIK
(h(y) · E(1 ♣ (Y , Z) = (y, z)))♣(y,z)=(Y ,Z) = h(y)♣(y,z)=(Y ,Z)
see
= h(Y ) above
= E(X ♣ Y ).
Solution 14
a) Here is a solution in R:
##' @title Generating Random Variates from a Multivariate t Distribution
##' @param n sample size (>= 1)
##' @param nu degrees of freedom parameter (> 0)
##' @param mu location vector (dimension d)
##' @param Sigma scale matrix (dimension c(d, d))
##' @return (n, d)-matrix containing in each row one multivariate t sample
##' @author Marius Hofert
sampling_multivariate_t <- function(n, nu, mu, Sigma)
{
## Input checks
d <- length(mu) # dimension
stopifnot(n >= 1, nu > 0, [Link](Sigma), dim(Sigma) == c(d, d))
## Find the Cholesky factor A of Sigma
## Note: chol() returns an upper triangular Cholesky factor, hence the
© 2024-25, HOFERT Marius, HKU
## transpose t()
A <- t(chol(Sigma))
## Generate the mixing variates
W <- 1/rgamma(n, shape = nu/2, rate = nu/2)
## Generate iid N(0,1) random variates
Z <- matrix(rnorm(n * d), ncol = d) # (n, d)-matrix
## Generate and return multivariate t samples
## Note: Matrices are vectors with attributes indicating when to
## 'wrap around' (when a new block starts which constitutes
## the next column of the 'matrix'). Hence rep(mu, each = n)
## is treated as an (n, d)-matrix containing in each row the
## location vector mu.
rep(mu, each = n) + sqrt(W) * t(A %*% t(Z))
}
b) Figure 1 shows the plot.
40
20
X2
0
−20
−10 0 10 20 30
X1
Figure 1 Sample of size 1000 from t2 (3.5, ( 00 ), ( 43 39 )).
Note. The solution was generated as follows.
## Define parameters
n <- 1000
nu <- 3.5
mu <- c(0,0)
Sigma <- matrix(c(4, 3, 3, 9), ncol = 2, byrow = TRUE)
## Call
[Link](271) # for reproducibility
X <- sampling_multivariate_t(n, nu = nu, mu = mu, Sigma = Sigma)
## Plot
© 2024-25, HOFERT Marius, HKU
pdf(file = "[Link]")
opar <- par(pty = "s") # to create a square plotting region
plot(X, pch = 20, xlab = expression(X[1]), ylab = expression(X[2]))
par(opar) # reset plot parameters
[Link]()
There is no true randomness on a computer. Instead, there are deterministic sequences that mimic
randomness, so-called pseudo-random number generators. When asking to generate random numbers
in a new session for the Ąrst time, the generated random numbers only appear to be random as the
starting point in the deterministic sequence (the seed) is determined uniquely (in R: based on the
current time and process ID; see ?[Link]). In the code above, we Ąxed the seed (via [Link]())
and so re-running the above code produces the exact same numbers, which is of utmost importance
in simulation studies (otherwise they would not be reproducible and every single replication would
provide different results).
© 2024-25, HOFERT Marius, HKU