Skip to content

Commit

Permalink
Copied over from bitbucket epiforecast repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwon Hyun committed Jan 9, 2017
0 parents commit f781126
Show file tree
Hide file tree
Showing 50 changed files with 7,913 additions and 0 deletions.
159 changes: 159 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# begin license for material from https://github.com/github/gitignore/**

# Copyright (c) 2015 GitHub, Inc.

# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

# end license for material from https://github.com/github/gitignore/**



# begin material from https://github.com/github/gitignore/blob/master/Global/Emacs.gitignore

*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*

# Org-mode
.org-id-locations
*_archive

# flymake-mode
*_flymake.*

# eshell files
/eshell/history
/eshell/lastdir

# elpa packages
/elpa/

# reftex files
*.rel

# AUCTeX auto folder
/auto/

# cask packages
.cask/

# end material from https://github.com/github/gitignore/blob/master/Global/Emacs.gitignore





# begin material from https://github.com/github/gitignore/blob/master/Global/Vim.gitignore

[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist
*~

# end material from https://github.com/github/gitignore/blob/master/Global/Vim.gitignore



# begin material from https://github.com/github/gitignore/blob/master/R.gitignore

# History files
.Rhistory
.Rapp.history

# Session Data files
.RData

# Example code in package build process
*-Ex.R

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# end material from https://github.com/github/gitignore/blob/master/R.gitignore



# begin material from https://github.com/github/gitignore/blob/master/C%2B%2B.gitignore

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# end material from https://github.com/github/gitignore/blob/master/C%2B%2B.gitignore

# Assume contents of man page directories are automatically generated:
man/**

# Ignore copy of delphi_epidata.R:
# /R_pkg/epiforecast/R/delphi_epidata.R
# /R_pkg/epiforecast/R/RcppExports.R
# /R_pkg/epiforecast/src/RcppExports.cpp

# Ignore epiforecast package data folder (it should be generated by scripts in data-raw):
/R_pkg/epiforecast/data/**


# (For now) offline copies of data that was fetched
*.csv
*.Rdata

# R documentatation
*.Rd

# Personal todo lists
*todo-justin.org
49 changes: 49 additions & 0 deletions demo/demo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
library(epiforecast)

## Make dummy csv
area.name = "hhs1"
hhs1.dat = fetchEpidataFullDat("fluview", area.name, "wili",
min.points.in.season=52L,
first.week.of.season = 21L,
cache.file=sprintf("fluview_%s_fetch.Rdata", area.name))

## Create a csv in the correct, desirable format
filename="./correct.csv"
hhs1.dat = lapply(hhs1.dat, function(myvec){ if(length(myvec)<53) return(c(myvec,NA)) else {return(myvec)}})
correct.hhs1.dat = do.call(cbind, hhs1.dat)
correct.hhs1.dat = correct.hhs1.dat[-53,]
write.csv(correct.hhs1.dat, file = filename,row.names=FALSE)
full.dat = read.from.file(filename)


## Try EB with basic options
mysim = eb.sim(full.dat, n.sims=1000)
epiforecast:::plot.sim(mysim)
targets = epiforecast:::forecast.sim(mysim,'pht')


## Try EB with more simulation settings
control.list = get.eb.control.list(sd.option="prior",max.match.length=5)
mysim = eb.sim(full.dat, n.sims=100, control.list=control.list)
epiforecast:::plot.sim(mysim)


## Try BR
mysim = br.sim(full.dat, n.sims=100, bootstrap=T)
epiforecast:::plot.sim(mysim)
epiforecast:::print.sim(mysim,verbose=TRUE)
targets = epiforecast:::forecast.sim(mysim, "pht")

## Try BR with more simulation settings
control.list = get_br_control_list(df=5, cv.rule="1se")
mysim = br.sim(full.dat, n.sims=100, bootstrap=T, control.list=control.list)
epiforecast:::plot.sim(mysim)
epiforecast:::print.sim(mysim,verbose=TRUE)
targets = epiforecast:::forecast.sim(mysim, "pht", plot.hist=TRUE)
targets = epiforecast:::forecast.sim(mysim, "pwk", plot.hist=TRUE)



## Try twkde
mysim = twkde.sim(full.dat)
epiforecast:::plot.sim(mysim)
Binary file added epiforecast.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions epiforecast/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inst/doc
54 changes: 54 additions & 0 deletions epiforecast/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Package: epiforecast
Type: Package
Title: Tools for forecasting semi-regular seasonal epidemic curves and similar
time series
Version: 0.0.1
Date: 2015-12-09
Author: Logan C. Brooks, David C. Farrow, Sangwon Hyun, Ryan J. Tibshirani, Roni
Rosenfeld
Maintainer: Logan C. Brooks <lcbrooks@cs.cmu.edu>
Imports:
stats,
utils,
lubridate,
splines,
glmgen,
glmnet,
httr,
Rcpp,
rlist,
RColorBrewer,
data.table,
hexbin,
plotrix
Description: Tools for forecasting semi-regular seasonal epidemic curves and
similar time series. Includes an empirical Bayes approach that forms a prior
by transforming historical curves, a basis regression approach that balances
matching observations from the current season and matching historical
seasons' measurements for future weeks, and timestep-by-timestep weighted
kernel density estimation on backward differences parameterized by both the
time series measurments and the current time.
License: GPL-2
RoxygenNote: 5.0.1.9000
Collate:
'RcppExports.R'
'match.R'
'utils.R'
'br.R'
'checks.R'
'cv.R'
'delphi_epidata.R'
'eb_dists.R'
'weeks.R'
'loaders.R'
'interface.R'
'eb.R'
'holidays.R'
'read.R'
'simclass.R'
'todo-by-file.R'
'twkde.R'
LinkingTo: Rcpp
SystemRequirements: C++14
Suggests:
testthat
53 changes: 53 additions & 0 deletions epiforecast/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Generated by roxygen2: do not edit by hand

export(DateToYearWeekWdayDF)
export(DatesOfSeason)
export(Seq)
export(augmentWeeklyDF)
export(br.sim)
export(br.smoothedCurve)
export(dat.to.matrix)
export(eb.createForecasts)
export(eb.fitSmoothCurves)
export(eb.sim)
export(fetchEpidataDF)
export(fetchEpidataFullDat)
export(get.latest.time)
export(get_br_control_list)
export(get_eb_control_list)
export(is_christmas)
export(is_newyear)
export(is_thanksgiving)
export(lastWeekNumber)
export(match.arg.else.default)
export(match.dat)
export(match.integer)
export(match.new.dat.sim)
export(match.single.na.or.numeric)
export(match.single.nonna.integer)
export(match.single.nonna.integer.or.null)
export(read.from.file)
export(seasonModelWeekDFToYearWeekDF)
export(seasonModelWeekToYearWeekDF)
export(seasonModelWeekWdayDFToDate)
export(seasonModelWeekWdayToDate)
export(seasonOfDate)
export(seasonOfYearWeek)
export(trimPartialPastSeasons)
export(twkde.markovian.sim)
export(twkde.sim)
export(unifChoicePrior)
export(weekConventions)
export(yearWeekDFToSeasonModelWeekDF)
export(yearWeekWdayDFToDate)
export(yearWeekWdayListsToDate)
export(yearWeekWdayVecsToDate)
import(RColorBrewer)
import(Rcpp)
import(data.table)
import(glmgen)
import(hexbin)
import(httr)
import(plotrix)
import(rlist)
useDynLib(epiforecast)
3 changes: 3 additions & 0 deletions epiforecast/R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file was generated by Rcpp::compileAttributes
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

Loading

0 comments on commit f781126

Please sign in to comment.