I'm encountering an error I can't resolve with the inlabru package and AR1 processes.
Code is below to reproduce the error, I define the model the usual INLA way which works and then with inlabru.
It works when no grouping, but fails when I include a group.
library(INLA)
library(inlabru)
# Simulate data - 3 groups with same AR1 param
n = 100
rho <- 0.8
x1 = arima.sim(n=n, model=list(ar=c(rho)))
x2 = arima.sim(n=n, model=list(ar=c(rho)))
x3 = arima.sim(n=n, model=list(ar=c(rho)))
# Poisson observations
y1 = rpois(n, lambda = exp(x1))
y2 = rpois(n, lambda = exp(x2))
y3 = rpois(n, lambda = exp(x3))
# First fit just to y1 with no groups, this works:
# ----------------------------------------------------------
df2 <- data.frame(y = y1, t = 1:n)
# Fit with INLA
fml <- y ~ f(t, model = "ar1")
result = inla(fml, family = "poisson", data = df2)
summary(result)
# Fit with inlabru
fml <- y ~ Intercept + myar1(map = t, model = "ar1", n = n) # now need to specify n, not sure why
fit <- bru(fml, family = "poisson", data = df2)
summary(fit)
# Now with groups, this works in INLA but not inlabru:
# ----------------------------------------------------------------------
df_groups <- data.frame(y = c(y1, y2, y3),
t = rep(1:n, 3),
ID = c(rep(1, n), rep(2, n), rep(3,n)))
# INLA
fml = y ~ f(t, model = "ar1", group = ID)
result = inla(fml, family = "poisson", data = df_groups)
summary(result)
# inlabru
fml <- y ~ Intercept + myar1(map = t, model = "ar1", group = ID, n = n) # n = n within group or n total?
fit <- bru(fml, family = "poisson", data = df_groups)
I'm not sure why I need the n argument in inlabru or how to specify it when grouping, but the error occurs with no n, n = n_group, n = n_total
Andy
df_groups <- data.frame(y = c(y1, y2, y3),
t = rep(1:n, 3),
ID = c(rep(1, n), rep(2, n), rep(3,n)))
# INLA
fml = y ~ f(t, model = "ar1", group = ID)
result = inla(fml, family = "poisson", data = df_groups)
summary(result)
# inlabru
fml <- y ~ Intercept + myar1(map = t, model = "ar1", group = ID, n = n)
fit <- bru(fml, family = "poisson", data = df_groups)