-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathMultivariateAnalysisPart2Summary.Rnw
3975 lines (2911 loc) · 96.2 KB
/
MultivariateAnalysisPart2Summary.Rnw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[12pt]{article}
%\usepackage[landscape]{geometry}
\usepackage[landscape,hmargin=2cm,vmargin=1.5cm,headsep=0cm]{geometry}
% See geometry.pdf to learn the layout options. There are lots.
\geometry{a4paper} % ... or a4paper or a5paper or ...
%\geometry{landscape} % Activate for for rotated page geometry
%\usepackage[parfill]{parskip} % Activate to begin paragraphs with an empty line rather than an indent
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{epstopdf}
\usepackage{framed}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage{float}
\setkeys{Gin}{width=0.25\textwidth}
\usepackage[table]{xcolor}
\newcommand\x{\times}
\newcommand\y{\cellcolor{green!10}}
\newcommand{\pder}[2][]{\frac{\partial#1}{\partial#2}}
\newcommand{\argmin}{\arg\!\min}
\newcommand{\argmax}{\arg\!\max}
\newtheorem{definition}{Definition}
\newtheorem{theorem}{Theorem}
\newtheorem{fact}{Fact}
\newtheorem{proposition}{Proposition}
% Turn off header and footer
\pagestyle{plain}
% Redefine section commands to use less space
\makeatletter
\renewcommand{\section}{\@startsection{section}{1}{0mm}%
{-1ex plus -.5ex minus -.2ex}%
{0.5ex plus .2ex}%x
{\normalfont\large\bfseries}}
\renewcommand{\subsection}{\@startsection{subsection}{2}{0mm}%
{-1explus -.5ex minus -.2ex}%
{0.5ex plus .2ex}%
{\normalfont\normalsize\bfseries}}
\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0mm}%
{-1ex plus -.5ex minus -.2ex}%
{1ex plus .2ex}%
{\normalfont\small\bfseries}}
\makeatother
% Define BibTeX command
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
% Don't print section numbers
%\setcounter{secnumdepth}{0}
\newcommand{\eps}{\epsilon}
\newcommand{\al}{\alpha}
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt plus 0.5ex}
\usepackage{Sweave}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}
\usepackage{cancel}
%% taken from http://brunoj.wordpress.com/2009/10/08/latex-the-framed-minipage/
\newsavebox{\fmbox}
\newenvironment{fmpage}[1]
{\begin{lrbox}{\fmbox}\begin{minipage}{#1}}
{\end{minipage}\end{lrbox}\fbox{\usebox{\fmbox}}}
\usepackage{mathtools}
\makeatletter
\newcommand{\explain}[2]{\underset{\mathclap{\overset{\uparrow}{#2}}}{#1}}
\newcommand{\explainup}[2]{\overset{\mathclap{\underset{\downarrow}{#2}}}{#1}}
\makeatother
\SweaveOpts{prefix.string=MatAlgfigs/MatAlgfig}
\SweaveOpts{cache=TRUE}
\title{Multivariate Analysis Summary Sheet (Part 2)}
\author{Shravan Vasishth ([email protected])}
\date{\today} % Activate to display a given date or no date
\newcommand\myfigure[1]{%
\medskip\noindent\begin{minipage}{\columnwidth}
\centering%
#1%
%figure,caption, and label go here
\end{minipage}\medskip}
\begin{document}
\SweaveOpts{concordance=TRUE}
\footnotesize
\maketitle
\tableofcontents
\newpage
\begin{multicols}{2}
\section{Preliminaries}
\subsection{Arithmetic series}
General form:
\begin{equation}
a+(a+d)+(a+2d)+\dots
\end{equation}
$k$-th partial sum for \textbf{arithmetic series}:
\begin{equation}
S_k = \underset{n=1}{\overset{k}{\sum}} (a+(n-1)d)
\end{equation}
The sum can be found by:
\begin{equation}
S_k = \frac{k}{2} (2a+(k-1)d)
\end{equation}
\subsection{Geometric series}
General form:
\begin{equation}
a+ar+ar^2\dots
\end{equation}
In summation notation:
\begin{equation}
\underset{n=1}{\overset{\infty}{\sum}} ar^{n-1}
\end{equation}
$k$-th partial sum:
\begin{equation}
S_k=\frac{a-(1-r^k)}{1-r}
\end{equation}
$S_\infty$ exists just in case $\mid r \mid < 1$.
\begin{equation}
S_\infty = \frac{a}{1-r}
\end{equation}
\subsection{Some basic results for computing covariance}
\begin{enumerate}
\item
Let $\bar{x}_i$ be vectors:
\begin{equation}
Var(\bar{x}_1 - \bar{x}_2) = var(\bar{x}_1) + var(\bar{x}_2) - 2 Cov(\bar{x}_1,\bar{x}_2)
\end{equation}
Note that $Cov(\bar{x}_1,\bar{x}_2)$ would be the matrix
$$
\begin{pmatrix}
Cov(x_1) & 0 \\
0 & Cov(x_2)\\
\end{pmatrix}
$$
where $Cov(x_1)$ is the covariance between the \textit{components} of $x_1$.
\item The sum of two RVs:
\begin{equation}
Var(X_1 + X_2) = var(X_1) + var(X_2) + 2 Cov(X_1,X_2)
\end{equation}
More generally:
\begin{equation}
Var(aX_1 + bX_2) = a^2 var(X_1) + b^2 var(X_2) + 2ab Cov(X_1,X_2)
\end{equation}
This generalizes to arbitrary numbers of terms:
\begin{equation}
Var(aX_1 + bX_2+cX_3) = a^2 var(X_1) + b^2 var(X_2) + 2ab Cov(X_1,X_2) +
2ac Cov(X_1,X_3) + 2bc Cov(X_2,X_3)
\end{equation}
\item Covariance of X and Y:
\begin{equation}
Cov(X,Y)=E[XY]-E[X]E[Y]
\end{equation}
\begin{equation}
Cov(aX+b,Y)= aCov(X,Y)
\end{equation}
\begin{equation}
Cov(aX+bY+cZ,W)= Cov(aX,W)+Cov(bY,W)+Cov(cZ,W)
\end{equation}
\end{enumerate}
\subsection{Completing the square: complex numbers}
Completing the square: $\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$
Often, we have imaginary numbers involved. Recall that $i^2 = \sqrt{-1}$. So we will often have roots with a real and complex part:
$4 + \sqrt{-25}= 4 + 5\sqrt{-1}=4 + 5i$. In the TS context, we need to know if the roots lie outside the unit circle; with imaginary components, we can determine this by simply computing the length of the vector:
$\sqrt{4^2 + 5^2}=6.4$.
\section{Time Series}
\subsection{Smoothing: Moving averages (MAs)} \label{movavg}
At each time point t, take the average of the observations around t, and plot
\begin{equation}
\frac{1}{2q+1} \sum_{i=-q}^q y_{t+i}\hbox{ against } t
\end{equation}
where $y_t$ is the observation at time $t$.
\textbf{The span} of the MA is the number of values averaged over.
\subsubsection{Linear filter: More general instance of MA (Weighting)}
Taking a moving average amounts to weighting each $y_t$ by 1/span:
\begin{equation}
x_i = \sum a_i y_{t+1} \hbox{ against } t \quad \sum a_i = 1
\end{equation}
The moving average is the special case where
\begin{equation}
a_i=
\begin{cases}
\frac{1}{2q+1} & \hbox{ if } \mid i \mid \leq q \\
0 & \hbox{otherwise}\\
\end{cases}
\end{equation}
A plausible weight be a=1/12 for monthly measurements, 1/4 for quarters.
Suppose we take a mean at $x=3$: $X_3'=\frac{y_1+y_2+y_3+y_4}{4}$, and then another one $X_3''=\frac{y_2+y_3+y_4+y_5}{4}$.
We could take a mean of these two means:
\begin{equation}
\begin{split}
\frac{1}{2}(X_3'+X_3'') =& \frac{1}{2}(\frac{y_1+y_2+y_3+y_4}{4}+
\frac{y_2+y_3+y_4+y_5}{4})\\
=& \frac{y_1}{8} + \frac{y_2+y_3+y_4}{4}+\frac{y_5}{8}
\end{split}
\end{equation}
The general formula is:
\begin{equation}
x_t = \frac{y_{t-2}}{8}
+
\frac{y_{t-1} + y_t + y_{t+1}}{4}
+
\frac{y_{t+2}}{8}
\end{equation}
to-do: Add examples from problems
\paragraph{Detrending using moving averages}
<<>>=
library(astsa)
library(MASS)
data(jj)
## moving average:
k = c(.5,1,1,1,.5)
(k = k/sum(k))
## weights:
fractions(k)
fjj = filter(jj, sides=2, k)
plot(jj)
## filtered MA:
lines(fjj, col="red")
@
<<>>=
## detrending using MA:
plot(jj-fjj)
@
%\subsubsection{Linear and polynomial estimates of trend}
\subsection{The classical decomposition}
\begin{equation}
\begin{split}
y_t =& m_t + s_t + r_t\\
=& \hbox{trend} + \hbox{seasonal/cyclic} + \hbox{residual/random}
\end{split}
\end{equation}
The trend is computed by $m_t$. We can \textbf{detrend} the
time series. $m_t$ is estimated from $\hat m_t$.
\begin{equation}
d_t = y-\hat m_t \approx s_t + r_t
\end{equation}
This is the detrending example shown above with R.
Take logs for multiplicative relationships to get back into linear space:
\begin{equation}
y_t = m_t \times s_t \times r_t
\end{equation}
The decomposition can be done in R as follows:
<<>>=
#str(decompose(jj))
@
Decomposition is useful because:
\begin{enumerate}
\item You can isolate specific components
\item Allows seasonal adjustment (done for monthly economic series and unemployment figures)
\begin{equation}
y-\hat s_t \approx m_t + r_t
\end{equation}
\item
Poor model performance in one component (trend,
seasonality) can be rectified in isolation.
\end{enumerate}
\subsection{Differencing}
\subsubsection{First-order differerencing}
This provides a simple method of removing trend, without explicitly estimating it.
\begin{equation}
\nabla y_t = y_t - y_{t-1}
\end{equation}
Define an operator $B$, called a
\textbf{backward shift operator}:
\begin{framed}
\begin{equation}
B y_t = y_{t-1}
\end{equation}
\end{framed}
This allows us to rewrite
\begin{equation}
\begin{split}
\nabla y_t =& y_t - y_{t-1}\\
=& y_t - B y_t\\
=& (1- B) y_t\\
\end{split}
\end{equation}
So what we have is \textbf{first-order differencing}, which removes linear trend:
\begin{equation}
\nabla y_t = (1- B) y_t
\end{equation}
<<>>=
## removes linear trend:
#plot(diff(jj))
@
\subsubsection{Second-order differencing}
Note that $By_t = y_{t-1}$, and $B^2 y_t = y_{t-2}$.
The power on B is telling you the lag.
\begin{equation}
\begin{split}
\nabla^2 y_t =& (y_t - y_{t-1}) - (y_{t-1} - y_{t-2})\\
=& y_t - 2y_{t-1} + y_{t-2}\\
=& (1-B)^2 y_t\\
\end{split}
\end{equation}
The last line holds because
\begin{equation}
\begin{split}
(1-B)^2 y_t =& (1 - 2B + B^2) y_t\\
=& y_t - 2B y_y + B^2 y_t\\
=& y_t - y_{t-1} - y_{t-1} + y_{t-2}
\end{split}
\end{equation}
Second-order differening removes polynomial trend.
\subsubsection{k-th order differencing}
%\begin{framed}
\begin{equation}
\nabla^k y_t = (1-B)^k y_t
\end{equation}
%\end{framed}
\noindent
removes k-th degree polynomial trend. Usually, k=1 or
k=2 is enough. Not really practical with k=2 or 3.
``First-, second-, \dots, k-th order differencing are
sometimes called \textbf{ordinary differencing}''.
\subsubsection{Seasonal differencing}
If there is \textbf{seasonal variation} with known
cyclicity k, the
period can be removed by doing a k-order differencing (Note: subscript on $\nabla$):
\begin{equation}
y_t - y_{t-12}=\nabla_{12} y_t = (1-B^{12}) y_t
\end{equation}
For k=12, we say \textbf{this is differencing with lag 12}, or seasonal differencing if monthly series are involved.
\paragraph{Exercise (Task 3)}: Show $\nabla \nabla_{12} = \nabla_{12}\nabla$, and interpret.
This first removes linear trend, then seasonal trend.
\begin{equation}
\begin{split}
\nabla \nabla_{12} y_t =& \nabla (y_t - y_{12})\\
=& \nabla y_t -\nabla y_{12}\\
=& (y_t- y_{t-1}) - (y_{t-12}- y_{t-12-1}) \\
=& (y_t- y_{t-12}) - (y_{t-1}- y_{t-1-12})\\
=& \nabla_{12} y_t - \nabla_{12} y_{t-1} \\
=& \nabla_{12} (y_t - y_{t-1})\\
=& \nabla_{12} \nabla y_t \\
=& \nabla_{12}(1-B)y_t=(1-B)\nabla_{12}y_t\\
=& (1-B)(1-B^{12})y_t\\
\end{split}
\end{equation}
\subsubsection{Summary}
So, there is k-th order differencing and differencing with lag:
\begin{enumerate}
\item
k-th order diff: $\nabla^{k} y_t=(1-B)^k y_t$
\item
diff with lag k: $\nabla_{k} y_t=(1-B^k) y_t = y_t - y_{t-k}$
\end{enumerate}
to-do: Need to improve code examples below:
<<echo=FALSE>>=
dir<-"/Users/shravanvasishth/Dropbox/MScStatistics/2014-2015/MAS6011/Semester2/Data/"
whisk<-read.table(paste(dir,"Whisk.txt",
sep=""))
whisk_ts<-ts(whisk,start=c(1980),end=1987,
frequency=12)
@
<<fig=FALSE>>=
ts.plot(whisk_ts,
ylab="hectoliters of whiskey
per month",
xlab="month")
@
Another example:
<<>>=
sheftempq<-scan(paste(dir,"Sheftemq.txt",
sep=""))
shef_ts<-ts(sheftempq,start=c(1963),end=1978,
frequency=4)
ts.plot(shef_ts,ylab="temp.",
xlab="quarter")
@
The decompose function:
<<>>=
whisk_ts_decomp<-decompose(whisk_ts)
#str(whisk_ts_decomp)
@
<<fig=FALSE>>=
op<-par(mfrow=c(1,3),pty="s")
plot(whisk_ts_decomp$seasonal)
plot(whisk_ts_decomp$trend)
plot(whisk_ts_decomp$random)
@
<<>>=
diffts<-diff(whisk_ts,lag=12)
plot(diffts)
@
\subsection{Auto-correlation function (ACF)}
ACF is not really a function, it's a sequence. It's a tool for
detecting patterns in data. For each lag h, we compute the standard correlation
coefficient.
\paragraph{Classical correlation} Suppose we have random variables
X, Y. Then, correlation is:
\begin{equation}
r = \frac{\sum (X_i - \bar{X})(Y_i - \bar{Y})}{
\sqrt{\sum (X_i - \bar{X})^2 \sum (Y_i - \bar{Y})^2} }
\end{equation}
Assuming that $y_t$ is stationary (h is the lag of the ACF), the correlation for each lag h is computed as follows:
\begin{equation}
r_h = \frac{\sum_{t=1}^{n-h} (Y_{t} - \bar{Y})(Y_{t+h} - \bar{Y})}{
\sqrt{\sum_{t=1}^{n} (Y_t - \bar{Y})^2 \sum_{t=1}^{n-h} (Y_{t+h} -
\bar{Y})^2}}
\end{equation}
<<fig=FALSE>>=
dljj <- diff(log(jj))
plot(dljj)
## correlation structure:
## dljj(t-lag) vs dljj(t)
lag.plot(dljj, 9, do.lines=FALSE)
lag1.plot(dljj, 9) ## astsa
acf(dljj)
@
The \textbf{sample ACF} is: $h \mapsto r_h$, and the plot is called a
\textbf{correlogram}. The plot is only made for $h\geq 1$. The correlation at h=0 is by definition 1.
<<fig=FALSE>>=
acf(whisk_ts)
@
\section{Probability models for stationarity and non-stationary time series}
General strategy:
\begin{enumerate}
\item
Plot series, note features
\item
Remove trend and seasonal components
\item
Choose a model to fit the residuals
\item
To forecast, forecast the residuals, then invert transformations (put back trend and seasonal components) to get forecast of the original series.
\end{enumerate}
The convention usually is $Y_1,\dots, Y_n$ are random variables; and $y_1,\dots, y_n$ are realizations of their values. In these notes, $y_i$ can refer to both the RV and the realization, depending on context. E.g., when we say $E[y_t]$, this refers to the RV, and $y_t=6$ refers to a realization.
\subsection{Strong stationarity}
This occurs when the \textbf{joint} distribution $y_{t_1},\dots,y_{t_k}$ is the same
as that of $y_{t_{1+s}},\dots,y_{t_{k+s}}$, for any $s, k, t_1, \dots, t_k$.
The probability properties of the sequence don't change over time.
$y_t$ has the same distribution as $y_{t+s}$.
Consequences:
\begin{enumerate}
\item
$\mu_t = E[y_t] = E[y_{t+s}] = \mu_{t+s}=\mu$
\item
$\sigma_t^2 = Var(y_t) = Var(y_{t+s}) = \sigma_{t+s}^2=\sigma^2$
\item
Covariance function (function only of $h$): $\gamma_h = Cov(y_t, y_{t+h}) = Cov(y_{t+s}, y_{t+h+s})$. $\gamma_h$ is the covariance function at lag $h$.
Note that knowing $\gamma_h$ for all $h$ tells us what the variance $\sigma^2$ is too, since $\gamma_0=\sigma^2$.
\end{enumerate}
\subsection{Weak or second-order stationarity}
The means, variances, and covariances are finite, and the following hold:
\begin{enumerate}
\item
$E[y_t] = \mu$
\item
$Var(y_t) = \sigma^2$
\item
$Cov(y_t,y_{t+h}) = \gamma_h$
\end{enumerate}
whatever the value of t.
Whenever we say stationarity, we mean weak stationarity.
\subsubsection{Practical implication of weak stationarity}
Stationarity helps us compute $E[y_t]$ and $Var(y_t)$. This also illustrates how to compute expectation and variance in a fairly complicated setting.
If you have a model like $y_t = 19 - \frac{1}{3}B y_t - \frac{1}{4}B^2 y_t + \epsilon_t-\frac{1}{2}\epsilon_{t-1}$, if you can prove causality, you have stationarity, and therefore you can compute $E[y_t]$ by solving for $\mu$ in
$E[y_t]=\mu = 19 - \frac{1}{3}\mu - \frac{1}{4}\mu$
Similarly, if $y_t$ is proved to be stationary, it's variance is
$Var(y_t) = V = Var(19 - \frac{1}{3}y_t - \frac{1}{4}y_{t-1} + \epsilon_t - \frac{1}{2}\epsilon_{t-1})$.
This can be solved using the formula:
$Var(aX + bY + cZ) = a^2 Var(X) + b^2 Var(Y) + c^2 Var(Z) + 2abCov(X,Y)+2acCov(X,Z) + 2bc Cov(Y,Z)$.
Notice that almost all covariances will be zero, except $Cov(y_{t-1},\epsilon_{t-1})=Cov(y_{t},\epsilon_{t})$ due to stationarity. Since the \textbf{random variables} $y_{t}=\epsilon_{t}$,
$Cov(y_{t},\epsilon_{t})=Var(\epsilon_{t})$.
Another covariance that is non-zero is $Cov(y_t,y_{t-1})$. Just expand $y_t$, and multiply each term in the expansion with $y_{t-1}$:
Since
$y_t = 19 - \frac{1}{3}B y_t - \frac{1}{4}B^2 y_t + \epsilon_t-\frac{1}{2}\epsilon_{t-1}$
we get
$Cov(19, y_{t-1}) + Cov(-\frac{1}{3}B y_t, y_{t-1}) + Cov(- \frac{1}{4}B^2 y_t, y_{t-1}) + Cov(\epsilon_t, y_{t-1})+
Cov(-\frac{1}{2}\epsilon_{t-1}, y_{t-1})$.
The second term, $Cov(-\frac{1}{3}B y_t, y_{t-1})$ requires another expansion of $y_t$.
\underline{Important insight with stationary processes}
Note that
\begin{equation}
Cov(y_{t-1},y_{t-2})=Cov(y_{t},y_{t-1})
\end{equation}
A further trick: to compute such covariances, assume that $Var(y_t)=Var(y_{t-1})=V$, and then expand only the first term. For example:
\begin{equation}
y_t = \frac{1}{3}y_{t-1} - \frac{1}{4}y_{t-2} + \epsilon_t
\end{equation}
Then:
\begin{equation}
Cov(y_{t-1},y_{t-2})=Cov(y_{t-},y_{t-1})
\end{equation}
See review questions 2.
\subsection{(Theoretical) ACF $\rho_h$}
This is the theoretical analog of the sample ACF.
For a weakly stationary process:
\begin{equation}
\rho_h = Cor(y_t,y_{t+h}) =
\frac{Cov(y_t,y_{t+h})}{\sqrt{Var(y_t) Var(y_{t+h})}} = \frac{\gamma_h}{\gamma_0}
\end{equation}
Note that $h=0, \pm 1,\dots$.
$\rho_h$ has the properties:
\begin{enumerate}
\item
$-1\leq \rho_h \leq 1$
\item
$\rho_h = \rho_{-h}$
\item
$\rho_0=1$
\item
$\rho_h=0$ if $y_t$ and $y_{t+h}$ independent.
Note: if $\rho_h=0$, this does not entail $y_t$ and $y_{t+h}$ independent unless both are normally distributed variables.
\end{enumerate}
\subsection{Purely random series (white noise, WN)}
This is a very important example of a stationary process. It's called white noise because, like with white light, all frequencies enter equally.
Such a sequence is called a white noise sequence:
\begin{equation}
y_t = \eps_t \quad E[\eps_t] = 0, Var( \eps_t) = \sigma^2
\end{equation}
$\rho_h=1$ for $h=0$, and 0 otherwise.
\subsubsection{Example of stationary process: A moving average}
See p.\ 14 of Cryer et al book.
\subsubsection{Example of non-stationary process: Random walk}
Examples: stock prices and Brownian motion.
Not stationary because of non-constant variance, and covariance function $\gamma_{t,s}=t\sigma^2$ does not depend on time lag.
Let $e_1,e_2,\dots$ be an iid sequence of RVs, mean zero and variance $\sigma^2$.
We can write:
\begin{equation}
y_t = y_{t-1} + e_1 = e_1 + \dots+e_t
\end{equation}
\begin{enumerate}
\item $E[y_t] = 0$
\item $Var(y_t) = t\sigma^2$
\item Covariance function. Assume without loss of generality that $1\leq t \leq s$.
Then:
\begin{equation}
\begin{split}
\gamma_{t,s}=&Cov(y_t,y_s) \\
=& Cov(e_1+\dots+e_t,e_1+\dots+e_s)\\
=& Cov(\sum_{i=1}^{t}e_i,\sum_{j=1}^{s}e_j)\\
\end{split}
\end{equation}
If $i\neq j$, then 0, else if $i=j$, it is $Var(e_i)=\sigma^2$.
Since $1\leq t \leq s$, there are t such cases, so
\begin{equation}
\gamma_{t,s}=t \sigma^2
\end{equation}
Note also that
\begin{equation}
\gamma_{s,s}=s \sigma^2 \quad \gamma_{t,t}=t \sigma^2
\end{equation}
\item
The ACF:
\begin{equation}
%% was incorrectly written as \gamma_{t,s}
\rho_s =
=\frac{\gamma_{t,s}}{\sqrt{\gamma_{t,t}\gamma_{s,s}}}=\frac{t \sigma^2}{\sqrt{t}\sqrt{s}\sigma^2}= \sqrt{\frac{t}{s}}
\end{equation}
\end{enumerate}
\textbf{Interesting observation in Cryer and Chan p 14}:
Note that in the plot below that even though the theoretical mean is 0 for all time points, the fact that variance increases with time and that neighboring values have correlation nearly 1 means that we should expect long excursions of the process away from the mean of zero.
<<>>=
ys<-rep(NA,1000)
for(i in 1:1000){
if (i==1){ys[i]<-rnorm(1)} else{
ys[i]<-ys[i-1]+rnorm(1)
}
}
plot(1:1000,ys,type="l")
@
Note that differencing: $\nabla y_t = y_t - y_{t-1}$ will make it stationary. See below.
\subsection{Autoregressive (AR) models}
This is the definition of an AR(p) sequence:
\begin{equation}
y_t = a_1y_{t-1} +a_2y_{t-2} +\dots+a_py_{t-p} + \eps_t
\end{equation}
$E[\eps_t] = 0, Var( \eps_t) = \sigma^2, \eps_t \sim WN(0,\sigma^2)$.
\paragraph{Example: Unemployment Figures}
\begin{itemize}
\item
$U_t$: the unemployment total at time t.
\item
$1-\alpha$: proportion who find a job before the next month. So $\alpha$ is proportion unemployed in next month.
\item
Then, $U_t$: people unemployed from last month plus people unemployed this month:
$U_t=\alpha U_{t-1} + \eta_t $
\item If $E[U_t]=\mu$ for all t, then, if we subtract $\mu$ from both sides:
\begin{equation}
U_t - \mu = \alpha U_{t-1} -\mu + \eta_t
\end{equation}
and then add $\alpha \mu - \alpha \mu$ to the RHS:
\begin{equation}
U_t - \mu = \alpha U_{t-1} -\mu + \eta_t + (\alpha \mu - \alpha \mu)
\end{equation}
Rearranging terms and collecting common terms together:
\begin{equation}
U_t - \mu= \alpha( U_{t-1} - \mu)+ (\alpha -1)\mu + \eta_t
\end{equation}
Setting $y_t = U_{t} - \mu$,
and $y_{t-1} = U_{t-1} - \mu$, and
$\eps_t = (\alpha-1)\mu + \eta_t$,
we can write:
\begin{equation}
y_t= \alpha y_{t-1}+ \eps_t
\end{equation}
\item
Two conditions that must be satisfied:
\begin{itemize}
\item
$E[y_t]=(\alpha-1)\mu+E[\eta_t] = 0$
\item
$E[\eps_t]=0, Var(\eps_t)=\sigma^2$
\end{itemize}
\end{itemize}
\subsubsection{AR(1)}
This is the special case where we regress only on the previous value:
\begin{equation}
y_t= \alpha y_{t-1}+ \eps_t \quad \eps_t \sim WN(0,\sigma^2)
\end{equation}
We can use the backward shift operator (a functional: a function that takes a function as an argument) B, to express AR(1).
By convention, we let $B^0 y_t = 1$. This allows us to write, more generally:
\begin{equation}
%By_t = y_{t-1} \quad \hbox{ or }
B^{i}y_t = y_{t-i}, i=1,\dots,t, 0 \leq i \leq t
\end{equation}
Then, we can write
\begin{equation}
y_t= \alpha y_{t-1}+ \eps_t
\end{equation}
as
\begin{equation}
y_t= \alpha By_t+ \eps_t
\end{equation}
Rearranging to get $\eps_t$ on RHS:
\begin{equation}
y_t - \alpha By_t= \eps_t \Rightarrow y_t(1 - \alpha B)= \eps_t
\end{equation}
\begin{equation}
\phi(B)y_t = \eps_t \quad \phi(B)=(1 - \alpha B)
\end{equation}
Here, $\phi(B)$ is a polynomial of degree one (a linear function of B).
We can express $y_t$ as follows:
\begin{equation}
y_t = \phi(B)^{-1}\eps_t \quad \phi(B)=(1 - \alpha B)
\end{equation}
\begin{framed}
More generally, for an AR(p) process,
$\phi(B)=1-a_1 B^1 -\dots-a_p B^p$
\end{framed}
\paragraph{Basic properties of AR(1) processes}\label{basicpropertiesAR1}
\begin{enumerate}
\item \textbf{MA($\infty$) representation}: Consider AR(1):
\begin{equation}
\begin{split}
y_t=& \alpha y_{t-1}+ \eps_t \\
=& \alpha (\alpha y_{t-2}+ \eps_{t-1}) + \eps_t \\
=& \alpha (\alpha (\alpha y_{t-3}+ \eps_{t-2})+
\eps_{t-1}) + \eps_t \\
=& \dots\\
=& \alpha^t y_0 + \sum_{i=0}^{t-1} \alpha^i \eps_{t-i}
\end{split}
\end{equation}
As $t\rightarrow \infty$, if $\mid \alpha \mid < 1$ and $y_0$ finite, we get:
\begin{equation}
y_t = \sum_{i=0}^{\infty} a^i \eps_{t-i}
\end{equation}
Thus, as long as $\mid a_i\mid <1$, we have a \textbf{minimum moving average} representation of AR(1):
\begin{equation}
y_t = \sum_{i=0}^{\infty} a^i \eps_{t-i}
\end{equation}
[Recall definition of MA's, section~\ref{movavg}.]
This will make it easier to compute mean, variance, and acf.
\item \textbf{Expectation, variance and acf}:
\underline{Expectation}
\begin{equation}
E[y_t] = \sum_{i=0}^{\infty} \alpha^i E[\eps_{t-i}] = 0
\end{equation}
\underline{Variance}
\begin{equation}
Var(y_t) = \sum_{i=0}^{\infty} \alpha^{2i}
\explain{Var(\eps_{t-i})}{\hbox{indep. because white noise}} =
\frac{\sigma^2}{1-\alpha^2} \quad \mid \alpha \mid < 1
\end{equation}
The above follows due to the geometric series (infinite sum).
\underline{Covariance}
The covariance: (Recall: Cov(X,Y)=E[XY] - E[X]E[Y])
\begin{equation}
\begin{split}
~& Cov(y_t, y_{t+h})= \\
\gamma_h =
~& E[y_t y_{t+h}]-\explain{E[y_t]}{=0}\explain{E[y_{t+h}]}{=0} =
E[y_ty_{t+h}] \\
\end{split}
\end{equation}
Since $y_t = \sum_{i=0}^{\infty} \alpha^i \eps_{t-i}$ and
$y_{t+h} = \sum_{j=0}^{\infty} \alpha^j \eps_{t+h-j}$,
\begin{equation}
\gamma_h = E[y_ty_{t+h}]
\end{equation}
\begin{equation}
\begin{split} \label{expectationytytplush}
E[y_ty_{t+h}] =&
E[\sum_{i=0}^{\infty} \alpha^i \eps_{t-i}
\sum_{j=0}^{\infty} \alpha^j \eps_{t+h-j}]\\
=& E[\sum_{i,j=0}^{\infty} \alpha^i \eps_{t-i}
\alpha^j \eps_{t+h-j}]\\
\end{split}
\end{equation}
\label{zeroexpectation}
If $t-i \neq t+h -j$, we have $E[\eps_{t-i}\eps_{t+h-j}]=0$ because the errors are independent.
And if $t-i = t+h -j$, this implies that $j=i+h$. Consequently, for this case, we can write
\begin{equation}
\begin{split}
E[\eps_{t-i}\eps_{t+h-j}] =&
E[\eps_{t-i}\eps_{t+h-(i+h)}]\\
=& E[\eps_{t-i}\eps_{t-i}]\\
=& E[\eps_{t-i}^2]=Var(\eps_{t-i})=\sigma^2
\end{split}
\end{equation}
The last line above follows because