Loo Guan Yee A0223941J Assign2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

ST4250 Assignment 2

Loo Guan Yee (A0223941J)

2023-10-07

Q1

Q1a)

We will use Lecture 3.40 example to solve(a).


 T
V = X1 X2 Y1 Y2
 
X
=
Y
≈ N4 (µ, Σ)

Σ11 AT
   
µ1 Σ11
where µ = and Σ = .
Aµ1 + b AΣ11 Ω + AΣ11 AT
Based on visual inspection,
 
2
µ1 =
1
 
1 0
Ω=
0 2
      
2X1 + 1 2 0 X1 1
= +
X1 − X2 1 −1 X2 0
 
2 0
A=
1 −1
 
1
b=
0

 
2 1
Σ11 =
1 2
  
T 2 1 2 1
Σ11 A =
1 2 0 −1
 
(2)(2) (2) − (1)
=
(1)(2) (1) + (2)(−1)
 
4 1
=
2 −1
  
2 0 2 1
AΣ11 =
1 −1 1 2
 
(2)(2) (2)(1)
=
(2) − (1) (1) − (2)
 
4 2
=
1 −1

1
     
1 0 2 0 2 1 2 1
Ω + AΣ11 AT = +
0 2 1 −1 1 2 0 −1
    
1 0 2 0 4 1
= +
0 2 1 −1 2 −1
   
1 0 (2)(4) (2)(1)
= +
0 2 (4)(1) + (−1)(2) (1)(1) + (−1)(−1)
   
1 0 8 2
= +
0 2 2 2
 
9 2
=
2 4

We will compute the µ1


 
µ1
µ=
Aµ1 + b
 
2
 1   
 
=
 2 0 2 1 
+
1 −1 1 0
 
2
  1  
 
=
 4 1 
+
1 0
 
2
1
= 
5
1

Σ11 AT
 
Σ11
We will compute the Σ =
AΣ11 Ω + AΣ11 AT

Σ11 AT
 
Σ11
Σ=
AΣ11 Ω + AΣ11 AT
   
2 1 4 1
 2 −1 
 1 2 
= 
 4 2 9 2 
1 −1 2 4
 
2 1 4 1
1 2 2 −1
=4 2 9 2 

1 −1 2 4

Therefore,
     
X1 2 2 1 4 1
X2  1 1 2 2 −1
 Y1  ≈ N4 5 , 4
V =     
2 9 2 

Y2 1 1 −1 2 4

2
Q1b)

   
5 9 2
Y ∼N ,
1 2 4

µ4 + σ21 T Σ11 −1 (Y1 − µ3 ) = 1 + (2)(9)−1 (Y1 − 5)


2
= 1 + (Y1 − 5)
9
2
= 1 + (Y1 − 5)
9
(2)(5) 2
=1− + Y1
9 9
1 2
= − + Y1
9 9
We will now compute the covariance matrix
T
σ22.1 = σ22 − σ21 Σ11 −1 σ12
= 4 − 2(9)−1 (2)
(2)(2)
=4−
9
32
=
9
Therefore,
1 2 32
Y1 |Y2 ∼ N (− + Y1 , )
9 9 9

3
Q1c)

W =X −Y
 
X1 − Y1
=
X2 − Y2

Based on visual inspection,

W = BV
 
X1
X2 
=B 
 Y1 
Y2
 
  X1
1 0 −1 0  X2 

=
0 1 0 −1 Y1 

Y2
 
1 0 −1 0
B=
0 1 0 −1

We will find the expectation


 
  2
1 0 −1 1
0  
Bµ =
0 1 0 −1 5
1
 
−3
=
0

We will find the covariance matrix


 
  2 1 4 1  T
T 1 0 −1 0  1 2 2 −1) 1 0
 −1 0
BΣB =
0 1 0 −1 4 2 9 2  0 1 0 −1
1 −1 2 4
 
  2−4 1−1
1 0 −1 0  1 − 2 2 + 1 

=
0 1 0 −1 4 − 9 2 − 2 
1 − 2 −1 − 4
 
  −2 0
1 0 −1 0  −1 3 

=
0 1 0 −1 −5 0 
−1 −5
 
−2 + (−1)(−5) 0
=
(1)(−1) + (−1)(−1) (1)(3) + (−1)(−5)
 
3 0
=
0 8

Therefore,
   
−3 3 0
B∼N ,
0 0 8

4
Q2

Q2a)
 
