Role of Random Walk 1or 2 models in climate predictors

51 views
Skip to first unread message

Vincent Arumadri

unread,
Sep 28, 2025, 3:38:36 PMSep 28
to R-inla discussion group
Hello INLA Group,

Hope this can be answered here because I could not find a specific answer on the topic anywhere else.

I am working on a model with mosquito-borne disease counts as an outcome and precipitation and temperature as predictors. Similar previous published studies on this have use random walk 1/2 models in INLA to account for temporal dimension (seasonality and interannual variation) in disease counts. 

However, I thought this would be explained by the predictors. I can understand the inclusion of random walk models where there are no climate predictors. What is the role of adding the random walk models to account for seasonality and and interannual variation in disease counts? Are the climate predictors not accounting for that? 

Thanks in advance!


Finn Lindgren

unread,
Sep 28, 2025, 4:02:47 PMSep 28
to Vincent Arumadri, R-inla discussion group
Hi,

In, short, the existence of informative predictor variables does not imply that those predictors 1) have a linear relationship with the response variable expectation (on the link function scale, typically a log-link for count variables) and/or 2) are sufficient predictors in their own right, even with some non-linear modelled relationship (which might itself be via a rw1/2 model!)
A rw1/2 model might then be added to compensate for those missing aspects of the model. An ar1 or ar2 model is also an option.
A combination of the above factors is likely why those other works have incorporated such model components.

Finn

On 28 Sep 2025, at 20:38, Vincent Arumadri <varu...@gmail.com> wrote:

Hello INLA Group,
--
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/f15ce9e5-f9a5-416d-83dc-e6d8390e9559n%40googlegroups.com.

Vincent Arumadri

unread,
Sep 28, 2025, 4:28:14 PMSep 28
to R-inla discussion group
Hi Finn, 

Thank you for your reply. It has improved my understanding already. 

Just as a follow-up and so I can fully explain this to others, perhaps I can give more context – the climate predictors themselves are have a non-linear relationship with the response varaible that is defined using natural cubic splines using another package. In the INLA, they then add random effects (rw1/2) to month and year variables to account for seasonality and interannual variation respectively together with the predictors in the model. Is the motivation for addition of the rw1/2 models as temporal random effects in this case still to compensate for the missing aspects of the model? Such that seasonality and interannual variation cannot be fully explained by the predictors and these rw1/2 compensate for the aspects a model without rw1/2 random effects would miss.

Thanks again in advance.

Vincent. 

Finn Lindgren

unread,
Sep 28, 2025, 4:51:11 PMSep 28
to Vincent Arumadri, R-inla discussion group
You’d need to ask the authors of the study in the question to get the actual answer (I can’t know why they did what they did, but can only guess, in particular without having read what they wrote…), but regarding seasonality, I’d say that unless the predictor variables have a seasonal pattern in them, one would need _some_ kind of model component to handle it. A cyclic rw2 model is a simple but often effective way to model seasonal patterns.

But if you need to know why some specific authors did what they did, and it’s not clear from their paper, then contacting them and asking should give an authoritative answer about their motivations!

Finn

On 28 Sep 2025, at 21:28, Vincent Arumadri <varu...@gmail.com> wrote:

Hi Finn, 

Vincent Arumadri

unread,
Sep 28, 2025, 4:56:59 PMSep 28
to R-inla discussion group
Hi Finn,

Thank you for the added explanation. I will reach out to the authors for further details. 

Vincent 

Vincent Arumadri

unread,
Oct 26, 2025, 11:13:28 AM (5 days ago) Oct 26
to R-inla discussion group
Hi Finn, 

I was able to find an answer to my earlier question. The rw1/2 models explain any variability not explained by the climate predictors. This can be used as a model selection criterion where models in which the climate predictors explain most of the variability compared to rw1/2 models is selected. 

Similar to that, I have gone through the steps of setting rw1/2 models for month and year to assess seasonal and interannual variability in INLA. For timeseries dataset including month and year variables;

T1 <- data$month # for random effect to account for annual cycle (seasonality)
T2 <- data$year # for random effect to account for inter-annual variability

T1 describes the month index from 1-12 months. 
T2 describes the year index for the number of years in the data set. 

Random walk models can then be set within the model as;

"f(T1, model = 'rw2', cyclic = TRUE, constr = TRUE,",
             "scale.model = TRUE, hyper = precision.prior)
"f(T2, model = 'rw2', hyper = precision.prior)"

It is quite easy to understand the indicing system for years since the index just runs from 1 to n(n=total number of years in the dataset) However, I'm quite confused about the month index. How does the INLA program know when to move from month 12 of year 2024 for example to month 1 of 2025?

