Non-Gaussian Basic Structural (Time Series) Model
Constructs a non-Gaussian basic structural model with local level or local trend component, a seasonal component, and regression component (or subset of these components).
bsm_ng( y, sd_level, sd_slope, sd_seasonal, sd_noise, distribution, phi, u = 1, beta, xreg = NULL, period = frequency(y), a1, P1, C )
y |
Vector or a |
sd_level |
A fixed value or a prior for the standard error of the noise in level equation. See priors for details. |
sd_slope |
A fixed value or a prior for the standard error of the noise in slope equation. See priors for details. If missing, the slope term is omitted from the model. |
sd_seasonal |
A fixed value or a prior for the standard error of the noise in seasonal equation. See priors for details. If missing, the seasonal component is omitted from the model. |
sd_noise |
Prior for the standard error of the additional noise term. See priors for details. If missing, no additional noise term is used. |
distribution |
Distribution of the observed time series. Possible choices are
|
phi |
Additional parameter relating to the non-Gaussian distribution. For negative binomial distribution this is the dispersion term, for gamma distribution this is the shape parameter, and for other distributions this is ignored. |
u |
Constant parameter vector for non-Gaussian models. For Poisson, gamma, and negative binomial distribution, this corresponds to the offset term. For binomial, this is the number of trials. |
beta |
Prior for the regression coefficients. |
xreg |
Matrix containing covariates. |
period |
Length of the seasonal component i.e. the number of
observations per season. 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 1e5 on the diagonal. |
C |
Intercept terms for state equation, given as a m times n matrix. |
Object of class bsm_ng
.
model <- bsm_ng(Seatbelts[, "VanKilled"], distribution = "poisson", sd_level = halfnormal(0.01, 1), sd_seasonal = halfnormal(0.01, 1), beta = normal(0, 0, 10), xreg = Seatbelts[, "law"]) ## Not run: set.seed(123) mcmc_out <- run_mcmc(model, iter = 5000, particles = 10) mcmc_out$acceptance_rate theta <- expand_sample(mcmc_out, "theta") plot(theta) summary(theta) library("ggplot2") ggplot(as.data.frame(theta[,1:2]), aes(x = sd_level, y = sd_seasonal)) + geom_point() + stat_density2d(aes(fill = ..level.., alpha = ..level..), geom = "polygon") + scale_fill_continuous(low = "green", high = "blue") + guides(alpha = "none") # Traceplot using as.data.frame method for MCMC output: library("dplyr") as.data.frame(mcmc_out) %>% filter(variable == "sd_level") %>% ggplot(aes(y = value, x = iter)) + geom_line() ## End(Not run)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.