-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add script to create data for estimate truncation example * Remove data creation from estimate_truncation example * Generate and store dataset * Function to add truncation to dataset * Add NEWS item * Use usethis to save data * Replace hardcoding with seq() * Save data * Move function from utilities.R to data-raw * Improve comment in example * Document the truncation example dataset * Add reviewers * Use saveRDS to save data * Shorten name to example_truncated * Add punctuation and remove extra comment tag * Don't load here package * Use usethis to save data * Resave generated data and delete old one * Replace data generation in test with stored example data * CI fixes: Add usethis and here packages to setup-r-dependencies action * Fix typo in package name * Improve example Co-authored-by: Sebastian Funk <[email protected]> * Improve NEWS item * Generate docs * Use example_truncated dataset directly in tests --------- Co-authored-by: Sebastian Funk <[email protected]>
- Loading branch information
1 parent
c7213ce
commit 0c5c576
Showing
11 changed files
with
114 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ jobs: | |
with: | ||
dependencies: NA | ||
extra-packages: | | ||
here | ||
usethis | ||
stan-dev/cmdstanr | ||
any::gh | ||
any::lintr | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
library("EpiNow2") | ||
|
||
#' Apply truncation to a data set | ||
#' | ||
#' @param index Index from which to truncate | ||
#' @param data Data set | ||
#' @param dist Truncation distribution | ||
#' @importFrom stats dgamma dlnorm | ||
#' | ||
#' @return A truncated data set | ||
#' @keywords internal | ||
apply_truncation <- function(index, data, dist) { | ||
set.seed(index) | ||
if (dist$dist == 0) { | ||
dfunc <- dlnorm | ||
} else { | ||
dfunc <- dgamma | ||
} | ||
cmf <- cumsum( | ||
dfunc( | ||
1:(dist$max + 1), | ||
rnorm(1, dist$mean_mean, dist$mean_sd), | ||
rnorm(1, dist$sd_mean, dist$sd_sd) | ||
) | ||
) | ||
cmf <- cmf / cmf[dist$max + 1] | ||
cmf <- rev(cmf)[-1] | ||
trunc_data <- data.table::copy(data)[1:(.N - index)] | ||
trunc_data[ | ||
(.N - length(cmf) + 1):.N, confirm := as.integer(confirm * cmf) | ||
] | ||
return(trunc_data) | ||
} | ||
|
||
# get example case counts | ||
reported_cases <- example_confirmed[1:60] | ||
|
||
# define example truncation distribution (note not integer adjusted) | ||
trunc_dist <- dist_spec( | ||
mean = convert_to_logmean(3, 2), | ||
mean_sd = 0.1, | ||
sd = convert_to_logsd(3, 2), | ||
sd_sd = 0.1, | ||
max = 10 | ||
) | ||
|
||
# Use the make_truncated_data() function to generate example data for | ||
# an example using estimate_truncation() | ||
example_truncated <- purrr::map( | ||
seq(20, 0, -5), | ||
apply_truncation, | ||
data = reported_cases, | ||
dist = trunc_dist | ||
) | ||
|
||
usethis::use_data( | ||
example_truncated, | ||
overwrite = TRUE, | ||
compress = "xz" | ||
) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters