STAT429_sp24_HW03 - Copy
pdf
keyboard_arrow_up
School
University of Illinois, Urbana Champaign *
*We aren’t endorsed by this school
Course
429
Subject
Statistics
Date
Feb 20, 2024
Type
Pages
9
Uploaded by BrigadierAlbatrossPerson860
STAT 429 HW 03
Phillip Nguyen , pnguy6
If you choose to type the answers for this HW, you may find
•
Unless stated otherwise,
{
W
t
}
t
≥
0
is a white noise process with variance
σ
2
w
.
–
(
{
W
t
}
t
≥
0
is a collection of random variables, independent of each other, with zero means and
variance
σ
2
w
.)
•
Show your full work to receive full credit.
Question 1
(a) Simulate a series of
n
= 1000
white noise observations and compute the sample ACF,
ˆ
ρ
w
(
h
)
, to lag
30. Show the code and the ACF plot. What should be the (approximate) variance of
ˆ
ρ
w
(
h
)
(
h
̸
= 0)
?
Compare the sample ACF you obtain to the actual (theoretical) ACF of a white noise,
ρ
w
(
h
)
.
w_a
=
rnorm
(
502
,
0
,
1
)
v_a
=
filter
(w_a,
sides=
2
,
rep
(
1
,
3
)
/
3
)
print
(
acf
(v_a,
20
,
na.action =
na.pass))
1
0
5
10
15
20
0.0
0.2
0.4
0.6
0.8
1.0
Lag
ACF
Series v_a
##
## Autocorrelations of series ’v_a’, by lag
##
##
0
1
2
3
4
5
6
7
8
9
10
##
1.000
0.618
0.265 -0.034
0.055
0.040 -0.044 -0.121 -0.113 -0.062 -0.059
##
11
12
13
14
15
16
17
18
19
20
## -0.077 -0.114 -0.094 -0.098 -0.082 -0.079 -0.055 -0.037 -0.030 -0.010
he ACF of the sample size n = 500 has minimal positive and negative values whereas the theoretical ACF
should be zero. This is due to the noise being added to the signal model with mean 0 and variance 1.
(b) Repeat part (a) using only
n
= 50
. does changing
n
affect the results?
w_b
=
rnorm
(
52
,
0
,
1
)
v_b
=
filter
(w_b,
sides=
2
,
rep
(
1
,
3
)
/
3
)
print
(
acf
(v_b,
20
,
na.action =
na.pass))
2
0
5
10
15
20
-0.2
0.2
0.4
0.6
0.8
1.0
Lag
ACF
Series v_b
##
## Autocorrelations of series ’v_b’, by lag
##
##
0
1
2
3
4
5
6
7
8
9
10
##
1.000
0.602
0.248 -0.225 -0.214 -0.101
0.099
0.033 -0.067 -0.235 -0.131
##
11
12
13
14
15
16
17
18
19
20
## -0.070
0.063 -0.049 -0.149 -0.314 -0.227 -0.141
0.050
0.010 -0.003
The ACF using n = 50 is much farther to zero compared to the ACF using n = 500. From this we can infer
that as we increase the sample size, its ACF becomes closer to the population ACF.
Question 2
Consider the two series
{
X
t
}
t
≥
0
and
{
Y
t
}
t
≥
0
such that
X
t
=
W
t
+ 0
.
5
W
t
−
1
,
Y
t
=
W
t
+
U
t
,
where
{
W
t
}
t
≥
0
and
{
U
t
}
t
≥
0
are independent white noise series with variances
σ
2
w
and
σ
2
u
, respectively.
(a) Is
X
t
and
Y
t
jointly stationary? Why or why not? Show your full work.
3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
We need to check if
X
t
and
Y
t
are jointly stationary by verifying if their means, variances, and autocovariance
functions are time-invariant.
For series
X
t
: Mean:
E
[
X
t
] =
E
[
W
t
+ 0
.
5
W
t
−
1
] =
E
[
W
t
] + 0
.
5
E
[
W
t
−
1
] = 0
(since the mean of a white noise process is zero)
Variance:
Var
(
X
t
) =
Var
(
W
t
+ 0
.
5
W
t
−
1
) =
Var
(
W
t
) + 0
.
25
Var
(
W
t
−
1
)
(since
W
t
and
W
t
−
1
are independent)
=
σ
2
w
+ 0
.
25
σ
2
w
= 1
.
25
σ
2
w
For series
Y
t
: Mean:
E
[
Y
t
] =
E
[
W
t
+
U
t
] =
E
[
W
t
] +
E
[
U
t
] = 0
(since the mean of a white noise process is zero)
Variance:
Var
(
Y
t
) =
Var
(
W
t
+
U
t
) =
Var
(
W
t
) +
Var
(
U
t
)
(since
W
t
and
U
t
are independent)
=
σ
2
w
+
σ
2
u
autocovariance functions for both series:
For series
X
t
:
Cov
(
X
t
, X
t
−
k
) =
Cov
(
W
t
+ 0
.
5
W
t
−
1
, W
t
−
k
+ 0
.
5
W
t
−
k
−
1
)
=
Cov
(
W
t
, W
t
−
k
) + 0
.
5
Cov
(
W
t
−
1
, W
t
−
k
) + 0
.
5
Cov
(
W
t
, W
t
−
k
−
1
) + 0
.
25
Cov
(
W
t
−
1
, W
t
−
k
−
1
)
Since
W
t
and
W
t
−
1
are independent white noise processes, their covariance is zero unless
k
= 1
, in which
case it’s
σ
2
w
. Therefore,
Cov
(
X
t
, X
t
−
k
) =
σ
2
w
for
k
= 1
0
otherwise
For series
Y
t
:
Cov
(
Y
t
, Y
t
−
k
) =
Cov
(
W
t
+
U
t
, W
t
−
k
+
U
t
−
k
)
=
Cov
(
W
t
, W
t
−
k
) +
Cov
(
W
t
, U
t
−
k
) +
Cov
(
U
t
, W
t
−
k
) +
Cov
(
U
t
, U
t
−
k
)
Since
W
t
and
U
t
are independent white noise processes, their covariance is zero. Therefore,
Cov
(
Y
t
, Y
t
−
k
) =
σ
2
w
for
k
= 0
0
otherwise
Since the autocovariance function for series
X
t
depends on the lag
k
, it is not time-invariant. However, the
autocovariance function for series
Y
t
is time-invariant.
Thus,
X
t
is not jointly stationary with
Y
t
due to the time-varying autocovariance function.
(b) Compute the CCF (cross-correlation function) of relating
{
X
t
}
t
≥
0
and
{
Y
t
}
t
≥
0
.
4
To compute the cross-correlation function (CCF) between the series
{
X
t
}
and
{
Y
t
}
, we need to find the
correlation between each pair of corresponding observations at different lags. The CCF at lag
k
is given by:
CCF
(
k
) =
Cov
(
X
t
, Y
t
−
k
)
qqqqqqq
Var
(
X
t
)
·
Var
(
Y
t
−
k
)
Given that the series are jointly stationary, the covariance between
X
t
and
Y
t
−
k
will depend only on the lag
k
, and the variances of
X
t
and
Y
t
−
k
will remain constant.
We already have expressions for the covariance and variances:
For series
X
t
: Mean:
E
[
X
t
] = 0
Variance: Var
(
X
t
) = 1
.
25
σ
2
w
For series
Y
t
: Mean:
E
[
Y
t
] = 0
Variance: Var
(
Y
t
) =
σ
2
w
+
σ
2
u
Now, let’s compute the cross-correlation function for different lags
k
:
For
k
= 0
:
CCF
(0) =
Cov
(
X
t
, Y
t
)
qqqqqqq
Var
(
X
t
)
·
Var
(
Y
t
)
For
k
= 1
:
CCF
(1) =
Cov
(
X
t
, Y
t
−
1
)
qqqqqqq
Var
(
X
t
)
·
Var
(
Y
t
−
1
)
For
k >
1
, Cov
(
X
t
, Y
t
−
k
) = 0
because the processes are independent.
Thus, the CCF is given by:
CCF
(0) =
σ
2
w
qqqqqqq
1
.
25
σ
2
w
·
(
σ
2
w
+
σ
2
u
)
CCF
(1) =
σ
2
w
qqqqqqq
1
.
25
σ
2
w
·
σ
2
w
CCF
(
k
) = 0
,
for
k >
1
5
Question 3
Consider the two series
{
X
t
}
t
≥
0
and
{
Y
t
}
t
≥
0
:
X
t
=
W
t
Y
t
=
W
t
−
1
+
U
t
,
{
W
t
}
t
≥
0
and
{
U
t
}
t
≥
0
are independent white noise series with variances
σ
2
w
and
σ
2
u
, respectively.
(a) Is there any lagging/leading relationship between
{
X
t
}
t
≥
0
and
{
Y
t
}
t
≥
0
? If so, which one is leading?
Yes, there is a lagging relationship between {Xt}t>=0 and {Yt}t>=0. Since Yt depends on Wt-1, it can be
considered as lagging behind Xt. Specifically, Yt is lagged by one time period compared to Xt, as it depends
on the previous value of the white noise process Wt.
(b) Compute the CCF (cross-correlation function) relating
{
X
t
}
t
≥
0
and
{
Y
t
}
t
≥
0
.
To compute the cross-correlation function (CCF) between {Xt}t>=0 and {Yt}t>=0, we need to calculate
the correlation between Xt and Yt for various lags. Let’s denote the lag by k. Then the CCF is given by:
CCF
(
k
) =
Cov
(
X
t
, Y
t
−
k
)
qqqqqqq
Var
(
X
t
)
·
Var
(
Y
t
−
k
)
For lag k = 0:
CCF
(0) =
σ
2
w
qqqqqqq
σ
2
w
·
(
σ
2
w
+
σ
2
u
)
For lag k = 1:
CCF
(1) =
σ
2
w
qqqqqqq
σ
2
w
·
(
σ
2
w
+
σ
2
u
)
For lag k > 1, the covariance becomes 0 because Wt and Ut are independent white noise series.
(c) Using the random seed 429, generate
{
X
t
}
t
=1
,...,
500
and
{
Y
t
}
t
=1
,...,
500
and create a plot for sample CCF
and compare with your answer in (b).
# Seed
set.seed
(
429
)
# Parameters
sigma_w
<-
1
# Var of Wn series Wt
sigma_u
<-
1
# Var of Wn series Ut
T
<-
500
W
<-
rnorm
(T
+
1
,
mean =
0
,
sd =
sqrt
(sigma_w))
U
<-
rnorm
(T,
mean =
0
,
sd =
sqrt
(sigma_u))
6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
X
<-
W[
2
:
(T
+
1
)]
# Xt = Wt
Y
<-
W[
1
:
T]
+
U
# Yt = Wt-1 + Ut
ccf_result
<-
ccf
(X, Y,
plot =
FALSE
)
plot
(ccf_result,
main =
"Sample Cross-Correlation Function (CCF)"
,
xlab =
"Lag"
,
ylab =
"CCF"
)
grid
()
-20
-10
0
10
20
0.0
0.2
0.4
0.6
Lag
CCF
Sample Cross-Correlation Function (CCF)
Question 4
(a) Using R, create your own function that computes ACF (auto-correlation function). You may not use
built-in functions like
acf
,
acf1
, or
acf2
.
acf_my_function
<-
function
(ts,maxh){
#function content goes here
#ts: time series data, maxh: maximum h value
#final line of the function should return the vector of size maxh,
#containing acf values, c(rho(1), ..., rho(maxh)).
n
<-
length
(ts)
acf_values
<-
numeric
(maxh)
for
(h
in
1
:
maxh) {
ts_shifted
<-
ts[h
:
n]
ts_original
<-
ts[
1
:
(n
-
h
+
1
)]
7
acf_values[h]
<-
cor
(ts_original, ts_shifted)
}
return
(acf_values)
}
(b) Compute the acf of
soi
series of
astsa
package using your own function in (4a). Check your answer
using
acf1
function of
astsa
package.
library
(astsa)
## Warning: package ’astsa’ was built under R version 4.3.2
# Load the SOI data
data
(soi)
# Compute ACF using custom function
acf_custom
<-
acf_my_function
(soi,
30
)
# Compute ACF using acf1 function
acf_astsa
<-
acf1
(soi,
30
)
0.0
0.5
1.0
1.5
2.0
2.5
-0.4
-0.2
0.0
0.2
0.4
0.6
0.8
Series: soi
LAG ÷ 12
ACF
8
# Check if results are the same
print
(acf_custom[
-
1
])
##
[1]
0.60450492
0.37438813
0.21491430
0.05047225 -0.10773689 -0.18836953
##
[7] -0.17651708 -0.09740931
0.04992764
0.22515857
0.36632062
0.41214817
## [13]
0.31613919
0.10604719 -0.05975919 -0.17877725 -0.29944433 -0.37887324
## [19] -0.32924618 -0.19947183 -0.04054139
0.14952966
0.31585614
0.35763929
## [25]
0.26320156
0.09925493 -0.03355475 -0.16587211 -0.29107394
print
(acf_astsa)
##
[1]
0.60
0.37
0.21
0.05 -0.11 -0.19 -0.18 -0.10
0.05
0.22
0.36
0.41
## [13]
0.31
0.10 -0.06 -0.17 -0.29 -0.37 -0.32 -0.19 -0.04
0.15
0.31
0.35
## [25]
0.25
0.10 -0.03 -0.16 -0.28 -0.37
My functions performs pretty well in comparison to acf1 function but there seems to be more rounding as
my function takes 8 decimal places as the acf1 function take up to 2 decimal places.
9
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Documents
Recommended textbooks for you
Holt Mcdougal Larson Pre-algebra: Student Edition...
Algebra
ISBN:9780547587776
Author:HOLT MCDOUGAL
Publisher:HOLT MCDOUGAL
Algebra & Trigonometry with Analytic Geometry
Algebra
ISBN:9781133382119
Author:Swokowski
Publisher:Cengage
Recommended textbooks for you
- Holt Mcdougal Larson Pre-algebra: Student Edition...AlgebraISBN:9780547587776Author:HOLT MCDOUGALPublisher:HOLT MCDOUGALAlgebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:Cengage
Holt Mcdougal Larson Pre-algebra: Student Edition...
Algebra
ISBN:9780547587776
Author:HOLT MCDOUGAL
Publisher:HOLT MCDOUGAL
Algebra & Trigonometry with Analytic Geometry
Algebra
ISBN:9781133382119
Author:Swokowski
Publisher:Cengage