grambank / grambank-analysed

3 stars 0 forks source link

making precision matrices for INLA and BRMS same time #54

Closed HedvigS closed 2 years ago

HedvigS commented 2 years ago

On my to do-list is to re-write the make precision matrices r script so that it also can make the approrpriate precision matrices for what @blasid wants to do with unusualness and BRMS. Current plan is to rewrite the code into a function that takes a list of lgs and other parameters and makes the appropriate things for each model.

I will do that as soon as #53 is resolved. Don't want to mess with anything before that.

RustyGray commented 2 years ago

Hi, is this essential? Can’t you just give Damian the matrices he wants now and sort thins out later? I am concerned that we are running out of time to get this submitted before your wedding and ICHL. Can we discuss this tomorrow please? Thanks, Russell.

On 3. Jul 2022, at 15:08, Hedvig Skirgård @.***> wrote:

On my to do-list is to re-write the make precision matrices r script so that it also can make the approrpriate precision matrices for what @blasid https://github.com/blasid wants to do with unusualness and BRMS. Current plan is to rewrite the code into a function that takes a list of lgs and other parameters and makes the appropriate things for each model.

I will do that as soon as #53 https://github.com/grambank/grambank-analysed/issues/53 is resolved. Don't want to mess with anything before that.

— Reply to this email directly, view it on GitHub https://github.com/grambank/grambank-analysed/issues/54, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEETOPCKZ5BQ5CIMZ3USA5DVSGGFDANCNFSM52QVUHAA. You are receiving this because you are subscribed to this thread.

SamPassmore commented 2 years ago

Hi Hedvig, If Damian is not going to use INLA - then I think this is unnecessary. The construction of the matrices are completely different for each approach. For code readability, I would think it better to build the BRMS covariance matrices next to the BRMS model. Since, as far as I am aware, there is only one response and one script.

Creating the INLA precision matrices in a separate script makes sense because we need to recalculate them for every feature - so it saves a bit of computational time.

HedvigS commented 2 years ago

Hi Hedvig, If Damian is not going to use INLA - then I think this is unnecessary. The construction of the matrices are completely different for each approach. For code readability, I would think it better to build the BRMS covariance matrices next to the BRMS model. Since, as far as I am aware, there is only one response and one script.

Creating the INLA precision matrices in a separate script makes sense because we need to recalculate them for every feature - so it saves a bit of computational time.

I was thinking to make a function and feed it parameters specific to each of the two situations, but okay sure. If you think it's better to just have two scripts let's do that.

HedvigS commented 2 years ago

Either way, @blasid I need to know what parameters you want for the precision matrices.

For the INLA models,

You can read out script doing this here, this is the old version from before last friday.

HedvigS commented 2 years ago

Creating the INLA precision matrices in a separate script makes sense because we need to recalculate them for every feature - so it saves a bit of computational time.

@SamPassmore in the current set-up we don't recalculate the precision matrices for every feature. We have the same set of observations each time, the only thing that changes with features is the feature values (incl missing data) which doesn't go into the making of the precision matrices. We make them once, save them at output/spatiophylogenetic_modelling/processed_data/precision_matrices.RDS and use the same ones for every model and every feature.

HedvigS commented 2 years ago

I'm going to go back into git history and look at how @lmaurits and I set up the precision matrices for the BRMS for predicting the old unusualness score. That should be the place to start to give @blasid what he wants.

HedvigS commented 2 years ago

For the using BRMS to predict the old unusualness score, @lmaurits just used ape::vcvphylo() for the phylo matrix. This can be seen in this old script.

Is that enough for you too @blasid ?

SamPassmore commented 2 years ago

Hi Hedvig,

Creating the INLA precision matrices in a separate script makes sense because we need to recalculate them for every feature - so it saves a bit of computational time.

@SamPassmore in the current set-up we don't recalculate the precision matrices for every feature.

Yes, I know. I should have written "because otherwise we need to recalculate them for every feature". We wouldnt be saving time if we were recalculating them for each feature.

But my more general point is that BRMS and INLA don't have the same matrix inputs. Since in #23 it was decided that surprisal would be modelled using BRMS. That is BRMS doesn't use precision matrices, it uses covariances. So, in make_precisionmatrices.R you would need a section that makes the matrices for BRMS and a section that makes them for INLA. You may as well put the BRMS matrix code with the BRMS model, which will make reading that part of the analyses easier.

@lmaurits just used ape::vcvphylo() for the phylo matrix.

Yes, this should be right.

HedvigS commented 2 years ago

Hi Hedvig,

Creating the INLA precision matrices in a separate script makes sense because we need to recalculate them for every feature - so it saves a bit of computational time.

@SamPassmore in the current set-up we don't recalculate the precision matrices for every feature.

Yes, I know. I should have written "because otherwise we need to recalculate them for every feature". We wouldnt be saving time if we were recalculating them for each feature.

Excellent, all good :)

But my more general point is that BRMS and INLA don't have the same matrix inputs. Since in #23 it was decided that surprisal would be modelled using BRMS. That is BRMS doesn't use precision matrices, it uses covariances. So, in make_precisionmatrices.R you would need a section that makes the matrices for BRMS and a section that makes them for INLA. You may as well put the BRMS matrix code with the BRMS model, which will make reading that part of the analyses easier.

@lmaurits just used ape::vcvphylo() for the phylo matrix.

Yes, this should be right.

Great good. I set up a script for Damián that does this yesterday and sent him over files over email while we wait for #53 to be resolved.

HedvigS commented 2 years ago

We're no longer doing BRMS analysis in this paper.