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

add sample_posterior_R function #76

Merged
merged 7 commits into from Jul 2, 2019
Merged

add sample_posterior_R function #76

merged 7 commits into from Jul 2, 2019

Conversation

zkamvar
Copy link
Collaborator

@zkamvar zkamvar commented Jun 6, 2019

This will fix #70, but I've modified it so that it takes from a specific time window of R:

library("EpiEstim")
#> Registered S3 methods overwritten by 'ggplot2':
#>   method         from 
#>   [.quosures     rlang
#>   c.quosures     rlang
#>   print.quosures rlang
data("Flu2009")

res <- estimate_R(incid = Flu2009$incidence, 
                  method = "non_parametric_si",
                  config = make_config(list(si_distr = Flu2009$si_distr)))
#> Default config will estimate R on weekly sliding windows.
#>     To change this change the t_start and t_end arguments.

hist(sample_posterior_R(res, n = 5000, window = 1L), col = "grey",
     main = "5000 samples of R from the first weekly window",
     xlab = "R",
     xlim = c(0, 4))

hist(sample_posterior_R(res, n = 5000, window = 10L), col = "grey",
     main = "5000 samples of R from the tenth weekly window",
     xlab = "R",
     xlim = c(0, 4))

win_col <- ifelse(seq(nrow(res$R)) %in% c(1, 10), "red", "black")
plot(res, "R") + ggplot2::geom_point(color = win_col)

Created on 2019-06-06 by the reprex package (v0.3.0)

Copy link
Collaborator

@jstockwin jstockwin left a comment

Choose a reason for hiding this comment

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

From a code-style perspective this LGTM. This does not include a review of the mathematics of the actual function, though :)

Does EpiEstimApp require any changes from this?

@zkamvar
Copy link
Collaborator Author

zkamvar commented Jun 6, 2019

Does EpiEstimApp require any changes from this?

No, the app shouldn't require any change from this. It is an extra feature.

@codecov-io
Copy link

Codecov Report

Merging #76 into master will increase coverage by 0.72%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #76      +/-   ##
=========================================
+ Coverage   49.07%   49.8%   +0.72%     
=========================================
  Files          12      13       +1     
  Lines        1243    1251       +8     
=========================================
+ Hits          610     623      +13     
+ Misses        633     628       -5
Impacted Files Coverage Δ
R/sample_posterior_R.R 100% <100%> (ø)
R/make_config.R 100% <0%> (+14.28%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6d12c57...4519a8d. Read the comment docs.

@zkamvar
Copy link
Collaborator Author

zkamvar commented Jun 10, 2019

@annecori, Can you take a look at this and see if it works for you?

@zkamvar
Copy link
Collaborator Author

zkamvar commented Jul 1, 2019

bumping @annecori to see if this function makes sense to her.

Copy link
Collaborator

@annecori annecori left a comment

Choose a reason for hiding this comment

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

looks great thanks @zkamvar, I've only added a small comment explaining the set.seed call in the example, hope that's ok

@zkamvar zkamvar merged commit 7f4c40e into master Jul 2, 2019
@zkamvar zkamvar deleted the fix-70 branch July 2, 2019 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add a function to sample from posterior
4 participants