-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging branch 'ericfigs-docker' to integrate reviewed code into master.
- Loading branch information
Showing
32 changed files
with
2,301 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
eric-figs/design/ filter=lfs diff=lfs merge=lfs -text | ||
eric-figs/output/data/ filter=lfs diff=lfs merge=lfs -text | ||
eric-figs/packrat/bundles/* filter=lfs diff=lfs merge=lfs -text | ||
eric-figs/*.nb.html filter=lfs diff=lfs merge=lfs -text | ||
eric-figs/*.csv filter=lfs diff=lfs merge=lfs -text |
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,3 @@ | ||
#### -- Packrat Autoloader (version 0.4.8-20) -- #### | ||
source("packrat/init.R") | ||
#### -- End Packrat Autoloader -- #### |
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,6 @@ | ||
.git | ||
./data/* | ||
./ouput/* | ||
./packrat/lib*/* | ||
./packrat/bundles/* | ||
./packrat/src/* |
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,7 @@ | ||
# Packrat | ||
packrat/lib*/ | ||
packrat/src | ||
|
||
# Ignored folders | ||
sketches/ | ||
design/ |
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,20 @@ | ||
FROM r-base:3.4.3 | ||
MAINTAINER Eamon O'Dea <[last name without apostrophe]35@gmail.com> | ||
RUN apt-get update && apt-get install -y -q --no-install-recommends \ | ||
libcurl4-openssl-dev \ | ||
libgdal-dev \ | ||
libnlopt-dev \ | ||
libproj-dev \ | ||
libpng-dev \ | ||
libpoppler-cpp-dev \ | ||
librsvg2-dev \ | ||
libssl-dev \ | ||
libwebp-dev \ | ||
libxml2-dev | ||
RUN install2.r --error packrat | ||
RUN mkdir /root/work | ||
COPY ./packrat /root/work/packrat | ||
COPY ./.Rprofile /root/work/ | ||
RUN /usr/bin/Rscript -e "setwd(\"/root/work\"); source(\".Rprofile\"); packrat::restore()" |
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,110 @@ | ||
# all packages used in ericfigs/ | ||
library(graphics) # standard R package | ||
library(grDevices) # standard R package | ||
library(utils) # standard R package | ||
library(stats) # standard R package | ||
library(colorspace) # for constructing color | ||
library(scales) | ||
library(zoo) | ||
library(reshape) | ||
library(magrittr) | ||
library(latex2exp) # used to include LaTeX expressions in plot text | ||
library(pomp) # required by spaero | ||
library(spaero) # model simulation and statistics | ||
|
||
|
||
# Helper functions -------------------------------------------------------- | ||
|
||
## Sample process | ||
sample_process <- function(external_forcing = 1 / 7, host_lifetime = 70 * 365, | ||
infectious_days = 7, observation_days = 20 * 365, | ||
sampling_interval = 1, population_size = 1e6, | ||
process_reps = 1){ | ||
## Runs model and returns sample of state variables and flow from I to R, which is the cases column | ||
## Default parameters are those used in the simulation study. | ||
|
||
times <- seq(0, observation_days, by = sampling_interval) | ||
params <- c(gamma=1 / infectious_days, mu=1 / host_lifetime, | ||
d=1 / host_lifetime, eta=external_forcing / population_size, | ||
beta=0, rho=0.1, S_0=1, I_0=0, R_0=0, N_0=population_size) | ||
beta_final <- (params["gamma"] + params["d"]) / population_size | ||
covalt <- data.frame(gamma_t=c(0, 0), mu_t=c(0, 0), d_t=c(0, 0), | ||
eta_t=c(0, 0), beta_t=c(0, beta_final), | ||
time=c(0, observation_days)) | ||
|
||
simtest <- spaero::create_simulator(times=times, params=params, covar=covalt) | ||
|
||
ret <- list() | ||
do_sim <- function(obj, nsim=process_reps){ | ||
cols_to_delete <- c("reports", "gamma_t", "mu_t", "d_t", "eta_t") | ||
ret <- pomp::simulate(obj, nsim=nsim, as.data.frame=TRUE) | ||
ret[, !colnames(ret) %in% cols_to_delete] | ||
} | ||
do_sim(simtest) | ||
} | ||
|
||
## Sample observations taking a time series as input | ||
sample_observation <- function (cases, sampling_interval = 1, tau = 1, reporting_prob = 1, dispersion_parameter = 100) { | ||
tots <- aggregate.ts(cases, nfrequency = 1/(tau/sampling_interval)) | ||
mu <- tots * reporting_prob | ||
n <- length(mu) | ||
sampled <- rnbinom(n = n, mu = mu, size = dispersion_parameter) | ||
ts(sampled,start=start(tots),end=end(tots),frequency=frequency(tots)) | ||
} | ||
|
||
## Statistical Analysis | ||
analysis <- function(data,params){ | ||
get_stats( | ||
data, | ||
center_trend = params$center_trend, | ||
stat_trend = params$stat_trend, | ||
center_kernel = params$center_kernel, | ||
stat_kernel = params$stat_kernel, | ||
center_bandwidth = params$center_bandwidth, | ||
stat_bandwidth = params$stat_bandwidth, | ||
lag = params$lag) | ||
} | ||
|
||
## CDC Epiweek to Dates | ||
## returns the start date of the CDC epiweek | ||
cdcweekToDate <- function(epiweek, weekday = 0, year = NULL, week = NULL) { | ||
if(missing(epiweek)) { | ||
year <- year | ||
week <- week | ||
}else{ | ||
year <- epiweek %/% 1e2 | ||
week <- epiweek %% 1e2 | ||
} | ||
jan1 <- as.Date(ISOdate(year,1,1)) | ||
jan1.wday <- as.POSIXlt(jan1)$wday | ||
if (jan1.wday < 4) { | ||
origin <- jan1 - jan1.wday | ||
}else{ | ||
origin <- jan1 + (7-jan1.wday) | ||
} | ||
date <- origin+(week-1)*7+weekday | ||
return(date) | ||
} | ||
|
||
|
||
# Color palettes ---------------------------------------------------------- | ||
|
||
unipalette.lorder <- c( | ||
"black"="#252525", # Nero (grey) | ||
"purple"="#5e2b7b", # Blue Diamond (violet) | ||
"red"="#a11c3e", # Fire Brick (red) | ||
"blue"="#226e83", # Allports (blue) | ||
"green"="#319045", # Sea Green (green) | ||
"lightblue"="#5798d1", # Picton Blue (blue) | ||
"pink"="#e2908c" # Sea Pink (red) | ||
) | ||
unipalette <- unipalette.diff <- unipalette.lorder[c(3,6,1,5,2,7,4)] | ||
unipalette.hybrid <- unipalette.lorder[c(1,3,2,5,4,7,6)] | ||
|
||
AUC.colors <- diverge_hcl( | ||
n = 20, # number of colors | ||
h = c(45, 225), # Hues (low, hi) | ||
c = 100, # fixed Chroma or Chroma Range (edges, center) | ||
l = c(90, 10), # Lightness range (edges, center) | ||
power = 1 # exponent | ||
) |
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,19 @@ | ||
# Working Directory | ||
|
||
The R working directory is assumed to be ```eric-figs/``` | ||
|
||
# Directory Structure | ||
|
||
Directory ```eric-figs/``` contains code and output for simulated data, and for figures 1, 2, and 3. | ||
|
||
```eric-figs/data/``` contains source data files, in this case consisting of saved snapshots of | ||
1. the complete description of the random number generator state, required to reproduce simulations used in the figures exactly. Simulations were produced using a RNG of kind "Mersenne-Twister" and normal.kind "Inversion" under R version 3.3.2 eunning on OSX 10.9.5. | ||
2. A copy of Level 1 data from Project Tycho, used for figure 1. | ||
|
||
```eric-figs/output/plots``` contains plots output from ```eric-figs/fig1.R```, ```eric-figs/fig2.R```, and ```eric-figs/fig3.R``` in PDF format | ||
|
||
```eric-figs/output/data``` contain simulation data generated by ```eric-figs/simulation.R```. | ||
|
||
```eric-figs/packrat``` contains packrat package management directories. | ||
|
||
```eric-figs/R/``` contains script(s) sourced by top level scripts |
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 @@ | ||
docker build -t eamon/reporting-proc-eric-figs:v20180223 . |
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,17 @@ | ||
#!/usr/bin/bash | ||
|
||
cp /mnt/input/*.R . | ||
cp -r /mnt/input/data . | ||
cp -r /mnt/input/R . | ||
mkdir /mnt/output/data | ||
mkdir /mnt/output/plots | ||
mkdir output | ||
cd output | ||
ln -s /mnt/output/data . | ||
ln -s /mnt/output/plots . | ||
cd .. | ||
ls -lR > ./output/data/container-file-tree | ||
Rscript ./simulation.R | ||
Rscript ./fig1.R | ||
Rscript ./fig2.R | ||
Rscript ./fig3.R |
Git LFS file not shown
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 @@ | ||
{"@type": "dcat:Dataset", "accessLevel": "public", "bureauCode": ["009:00"], "contactPoint": {"fn": "Project Tycho", "hasEmail": "mailto:Tycho@phdl.pitt.edu"}, "describedBy": "http://www.tycho.pitt.edu/about.php", "description": "<p>US weekly Nationally Notifiable Disease Surveillance Data from 1888 to 2013. These data include tables of disease counts reported by US states and cities to the Federal Health Authorities every week since 1888. These tables have been published in various journals over time and are available in various online repositories but are now also available in digital, computer-readable format.</p>\n", "distribution": [{"@type": "dcat:Distribution", "downloadURL": "https://www.healthdata.gov/sites/default/files/ProjectTycho_Level1_v1.0.0.csv", "format": ".csv", "mediaType": "text/csv", "title": "Project Tycho \u00ae Level 1 Data"}], "identifier": "c3d4c2ac-ddff-46ec-9343-8d8a5cac888f", "keyword": ["disease data", "nndss", "Notifiable diseases", "reported diseases", "surveillance"], "language": ["en"], "license": "http://opendefinition.org/licenses/odc-odbl/", "modified": "2016-09-02", "programCode": ["009:000"], "publisher": {"@type": "org:Organization", "name": "Department of Health & Human Services"}, "references": ["http://www.healthdata.gov/blog/project-tycho-unlocking-125-years-data"], "temporal": "1887-12-31T19:00:00-05:00/2013-08-15T20:00:00-04:00", "title": "Project Tycho \u00ae Level 1 Data"} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.