From 1b4482aa13df8172b3ddafd0c0f197af02bfcfc3 Mon Sep 17 00:00:00 2001 From: palatej Date: Wed, 3 Jul 2024 12:25:08 +0200 Subject: [PATCH 1/2] Vignettes (initial) --- .Rbuildignore | 2 + .gitignore | 2 + DESCRIPTION | 2 + Meta/vignette.rds | Bin 0 -> 269 bytes inst/doc/bsm.R | 75 +++++++ inst/doc/bsm.Rmd | 127 ++++++++++++ inst/doc/bsm.html | 459 +++++++++++++++++++++++++++++++++++++++++ inst/doc/sts.R | 14 ++ inst/doc/sts.Rmd | 46 +++++ inst/doc/sts.html | 382 ++++++++++++++++++++++++++++++++++ inst/doc/tdvar.R | 87 ++++++++ inst/doc/tdvar.Rmd | 141 +++++++++++++ inst/doc/tdvar.html | 484 ++++++++++++++++++++++++++++++++++++++++++++ vignettes/bsm.Rmd | 127 ++++++++++++ vignettes/sts.Rmd | 46 +++++ vignettes/tdvar.Rmd | 141 +++++++++++++ 16 files changed, 2135 insertions(+) create mode 100644 Meta/vignette.rds create mode 100644 inst/doc/bsm.R create mode 100644 inst/doc/bsm.Rmd create mode 100644 inst/doc/bsm.html create mode 100644 inst/doc/sts.R create mode 100644 inst/doc/sts.Rmd create mode 100644 inst/doc/sts.html create mode 100644 inst/doc/tdvar.R create mode 100644 inst/doc/tdvar.Rmd create mode 100644 inst/doc/tdvar.html create mode 100644 vignettes/bsm.Rmd create mode 100644 vignettes/sts.Rmd create mode 100644 vignettes/tdvar.Rmd diff --git a/.Rbuildignore b/.Rbuildignore index b84e788..948c804 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -7,3 +7,5 @@ ^_pkgdown\.yml$ ^docs$ ^pkgdown$ +^doc$ +^Meta$ diff --git a/.gitignore b/.gitignore index 138866d..cc0b0d7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ .Ruserdata inst/doc docs +/doc/ +/Meta/ diff --git a/DESCRIPTION b/DESCRIPTION index f0c26de..ae2071b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,6 +20,7 @@ SystemRequirements: Java (>= 17) License: EUPL URL: https://github.com/rjdverse/rjd3sts, https://rjdverse.github.io/rjd3sts LazyData: TRUE +Suggests: knitr, rmarkdown RoxygenNote: 7.3.1 BugReports: https://github.com/rjdverse/rjd3sts Roxygen: list(markdown = TRUE) @@ -32,3 +33,4 @@ Collate: 'jd3_stsoutliers.R' 'protobuf.R' 'zzz.R' +VignetteBuilder: knitr diff --git a/Meta/vignette.rds b/Meta/vignette.rds new file mode 100644 index 0000000000000000000000000000000000000000..37d4db3a099d45fe80449c72f8cbedf724f31ab3 GIT binary patch literal 269 zcmV+o0rLJIiwFP!0000028B_7av*@w9cNu z)XAMNp)sT-FV$NtpDNR?Tx&#~FO-J70;9m@tyRq?e=R|SGvYZeKZX^2v-49NNS~$X z?Ad`kuj|X{ny?pkg0q9N&>1psf+GUK51ET@u$%_Mfygf8D|0@^Frpic&_MbpvB_tu z23lAscLd3MIg91!D6E8UXrv{tbLjS4gLrr-HQRkb$L{^l{lU=p{qMP=RV^$jqGl$A T6UEvfAJN}GG4uUa9s&RWIW2xg literal 0 HcmV?d00001 diff --git a/inst/doc/bsm.R b/inst/doc/bsm.R new file mode 100644 index 0000000..64a6d9c --- /dev/null +++ b/inst/doc/bsm.R @@ -0,0 +1,75 @@ +## ----echo=FALSE--------------------------------------------------------------- + +suppressPackageStartupMessages(library(rjd3toolkit)) +suppressPackageStartupMessages(library(rjd3sts)) +library(knitr) + + + +## ----data--------------------------------------------------------------------- +s<-log(retail$BookStores) + +## ----bsm1--------------------------------------------------------------------- + +# create the model +bsm<-model() +# create the components and add them to the model +add(bsm, locallineartrend("ll")) +add(bsm, seasonal("s", 12, type="HarrisonStevens")) +add(bsm, noise("n")) +rslt<-estimate(bsm, log(s), marginal=T) + + + +## ----bsm2--------------------------------------------------------------------- + +# create the model +bsm<-model() +# create the components and add them to the model +add(bsm, locallineartrend("ll")) +add(bsm, seasonal("s", 12, type="HarrisonStevens")) + # create the equation (fix the variance to 1) +eq<-equation("eq", 1,T) +add_equation(eq, "ll") +add_equation(eq, "s") +add(bsm, eq) +rslt<-estimate(bsm, log(s), marginal=T) + +## ----bsm3--------------------------------------------------------------------- + +# create the model +bsm<-model() + # create the components, with fixed variances, and add them to the model +add(bsm, locallineartrend("ll", + levelVariance = 1, fixedLevelVariance = TRUE) ) +add(bsm, seasonal("s", 12, type="HarrisonStevens", + variance = 1, fixed = TRUE)) +add(bsm, noise("n", 1, fixed=TRUE)) + # create the equation (fix the variance to 1) +eq<-equation("eq", 0, TRUE) +add_equation(eq, "ll", .01, FALSE) +add_equation(eq, "s", .01, FALSE) +add_equation(eq, "n") +add(bsm, eq) +rslt<-estimate(bsm, log(s), marginal=TRUE) +p<-result(rslt, "parameters") + +## ----bsm4--------------------------------------------------------------------- + +# create the model +bsm<-model() + # create the components and add them to the model +add(bsm, locallevel("l", initial = 0) ) +add(bsm, locallineartrend("lt", levelVariance = 0, + fixedLevelVariance = TRUE) ) +add(bsm, seasonal("s", 12, type="HarrisonStevens")) +add(bsm, noise("n", 1, fixed=TRUE)) + # create the equation (fix the variance to 1) +rslt<-estimate(bsm, log(s), marginal=TRUE) + + +## ----fig.width=6-------------------------------------------------------------- +ss<-smoothed_states(rslt) +plot(ss[,1]+ss[,2], type='l', col='blue', ylab='trends') +lines(ss[, 2], col='red') + diff --git a/inst/doc/bsm.Rmd b/inst/doc/bsm.Rmd new file mode 100644 index 0000000..0573d18 --- /dev/null +++ b/inst/doc/bsm.Rmd @@ -0,0 +1,127 @@ +--- +title: "BSM" +author: "Jean Palate" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{BSM} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +## Defining a Basic Structural Model with rjd3sts + +The package allows several equivalent definitions of a basic structural model. +We present below some of them. + +To compare the results (more precisely the likelihood) of the different approaches, +it is important to compute the marginal likelihood. + +```{r echo=FALSE} + +suppressPackageStartupMessages(library(rjd3toolkit)) +suppressPackageStartupMessages(library(rjd3sts)) +library(knitr) + + +``` + +```{r data} +s<-log(retail$BookStores) +``` + +### Standard definition, noise in the state + +```{r bsm1 } + +# create the model +bsm<-model() +# create the components and add them to the model +add(bsm, locallineartrend("ll")) +add(bsm, seasonal("s", 12, type="HarrisonStevens")) +add(bsm, noise("n")) +rslt<-estimate(bsm, log(s), marginal=T) + + +``` + +* Likelihood = `r result(rslt, "likelihood.ll")` +* Parameters = `r sapply(result(rslt, "parameters"), function(num) sprintf(num, fmt = '%#.6f'))` + +### Standard definition, noise in the measurement + +```{r bsm2} + +# create the model +bsm<-model() +# create the components and add them to the model +add(bsm, locallineartrend("ll")) +add(bsm, seasonal("s", 12, type="HarrisonStevens")) + # create the equation (fix the variance to 1) +eq<-equation("eq", 1,T) +add_equation(eq, "ll") +add_equation(eq, "s") +add(bsm, eq) +rslt<-estimate(bsm, log(s), marginal=T) +``` +* Likelihood = `r result(rslt, "likelihood.ll")` +* Parameters = `r sapply(result(rslt, "parameters"), function(num) sprintf(num, fmt = '%#.6f'))` + + +### components with fixed variances, aggregated with diffuse weights (noise in the state) + +```{r bsm3} + +# create the model +bsm<-model() + # create the components, with fixed variances, and add them to the model +add(bsm, locallineartrend("ll", + levelVariance = 1, fixedLevelVariance = TRUE) ) +add(bsm, seasonal("s", 12, type="HarrisonStevens", + variance = 1, fixed = TRUE)) +add(bsm, noise("n", 1, fixed=TRUE)) + # create the equation (fix the variance to 1) +eq<-equation("eq", 0, TRUE) +add_equation(eq, "ll", .01, FALSE) +add_equation(eq, "s", .01, FALSE) +add_equation(eq, "n") +add(bsm, eq) +rslt<-estimate(bsm, log(s), marginal=TRUE) +p<-result(rslt, "parameters") +``` + +* Likelihood = `r result(rslt, "likelihood.ll")` +* Parameters = `r sapply(p, function(num) sprintf(num, fmt = '%#.4f'))` + +To be noted: + +* Level variance = $p[5]\times p[5]$ = `r sprintf(p[5]*p[5], fmt = '%#.6f')` +* Slope variance = $p[5]\times p[5] \times p[2]$ = `r sprintf(p[5]*p[5]*p[2], fmt = '%#.6f')` +* Seas variance = $p[6]\times p[6]$ = `r sprintf(p[6]*p[6], fmt = '%#.6f')` + + + +### bsm with long term trend and cycle + +```{r bsm4} + +# create the model +bsm<-model() + # create the components and add them to the model +add(bsm, locallevel("l", initial = 0) ) +add(bsm, locallineartrend("lt", levelVariance = 0, + fixedLevelVariance = TRUE) ) +add(bsm, seasonal("s", 12, type="HarrisonStevens")) +add(bsm, noise("n", 1, fixed=TRUE)) + # create the equation (fix the variance to 1) +rslt<-estimate(bsm, log(s), marginal=TRUE) + +``` +* Likelihood = `r result(rslt, "likelihood.ll")` +* Parameters = `r sapply(result(rslt, "parameters"), function(num) sprintf(num, fmt = '%#.6f'))` + +```{r, fig.width=6} +ss<-smoothed_states(rslt) +plot(ss[,1]+ss[,2], type='l', col='blue', ylab='trends') +lines(ss[, 2], col='red') +``` diff --git a/inst/doc/bsm.html b/inst/doc/bsm.html new file mode 100644 index 0000000..a64c73f --- /dev/null +++ b/inst/doc/bsm.html @@ -0,0 +1,459 @@ + + + + + + + + + + + + + + + + +BSM + + + + + + + + + + + + + + + + + + + + + + + + + + +

