inlabru-org / inlabru

inlabru
https://inlabru-org.github.io/inlabru/
76 stars 21 forks source link

BYM-model #75

Closed fredriklaa closed 3 years ago

fredriklaa commented 4 years ago

When I try to predict on a BYM-model from INLA, I get the following error message: Error in g(region, model = "iid") : Please provide parameter 'n' for effect 'region'

Example code (copy pasted from INLA-example pages): INLA:::inla.dynload.workaround() data(Germany) g2 = system.file("demodata/germany.graph", package="INLA") source(system.file("demodata/Bym-map.R", package="INLA")) summary(Germany)

just make a duplicated column

Germany = cbind(Germany,region.struct=Germany$region)

standard BYM model (without covariates)

formula1 = Y ~ f(region.struct,model="besag",graph=g2) + f(region,model="iid") result1 = inla(formula1,family="poisson",data=Germany,E=Germany$E,verbose = TRUE) predictresult1<-predict(result1,data=Germnay)

Best regards Fredrik

finnlindgren commented 3 years ago

The development version can now auto-determine the model size in more cases, including this one. Working example with inlabru 2.1.15:

library(INLA)
library(inlabru)

data(Germany)
g2 <- system.file("demodata/germany.graph", package = "INLA")
source(system.file("demodata/Bym-map.R", package = "INLA"))
summary(Germany)

# BYM model (without covariates) (with explicit components instead of builtin
# INLA bym/bym2 models)
formula1 <-
  Y ~ region_struct(region, model = "besag", graph = g2) +
    region(region, model = "iid")
result1 <- bru(formula1,
  family = "poisson", data = Germany, E = Germany$E,
  options = list(verbose = TRUE)
)

predict_result1 <- predict(result1, data = Germany, ~ region_struct + region)