Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024-08-08 update : adding spatial to wwinference model. #56

Merged

Conversation

cbernalz
Copy link
Collaborator

@cbernalz cbernalz commented Aug 8, 2024

This PR is regarding the following issue : #44 (comment) . The model that will be added into this will be coming from this issue : #25 (comment) .

@cbernalz cbernalz added this to the P sprint milestone Aug 8, 2024
@cbernalz cbernalz self-assigned this Aug 8, 2024
@cbernalz
Copy link
Collaborator Author

cbernalz commented Aug 8, 2024

This is not ready yet, but I wanted to take input from both of you : @dylanhmorris and @kaitejohnson . Spatial components are in the model and using the testfile, I ran everything and things definitely change. There is a lot more variability, mainly in the forecast period. Rt take values that reach past 2, and site Rt's occasionally reach past 5.

@kaitejohnson
Copy link
Collaborator

This is not ready yet, but I wanted to take input from both of you : @dylanhmorris and @kaitejohnson . Spatial components are in the model and using the testfile, I ran everything and things definitely change. There is a lot more variability, mainly in the forecast period. Rt take values that reach past 2, and site Rt's occasionally reach past 5.

Interesting! How does that compare to the ground truth R(t) values in each subpopulation? Might be worth making a plot of the estimated R(t)s and the known R(t)s that you simulated.

Also, how tight are your priors around the ground truth values of $\phi$ and $\sigma_{\epsilon}$? To start, we might want to force those to be pretty tightly specified just to see if that allows us to reproduce the ground truth results (so cheating a little, but enforcing identifiability).

@cbernalz
Copy link
Collaborator Author

cbernalz commented Aug 9, 2024

This is not ready yet, but I wanted to take input from both of you : @dylanhmorris and @kaitejohnson . Spatial components are in the model and using the testfile, I ran everything and things definitely change. There is a lot more variability, mainly in the forecast period. Rt take values that reach past 2, and site Rt's occasionally reach past 5.

Interesting! How does that compare to the ground truth R(t) values in each subpopulation? Might be worth making a plot of the estimated R(t)s and the known R(t)s that you simulated.

Also, how tight are your priors around the ground truth values of ϕ and σ ϵ ? To start, we might want to force those to be pretty tightly specified just to see if that allows us to reproduce the ground truth results (so cheating a little, but enforcing identifiability).

Yes, I worked on changing these values and how big they are, but it seems like the thing that makes these values explode is using sigma_generalized, or the generalized variance formulation, from the normalization of the omega matrix. When I removed this part from the model and did the traditional decomposition of $\Sigma$, I saw from the site Rt plots values are more realistic to what I believe the actual ones are.

I could have written the generalized variance into stan wrong, it might be good to look over that particular part @kaitejohnson and @dylanhmorris on lines 236 in the wwinference.stan model.

@dylanhmorris
Copy link
Collaborator

@cbernalz can you make some plots and share them in the other repo?

@cbernalz cbernalz requested a review from athowes August 9, 2024 15:36
@kaitejohnson
Copy link
Collaborator

@cbernalz can you make some plots and share them in the other repo?

You could share them here because it only simulated data?

@cbernalz
Copy link
Collaborator Author

cbernalz commented Aug 9, 2024

@dylanhmorris and @kaitejohnson I am currently adjusting the generate_simulation_data function to use the generalized variance decomposition, I think this may have been the problem with the fitting. I wanted to ask if we have the site Rt's with a generalized variance as $c$, what variance would I use for the aux site process. Would I use this same $c$, so aux site deviations would have a $\text{Normal}(0,\text{scalingfactor}\cdot c)$?

@kaitejohnson
Copy link
Collaborator

@dylanhmorris and @kaitejohnson I am currently adjusting the generate_simulation_data function to use the generalized variance decomposition, I think this may have been the problem with the fitting. I wanted to ask if we have the site Rt's with a generalized variance as c , what variance would I use for the aux site process. Would I use this same c , so aux site deviations would have a Normal ( 0 , scalingfactor ⋅ c ) ?

Yep, I think that is the idea! So if scalingfactor =1 on average each the auxiliary site subpopulation would have the same amount of deviation from the state R(t) as the (averaged across all sites) deviation from the state R(t) in the sites. But @dylanhmorris can correct me if this interpretation is wrong

@cbernalz
Copy link
Collaborator Author

cbernalz commented Aug 9, 2024

Great, @kaitejohnson and @dylanhmorris I figured out the problem was the strict prior placed on sigma_generalized. The plots are on the ent repo issue.

