1
00:00:00,005 --> 00:00:05,476
In this lecture, we will be
talking about Simulating MA (2),

2
00:00:05,476 --> 00:00:08,662
moving average of order two process.

3
00:00:11,246 --> 00:00:14,057
Objectives are to simulate
a moving average process and

4
00:00:14,057 --> 00:00:16,760
interpret correlogram of
a Moving average process.

5
00:00:18,500 --> 00:00:23,039
So let's remember,
moving average process of order two for

6
00:00:23,039 --> 00:00:27,845
example, Xt depends on the noise
two days back or two step back.

7
00:00:27,845 --> 00:00:31,030
It depends on Zt, Zt minus 1, zt minus 2.

8
00:00:31,030 --> 00:00:34,540
All of these are identical
distributed independent,

9
00:00:34,540 --> 00:00:39,140
normal random variables with some mean and
variance.

10
00:00:39,140 --> 00:00:44,720
And Zt minus 1 and Zt minus 2 has
some weight on it, theta1 and theta2.

11
00:00:45,770 --> 00:00:47,700
So in this simulation,

12
00:00:47,700 --> 00:00:53,009
we're going to use standard normal
distribution for our noise.

13
00:00:53,009 --> 00:00:57,377
So Xt = Zt + 0.7 Zt- 1 + 0.2 Zt- 2 and

14
00:00:57,377 --> 00:01:02,653
all of these noises are standard
normal distribution.

15
00:01:06,941 --> 00:01:12,718
So have here are up and running, we can
use a shell but for this simulation,

16
00:01:12,718 --> 00:01:18,150
I would like to open a document editor and
write the code on the editor.

17
00:01:18,150 --> 00:01:23,340
So you can do it by just going to
the file and say a new document and

18
00:01:23,340 --> 00:01:26,610
once you push new document,
there's a new document opened up.

19
00:01:26,610 --> 00:01:31,500
You can write our code here and
we can WAN the code but I have already

20
00:01:31,500 --> 00:01:35,790
opened up a document and
write some piece of code here.

21
00:01:35,790 --> 00:01:37,180
So let's go step by step here.

22
00:01:37,180 --> 00:01:39,920
At the beginning these are my comments.

23
00:01:39,920 --> 00:01:42,410
Comments always starts with a number sign.

24
00:01:43,570 --> 00:01:47,970
So I'm generate noise, remember,
noise are coming from normal distribution.

25
00:01:47,970 --> 00:01:53,380
I'm going to generate 10,000 dat point
from standard normal distribution.

26
00:01:53,380 --> 00:01:55,470
I'm going to call MA2.

27
00:01:55,470 --> 00:01:57,300
This is my variable.

28
00:01:57,300 --> 00:02:01,740
I'm going to introduce that variable into
the RM, I'm going to call it null and

29
00:02:01,740 --> 00:02:06,280
here with this loop, I am actually
getting a rating MA2 process.

30
00:02:06,280 --> 00:02:13,270
So, syntax for loop in R is that 4I,
I being the index in the range.

31
00:02:13,270 --> 00:02:16,611
My range will start from three to 10,000.

32
00:02:16,611 --> 00:02:19,960
Remember, my MA and MA2 process.

33
00:02:19,960 --> 00:02:25,190
My Xt values will depend on Ztn,
Zt minus one and

34
00:02:25,190 --> 00:02:30,090
Zt minus two, so
I'm going to use Z1 and Z2.

35
00:02:30,090 --> 00:02:32,750
That's why I need to start from X3.

36
00:02:32,750 --> 00:02:37,500
So I am starting from index three.

37
00:02:37,500 --> 00:02:43,360
This is my noise from right now, noise
from yesterday, noise from two days ago.

38
00:02:43,360 --> 00:02:46,650
And I have appropriate weights on them,
0.7 and 0.2,

39
00:02:46,650 --> 00:02:52,350
that would generate a data set where
the first two points are naught.

40
00:02:52,350 --> 00:02:55,010
So the first two points are missing.

41
00:02:55,010 --> 00:02:59,760
So I'm going to shift it, so I'm going to
shift all of it by two units to the left.

42
00:02:59,760 --> 00:03:05,550
I'm going to call MA2 from 3 to the n,
all of these basically shifted.

43
00:03:05,550 --> 00:03:10,710
Once I shift it I'm going to call a new
process, a moving average process.

44
00:03:10,710 --> 00:03:14,210
Remember, this moving average
process still is just a data point.

45
00:03:14,210 --> 00:03:17,830
It does not have time
series structure on it.

46
00:03:17,830 --> 00:03:20,170
So let's put some time
structure on this vanilla data.

