Skip to content

Commit

Permalink
adding basic infrastructure including testing (currently not passing)
Browse files Browse the repository at this point in the history
  • Loading branch information
atyre2 committed Sep 14, 2020
1 parent f1f1450 commit be9b639
Show file tree
Hide file tree
Showing 12 changed files with 1,789 additions and 1 deletion.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
^README\.Rmd$
^cran-comments\.md$
^\.github$
^data-raw$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.Rhistory
.RData
.Ruserdata
^data-raw$
6 changes: 5 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
Imports:
wnvdata
wnvdata,
dplyr,
readr
Depends:
R (>= 2.10)
1 change: 1 addition & 0 deletions NAMESPACE
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)
8 changes: 8 additions & 0 deletions R/data.R
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"
33 changes: 33 additions & 0 deletions R/fit_models.R
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())
}
1,657 changes: 1,657 additions & 0 deletions data-raw/predictionsthrough2018.csv

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions data-raw/sampledat.R
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 added data/sampledat.rda
Binary file not shown.
41 changes: 41 additions & 0 deletions man/fit_models.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions man/sampledat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/testthat/test-fit_models.R
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")
})

0 comments on commit be9b639

Please sign in to comment.