BSM

+

Jean Palate

+

2024-07-03

+ + + +
+

Defining a Basic Structural Model with rjd3sts

+

The package allows several equivalent definitions of a basic +structural model. We present below some of them.

+

To compare the results (more precisely the likelihood) of the +different approaches, it is important to compute the marginal +likelihood.

+
s<-log(retail$BookStores)
+
+

Standard definition, noise in the state

+
# create the model
+bsm<-model()
+# create the components and add them to the model
+add(bsm, locallineartrend("ll"))
+add(bsm, seasonal("s", 12, type="HarrisonStevens"))
+add(bsm, noise("n"))
+rslt<-estimate(bsm, log(s), marginal=T)
+
    +
  • Likelihood = 747.8184945
  • +
  • Parameters = 0.160016, 0.000396, 0.243922, 1.000000
  • +
+
+
+

Standard definition, noise in the measurement

+
# create the model
+bsm<-model()
+# create the components and add them to the model
+add(bsm, locallineartrend("ll"))
+add(bsm, seasonal("s", 12, type="HarrisonStevens"))
+  # create the equation (fix the variance to 1)
+eq<-equation("eq", 1,T)
+add_equation(eq, "ll")
+add_equation(eq, "s")
+add(bsm, eq)
+rslt<-estimate(bsm, log(s), marginal=T)
+
    +
  • Likelihood = 747.8184945
  • +
  • Parameters = 0.160016, 0.000396, 0.243922, 1.000000
  • +
