-
Notifications
You must be signed in to change notification settings - Fork 1
/
015-RandomWalk.Rmd
95 lines (65 loc) · 2.29 KB
/
015-RandomWalk.Rmd
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
# Random Walk Model {#randomWalk}
The *random walk* model is so simple that it's barely a model at all.
$$y_{t} = y_{t-1} + \epsilon_{t},\qquad\epsilon_{t} \sim N(0,\sigma_{\epsilon}^{2})$$
This says, "Today is like yesterday, only different."
Nonetheless, I find the model useful for exploring new time series data.
It answers the first basic question, how noisy is the data?
To estimate the model,
we first expand the definition into the state-space framework
expected by the software.
\begin{eqnarray*}
y_{t} & = & \mu_{t} \\
\mu_{t} & = & \mu_{t-1} + \xi_{t}, \qquad \xi_{t} \sim N(0,\sigma_{\xi}^{2})
\end{eqnarray*}
Notice that there is no error term in the first equation.
When we observe $y_{t}$, it's an uncorrupted copy of $\mu_{t}$.
The model has two parameters.
------------------ -------------------------------------------------
$\sigma_{\xi}^2$ Variance of the observational errors, $\xi_{t}$
$\mu_{0}$ Initial level of $\mu$
------------------ -------------------------------------------------
## Fitting a Random Walk Model
### Problem {-}
You want to fit your time series data to a random walk model.
### Solution {-}
You can fit a random walk using the `StructTS` function.
Fit the data to a [local level model](#localLevel)
while forcing the observational variance to be zero.
```{r,eval=FALSE}
model <- StructTS(y, type="level", fixed=c(0, NA))
```
### Discussion {-}
The R software always assumes that $y$ has an error term.
We get around that by forcing its variance to be zero,
effectively eliminating it.
### Example {-}
```{r echo=TRUE, eval=TRUE}
y <- datasets::Nile
model <- StructTS(y, type="level", fixed=c(0, NA))
print(model)
```
### See Also {-}
## Diagnosing a Random Walk Model
### Problem {-}
You want to evaluate a random walk model.
### Solution {-}
The `tsdiag` function creates diagnostic plots
for models created using the `StructTS` function.
```{r eval=FALSE}
tsdiag(model)
```
### Discussion {-}
### Example {-}
```{r echo=TRUE, eval=TRUE, fig.height=8}
y <- datasets::Nile
model <- StructTS(y, type="level", fixed=c(0, NA))
tsdiag(model)
```
### See Also {-}
## Forecasting with a Random Walk Model
### Problem {-}
You want to forecast a time series using the random walk model.
### Solution {-}
### Discussion {-}
### Example {-}
### See Also {-}