1
1
 
1 to represent the state’s total energy consumption for these major sources.
Let a =  
1
1

Sample mean of a state total’s consumption = aT E(X)


= aT µ
 
0.861
 0.532
 

= 1 1 1 1 1 0.414


0.050
0.137
= 0.861 + 0.532 + 0.414 + 0.050 + 0.137
= 1.994

We will now find the variance of a state’s total energy consumption for these major sources.

Sample variance of a state total’s consumption = aT ΣX a


  
1.365 1.116 0.346 −0.006 0.095 1
 
 1.116
 0.937 0.271 −0.010 0.073  1
  
= 1 1 1 1 1  0.346 0.271 0.202 −0.008 0.033   1
 
−0.006 −0.010 −0.008 0.015 −0.001 1
0.095 0.073 0.033 −0.001 0.018 1
 
1.365 + 1.116 + 0.346 + −0.006 + 0.095
 1.116 + 0.937 + 0.271 + −0.010 + 0.073 
  
= 1 1 1 1 1  0.346 + 0.271 + 0.202 + −0.008 + 0.033 

−0.006 + −0.010 + −0.008 + 0.015 + −0.001
0.095 + 0.073 + 0.033 + −0.001 + 0.018
 
2.916
  2.387 
 

= 1 1 1 1 1  0.844 

−0.01
0.218
= 2.916 + 2.387 + 0.844 + −0.01 + 0.218
= 6.355

5
Q2b)
 
1
−1
 
 0  to represent the excess of petroleum consumption over natural gas consumption.
Let a =  
0
0

Sample mean of excess consumption = aT E(X)


= aT µ
 
0.861
 0.532
 

= 1 −1 0 0 0 0.414


0.050
0.137
= 0.861 − 0.532
= 0.329

We will now compute the variance of the excess of petroleum consumption over natural gas consumption.

Sample variance of a state excess’s consumption = aT ΣX a


  
1.365 1.116 0.346 −0.006 0.095 1
 
 1.116 0.937 0.271 −0.010 0.073  −1
 
= 1 −1 0 0 0  0.346 0.271 0.202 −0.008  0 
0.033   
−0.006 −0.010 −0.008 0.015 −0.001  0 

0.095 0.073 0.033 −0.001 0.018 0
 
1.365 − 1.116
 1.116 − 0.937 
  
= 1 −1 0 0 0  0.346 − 0.271 

−0.006 − −0.010
0.095 − 0.073
 
0.249
 0.179
 

= 1 −1 0 0 0 0.075


0.004
0.022
= 0.249 − 0.179
= 0.07

Sample Covariance = Cov(X1 − X2 , X1 + X2 + X3 + X4 + X5 )


= Cov(X1 , X1 ) + Cov(X1 , X2 ) + Cov(X1 , X3 ) + Cov(X1 , X4 ) + Cov(X1 , X5 )
− Cov(X2 , X1 ) − Cov(X2 , X2 ) − Cov(X2 , X3 ) − Cov(X2 , X4 ) − Cov(X2 , X5 )
= V ar(X1 ) + Cov(X1 , X2 ) − Cov(X1 , X2 ) + Cov(X1 , X3 ) + Cov(X1 , X4 )
+ Cov(X1 , X5 ) − V ar(X2 ) − Cov(X2 , X3 ) − Cov(X2 , X4 ) − Cov(X2 , X5 )
= V ar(X1 ) + Cov(X1 , X3 ) + Cov(X1 , X4 ) + Cov(X1 , X5 )
− V ar(X2 ) − Cov(X2 , X3 ) − Cov(X2 , X4 ) − Cov(X2 , X5 )
= 1.365 + 0.346 + −0.006 + 0.095 − 0.937 − 0.271 − −0.010 − 0.073
= 1.8 − 1.271
= 0.529

6
Q3

Q3a)

We will denote the following hypothesis.


 
1
H0 : µ =
0.5
 
1
H1 : µ ̸=
0.5

Denote the following numbers

n = 60
 
0.8
X̄ =
0.4
 
2 −1
S=
−1 2
 
1
µ0 =
0.5

We will compute the test statistics


   T  −1    
0.8 1 2 −1 0.8 1
n(x̄ − µ0 )T S −1 x̄ − µ0 = 60

− −
0.4 0.5 −1 2 0.4 0.5
 T  −1  
−0.2 2 −1 −0.2
= 60
−0.1 −1 2 −0.1
  
  1 2 1 −0.2