+
+
+

components with fixed variances, aggregated with diffuse weights +(noise in the state)

+
# create the model
+bsm<-model()
+  # create the components, with fixed variances, and add them to the model
+add(bsm, locallineartrend("ll", 
+                             levelVariance = 1, fixedLevelVariance = TRUE) )
+add(bsm, seasonal("s", 12, type="HarrisonStevens", 
+                     variance = 1, fixed = TRUE))
+add(bsm, noise("n", 1, fixed=TRUE))
+  # create the equation (fix the variance to 1)
+eq<-equation("eq", 0, TRUE)
+add_equation(eq, "ll", .01, FALSE)
+add_equation(eq, "s", .01, FALSE)
+add_equation(eq, "n")
+add(bsm, eq)
+rslt<-estimate(bsm, log(s), marginal=TRUE)
+p<-result(rslt, "parameters")
+
    +
  • Likelihood = 747.8184944
  • +
  • Parameters = 1.0000, 0.0025, 1.0000, 1.0000, 0.4001, 0.4939
  • +
+

To be noted:

+
    +
  • Level variance = \(p[5]\times +p[5]\) = 0.160057
  • +
  • Slope variance = \(p[5]\times p[5] \times +p[2]\) = 0.000396
  • +
  • Seas variance = \(p[6]\times p[6]\) += 0.243976
  • +
+
+
+

bsm with long term trend and cycle

+
# create the model
+bsm<-model()
+  # create the components and add them to the model
+add(bsm, locallevel("l", initial = 0) )
+add(bsm, locallineartrend("lt", levelVariance = 0, 
+                             fixedLevelVariance = TRUE) )
+add(bsm, seasonal("s", 12, type="HarrisonStevens"))
+add(bsm, noise("n", 1, fixed=TRUE))
+  # create the equation (fix the variance to 1)
+rslt<-estimate(bsm, log(s), marginal=TRUE)
+
    +
  • Likelihood = 747.8184945
  • +
  • Parameters = 0.160016, 0.000000, 0.000396, 0.243922, 1.000000
  • +
+
ss<-smoothed_states(rslt)
+plot(ss[,1]+ss[,2], type='l', col='blue', ylab='trends')
+lines(ss[, 2], col='red')
+

+
+
+ + + + + + + + + + + diff --git a/inst/doc/sts.R b/inst/doc/sts.R new file mode 100644 index 0000000..ec61365 --- /dev/null +++ b/inst/doc/sts.R @@ -0,0 +1,14 @@ +## ----setup, include = FALSE--------------------------------------------------- +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) + +## ----echo=FALSE--------------------------------------------------------------- +suppressPackageStartupMessages(library(rjd3toolkit)) +suppressPackageStartupMessages(library(rjd3sts)) +library(knitr) + +## ----data--------------------------------------------------------------------- +s<-log(retail$BookStores) + diff --git a/inst/doc/sts.Rmd b/inst/doc/sts.Rmd new file mode 100644 index 0000000..a000c90 --- /dev/null +++ b/inst/doc/sts.Rmd @@ -0,0 +1,46 @@ +--- +title: "Sructural Time Series using JDemetra+" +author: "Jean Palate" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Sructural Time Series using JDemetra+} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r setup, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +# Introduction + +```{r echo=FALSE} +suppressPackageStartupMessages(library(rjd3toolkit)) +suppressPackageStartupMessages(library(rjd3sts)) +library(knitr) +``` + + + +# Data + +We illustrate the various methods using two sets of time series: + +* The **retail** data set contains monthly figures over US retail activity of various categories of goods and services from 1992 to 2010. +* The **ABS** data set contains long monthly series over Australian retail trade. + +```{r data} +s<-log(retail$BookStores) +``` + + +# Examples + + + + + diff --git a/inst/doc/sts.html b/inst/doc/sts.html new file mode 100644 index 0000000..fbae068 --- /dev/null +++ b/inst/doc/sts.html @@ -0,0 +1,382 @@ + + + + + + + + + + + + + + + + +Sructural Time Series using JDemetra+ + + + + + + + + + + + + + + + + + + + + + + + + + + +

Sructural Time Series using JDemetra+

+

Jean Palate

+

2024-07-03

+ + + +
+

Introduction

+
+
+

Data

+

We illustrate the various methods using two sets of time series:

+
    +
  • The retail data set contains monthly figures over +US retail activity of various categories of goods and services from 1992 +to 2010.
  • +
  • The ABS data set contains long monthly series over +Australian retail trade.
  • +
+
s<-log(retail$BookStores)
+
+
+

Examples