47
00:03:20,170 --> 00:03:27,250
I have this data, I'm using ts operator,
which will make it a time series.

48
00:03:27,250 --> 00:03:30,180
And I'm going to put it exactly back
into the moving average process.

49
00:03:30,180 --> 00:03:34,000
Now I truly have a moving average process.

50
00:03:34,000 --> 00:03:40,120
Now it's time to plot this moving
average process and at its column graph.

51
00:03:41,170 --> 00:03:44,510
So before I do that,
I'm going to do this partition.

52
00:03:44,510 --> 00:03:47,840
I'm going to partition
my multiple graphics.

53
00:03:47,840 --> 00:03:51,460
My graphs was going to
be basically one frame.

54
00:03:51,460 --> 00:03:54,790
My frame's going to have a multi-frame.

55
00:03:54,790 --> 00:03:57,010
Basically I'm going to have two rows.

56
00:03:57,010 --> 00:03:59,850
And each row is going to be the plot and

57
00:03:59,850 --> 00:04:03,540
the ACF and to do this,
I'm going to use this par routine.

58
00:04:03,540 --> 00:04:09,370
So par(mfrow), this stands for
multi frame row.

59
00:04:09,370 --> 00:04:12,715
And if I put 2, 1,
this means two rows and one columns.

60
00:04:13,750 --> 00:04:14,520
Now I can plot.

61
00:04:14,520 --> 00:04:18,810
I'm going to plot my moving average
process and I'm going to plot my ACF.

62
00:04:18,810 --> 00:04:21,970
I put a title for both of them and

63
00:04:21,970 --> 00:04:26,690
I am going to color my plot
to blue in the first row.

64
00:04:28,300 --> 00:04:33,740
So I do have it,
I can save it using dot our extension.

65
00:04:33,740 --> 00:04:37,750
And all I have to do, if you are Mac,
you just do command E.

66
00:04:37,750 --> 00:04:41,630
That will execute the source code.

67
00:04:41,630 --> 00:04:44,630
If you are on Windows,
I think you will do CTRL + E.

68
00:04:44,630 --> 00:04:49,538
So if I did Command E,
basically it just go to the shelve,

69
00:04:49,538 --> 00:04:54,230
runs it on the shelve,
and gives you the output.

70
00:04:54,230 --> 00:04:59,760
Here I have a moving
average process of order 2.

71
00:04:59,760 --> 00:05:00,980
Without analyzing it,

72
00:05:00,980 --> 00:05:04,970
it would be impossible to tell this
is actually moving average process.

73
00:05:04,970 --> 00:05:06,610
But here is the thing.

74
00:05:06,610 --> 00:05:12,380
I do have my ACF and
ACF has some particular structure.

75
00:05:12,380 --> 00:05:15,440
I realize that I have
a correlation at lag 0.

76
00:05:15,440 --> 00:05:16,950
This is always the case.

77
00:05:16,950 --> 00:05:19,733
It always starts ACF one but

78
00:05:19,733 --> 00:05:24,582
then there's a high
correlation with lag one.

79
00:05:24,582 --> 00:05:29,190
This makes sense because we are still
getting noises from the previous step.

80
00:05:29,190 --> 00:05:33,795
And there's also noise coming from
the two steps back, two days back and

81
00:05:33,795 --> 00:05:35,847
then boom, there's nothing.

82
00:05:35,847 --> 00:05:37,149
So this is very,

83
00:05:37,149 --> 00:05:43,710
very much a characteristic of MAQ process
if you are looking at MAQ process.

84
00:05:43,710 --> 00:05:48,696
If you take ACF off MA q process,
it lags or

85
00:05:48,696 --> 00:05:53,268
the correlation will cut off at LAGQ.

86
00:05:53,268 --> 00:05:59,538
In this case, we have MA2 process and
then ACF has to cut from lag 2.

87
00:05:59,538 --> 00:06:02,910
And this is lag 1, this is lag 2,
boom, I have nothing.

88
00:06:02,910 --> 00:06:08,886
So this is one of the ways we're going
to model our time series later on.

89
00:06:08,886 --> 00:06:14,374
You're going to look at ACF and
if you see an ACF cuts off after some lag,

90
00:06:14,374 --> 00:06:19,880
that gives us a reason to model our
data using a moving average process.

91
00:06:21,740 --> 00:06:22,950
What have you learned in this lecture?

92
00:06:22,950 --> 00:06:27,600
You have learned how to simulate
the moving average processes in R.

93
00:06:27,600 --> 00:06:30,650
And you have learned that ACF or

94
00:06:30,650 --> 00:06:35,120
moving average process of
all the q cuts off at lag q.