= 60 −0.2 −0.1
3 1 2 −0.1
 
60   2(−0.2) + (1)(−0.1)
= −0.2 −0.1
3 (−0.2) + (−0.2)
 
  −0.5
= 20 −0.2 −0.1
−0.4
= 20(0.14)
= 2.8

critical_value <- qf(0.95, 2, 58)


critical_value

## [1] 3.155932

(60 − 1)(2) (60 − 1)(2)


F0.05 (2, 60 − 2) = (3.155932) = 6.4207
(60 − 2) (60 − 2)

Decision Boundary
(60−1)(2)
Reject H0 if test statistic > (60−2) F0.05 (2, 60 − 2) = 6.4207.

  is less than the 6.4207, we do not reject the H0 . There is insufficient evidence at %5 significance level
Since the test statistic
1
to say that µ = .
0.5

7
Q3b)
n
S= Sn
n−1
n−1
Sn = S
n 
59 2 −1
Sn =
60 −1 2

We will compute the LR test statistic

−2logλ = nTr(Σ0 −1 Sn ) − nlog|Σ0 −1 Sn | − np


        
1 2 0 59 2 −1 1 2 0 59 2 −1
= 60Tr − 60log − (60)(2)
2 0 1 60 −1 2 2 0 1 60 −1 2
      
59 2 0 2 −1 59 2 0 2 −1
= 60Tr − 60log − 120
120 0 1 −1 2 120 0 1 −1 2
    
59 4 −2 59 4 −2
= 60Tr − 60log − 120
120 −1 2 120 −1 2
(60)(59) 59
= (4 + 2) − 60log| ((4)(2) − (−2)(−1))| − 120
120 120
592
= 177 − 60log( |(6)|) − 120
1202
= 177 − 60log(1.450416667) − 120
= 57 − 60log(1.450416667)
= 57 − 22.3110523
= 34.6889477 = 34.689 (5 Significant figures)

critical_value = qchisq(0.05, 3, lower.tail = FALSE)


critical_value

## [1] 7.814728

Decision Boundary
Reject H0 if −2logλ > χ2 0.95 (3) = 7.814728.
Conclusion
Since test statistics = 34.689 > 7.814728, we reject the H0 and conclude that at 5% significance level that there is significant
evidence against Σ = Σ0 .

8
Q4

library(mvtnorm)
mu1 <- c(3,1)
si1 <- matrix(c(4,2,2,9), ncol = 2)
set.seed(4250)
simunorm <- rmvnorm(100, mean = mu1, sigma = si1)
simunorm <- as.data.frame(simunorm)
head(simunorm, n = 5)

## V1 V2
## 1 2.362720 1.962778
## 2 2.621084 1.833044
## 3 7.883012 2.976779
## 4 1.278704 -3.664169
## 5 1.250515 -3.209010

apply(simunorm, 2, mean)

Q4a)

## V1 V2
## 2.9027170 0.9888259

var(simunorm)

## V1 V2
## V1 4.058433 1.293714
## V2 1.293714 9.390347

Obtaining the R output above,


 
2.9027170
X̄ =
0.9888259
 
4.058433 1.293714
S=
1.293714 9.390374
 
3
µ0 =
1

9
T 2 = n(x̄ − µ0 )T S −1 (x̄ − µ0 )
     −1    
2.9027170 3 T 4.058433 1.293714 2.9027170 3
= 100( − ) ( )( − )
0.9888259 1 1.293714 9.390374 0.9888259 1
 T   
−0.097283 1 9.390374 −1.293714 −0.097283
= 100
−0.0111741 (4.058433)(9.390374) − (1.293714)(1.293714) −1.293714 4.058433 −0.0111741
 T   
100 −0.097283 9.390374 −1.293714 −0.097283
=
36.43650781 −0.0111741 −1.293714 4.058433 −0.0111741
  
100   9.390374 −1.293714 −0.097283
= −0.097283 −0.0111741
36.43650781 −1.293714 4.058433 −0.0111741
 
100   (9.390374)(−0.097283) + (−1.293714)(−0.0111741)
= −0.097283 −0.0111741
36.43650781 (−1.293714)(−0.097283) + (4.058433)(−0.0111741)
 
100   −0.8990676642
= −0.097283 −0.0111741
36.43650781 0.08050704288
100
= (−0.097283 × −0.8990676642 + −0.0111741 × 0.08050704288)
36.43650781
100
= (0.08656440583)
36.43650781
= 0.2375760221
= 0.237576 (6 significant figures)

