grambank/grambank-analysed

making precision matrices for INLA and BRMS same time

Closed this issue · 10 comments

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.

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.

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.

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

For the INLA models,

  • we rescaled the tree tree$edge.length = tree$edge.length / 1000
  • we make a sparse Phylogenetic Covariance Matrix for all nodes, internal and tips (@rdinnager suggestion)
  • we standardize by the typical variance, to ensure variance is scaled to 1
  • etc

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

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.

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.

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 ?

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.

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.

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