bsm_lg {bssm} | R Documentation |
Constructs a basic structural model with local level or local trend component and seasonal component.
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 )
y |
Vector or a |
sd_y |
Standard deviation of the noise of observation equation.
Should be an object of class |
sd_level |
Standard deviation of the noise of level equation.
Should be an object of class |
sd_slope |
Standard deviation of the noise of slope equation.
Should be an object of class |
sd_seasonal |
Standard deviation of the noise of seasonal equation.
Should be an object of class |
beta |
Prior for the regression coefficients.
Should be an object of class |
xreg |
Matrix containing covariates with number of rows matching the
length of |
period |
Length of the seasonal pattern.
Default is |
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). |
Object of class bsm_lg
.
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)