+
+ + + + + + + + + + + diff --git a/inst/doc/tdvar.R b/inst/doc/tdvar.R new file mode 100644 index 0000000..8bb2d54 --- /dev/null +++ b/inst/doc/tdvar.R @@ -0,0 +1,87 @@ +## ----setup, include = FALSE--------------------------------------------------- +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) + +## ----echo=FALSE--------------------------------------------------------------- + +suppressPackageStartupMessages(library(rjd3toolkit)) +suppressPackageStartupMessages(library(rjd3sts)) +library(knitr) + +## ----data--------------------------------------------------------------------- +# take a (transformed) series +s<-log(rjd3toolkit::ABS$X0.2.09.10.M) + +## ----tdvar1------------------------------------------------------------------- + +# create the model +model<-rjd3sts::model() + +# create the components and add them to the model +rjd3sts::add(model, rjd3sts::sarima("airline", 12, c(0,1,1), c(0,1,1))) + +rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = F)) +#estimate the model +rslt<-rjd3sts::estimate(model, s) + +ss<-rjd3toolkit::result(rslt, "ssf.smoothing.states") +vss<-rjd3toolkit::result(rslt, "ssf.smoothing.vstates") + + +## ----------------------------------------------------------------------------- +print(rjd3toolkit::dictionary(rslt)) + +## ----tdvar1_chart, fig.width=6, fig.height=4---------------------------------- + +colfunc<-colorRampPalette(c("red","blue","green","#196F3D")) +colors <- (colfunc(7)) + +pos<-rjd3toolkit::result(rslt, "ssf.cmppos") +plot(ss[,pos[2]+1], type='l', col=colors[1], ylim=c(-0.04, 0.03), ylab='coeff') +lines(ss[,pos[2]+2], col=colors[2]) +lines(ss[,pos[2]+3], col=colors[3]) +lines(ss[,pos[2]+4], col=colors[4]) +lines(ss[,pos[2]]+5, col=colors[5]) +lines(ss[,pos[2]+6], col=colors[6]) +lines(-rowSums(ss[,pos[2]+(1:6)]), col=colors[7]) + + +## ----tdvar2------------------------------------------------------------------- +# take a (transformed) series +s<-log(rjd3toolkit::ABS$X0.2.09.10.M) + +# create the model +model<-rjd3sts::model() + +# create the components and add them to the model +llt<-rjd3sts::locallineartrend('l') +seas<-rjd3sts::seasonal("s", 12, "HarrisonStevens") +n<-rjd3sts::noise('n') +rjd3sts::add(model, llt) +rjd3sts::add(model, seas) +rjd3sts::add(model, n) +rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = F)) +#estimate the model +rslt<-rjd3sts::estimate(model, s) + +ss<-rjd3toolkit::result(rslt, "ssf.smoothing.states") +vss<-rjd3toolkit::result(rslt, "ssf.smoothing.vstates") + + +## ----tdvar2_chart, fig.width=6, fig.height=4---------------------------------- + +colfunc<-colorRampPalette(c("red","blue","green","#196F3D")) +colors <- (colfunc(7)) + +pos<-rjd3toolkit::result(rslt, "ssf.cmppos") +plot(ss[,pos[4]+1], type='l', col=colors[1], ylim=c(-0.04, 0.03), ylab='coeff') +lines(ss[,pos[4]+2], col=colors[2]) +lines(ss[,pos[4]+3], col=colors[3]) +lines(ss[,pos[4]+4], col=colors[4]) +lines(ss[,pos[4]]+5, col=colors[5]) +lines(ss[,pos[4]+6], col=colors[6]) +lines(-rowSums(ss[,pos[4]+(1:6)]), col=colors[7]) + + diff --git a/inst/doc/tdvar.Rmd b/inst/doc/tdvar.Rmd new file mode 100644 index 0000000..82637ed --- /dev/null +++ b/inst/doc/tdvar.Rmd @@ -0,0 +1,141 @@ +--- +title: "Time varying trading days" +author: "Jean Palate" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Time varying trading days} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r setup, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +## Time-varying trading days + +### Introduction +The state space framework allows an easy estimation of time-varying trading days effects. + + +```{r echo=FALSE} + +suppressPackageStartupMessages(library(rjd3toolkit)) +suppressPackageStartupMessages(library(rjd3sts)) +library(knitr) +``` + + +```{r data} +# take a (transformed) series +s<-log(rjd3toolkit::ABS$X0.2.09.10.M) +``` + + +### Modelling + +We model such effects by integrating in the state array the regression coefficients. +As usual, the regression variables are modeled by using contrasts (for instance: #days-#Sundays). +the coefficient follow a multivariate random walk. As for the usual regression, we put +the constraint that the sum of the coefficients is 0 (which implies that one coefficient +is derived from the others). + +To be noted that fixed coefficients correspond to no innovation in the random walk. +We consider that the same innovation variance applies on the coefficients of each day (option contrast=FALSE) +or of each contrasts (option contrast=TRUE). +In this latter case, the variance of the innovation of the contrasting (group of) days is larger. + +Such time varying trading days can be plugged in any representation of the series. + +### SARIMA + TDvar + + +```{r tdvar1} + +# create the model +model<-rjd3sts::model() + +# create the components and add them to the model +rjd3sts::add(model, rjd3sts::sarima("airline", 12, c(0,1,1), c(0,1,1))) + +rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = F)) +#estimate the model +rslt<-rjd3sts::estimate(model, s) + +ss<-rjd3toolkit::result(rslt, "ssf.smoothing.states") +vss<-rjd3toolkit::result(rslt, "ssf.smoothing.vstates") + +``` + +### Available results + +The results can be retrieved through the "result" function. All the available +information are displayed by means of the "dictionary" method + +```{r} +print(rjd3toolkit::dictionary(rslt)) +``` +Time varying trading days + +```{r tdvar1_chart, fig.width=6, fig.height=4} + +colfunc<-colorRampPalette(c("red","blue","green","#196F3D")) +colors <- (colfunc(7)) + +pos<-rjd3toolkit::result(rslt, "ssf.cmppos") +plot(ss[,pos[2]+1], type='l', col=colors[1], ylim=c(-0.04, 0.03), ylab='coeff') +lines(ss[,pos[2]+2], col=colors[2]) +lines(ss[,pos[2]+3], col=colors[3]) +lines(ss[,pos[2]+4], col=colors[4]) +lines(ss[,pos[2]]+5, col=colors[5]) +lines(ss[,pos[2]+6], col=colors[6]) +lines(-rowSums(ss[,pos[2]+(1:6)]), col=colors[7]) + +``` + +### BSM + TDvar + +```{r tdvar2} +# take a (transformed) series +s<-log(rjd3toolkit::ABS$X0.2.09.10.M) + +# create the model +model<-rjd3sts::model() + +# create the components and add them to the model +llt<-rjd3sts::locallineartrend('l') +seas<-rjd3sts::seasonal("s", 12, "HarrisonStevens") +n<-rjd3sts::noise('n') +rjd3sts::add(model, llt) +rjd3sts::add(model, seas) +rjd3sts::add(model, n) +rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = F)) +#estimate the model +rslt<-rjd3sts::estimate(model, s) + +ss<-rjd3toolkit::result(rslt, "ssf.smoothing.states") +vss<-rjd3toolkit::result(rslt, "ssf.smoothing.vstates") + +``` + +Time varying trading days + +```{r tdvar2_chart, fig.width=6, fig.height=4} + +colfunc<-colorRampPalette(c("red","blue","green","#196F3D")) +colors <- (colfunc(7)) + +pos<-rjd3toolkit::result(rslt, "ssf.cmppos") +plot(ss[,pos[4]+1], type='l', col=colors[1], ylim=c(-0.04, 0.03), ylab='coeff') +lines(ss[,pos[4]+2], col=colors[2]) +lines(ss[,pos[4]+3], col=colors[3]) +lines(ss[,pos[4]+4], col=colors[4]) +lines(ss[,pos[4]]+5, col=colors[5]) +lines(ss[,pos[4]+6], col=colors[6]) +lines(-rowSums(ss[,pos[4]+(1:6)]), col=colors[7]) + +``` diff --git a/inst/doc/tdvar.html b/inst/doc/tdvar.html new file mode 100644 index 0000000..66b6479 --- /dev/null +++ b/inst/doc/tdvar.html @@ -0,0 +1,484 @@ + + + + + + + + + + + + + + + + +Time varying trading days + + + + + + + + + + + + + + + + + + + + + + + + + + +