Best wishes,
Vincent 

Helpdesk (Haavard Rue)

unread,
Oct 26, 2025, 12:58:21 PM (5 days ago) Oct 26
to Vincent Arumadri, R-inla discussion group
I think you're using the model wrong, or, what you want is not what the code say

I think the attached example will clarify it.

if you want 'stochastic' version of this cyclic, there is this model 'seasonal',
but I am not sure that is what you want.

best
H
> > > > https://groups.google.com/d/msgid/r-inla-discussion-group/e7828ec6-a839-46db-a44e-e8bc03193721n%40googlegroups.com
> > > > .
> --
> 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/47de62d7-86a9-4089-a71d-cf9d41d31cf8n%40googlegroups.com
> .

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

Vincent Arumadri

unread,
Oct 26, 2025, 3:24:54 PM (5 days ago) Oct 26
to R-inla discussion group
Thank you for your response. I will give more information about the problem. 

I'm trying to understand and implement a previous study methodology in a different setting without the spatial part. I share some of the code from that study here;
–––––––––––––––––––––––––––––––––––––
# total number of months
ntime <- length(unique(data$time))
# total number of years
nyear <- length(unique(data$year))
# total number of microregions
nmicro <- length(unique(data$micro_code))
# total number of states
nstate <- length(unique(data$state_code))

# set first year (in this case 2001) to 1
data$year_index <- data$year - 2000

# set data for models
Y  <- data$dengue_cases # response variable
N  <- length(Y) # total number of data points
E  <- data$population/10^5 # model offset so that response is equivalent to an incidence rate per 100,000 people

T1 <- data$month # for random effect to account for annual cycle (seasonality)
T2 <- data$year_index # for random effect to account for inter-annual variability
S1 <- data$micro_index # for microregion spatial random effect
S2 <- data$state_index # for state interaction with month random effect
Vu <- data$urban # include level of urbanisation (% pop living in urban areas) variable along with linear urban interaction
Vw <- data$water_shortage # include frequency of water shortages along with linear water shortage interaction

baseformula <- Y ~ 1 + f(T1, replicate = S2, model = "rw1", cyclic = TRUE, constr = TRUE,
                     scale.model = TRUE,  hyper = precision.prior) +
  f(S1, model = "bym2", replicate = T2, graph = "output/map.graph",
    scale.model = TRUE, hyper = precision.prior) 
–––––––––––––––––––––––––––––––––––––––––––

I'm building a model for only one area so I exclude the spatial part in the model above. 

My model includes climate predictors and random effects defined as;


"f(T1, model = 'rw2', cyclic = TRUE, constr = TRUE,",
             "scale.model = TRUE, hyper = precision.prior)
"f(T2, model = 'rw2', hyper = precision.prior)"

T1 is 1,2...12 # index for number of months
T2 is 1,2...19 # index for number of years 

How does the transition happen from the last month of one year to the first month of the next? I ask this because the coefficients for T1 (model$summary.random$T1) are given only for 12 months so I suppose its an 'average' across the years. However, its not clear to me how this happens. 

Thanks in advance. 

PS: Just started learning INLA a few months ago. 

Helpdesk (Haavard Rue)

unread,
Oct 27, 2025, 1:31:19 AM (4 days ago) Oct 27
to Vincent Arumadri, R-inla discussion group
On Sun, 2025-10-26 at 12:24 -0700, Vincent Arumadri wrote:
>
> "f(T1, model = 'rw2', cyclic = TRUE, constr = TRUE,",
>              "scale.model = TRUE, hyper = precision.prior)
> "f(T2, model = 'rw2', hyper = precision.prior)"
>
> T1 is 1,2...12 # index for number of months
> T2 is 1,2...19 # index for number of years 
>
> How does the transition happen from the last month of one year to the first
> month of the next? I ask this because the coefficients for T1
> (model$summary.random$T1) are given only for 12 months so I suppose its an
> 'average' across the years. However, its not clear to me how this happens. 
>
>

the rw2+cyclic is a rw2 model on a circle with length 12.

if x is the rw2, then x_i|the rest depends on x_{i-1}, x_{i-2}, x_{i+1}, x_{i+2}

where the indexes is modulus 12 (here 1...12), so x_12 will depend conditionally
on x_10, x_11, x_1 and x_2



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

Vincent Arumadri

unread,
Oct 28, 2025, 5:49:33 AM (3 days ago) Oct 28
to R-inla discussion group
Thank you so much for the explanation, I fully understand how this happens now. 

Best wishes,
Vincent 

Reply all
Reply to author
Forward
0 new messages