Skip to content

Commit

Permalink
Merge pull request #21 from palatej/develop
Browse files Browse the repository at this point in the history
Add usages in readme
  • Loading branch information
palatej authored May 8, 2024
2 parents ed9e985 + 7193011 commit 362fc9c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 10 deletions.
14 changes: 9 additions & 5 deletions R/jd3_ssf.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ MODELESTIMATION<-'JD3_SsfModelEstimation'
MODEL<-'JD3_SsfModel'
STATEBLOCK<-'JD3_SsfStateBlock'

#' Add Latent variable
#' Add a building block to the considered equation
#'
#' @param equation the equation
#' @param item
#' @param item the block of the state array that will be linked to the observation corresponding to this equation through the specified loading and coefficient
#' @param coeff the value of the coefficient associated to the block of latent variables defined by `item`.
#' @param fixed logical that triggers estimation of coeff (FALSE) or fixes it (TRUE) to a pre-specified value
#' @param loading
#' @param loading the loading that links the block to the observation
#'
#' @return
#' @export
#'
#' @examples
#'
#' model<- equation('eq1)
#' ll<-locallevel('ll')
#' n<-noise('n')
#' add_equation(model, ll)
#' add_equation(model, n)
add_equation<-function(equation, item, coeff=1, fixed=TRUE, loading=NULL){
if (! is(equation, EQUATION))
stop("Not an equation")
Expand Down Expand Up @@ -394,7 +398,7 @@ seasonal<-function(name, period, type=c("Trigonometric", "Crude", "HarrisonSteve
return (rjd3toolkit::.jd3_object(jrslt, STATEBLOCK))
}

#' Title
#' Noise component
#'
#' @param name
#' @param variance
Expand Down
21 changes: 21 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,28 @@ To get the current development version from GitHub:
# install.packages("remotes")
remotes::install_github("rjdverse/rjd3sts")
```
## Usage

```{r sts-var-td}
library("rjd3sts")
y <- log(rjd3toolkit::ABS$X0.2.09.10.M)
days<-c(1,1,1,1,2,3,0)
model<-rjd3sts::model()
sarima<-rjd3sts::sarima('arima', 12, orders=c(0,1,1), seasonal=c(0,1,1))
td<-rjd3sts::reg_td('td', 12, start(y), length(y), variance=1, fixed=FALSE)
rjd3sts::add(model, sarima)
rjd3sts::add(model, td)
rslt<-rjd3sts::estimate(model, y)
cmp<-rjd3sts::smoothed_components(rslt)
ss<-rjd3sts::smoothed_states(rslt)
plot(cmp[,2], type='l', ylim=c(-0.05, 0.04), col='blue', main="Time-varying td effect (+ Sundays coeff.)", xlab="", ylab="td effect")
lines(-rowSums(ss[,15:20]), col='green', lwd = 3)
```

## Package Maintenance and contributing

Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,36 @@ To get the current development version from GitHub:
remotes::install_github("rjdverse/rjd3sts")
```

## Usage

``` r
library("rjd3sts")
#>
#> Attaching package: 'rjd3sts'
#> The following objects are masked from 'package:stats':
#>
#> ar, arima, cycle

y <- log(rjd3toolkit::ABS$X0.2.09.10.M)
days<-c(1,1,1,1,2,3,0)

model<-rjd3sts::model()
sarima<-rjd3sts::sarima('arima', 12, orders=c(0,1,1), seasonal=c(0,1,1))
td<-rjd3sts::reg_td('td', 12, start(y), length(y), variance=1, fixed=FALSE)

rjd3sts::add(model, sarima)
rjd3sts::add(model, td)

rslt<-rjd3sts::estimate(model, y)
cmp<-rjd3sts::smoothed_components(rslt)
ss<-rjd3sts::smoothed_states(rslt)

plot(cmp[,2], type='l', ylim=c(-0.05, 0.04), col='blue', main="Time-varying td effect (+ Sundays coeff.)", xlab="", ylab="td effect")
lines(-rowSums(ss[,15:20]), col='green', lwd = 3)
```

<img src="man/figures/README-sts-var-td-1.png" width="100%" />

## Package Maintenance and contributing

Any contribution is welcome and should be done through pull requests
Expand Down
8 changes: 5 additions & 3 deletions man/add_equation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added man/figures/README-sts-var-td-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions man/noise.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 362fc9c

Please sign in to comment.