Time varying trading days

+

Jean Palate

+

2024-07-03

+ + + +
+

Time-varying trading days

+
+

Introduction

+

The state space framework allows an easy estimation of time-varying +trading days effects.

+
# take a (transformed) series
+s<-log(rjd3toolkit::ABS$X0.2.09.10.M)
+
+
+

Modelling

+

We model such effects by integrating in the state array the +regression coefficients. As usual, the regression variables are modeled +by using contrasts (for instance: #days-#Sundays). the coefficient +follow a multivariate random walk. As for the usual regression, we put +the constraint that the sum of the coefficients is 0 (which implies that +one coefficient is derived from the others).

+

To be noted that fixed coefficients correspond to no innovation in +the random walk. We consider that the same innovation variance applies +on the coefficients of each day (option contrast=FALSE) or of each +contrasts (option contrast=TRUE). In this latter case, the variance of +the innovation of the contrasting (group of) days is larger.

+

Such time varying trading days can be plugged in any representation +of the series.

+
+
+

SARIMA + TDvar

+

+# create the model
+model<-rjd3sts::model()
+
+# create the components and add them to the model
+rjd3sts::add(model, rjd3sts::sarima("airline", 12, c(0,1,1), c(0,1,1)))
+
+rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = F))
+#estimate the model
+rslt<-rjd3sts::estimate(model, s)
+
+ss<-rjd3toolkit::result(rslt, "ssf.smoothing.states")
+vss<-rjd3toolkit::result(rslt, "ssf.smoothing.vstates")
+
+
+

Available results

+

The results can be retrieved through the “result” function. All the +available information are displayed by means of the “dictionary” +method

+
print(rjd3toolkit::dictionary(rslt))
+#>  [1] "likelihood.ll"                   "likelihood.ser"                 
+#>  [3] "likelihood.residuals"            "scalingfactor"                  
+#>  [5] "ssf.ncmps"                       "ssf.cmppos"                     
+#>  [7] "ssf.cmpnames"                    "parameters"                     
+#>  [9] "parametersnames"                 "fn.parameters"                  
+#> [11] "ssf.T(*)"                        "ssf.V(*)"                       
+#> [13] "ssf.Z(*)"                        "ssf.P0"                         
+#> [15] "ssf.B0"                          "ssf.smoothing.array(?)"         
+#> [17] "ssf.smoothing.varray(?)"         "ssf.smoothing.cmp(?)"           
+#> [19] "ssf.smoothing.vcmp(?)"           "ssf.smoothing.components(?)"    
+#> [21] "ssf.smoothing.fastcomponents(?)" "ssf.smoothing.vcomponents(?)"   
+#> [23] "ssf.smoothing.state(?)"          "ssf.smoothing.vstate(?)"        
+#> [25] "ssf.smoothing.states"            "ssf.smoothing.vstates"          
+#> [27] "ssf.filtering.array(?)"          "ssf.filtering.varray(?)"        
+#> [29] "ssf.filtering.cmp(?)"            "ssf.filtering.vcmp(?)"          
+#> [31] "ssf.filtering.state(?)"          "ssf.filtering.states"           
+#> [33] "ssf.filtering.vstates"           "ssf.filtering.vstate(?)"        
+#> [35] "ssf.filtered.array(?)"           "ssf.filtered.varray(?)"         
+#> [37] "ssf.filtered.cmp(?)"             "ssf.filtered.vcmp(?)"           
+#> [39] "ssf.filtered.state(?)"           "ssf.filtered.vstate(?)"         
+#> [41] "ssf.filtered.states"             "ssf.filtered.vstates"
+

Time varying trading days

+

+colfunc<-colorRampPalette(c("red","blue","green","#196F3D"))
+colors <- (colfunc(7))
+
+pos<-rjd3toolkit::result(rslt, "ssf.cmppos")
+plot(ss[,pos[2]+1], type='l', col=colors[1], ylim=c(-0.04, 0.03), ylab='coeff')
+lines(ss[,pos[2]+2], col=colors[2])
+lines(ss[,pos[2]+3], col=colors[3])
+lines(ss[,pos[2]+4], col=colors[4])
+lines(ss[,pos[2]]+5, col=colors[5])
+lines(ss[,pos[2]+6], col=colors[6])
+lines(-rowSums(ss[,pos[2]+(1:6)]), col=colors[7])
+

+
+
+

BSM + TDvar

+
# take a (transformed) series
+s<-log(rjd3toolkit::ABS$X0.2.09.10.M)
+
+# create the model
+model<-rjd3sts::model()
+
+# create the components and add them to the model
+llt<-rjd3sts::locallineartrend('l')
+seas<-rjd3sts::seasonal("s", 12, "HarrisonStevens")
+n<-rjd3sts::noise('n')
+rjd3sts::add(model, llt)
+rjd3sts::add(model, seas)
+rjd3sts::add(model, n)
+rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = F))
+#estimate the model
+rslt<-rjd3sts::estimate(model, s)
+
+ss<-rjd3toolkit::result(rslt, "ssf.smoothing.states")
+vss<-rjd3toolkit::result(rslt, "ssf.smoothing.vstates")
+

Time varying trading days

+

+colfunc<-colorRampPalette(c("red","blue","green","#196F3D"))
+colors <- (colfunc(7))
+
+pos<-rjd3toolkit::result(rslt, "ssf.cmppos")
+plot(ss[,pos[4]+1], type='l', col=colors[1], ylim=c(-0.04, 0.03), ylab='coeff')
+lines(ss[,pos[4]+2], col=colors[2])
+lines(ss[,pos[4]+3], col=colors[3])
+lines(ss[,pos[4]+4], col=colors[4])
+lines(ss[,pos[4]]+5, col=colors[5])
+lines(ss[,pos[4]+6], col=colors[6])
+lines(-rowSums(ss[,pos[4]+(1:6)]), col=colors[7])
+