Q4b)

Denote the following hypothesis


 
3
H0 : µ =
1
 
3
H1 : µ ̸=
1

critical_value = qf(0.95, 2,98)


critical_value

## [1] 3.089203

Decision Boundary:
Reject H0 if T 2 > 99(2)
98 F0.05 (2, 98) =
99(2)(3.089203)
98 = 6.2414509.
 
2 3
Since the T = 0.237576 < 6.2414509, we do not reject the null hypothesis. There is insufficient evidence to say that µ ̸= .
1

Q4c)

We will use this formula from Lecture 5 Slide


 5.38.

For the µ1 computation, we will use a = 1 0 ,

critical_value <- qf(0.95, 2, 98)


critical_value

## [1] 3.089203

10
s s
T (n − 1)(p) T T (n − 1)(p)
a X̄ − F1−α (p, n − p)aT Sa ≤ a µ ≤ a X̄ + F1−α (p, n − p)aT Sa
n(n − p) n(n − p)
  s  
  2.9027170 (100 − 1)(2)   1
1 0 − F1−0.05 (2, 100 − 2) 1 0 S ≤ µ1 and
0.9888259 100(100 − 2) 0
  s  
  2.9027170 (100 − 1)(2)   1
1 0 + F1−0.05 (2, 100 − 2) 1 0 S ≥ µ1
0.9888259 100(100 − 2) 0
s   
(99)(2)   4.058433 1.293714 1
2.9027170 − (3.089203) 1 0 ≤ µ1 and
100(98) 1.293714 9.390374 0
s   
(99)(2)   4.058433 1.293714 1
2.9027170 + (3.089203) 1 0 ≥ µ1
100(98) 1.293714 9.390374 0
s   s  
(99)(2)   4.058433 (99)(2)   4.058433
2.9027170 − (3.089203) 1 0 ≤ µ1 ≤ 2.9027170 + (3.089203) 1 0
100(98) 1.293714 100(98) 1.293714
s s
(99)(2) (99)(2)
2.9027170 − (3.089203)(4.058433) ≤ µ1 ≤ 2.9027170 + (3.089203)(4.058433)
100(98) 100(98)
√ √
2.9027170 − 0.2533051054 ≤ µ1 ≤ 2.9027170 + 0.2533051054
2.3994227747 ≤ µ1 ≤ 3.406011253
2.3994 ≤ µ1 ≤ 3.4060 (5 significant figures)

 
For the µ2 computation, we will use a = 0 1 ,
s s
T (n − 1)(p) T T T (n − 1)(p)
a X̄ − F1−α (p, n − p)a Sa ≤ a µ ≤ a X̄ + F1−α (p, n − p)aT Sa
n(n − p) n(n − p)
  s  
  2.9027170 (100 − 1)(2)   0
0 1 − F1−0.05 (2, 100 − 2) 0 1 S ≤ µ2 and
0.9888259 100(100 − 2) 1
  s  
  2.9027170 (100 − 1)(2)   0
0 1 + F1−0.05 (2, 100 − 2) 0 1 S ≥ µ2
0.9888259 100(100 − 2) 1
s   
(99)(2)   4.058433 1.293714 0
0.9888259 − (3.089203) 0 1 ≤ µ2 and
100(98) 1.293714 9.390374 1
s   
(99)(2)   4.058433 1.293714 0
0.9888259 + (3.089203) 0 1 ≥ µ2
100(98) 1.293714 9.390374 1
s   s  
(99)(2)   1.293714 (99)(2)   1.293714
0.9888259 − (3.089203) 0 1 ≤ µ1 ≤ 0.9888259 + (3.089203) 0 1
100(98) 9.390374 100(98) 9.390374
s s
(99)(2) (99)(2)
0.9888259 − (3.089203)(9.390374) ≤ µ2 ≤ 0.9888259 + (3.089203)(9.390374)
100(98) 100(98)
√ √
0.9888259 − 0.2841593301 ≤ µ2 ≤ 0.9888259 + 0.2841593301
0.9888259 − 0.7655688004 ≤ µ2 ≤ 0.9888259 + 0.7655688004
0.2232570996 ≤ µ2 ≤ 1.7543947
0.22326 ≤ µ2 ≤ 1.7544 (5 signficant figures)

11

You might also like