Variance/precisions of structured random effects

56 views
Skip to first unread message

Maria

unread,
Jul 12, 2022, 6:39:24 AM7/12/22
to R-inla discussion group
Hi,

I am fitting a model with split random effects and separate intercepts (taking account the sampling weights) of a country separated by the sea into 2 separate regions. I was wondering if there were any recent changes in INLA as the output for the variance/ precisions of the structured random effects in the models fitted in April were different from the output in July (using the same codes and data). Below are the codes:


props.w$unstruct <- props.w$struct <- 1:n.area
formula1 = logit.p ~ -1 + factor(Region) +
  f(struct1, model = 'besag', graph = mat1, scale.model = TRUE, param = c(0.5,0.005)) +  
  f(unstruct1, model = 'iid',  param = c(0.5,0.005)) +
  f(struct2, model = 'besag', graph = mat2, scale.model = TRUE, param = c(0.5,0.005)) +  
  f(unstruct2, model = 'iid',  param = c(0.5,0.005))

fit1 <- inla(formula1,
                     family="gaussian", data=props.w,
                     control.predictor = list(compute = TRUE),
                     control.compute = list(dic = TRUE, cpo = TRUE, waic=TRUE),
                     control.family = list(hyper = list(prec = list(
                       initial = log(1), fixed=TRUE))),
                     scale=props.w$logit.prec)
summary(fit1)

# variance region1
m <- fit1$internal.marginals.hyperpar$"Log precision for struct1"
m.var <- inla.tmarginal(function(x) 1/exp(x), m)
inla.zmarginal(m.var)

m1 <- fit1$internal.marginals.hyperpar$"Log precision for unstruct1"
m1.var <- inla.tmarginal(function(x) 1/exp(x), m1)
inla.zmarginal(m1.var)

# variance region2 
m2 <- fit1$internal.marginals.hyperpar$"Log precision for struct2"
m2.var <- inla.tmarginal(function(x) 1/exp(x), m2)
inla.zmarginal(m2.var)

m3 <- fit1$internal.marginals.hyperpar$"Log precision for unstruct2"
m3.var <- inla.tmarginal(function(x) 1/exp(x), m3)
inla.zmarginal(m3.var) 


Thank you in advance for your help.

BR,
Maria

Helpdesk

unread,
Jul 27, 2022, 3:41:54 PM7/27/22
to Maria, R-inla discussion group

even if you run the same model twice you'll not get exact the same
results unless you turn off parallelisation. the code is developing all
the time, and for inla.mode="experimental", then different
approximations are used.

if you think there is an error, then I would need code & data to rerun
here
> --
> You received this message because you are subscribed to the Google
> Groups "R-inla discussion group" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to r-inla-discussion...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/r-inla-discussion-group/d114f43c-9356-41a8-b01d-fa54f691362bn%40googlegroups.com
> .

--
Håvard Rue
he...@r-inla.org

Maria

unread,
Aug 5, 2022, 10:16:31 AM8/5/22
to R-inla discussion group
Hi,

Thank you very much for your feedback. 

I am new in INLA and Bayesian inference. I understand that I will not get the same results if I run the same model twice. I found the recent outputs were more stable compared to the previous output. I was wondering if there were any changes on the way INLA handle the analysis. Please find below the output when running these codes:

props.w$unstruct <- props.w$struct <- 1:n.area
formula.weighted1 = logit.p ~ -1 + factor(Region) +
  f(struct1, model = 'besag', graph = mat1, scale.model = TRUE, param = c(0.5,0.005)) +  
  f(unstruct1, model = 'iid',  param = c(0.5,0.005)) +
  f(struct2, model = 'besag', graph = mat2, scale.model = TRUE, param = c(0.5,0.005)) +  
  f(unstruct2, model = 'iid',  param = c(0.5,0.005))

fit.weighted1 <- inla(formula.weighted1,

                     family="gaussian", data=props.w,
                     control.predictor = list(compute = TRUE),
                     control.compute = list(dic = TRUE, cpo = TRUE, waic=TRUE),
                     control.family = list(hyper = list(prec = list(
                       initial = log(1), fixed=TRUE))),
                     scale=props.w$logit.prec)
summary(fit.weighted1)

Output_April.JPG


Output_July.JPG


Thank you in advance for your kind help. I really appreciate it.

BR,
Maria
Reply all
Reply to author
Forward
0 new messages