Skip to content

Commit

Permalink
Final version corrected, ver. 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
k41m4n committed Sep 4, 2020
1 parent 63acac7 commit 8dc0d88
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ Loading data on UK drivers killed or seriously injured (KSI):
```{r message=FALSE, warning=FALSE}
dataUKdriversKSI <- log(read.table("UKdriversKSI.txt")) %>%
ts(start = 1969, frequency = 12)
head(dataUKdriversKSI, 24)
tail(dataUKdriversKSI, 24)
```

Defining the model using function `SSModel()` of the KFAS package:
Expand Down Expand Up @@ -311,6 +313,7 @@ Extracting the values for trend (stochastic level + slope) using function `signa
```{r message=FALSE, warning=FALSE}
trend <-signal(outKFS, states = "trend")$signal
head(trend, 24)
tail(trend, 24)
```

Showing Figure 3.1. of the book for trend of stochastic linear trend model:
Expand All @@ -335,6 +338,8 @@ legend("topleft",leg = "stochastic slope",
Extracting auxiliary irregular residuals (non-standardised) using function `residuals()` of the KFAS package:
```{r message=FALSE, warning=FALSE}
irregResid <- residuals(outKFS, "pearson")
head(irregResid, 24)
tail(irregResid, 24)
```


Expand Down
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ Loading data on UK drivers killed or seriously injured (KSI):
``` r
dataUKdriversKSI <- log(read.table("UKdriversKSI.txt")) %>%
ts(start = 1969, frequency = 12)
head(dataUKdriversKSI, 24)
#> Jan Feb Mar Apr May Jun Jul
#> 1969 7.430707 7.318540 7.317876 7.233455 7.397562 7.320527 7.351800
#> 1970 7.468513 7.475906 7.448334 7.351158 7.362011 7.326466 7.498316
#> Aug Sep Oct Nov Dec
#> 1969 7.396335 7.364547 7.410347 7.674153 7.672292
#> 1970 7.495542 7.449498 7.604894 7.715124 7.815207
tail(dataUKdriversKSI, 24)
#> Jan Feb Mar Apr May Jun Jul
#> 1983 7.309212 6.963190 7.104965 7.063048 7.119636 6.981006 7.068172
#> 1984 7.213032 7.060476 7.156177 7.012115 7.167809 7.077498 7.108244
#> Aug Sep Oct Nov Dec
#> 1983 7.037906 7.263330 7.304516 7.301822 7.321850
#> 1984 7.157735 7.275172 7.362011 7.459915 7.474772
```

Defining the model using function `SSModel()` of the KFAS package:
Expand Down Expand Up @@ -150,6 +164,13 @@ head(trend, 24)
#> Aug Sep Oct Nov Dec
#> 1969 7.388317 7.376828 7.435665 7.639474 7.644703
#> 1970 7.490569 7.474472 7.601383 7.708188 7.775278
tail(trend, 24)
#> Jan Feb Mar Apr May Jun Jul
#> 1983 7.308694 7.024342 7.090157 7.071173 7.098717 7.006473 7.060062
#> 1984 7.208837 7.089071 7.133044 7.044559 7.141850 7.090491 7.113531
#> Aug Sep Oct Nov Dec
#> 1983 7.067213 7.242181 7.296049 7.301432 7.304580
#> 1984 7.166847 7.272340 7.361614 7.448617 7.470927
```

Showing Figure 3.1. of the book for trend of stochastic linear trend model:
Expand Down Expand Up @@ -180,6 +201,26 @@ Extracting auxiliary irregular residuals (non-standardised) using function `resi

``` r
irregResid <- residuals(outKFS, "pearson")
head(irregResid, 24)
#> Jan Feb Mar Apr May
#> 1969 0.014971154 -0.011757877 0.005689260 -0.028043196 0.026170167
#> 1970 -0.023439520 0.002484397 0.007669682 -0.012830394 0.001228027
#> Jun Jul Aug Sep Oct
#> 1969 -0.010901472 -0.002089700 0.008018528 -0.012281231 -0.025317464
#> 1970 -0.024078894 0.020128715 0.004973270 -0.024974219 0.003511262
#> Nov Dec
#> 1969 0.034679100 0.027589003
#> 1970 0.006935629 0.039929223
tail(irregResid, 24)
#> Jan Feb Mar Apr May
#> 1983 0.0005184131 -0.0611517047 0.0148088188 -0.0081251822 0.0209190398
#> 1984 0.0041951480 -0.0285946618 0.0231321567 -0.0324432815 0.0259595873
#> Jun Jul Aug Sep Oct
#> 1983 -0.0254675168 0.0081097971 -0.0293069304 0.0211484965 0.0084671400
#> 1984 -0.0129927620 -0.0052871789 -0.0091118808 0.0028323560 0.0003965910
#> Nov Dec
#> 1983 0.0003903769 0.0172699294
#> 1984 0.0112977453 0.0038452836
```

Showing Figure 3.3. of the book for irregular component of stochastic trend model:
Expand Down

0 comments on commit 8dc0d88

Please sign in to comment.