-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding basic infrastructure including testing (currently not passing)
- Loading branch information
Showing
12 changed files
with
1,789 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
^README\.Rmd$ | ||
^cran-comments\.md$ | ||
^\.github$ | ||
^data-raw$ |
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
.Rhistory | ||
.RData | ||
.Ruserdata | ||
^data-raw$ |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(fit_models) |
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,8 @@ | ||
#' sampledat | ||
#' | ||
#' simulated data on annual numbers of human cases of neuro-invasive and non-neuro-invasive | ||
#' West Nile Virus in Nebraska counties. It is predictions of a model that was trained on | ||
#' actual numbers of cases as recorded in CDC's Arbonet database. | ||
#' @docType data | ||
#' | ||
"sampledat" |
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,33 @@ | ||
#' Fit all the models and return a list object suitable for DFMIP. | ||
#' | ||
#' @param x tibble or data frame that defines the desired prediction targets. Must have at least a FIPS code and year. | ||
#' @param path_2_case_data character file path to the case data | ||
#' @param case_type character type of case data | ||
#' @param case_variable character name of the case field in the case data | ||
#' | ||
#' @details This function uses the rows in x to define the prediction | ||
#' targets for the models. There must be at least two fields, the 5 digit fips code | ||
#' to identify the county as a character variable and a year numeric variable to | ||
#' identify the year. | ||
#' | ||
#' The WNV case data cannot be posted publicly as a part of this package. This package | ||
#' assumes the case data are available in a subdirectory of the working directory | ||
#' called `data-raw`, which has rows | ||
#' identified by the same fips codes and a year variable. Case counts are assumed | ||
#' to be in a variable called "cases". There must be at least one row for each | ||
#' fips code in `x`. | ||
#' | ||
#' | ||
#' @return a list of containing predicted cases for the target in the format expected by `DFMIP` | ||
#' @export | ||
fit_models <- function(x, path_2_case_data = here::here("data-raw/wnv_by_county.csv"), | ||
case_type = c("neuro", "all"), | ||
case_variable = "cases"){ | ||
if(is.null(x) | !is.data.frame(x) | !tibble::is.tibble(x)){ | ||
stop("x must be a data frame or tibble.") | ||
} | ||
if(!file.exists(path_2_case_data)){ | ||
stop("Please provide a valid path to the WNV case data.") | ||
} | ||
return(list()) | ||
} |
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## code to prepare `sampledat` dataset goes here | ||
# make sampledat from fitted model | ||
# assumes an input file with the fitted values in the cases column. | ||
#sampledat <- readr::read_csv("data-raw/sampledat.csv") | ||
sampledat <- readr::read_csv("data-raw/predictionsthrough2018.csv") %>% | ||
rename(cases = pred) | ||
# fix arthur county with bayesian posterior for 16 samples of 0 from a poisson distribution | ||
# given a 1, 1 gamma prior we have gamma(1, 17) as the posterior. This | ||
# still has a probability 0.52 of observing 16 zeros at the median. | ||
# So the median is 0.04077336 | ||
sampledat <- dplyr::bind_rows(sampledat, dplyr::tibble(year = 2002:2019, | ||
County = "Arthur", | ||
cases = 0.0477336)) | ||
usethis::use_data(sampledat, overwrite = TRUE) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
test_that("data checks work", { | ||
expect_error(fit_models(x = NULL), "x must be a data frame or tibble.") | ||
expect_error(fit_models(x = sampledat, path_2_case_data = "~"), | ||
"Please provide a valid path to the WNV case data.") | ||
}) | ||
|
||
test_that("return value valid", { | ||
expect_type(fit_models(x = sampledat), "list") | ||
}) |