grambank / grambank-analysed

3 stars 0 forks source link

Inla roboust priors #72

Closed HedvigS closed 2 years ago

HedvigS commented 2 years ago

Dear @SamPassmore

What I've done here is set up a workflow where the INLA dual and trial model can loop through 4 different pcpriors (0.01, 0.1. 0.5 and 0.99). If the script is run from inside Rstudio directly it won't have any CLI arguments, and if so it'll go with the default pcprior and just loop through all the features for all the models for that one (0.1). However, if a 5th argument is specified from the command line which is "loop_all_priors" then it'll loop through all the priors.

In either case it saves the prior used to the file name for the qs file.

Example of running it on command line with arguments specified.

Rscript spatiophylogenetic_modelling/analysis/INLA_multi_models.R "real" 1 113 precision_matrices_kappa_2_sigma_1.15.RDS "loop_all_priors" `

This will run through al 113 real features (not the simulated) with a particular precision matrix and over all the priors.

This means that in order to run it for all combinations of precision matrices and priors, I'll have to go

Rscript spatiophylogenetic_modelling/analysis/INLA_multi_models.R "real" 1 113 precision_matrices_kappa_2_sigma_1.15.RDS "loop_all_priors" `

Rscript spatiophylogenetic_modelling/analysis/INLA_multi_models.R "real" 1 113 precision_matrices_kappa_2_sigma_2.RDS "loop_all_priors" 

Rscript spatiophylogenetic_modelling/analysis/INLA_multi_models.R "real" 1 113 precision_matrices_kappa_2.5_sigma_3.RDS "loop_all_priors" `

Is it the most elegant thing I've ever written? No. Does it work? Seems so :)

If you think it's good enough, please approve this PR.

I'll get my desktop office machine running on this either way now over the weekend.

Please note I've also added some objects to strip_inla(), it now also saves summary.fixed and summary.fitted.values from the INLA objects. This I think is a good idea for #60

HedvigS commented 2 years ago

What do you think of this @SamPassmore ?

SamPassmore commented 2 years ago

Hi Hedvig,

Sorry for the delay on this - I remember replying to this, but obviously I did something wrong.

I had said that I think this is fine - but for practicaly purposes we probably only need to run the range of priors on the main result (i.e. with spatial parameters kappa_2_sigma_1.15).

also a package you might find useful in future (that is - we don't need to change this but it might be useful for you in future projects) is optparse, which will allow you to set defaults without the ifelse statement you have at the beginning.

HedvigS commented 2 years ago

@SamPassmore Thanks!

HedvigS commented 2 years ago

Hi @SamPassmore . Just checking, is there anything you wanted to plot or do here with the varying pcpriors?

SamPassmore commented 2 years ago

Hi @HedvigS are these results somewhere? Maybe it would be good to have a plot as well. I can only see results that vary the spatial parameters. I think we only need to show prior influence on the main text reported results (ie. kappa_2_sigma_1.15)

HedvigS commented 2 years ago

@SamPassmore Yes, sorry about that. I'm re-running some stuff now to fix with #71 so I'm re-generating things. I'll get it all for you in #45 soon.

In the meantime, would you be able to try out

Rscript spatiophylogenetic_modelling/analysis/INLA_multi_models.R "real" 1 113 precision_matrices_kappa_2_sigma_1.15.RDS "loop_all_priors" `

Rscript spatiophylogenetic_modelling/analysis/INLA_multi_models.R "real" 1 113 precision_matrices_kappa_2_sigma_2.RDS "loop_all_priors" 

Rscript spatiophylogenetic_modelling/analysis/INLA_multi_models.R "real" 1 113 precision_matrices_kappa_2.5_sigma_3.RDS "loop_all_priors" `

On a machine of yours as well? Just so we know it all runs okay.

SamPassmore commented 2 years ago

Hi Hedvig, yes this code seems to run on my machine. I've run over a few models but not all the way through because I need my computer to run some other things today, sorry.

HedvigS commented 2 years ago

Hi Hedvig, yes this code seems to run on my machine. I've run over a few models but not all the way through because I need my computer to run some other things today, sorry.

nw!