View source: R/temporal_core.R
| temporal_ar1 | R Documentation |
Specify a first-order autoregressive temporal random effect.
AR1 models temporal correlation where each time point depends on
the previous one: phi[t] = rho * phi[t-1] + epsilon[t].
Unlike RW1/RW2, AR1 is a proper (stationary) model with an estimated autocorrelation parameter rho.
temporal_ar1(time_var, group_var = NULL, shared = NULL, rho_prior = NULL)
time_var |
A formula ( |
group_var |
Optional formula ( |
shared |
Whether the temporal effect is shared across processes in a
multi-process model. |
rho_prior |
Prior for the AR(1) autocorrelation. Default |
The AR1 process has marginal variance sigma^2 / (1 - rho^2) and correlation between time points t and s of rho^|t-s|.
The precision matrix is tridiagonal and full rank, so no constraints are needed.
A tulpa_temporal object
# Create temporal AR1 specification
temporal_ar1("year")
temporal_ar1("year", group = "site")
# AR1 temporal correlation
set.seed(127)
df <- data.frame(
year = rep(1:20, each = 3),
x = rnorm(60)
)
f <- as.numeric(arima.sim(list(ar = 0.7), 20, sd = 0.4))
df$count <- rpois(60, exp(1 + 0.3 * df$x + f[df$year]))
fit <- tulpa(
count ~ x,
data = df,
family = "poisson",
temporal = temporal_ar1("year"),
mode = "auto"
)
summary(fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.