ar1_lg | R Documentation |
Constructs a simple Gaussian model where the state dynamics follow an AR(1) process.
ar1_lg(y, rho, sigma, mu, sd_y, beta, xreg = NULL)
y |
A vector or a |
rho |
A prior for autoregressive coefficient.
Should be an object of class |
sigma |
A prior for the standard deviation of noise of the AR-process.
Should be an object of class |
mu |
A fixed value or a prior for the stationary mean of the latent
AR(1) process. Should be an object of class |
sd_y |
A prior for the standard deviation of observation equation. |
beta |
A prior for the regression coefficients.
Should be an object of class |
xreg |
A matrix containing covariates with number of rows matching the
length of |
An object of class ar1_lg
.
set.seed(1) mu <- 2 rho <- 0.7 sd_y <- 0.1 sigma <- 0.5 beta <- -1 x <- rnorm(30) z <- y <- numeric(30) z[1] <- rnorm(1, mu, sigma / sqrt(1 - rho^2)) y[1] <- rnorm(1, beta * x[1] + z[1], sd_y) for(i in 2:30) { z[i] <- rnorm(1, mu * (1 - rho) + rho * z[i - 1], sigma) y[i] <- rnorm(1, beta * x[i] + z[i], sd_y) } model <- ar1_lg(y, rho = uniform(0.5, -1, 1), sigma = halfnormal(1, 10), mu = normal(0, 0, 1), sd_y = halfnormal(1, 10), xreg = x, beta = normal(0, 0, 1)) out <- run_mcmc(model, iter = 2e4) summary(out, return_se = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.