bsm_lg {bssm}R Documentation

Basic Structural (Time Series) Model

Description

Constructs a basic structural model with local level or local trend component and seasonal component.

Usage

bsm_lg(
  y,
  sd_y,
  sd_level,
  sd_slope,
  sd_seasonal,
  beta,
  xreg = NULL,
  period = frequency(y),
  a1 = NULL,
  P1 = NULL,
  D = NULL,
  C = NULL
)

Arguments

y

Vector or a ts object of observations.

sd_y

Standard deviation of the noise of observation equation. Should be an object of class bssm_prior or scalar.

sd_level

Standard deviation of the noise of level equation. Should be an object of class bssm_prior or scalar value defining a known value such as 0.

sd_slope

Standard deviation of the noise of slope equation. Should be an object of class bssm_prior, scalar value defining a known value such as 0, or missing, in which case the slope term is omitted from the model.

sd_seasonal

Standard deviation of the noise of seasonal equation. Should be an object of class bssm_prior, scalar value defining a known value such as 0, or missing, in which case the seasonal term is omitted from the model.

beta

Prior for the regression coefficients. Should be an object of class bssm_prior or bssm_prior_list (in case of multiple coefficients) or missing in case of no covariates.

xreg

Matrix containing covariates with number of rows matching the length of y.

period

Length of the seasonal pattern. Default is frequency(y). Must be a positive integer greater than 2 and less than the length of the input time series.

a1

Prior means for the initial states (level, slope, seasonals). Defaults to vector of zeros.

P1

Prior covariance for the initial states (level, slope, seasonals). Default is diagonal matrix with 1000 on the diagonal.

D, C

Intercept terms for observation and state equations, given as a length n vector and m times n matrix respectively (or scalar and m times 1 matrix).

Value

Object of class bsm_lg.

Examples


prior <- uniform(0.1 * sd(log10(UKgas)), 0, 1)
# period here is redundant as frequency(UKgas) = 4
model <- bsm_lg(log10(UKgas), sd_y = prior, sd_level =  prior,
  sd_slope =  prior, sd_seasonal =  prior, period = 4)

mcmc_out <- run_mcmc(model, iter = 5000)
summary(expand_sample(mcmc_out, "theta"))$stat
mcmc_out$theta[which.max(mcmc_out$posterior), ]
sqrt((fit <- StructTS(log10(UKgas), type = "BSM"))$coef)[c(4, 1:3)]

set.seed(1)
n <- 10
x <- rnorm(n)
level <- numeric(n)
level[1] <- rnorm(1)
for (i in 2:n) level[i] <- rnorm(1, -0.2 + level[i-1], sd = 0.1)
y <- rnorm(n, 2.1 + x + level)
model <- bsm_lg(y, sd_y = halfnormal(1, 5), sd_level = 0.1, a1 = level[1], 
  P1 = matrix(0, 1, 1), xreg = x, beta = normal(1, 0, 1),
  D = 2.1, C = matrix(-0.2, 1, 1))
  
ts.plot(cbind(fast_smoother(model), level), col = 1:2)


[Package bssm version 1.1.7-1 Index]