Skip to content

Commit 97239a3

Browse files
author
Jouni Helske
committed
added a SSMbespoke component
1 parent 9b29f8e commit 97239a3

File tree

8 files changed

+127
-41
lines changed

8 files changed

+127
-41
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Changes from version 1.5.1 to 1.6.0
2+
* Added a new function `SSMbespoke` to be used inside `SSModel`. This allows
3+
users to abstract the functionality of `SSMcustom` via their own bespoke
4+
function using, e.g., `SSMbespoke(myfun()) in the model formula.
5+
16
Changes from version 1.5.0 to 1.5.1
27
* Added explicit alias for KFAS-package due to changes in roxygen2.
38

DESCRIPTION

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
Package: KFAS
2-
Version: 1.5.1
3-
Title: Kalman Filter and Smoother for Exponential Family State Space Models
4-
Authors@R:
5-
person(given = "Jouni",
6-
family = "Helske",
7-
role = c("aut", "cre"),
8-
email = "jouni.helske@iki.fi",
9-
comment = c(ORCID = "0000-0001-7130-793X"))
10-
Depends:
11-
R (>= 3.1.0)
12-
Imports:
13-
stats
14-
Suggests:
15-
knitr,
16-
lme4,
17-
MASS,
18-
Matrix,
19-
testthat
20-
Description: State space modelling is an efficient and flexible framework for
21-
statistical inference of a broad class of time series and other data. KFAS
22-
includes computationally efficient functions for Kalman filtering, smoothing,
23-
forecasting, and simulation of multivariate exponential family state space models,
24-
with observations from Gaussian, Poisson, binomial, negative binomial, and gamma
25-
distributions. See the paper by Helske (2017) <doi:10.18637/jss.v078.i10> for details.
26-
License: GPL (>= 2)
27-
BugReports: https://github.com/helske/KFAS/issues
28-
VignetteBuilder: knitr
29-
RoxygenNote: 7.2.3
30-
Encoding: UTF-8
31-
ByteCompile: true
32-
URL: https://github.com/helske/KFAS
1+
Package: KFAS
2+
Version: 1.6.0
3+
Title: Kalman Filter and Smoother for Exponential Family State Space Models
4+
Authors@R:
5+
person(given = "Jouni",
6+
family = "Helske",
7+
role = c("aut", "cre"),
8+
email = "jouni.helske@iki.fi",
9+
comment = c(ORCID = "0000-0001-7130-793X"))
10+
Depends:
11+
R (>= 3.1.0)
12+
Imports:
13+
stats
14+
Suggests:
15+
knitr,
16+
lme4,
17+
MASS,
18+
Matrix,
19+
testthat
20+
Description: State space modelling is an efficient and flexible framework for
21+
statistical inference of a broad class of time series and other data. KFAS
22+
includes computationally efficient functions for Kalman filtering, smoothing,
23+
forecasting, and simulation of multivariate exponential family state space models,
24+
with observations from Gaussian, Poisson, binomial, negative binomial, and gamma
25+
distributions. See the paper by Helske (2017) <doi:10.18637/jss.v078.i10> for details.
26+
License: GPL (>= 2)
27+
BugReports: https://github.com/helske/KFAS/issues
28+
VignetteBuilder: knitr
29+
Encoding: UTF-8
30+
ByteCompile: true
31+
URL: https://github.com/helske/KFAS
32+
RoxygenNote: 7.3.2

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ S3method(subset,SSModel)
2121
export("subset<-")
2222
export(KFS)
2323
export(SSMarima)
24+
export(SSMbespoke)
2425
export(SSMcustom)
2526
export(SSMcycle)
2627
export(SSModel)

R/KFAS-package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@
592592
#'
593593
#' }
594594
#'
595-
NULL
595+
"_PACKAGE"
596596
#' Oxford-Cambridge boat race results 1829-2011
597597
#'
598598
#' Results of the annual boat race between universities of Oxford (0) and Cambridge (1).

R/SSMbespoke.R

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#' @rdname SSModel
2+
#' @param f An user-defined function which should return the output from
3+
#' \code{\link{SSMcustom}}. See examples.
4+
#' @examples
5+
#' # Example on bespoke function for time-varying trend
6+
#' trend <- function(sigma, n) {
7+
#' Z <- array(seq_len(n), c(1, 1, n))
8+
#' T <- R <- matrix(1, 1, 1)
9+
#' Q <- matrix(sigma^2, 1, 1)
10+
#' a1 <- 0
11+
#' P1 <- 10
12+
#' SSMcustom(Z, T, R, Q, a1, P1, n = n, state_names = "timevarying trend")
13+
#' }
14+
#'
15+
#' model <- SSModel(Nile ~ SSMbespoke(trend(NA, length(Nile))), H = NA)
16+
#' updatefn <- function(pars, model){
17+
#' model$Q[1, 1, 1] <- exp(0.5 * pars[1])
18+
#' model$H[1, 1, 1] <- exp(0.5 * pars[2])
19+
#' model
20+
#' }
21+
#'
22+
#' fit <- fitSSM(model, c(1, 20), updatefn, method = "BFGS")
23+
#' conf_intv <- predict(fit$model, interval = "confidence", level = 0.95)
24+
#'
25+
#' ts.plot(
26+
#' cbind(Nile, conf_intv),
27+
#' col = c(1, 2, 2, 2),
28+
#' ylab = "Predicted Annual flow",
29+
#' main = "River Nile"
30+
#' )
31+
#' @export
32+
SSMbespoke <- function(f, index, n) {
33+
f
34+
}

R/SSModel.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@
88
#' functions defining different types of components of the model, named as
99
#' \code{SSMarima}, \code{SSMcustom}, \code{SSMcycle}, \code{SSMregression},
1010
#' \code{SSMseasonal} and \code{SSMtrend}.
11-
#'
12-
#' For more details, see package vignette (the mathematical notation is somewhat non-readable in ASCII).
11+
#'
12+
#' \code{SSMbespoke} function is similar to \code{\link{SSMcustom}} but instead
13+
#' of defining the model component directly via system matrices, it wraps an
14+
#' arbitrary user-defined function which should return the output from
15+
#' \code{\link{SSMcustom}}.
16+
#' For more details, see package vignette.
1317
#'
1418
#' @export
1519
#' @importFrom stats terms update.formula drop.terms model.response model.matrix delete.response update.formula
1620
#' @rdname SSModel
1721
#' @name SSModel
18-
#' @seealso \code{\link{KFAS}} for more examples.
22+
#' @seealso \code{\link{KFAS}} for more examples and \code{link{SSMbespoke}} for
23+
#' an alternative way of creating custom components.
1924
#' @param formula An object of class \code{\link{formula}} containing the
2025
#' symbolic description of the model. The intercept term can be removed with
2126
#' \code{-1} as in \code{lm}. In case of trend or differenced arima component the
@@ -253,7 +258,7 @@ SSModel <- function(formula, data, H, u, distribution,
253258
mf[[1L]] <- as.name("model.frame")
254259
mf$na.action <- as.name("na.pass")
255260
components <- c("SSMregression", "SSMtrend", "SSMseasonal", "SSMcycle",
256-
"SSMarima", "SSMcustom")
261+
"SSMarima", "SSMcustom", "SSMbespoke")
257262

258263
all_terms <- terms_out <- terms(formula, specials = components, data = data)
259264
specials <- attr(all_terms, "specials")

man/KFAS.Rd

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/SSModel.Rd

Lines changed: 41 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)