+
+
+ + + + + + + + + + + diff --git a/vignettes/bsm.Rmd b/vignettes/bsm.Rmd new file mode 100644 index 0000000..0573d18 --- /dev/null +++ b/vignettes/bsm.Rmd @@ -0,0 +1,127 @@ +--- +title: "BSM" +author: "Jean Palate" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{BSM} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +## Defining a Basic Structural Model with rjd3sts + +The package allows several equivalent definitions of a basic structural model. +We present below some of them. + +To compare the results (more precisely the likelihood) of the different approaches, +it is important to compute the marginal likelihood. + +```{r echo=FALSE} + +suppressPackageStartupMessages(library(rjd3toolkit)) +suppressPackageStartupMessages(library(rjd3sts)) +library(knitr) + + +``` + +```{r data} +s<-log(retail$BookStores) +``` + +### Standard definition, noise in the state + +```{r bsm1 } + +# create the model +bsm<-model() +# create the components and add them to the model +add(bsm, locallineartrend("ll")) +add(bsm, seasonal("s", 12, type="HarrisonStevens")) +add(bsm, noise("n")) +rslt<-estimate(bsm, log(s), marginal=T) + + +``` + +* Likelihood = `r result(rslt, "likelihood.ll")` +* Parameters = `r sapply(result(rslt, "parameters"), function(num) sprintf(num, fmt = '%#.6f'))` + +### Standard definition, noise in the measurement + +```{r bsm2} + +# create the model +bsm<-model() +# create the components and add them to the model +add(bsm, locallineartrend("ll")) +add(bsm, seasonal("s", 12, type="HarrisonStevens")) + # create the equation (fix the variance to 1) +eq<-equation("eq", 1,T) +add_equation(eq, "ll") +add_equation(eq, "s") +add(bsm, eq) +rslt<-estimate(bsm, log(s), marginal=T) +``` +* Likelihood = `r result(rslt, "likelihood.ll")` +* Parameters = `r sapply(result(rslt, "parameters"), function(num) sprintf(num, fmt = '%#.6f'))` + + +### components with fixed variances, aggregated with diffuse weights (noise in the state) + +```{r bsm3} + +# create the model +bsm<-model() + # create the components, with fixed variances, and add them to the model +add(bsm, locallineartrend("ll", + levelVariance = 1, fixedLevelVariance = TRUE) ) +add(bsm, seasonal("s", 12, type="HarrisonStevens", + variance = 1, fixed = TRUE)) +add(bsm, noise("n", 1, fixed=TRUE)) + # create the equation (fix the variance to 1) +eq<-equation("eq", 0, TRUE) +add_equation(eq, "ll", .01, FALSE) +add_equation(eq, "s", .01, FALSE) +add_equation(eq, "n") +add(bsm, eq) +rslt<-estimate(bsm, log(s), marginal=TRUE) +p<-result(rslt, "parameters") +``` + +* Likelihood = `r result(rslt, "likelihood.ll")` +* Parameters = `r sapply(p, function(num) sprintf(num, fmt = '%#.4f'))` + +To be noted: + +* Level variance = $p[5]\times p[5]$ = `r sprintf(p[5]*p[5], fmt = '%#.6f')` +* Slope variance = $p[5]\times p[5] \times p[2]$ = `r sprintf(p[5]*p[5]*p[2], fmt = '%#.6f')` +* Seas variance = $p[6]\times p[6]$ = `r sprintf(p[6]*p[6], fmt = '%#.6f')` + + + +### bsm with long term trend and cycle + +```{r bsm4} + +# create the model +bsm<-model() + # create the components and add them to the model +add(bsm, locallevel("l", initial = 0) ) +add(bsm, locallineartrend("lt", levelVariance = 0, + fixedLevelVariance = TRUE) ) +add(bsm, seasonal("s", 12, type="HarrisonStevens")) +add(bsm, noise("n", 1, fixed=TRUE)) + # create the equation (fix the variance to 1) +rslt<-estimate(bsm, log(s), marginal=TRUE) + +``` +* Likelihood = `r result(rslt, "likelihood.ll")` +* Parameters = `r sapply(result(rslt, "parameters"), function(num) sprintf(num, fmt = '%#.6f'))` + +```{r, fig.width=6} +ss<-smoothed_states(rslt) +plot(ss[,1]+ss[,2], type='l', col='blue', ylab='trends') +lines(ss[, 2], col='red') +``` diff --git a/vignettes/sts.Rmd b/vignettes/sts.Rmd new file mode 100644 index 0000000..a000c90 --- /dev/null +++ b/vignettes/sts.Rmd @@ -0,0 +1,46 @@ +--- +title: "Sructural Time Series using JDemetra+" +author: "Jean Palate" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Sructural Time Series using JDemetra+} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r setup, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +# Introduction + +```{r echo=FALSE} +suppressPackageStartupMessages(library(rjd3toolkit)) +suppressPackageStartupMessages(library(rjd3sts)) +library(knitr) +``` + + + +# Data + +We illustrate the various methods using two sets of time series: + +* The **retail** data set contains monthly figures over US retail activity of various categories of goods and services from 1992 to 2010. +* The **ABS** data set contains long monthly series over Australian retail trade. + +```{r data} +s<-log(retail$BookStores) +``` + + +# Examples + + + + + diff --git a/vignettes/tdvar.Rmd b/vignettes/tdvar.Rmd new file mode 100644 index 0000000..82637ed --- /dev/null +++ b/vignettes/tdvar.Rmd @@ -0,0 +1,141 @@ +--- +title: "Time varying trading days" +author: "Jean Palate" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Time varying trading days} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r setup, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +## Time-varying trading days + +### Introduction +The state space framework allows an easy estimation of time-varying trading days effects. + + +```{r echo=FALSE} + +suppressPackageStartupMessages(library(rjd3toolkit)) +suppressPackageStartupMessages(library(rjd3sts)) +library(knitr) +``` + + +```{r data} +# take a (transformed) series +s<-log(rjd3toolkit::ABS$X0.2.09.10.M) +``` + + +### Modelling + +We model such effects by integrating in the state array the regression coefficients. +As usual, the regression variables are modeled by using contrasts (for instance: #days-#Sundays). +the coefficient follow a multivariate random walk. As for the usual regression, we put +the constraint that the sum of the coefficients is 0 (which implies that one coefficient +is derived from the others). + +To be noted that fixed coefficients correspond to no innovation in the random walk. +We consider that the same innovation variance applies on the coefficients of each day (option contrast=FALSE) +or of each contrasts (option contrast=TRUE). +In this latter case, the variance of the innovation of the contrasting (group of) days is larger. + +Such time varying trading days can be plugged in any representation of the series. + +### SARIMA + TDvar + + +```{r tdvar1} + +# create the model +model<-rjd3sts::model() + +# create the components and add them to the model +rjd3sts::add(model, rjd3sts::sarima("airline", 12, c(0,1,1), c(0,1,1))) + +rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = F)) +#estimate the model +rslt<-rjd3sts::estimate(model, s) + +ss<-rjd3toolkit::result(rslt, "ssf.smoothing.states") +vss<-rjd3toolkit::result(rslt, "ssf.smoothing.vstates") + +``` + +### Available results + +The results can be retrieved through the "result" function. All the available +information are displayed by means of the "dictionary" method + +```{r} +print(rjd3toolkit::dictionary(rslt)) +``` +Time varying trading days + +```{r tdvar1_chart, fig.width=6, fig.height=4} + +colfunc<-colorRampPalette(c("red","blue","green","#196F3D")) +colors <- (colfunc(7)) + +pos<-rjd3toolkit::result(rslt, "ssf.cmppos") +plot(ss[,pos[2]+1], type='l', col=colors[1], ylim=c(-0.04, 0.03), ylab='coeff') +lines(ss[,pos[2]+2], col=colors[2]) +lines(ss[,pos[2]+3], col=colors[3]) +lines(ss[,pos[2]+4], col=colors[4]) +lines(ss[,pos[2]]+5, col=colors[5]) +lines(ss[,pos[2]+6], col=colors[6]) +lines(-rowSums(ss[,pos[2]+(1:6)]), col=colors[7]) + +``` + +### BSM + TDvar + +```{r tdvar2} +# take a (transformed) series +s<-log(rjd3toolkit::ABS$X0.2.09.10.M) + +# create the model +model<-rjd3sts::model() + +# create the components and add them to the model +llt<-rjd3sts::locallineartrend('l') +seas<-rjd3sts::seasonal("s", 12, "HarrisonStevens") +n<-rjd3sts::noise('n') +rjd3sts::add(model, llt) +rjd3sts::add(model, seas) +rjd3sts::add(model, n) +rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = F)) +#estimate the model +rslt<-rjd3sts::estimate(model, s) + +ss<-rjd3toolkit::result(rslt, "ssf.smoothing.states") +vss<-rjd3toolkit::result(rslt, "ssf.smoothing.vstates") + +``` + +Time varying trading days + +```{r tdvar2_chart, fig.width=6, fig.height=4} + +colfunc<-colorRampPalette(c("red","blue","green","#196F3D")) +colors <- (colfunc(7)) + +pos<-rjd3toolkit::result(rslt, "ssf.cmppos") +plot(ss[,pos[4]+1], type='l', col=colors[1], ylim=c(-0.04, 0.03), ylab='coeff') +lines(ss[,pos[4]+2], col=colors[2]) +lines(ss[,pos[4]+3], col=colors[3]) +lines(ss[,pos[4]+4], col=colors[4]) +lines(ss[,pos[4]]+5, col=colors[5]) +lines(ss[,pos[4]+6], col=colors[6]) +lines(-rowSums(ss[,pos[4]+(1:6)]), col=colors[7]) + +``` From 8507f002ccb4fdf7a11054199199ec041758b125 Mon Sep 17 00:00:00 2001 From: palatej Date: Wed, 3 Jul 2024 12:45:20 +0200 Subject: [PATCH 2/2] Changes of T and F --- inst/doc/bsm.R | 6 +++--- inst/doc/bsm.Rmd | 6 +++--- inst/doc/bsm.html | 6 +++--- inst/doc/tdvar.R | 4 ++-- inst/doc/tdvar.Rmd | 4 ++-- inst/doc/tdvar.html | 4 ++-- vignettes/bsm.Rmd | 6 +++--- vignettes/tdvar.Rmd | 4 ++-- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/inst/doc/bsm.R b/inst/doc/bsm.R index 64a6d9c..45eff97 100644 --- a/inst/doc/bsm.R +++ b/inst/doc/bsm.R @@ -17,7 +17,7 @@ bsm<-model() add(bsm, locallineartrend("ll")) add(bsm, seasonal("s", 12, type="HarrisonStevens")) add(bsm, noise("n")) -rslt<-estimate(bsm, log(s), marginal=T) +rslt<-estimate(bsm, log(s), marginal=TRUE) @@ -29,11 +29,11 @@ bsm<-model() add(bsm, locallineartrend("ll")) add(bsm, seasonal("s", 12, type="HarrisonStevens")) # create the equation (fix the variance to 1) -eq<-equation("eq", 1,T) +eq<-equation("eq", 1,TRUE) add_equation(eq, "ll") add_equation(eq, "s") add(bsm, eq) -rslt<-estimate(bsm, log(s), marginal=T) +rslt<-estimate(bsm, log(s), marginal=TRUE) ## ----bsm3--------------------------------------------------------------------- diff --git a/inst/doc/bsm.Rmd b/inst/doc/bsm.Rmd index 0573d18..636f44d 100644 --- a/inst/doc/bsm.Rmd +++ b/inst/doc/bsm.Rmd @@ -40,7 +40,7 @@ bsm<-model() add(bsm, locallineartrend("ll")) add(bsm, seasonal("s", 12, type="HarrisonStevens")) add(bsm, noise("n")) -rslt<-estimate(bsm, log(s), marginal=T) +rslt<-estimate(bsm, log(s), marginal=TRUE) ``` @@ -58,11 +58,11 @@ bsm<-model() add(bsm, locallineartrend("ll")) add(bsm, seasonal("s", 12, type="HarrisonStevens")) # create the equation (fix the variance to 1) -eq<-equation("eq", 1,T) +eq<-equation("eq", 1,TRUE) add_equation(eq, "ll") add_equation(eq, "s") add(bsm, eq) -rslt<-estimate(bsm, log(s), marginal=T) +rslt<-estimate(bsm, log(s), marginal=TRUE) ``` * Likelihood = `r result(rslt, "likelihood.ll")` * Parameters = `r sapply(result(rslt, "parameters"), function(num) sprintf(num, fmt = '%#.6f'))` diff --git a/inst/doc/bsm.html b/inst/doc/bsm.html index a64c73f..bcf1654 100644 --- a/inst/doc/bsm.html +++ b/inst/doc/bsm.html @@ -360,7 +360,7 @@

