Correlated grouping term in a random slope model

55 views
Skip to first unread message

Thomas F Johnson

unread,
Jun 7, 2021, 11:51:56 AM6/7/21
to R-inla discussion group
I need to account for known correlations between a grouping term in a random slope model

Ignoring the known correlations, I can fit a model like so:
inla(y ~ 1 + f(time, species, model = "ar1"), data = dat)
where, assuming I'm right (?), I've fit different slopes for the temporal term 'time' within each of the grouping terms (species), accounting for the first-order autoregressive process.

However, as species are evolutionarily linked, with varying relation (correlation) to one another, I also need to account for the similarity in the slopes depending on the species relatedness. Something like:
inla(y ~ 1 + f(time, species, model1 = "ar1", model2 = "generic0", Cmatrix = precision_matrix), data = dat)
where the model1 term accounts for the autoregressive process of time, whilst model2 and Cmatrix account for the correlation of slopes between species.

Is anything like this possible?




Helpdesk

unread,
Jun 7, 2021, 12:43:23 PM6/7/21
to Thomas F Johnson, R-inla discussion group
On Mon, 2021-06-07 at 08:51 -0700, Thomas F Johnson wrote:
> I need to account for known correlations between a grouping term in a
> random slope model
>
> Ignoring the known correlations, I can fit a model like so:
> inla(y ~ 1 + f(time, species, model = "ar1"), data = dat)
> where, assuming I'm right (?), I've fit different slopes for the
> temporal term 'time' within each of the grouping terms (species),
> accounting for the first-order autoregressive process.

I'm not sure if you describe this

f(time, model="ar1", replicate=species)

this will give for each 'species', an AR1 in time, wheras the above on,
gives ONE AR1 in time multiplied with species.

[I assume species is numeric 1,2,3 (or as.numeric() if its a factor) ]



>
> However, as species are evolutionarily linked, with varying relation
> (correlation) to one another, I also need to account for the
> similarity in the slopes depending on the species relatedness.
> Something like:
> inla(y ~ 1 + f(time, species, model1 = "ar1", model2 = "generic0",
> Cmatrix = precision_matrix), data = dat)
> where the model1 term accounts for the autoregressive process of time,
> whilst model2 and Cmatrix account for the correlation of slopes
> between species.

depends on 'how many' species' you have

let me know, to many loose ends right now
--
Håvard Rue
he...@r-inla.org

Thomas F Johnson

unread,
Jun 7, 2021, 1:54:18 PM6/7/21
to R-inla discussion group
> I'm not sure if you describe this

>   f(time, model="ar1", replicate=species)

>   this will give for each 'species', an AR1 in time, wheras the above on,
>   gives ONE AR1 in time multiplied with species.

>   [I assume species is numeric 1,2,3 (or as.numeric() if its a factor) ]

Okay, awesome, that makes sense. I haven't seen the replicate option is use before. Thank you. And yes, species is in an integer (that corresponds to a factor)


>   depends on 'how many' species' you have
>   
>     let me know, to many loose ends right now

There could be anywhere from 10 - 10,000 species (perhaps a median of 50), and the correlation matrix simply describes how far each species is from each other on a phylogenetic tree, similar to a distance matrix when working in space.

The overall goal is to try and account for the temporal and phylogenetic autocorrelation within timeseries

Tom

Helpdesk

unread,
Jun 7, 2021, 4:00:32 PM6/7/21
to Thomas F Johnson, R-inla discussion group

Then I guess you're after either

f(time, model="ar1", group=species, 
control.group=list(model="besag" graph="species.graph"))

or the other way around

f(species, model="besag", graph="species.graph", group=time,
control.group=list(model="ar1"))

depending on, if there are constraints over 'species' or not.

Helpdesk

unread,
Jun 7, 2021, 4:01:59 PM6/7/21
to Thomas F Johnson, R-inla discussion group

so the phylogenetic tree will be reflected in the graph. if you're after
spesific weights, you'll need to use model='generic' (and then the
second variant)

Thomas F Johnson

unread,
Jun 8, 2021, 4:33:33 AM6/8/21
to R-inla discussion group
Amazing, thank you for the rapid and excellent support!
Reply all
Reply to author
Forward
0 new messages