@cbernalz cbernalz marked this pull request as ready for review August 19, 2024 16:40
@cbernalz cbernalz requested review from dylanhmorris and removed request for athowes August 19, 2024 16:41
@kaitejohnson
Copy link
Collaborator

Weirdly I am not able to see the full set of CI jobs (including the failure) for the check-package

@cbernalz cbernalz requested review from kaitejohnson and removed request for kaitejohnson August 20, 2024 18:20
Copy link
Collaborator

@dylanhmorris dylanhmorris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor suggestions / comments, @cbernalz

R/wwinference.R Outdated Show resolved Hide resolved
R/generate_simulated_data.R Outdated Show resolved Hide resolved
R/generate_simulated_data.R Outdated Show resolved Hide resolved
inst/stan/wwinference.stan Outdated Show resolved Hide resolved
Copy link
Collaborator

@kaitejohnson kaitejohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbernalz This looks really really good! Great job putting this all together, and apologies for letting this PR get so big!

My only high level suggestion that I think requires fixing in this PR is the comment about not putting the distance matrix in as default to the wwinference() wrapper function. And requiring the user specify that will require editing the vignette but it should be a pretty easy fix. The other stuff like moving the distance matrix to be package data as well can be done in another PR! I just want to make sure it's super easy for us to modify the distance matrix that we either pass in as a default to generate_simulated_data() or that we fit the model to in a simulation analysis.

R/data.R Outdated Show resolved Hide resolved
R/data.R Show resolved Hide resolved
R/data.R Show resolved Hide resolved
R/generate_simulated_data.R Outdated Show resolved Hide resolved
R/generate_simulated_data.R Show resolved Hide resolved
inst/stan/wwinference.stan Outdated Show resolved Hide resolved
inst/stan/wwinference.stan Outdated Show resolved Hide resolved
inst/stan/wwinference.stan Show resolved Hide resolved
inst/stan/wwinference.stan Outdated Show resolved Hide resolved
inst/stan/wwinference.stan Outdated Show resolved Hide resolved
@cbernalz
Copy link
Collaborator Author

@dylanhmorris and @kaitejohnson I updated all of your comments and the biggest change is that I added a way to use either an independent correlation function (default if no dist_matrix is provided) and the exponential decay correlation function (if dist_matrix is provided). Let me know what should be changed!

kaitejohnson
kaitejohnson previously approved these changes Aug 21, 2024
Copy link
Collaborator

@kaitejohnson kaitejohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, sounds like you've also pretty much figured out how to do the switch on and off too which is great. See my one comment about how to specify that from the "user" side in the wwinference() function. But think thats for another PR.

Great work on this!! It's looking really nice. Excited to see it in action

R/get_stan_data.R Show resolved Hide resolved
inst/stan/wwinference.stan Outdated Show resolved Hide resolved
Copy link
Collaborator

@dylanhmorris dylanhmorris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking very good @cbernalz. A few minor suggestions / fixes.

R/get_stan_data.R Outdated Show resolved Hide resolved
R/get_stan_data.R Show resolved Hide resolved
inst/stan/wwinference.stan Outdated Show resolved Hide resolved
inst/stan/wwinference.stan Outdated Show resolved Hide resolved
inst/stan/wwinference.stan Outdated Show resolved Hide resolved
inst/stan/wwinference.stan Outdated Show resolved Hide resolved
inst/stan/wwinference.stan Outdated Show resolved Hide resolved
inst/stan/wwinference.stan Outdated Show resolved Hide resolved
dylanhmorris
dylanhmorris previously approved these changes Aug 21, 2024
Copy link
Collaborator

@dylanhmorris dylanhmorris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @cbernalz

A couple minor things I missed before about explicitly noting 1 and 0 as integers rather than floats (1L, 0L). Can take or leave, and then merge.

R/get_stan_data.R Outdated Show resolved Hide resolved
R/get_stan_data.R Outdated Show resolved Hide resolved
Co-authored-by: Dylan H. Morris <[email protected]>
Co-authored-by: Dylan H. Morris <[email protected]>
Copy link
Collaborator

@dylanhmorris dylanhmorris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will let you merge, @cbernalz

@cbernalz cbernalz merged commit a12ab56 into spatial-main Aug 21, 2024
4 checks passed
@cbernalz cbernalz deleted the 44-incorporate-stan-spatial-functions-into-wwinferencestan branch August 21, 2024 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants