my random slope estimates are much larger than the slopes I get when running each set separately...

17 views
Skip to first unread message

Roel van Klink

unread,
Nov 15, 2025, 5:24:00 AM (12 days ago) Nov 15
to R-inla discussion group
I'm running a multi-level random effects model with data from multiple studies, and am primarily interested in the slopes of both the fixed and random effects.
 
Thanks to help from Harvard Rue (https://groups.google.com/g/r-inla-discussion-group/c/E8AIGDPz_-M/m/uagf6R01BQAJ) , the model runs quite efficiently, but when I compare the random slopes from this negative binomial model (see below) to the slopes I get when I analyse each dataset separately (mostly same model structure, in INLA), the random slopes are MUCH larger than the 'true' slopes. Also, for some datasets the sign of the slope is actually flipped. 

They are correlated, though:
corr real and random slope prior of 0.3 on both models.jpeg

I've tried setting a smaller prior, but I get almost the same values.  

Does anyone understand why this is happening? And what I can do about it? 

Thanks 

here's my model specification: 
#prior: 
prior.prec <- list(prec = list(prior = "pc.prec", param = c(0.3, 0.01))) 


inla(NumberRounded ~ cYear +
         f(Period_4INLA,                             model='iid', hyper = prior.prec)+
         f(Datasource_4INLA,                         model='iid', hyper = prior.prec)+
         f(DatasourceLoc_4INLA,                      model='iid', hyper = prior.prec)+
         f(DatasourceLocPlot_4INLA,                  model='iid', hyper = prior.prec)+
         f(Datasource_4INLAslope,       iYear.scale, model='iid', hyper = prior.prec)+
         f(DatasourceLoc_4INLAslope,    iYear.scale, model='iid', hyper = prior.prec)+
         f(DatasourceLocPlot_4INLAslope,iYear.scale, model='iid', hyper = prior.prec)+
         f(iYear, model='ar1', ##constr = TRUE,
           values = seq(val[1], val[2]),
           hyper = list(prec = list(prior = "pc.prec",
                                    param = c(sd.res, 0.01)),
                        rho = list(prior = "pc.cor1",
                                   param = c(0.95, 0.5))),
           replicate=Plot_ID_rep), # auto regression at plot level
       family = 'nbinomial',
       offset = log(E),
       control.compute = list(
         config = TRUE,
         dic=TRUE,
         waic=TRUE,
         cpo = TRUE ),
       control.predictor = list(link = 1) ,
       verbose = F,
       quantiles=c(0.001, 0.01, 0.025, 0.05, 0.1, 0.3, 0.5, 0.7, 0.9, 0.95, 0.975, 0.99, 0.999)  ,    
       num.threads = threads,
       control.fixed = list(prec = 1, prec.intercept = 1),
       data=completeDataPollinators)



Helpdesk (Haavard Rue)

unread,
Nov 15, 2025, 1:01:55 PM (11 days ago) Nov 15
to Roel van Klink, R-inla discussion group
The best way to verify your model, is to simulate similar data, and then refit
it with your code. In this way you have a a reference for what it should be. If
you can set it up, so that you can send 'something', one or more, to infinity,
you have a way to check what could cause and 'inprecise' fit. l


On Sat, 2025-11-15 at 02:24 -0800, Roel van Klink wrote:
> I'm running a multi-level random effects model with data from multiple
> studies, and am primarily interested in the slopes of both the fixed and
> random effects.
>  
> Thanks to help from Harvard Rue
> (https://groups.google.com/g/r-inla-discussion-group/c/E8AIGDPz_-M/m/uagf6R01B
> QAJ) , the model runs quite efficiently, but when I compare the random slopes
> from this negative binomial model (see below) to the slopes I get when I
> analyse each dataset separately (mostly same model structure, in INLA), the
> random slopes are MUCH larger than the 'true' slopes. Also, for some datasets
> the sign of the slope is actually flipped. 
>
> They are correlated, though:
> --
> 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, visit
> https://groups.google.com/d/msgid/r-inla-discussion-group/f0924946-e7d5-45ef-8e79-8f5eee2edad1n%40googlegroups.com
> .

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

Thierry Onkelinx

unread,
Nov 17, 2025, 8:22:07 AM (9 days ago) Nov 17
to Roel van Klink, R-inla discussion group
Dear Roel,

Check for the number of non-zero observations linked to the random slope. I wouldn't be surprised when you have only a handful non-zero observations for the extreme random slopes.
What worked for me is setting the identifier for the random slope to NA when there are less than 6 non-zero observations. And thus not fitting a random slope for that level.

Best regards,

Thierry

ir. Thierry Onkelinx
Statisticus / Statistician

Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry....@inbo.be
Havenlaan 88 bus 73, 1000 Brussel
Postadres: Koning Albert II-laan 15 bus 186, 1210 Brussel
Poststukken die naar dit adres worden gestuurd, worden ingescand en digitaal aan de geadresseerde bezorgd. Zo kan de Vlaamse overheid haar dossiers volledig digitaal behandelen. Poststukken met de vermelding ‘vertrouwelijk’ worden niet ingescand, maar ongeopend aan de geadresseerde bezorgd.
www.inbo.be

///////////////////////////////////////////////////////////////////////////////////////////
To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey
///////////////////////////////////////////////////////////////////////////////////////////




Op za 15 nov 2025 om 11:24 schreef Roel van Klink <roel.v...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "R-inla discussion group" group.
Reply all
Reply to author
Forward
0 new messages