Standard definition, noise in the state

add(bsm, locallineartrend("ll")) add(bsm, seasonal("s", 12, type="HarrisonStevens")) add(bsm, noise("n")) -rslt<-estimate(bsm, log(s), marginal=T) +rslt<-estimate(bsm, log(s), marginal=TRUE)
  • Likelihood = 747.8184945
  • Parameters = 0.160016, 0.000396, 0.243922, 1.000000
  • @@ -374,11 +374,11 @@

    Standard definition, noise in the measurement

    add(bsm, locallineartrend("ll")) add(bsm, seasonal("s", 12, type="HarrisonStevens")) # create the equation (fix the variance to 1) -eq<-equation("eq", 1,T) +eq<-equation("eq", 1,TRUE) add_equation(eq, "ll") add_equation(eq, "s") add(bsm, eq) -rslt<-estimate(bsm, log(s), marginal=T) +rslt<-estimate(bsm, log(s), marginal=TRUE)
    • Likelihood = 747.8184945
    • Parameters = 0.160016, 0.000396, 0.243922, 1.000000
    • diff --git a/inst/doc/tdvar.R b/inst/doc/tdvar.R index 8bb2d54..1b57b32 100644 --- a/inst/doc/tdvar.R +++ b/inst/doc/tdvar.R @@ -22,7 +22,7 @@ model<-rjd3sts::model() # create the components and add them to the model rjd3sts::add(model, rjd3sts::sarima("airline", 12, c(0,1,1), c(0,1,1))) -rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = F)) +rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = FALSE)) #estimate the model rslt<-rjd3sts::estimate(model, s) @@ -62,7 +62,7 @@ n<-rjd3sts::noise('n') rjd3sts::add(model, llt) rjd3sts::add(model, seas) rjd3sts::add(model, n) -rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = F)) +rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = FALSE)) #estimate the model rslt<-rjd3sts::estimate(model, s) diff --git a/inst/doc/tdvar.Rmd b/inst/doc/tdvar.Rmd index 82637ed..46d6d8e 100644 --- a/inst/doc/tdvar.Rmd +++ b/inst/doc/tdvar.Rmd @@ -62,7 +62,7 @@ model<-rjd3sts::model() # create the components and add them to the model rjd3sts::add(model, rjd3sts::sarima("airline", 12, c(0,1,1), c(0,1,1))) -rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = F)) +rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = FALSE)) #estimate the model rslt<-rjd3sts::estimate(model, s) @@ -113,7 +113,7 @@ n<-rjd3sts::noise('n') rjd3sts::add(model, llt) rjd3sts::add(model, seas) rjd3sts::add(model, n) -rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = F)) +rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = FALSE)) #estimate the model rslt<-rjd3sts::estimate(model, s) diff --git a/inst/doc/tdvar.html b/inst/doc/tdvar.html index 66b6479..d6115fa 100644 --- a/inst/doc/tdvar.html +++ b/inst/doc/tdvar.html @@ -378,7 +378,7 @@

      SARIMA + TDvar

      # create the components and add them to the model rjd3sts::add(model, rjd3sts::sarima("airline", 12, c(0,1,1), c(0,1,1))) -rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = F)) +rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = FALSE)) #estimate the model rslt<-rjd3sts::estimate(model, s) @@ -442,7 +442,7 @@

      BSM + TDvar

      rjd3sts::add(model, llt) rjd3sts::add(model, seas) rjd3sts::add(model, n) -rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = F)) +rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = FALSE)) #estimate the model rslt<-rjd3sts::estimate(model, s) diff --git a/vignettes/bsm.Rmd b/vignettes/bsm.Rmd index 0573d18..636f44d 100644 --- a/vignettes/bsm.Rmd +++ b/vignettes/bsm.Rmd @@ -40,7 +40,7 @@ bsm<-model() add(bsm, locallineartrend("ll")) add(bsm, seasonal("s", 12, type="HarrisonStevens")) add(bsm, noise("n")) -rslt<-estimate(bsm, log(s), marginal=T) +rslt<-estimate(bsm, log(s), marginal=TRUE) ``` @@ -58,11 +58,11 @@ bsm<-model() add(bsm, locallineartrend("ll")) add(bsm, seasonal("s", 12, type="HarrisonStevens")) # create the equation (fix the variance to 1) -eq<-equation("eq", 1,T) +eq<-equation("eq", 1,TRUE) add_equation(eq, "ll") add_equation(eq, "s") add(bsm, eq) -rslt<-estimate(bsm, log(s), marginal=T) +rslt<-estimate(bsm, log(s), marginal=TRUE) ``` * Likelihood = `r result(rslt, "likelihood.ll")` * Parameters = `r sapply(result(rslt, "parameters"), function(num) sprintf(num, fmt = '%#.6f'))` diff --git a/vignettes/tdvar.Rmd b/vignettes/tdvar.Rmd index 82637ed..46d6d8e 100644 --- a/vignettes/tdvar.Rmd +++ b/vignettes/tdvar.Rmd @@ -62,7 +62,7 @@ model<-rjd3sts::model() # create the components and add them to the model rjd3sts::add(model, rjd3sts::sarima("airline", 12, c(0,1,1), c(0,1,1))) -rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = F)) +rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = FALSE)) #estimate the model rslt<-rjd3sts::estimate(model, s) @@ -113,7 +113,7 @@ n<-rjd3sts::noise('n') rjd3sts::add(model, llt) rjd3sts::add(model, seas) rjd3sts::add(model, n) -rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = F)) +rjd3sts::add(model, vtd<-rjd3sts::reg_td("td", 12, start(s), length(s), contrast = FALSE)) #estimate the model rslt<-rjd3sts::estimate(model, s)