-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2ed4434
Showing
23 changed files
with
3,959 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,45 @@ | ||
Package: REffectivePred | ||
Type: Package | ||
Title: Pandemic Prediction Model in an SIRS Framework | ||
Version: 1.0.0 | ||
Authors@R: c(person(given = "Razvan", | ||
family = "Romanescu", | ||
role = c("aut", "cre"), | ||
email = "Razvan.Romanescu@umanitoba.ca"), | ||
person(given = "Songdi", | ||
family = "Hu", | ||
role = "aut"), | ||
person(given = "Md Ashiqul", | ||
family = "Haque", | ||
role = "aut"), | ||
person(given = "Olivier", | ||
family = "Tremblay-Savard", | ||
role = "aut")) | ||
Maintainer: Razvan Romanescu <Razvan.Romanescu@umanitoba.ca> | ||
Description: A suite of methods to fit and predict case count data using | ||
a compartmental SIRS (Susceptible – Infectious – Recovered – Susceptible) | ||
model, based on an assumed specification of the effective reproduction | ||
number. The significance of this approach is that it relates epidemic | ||
progression to the average number of contacts of infected individuals, | ||
which decays as a function of the total susceptible fraction remaining | ||
in the population. The main functions are pred.curve(), which computes | ||
the epidemic curve for a set of parameters, and estimate.mle(), which | ||
finds the best fitting curve to observed data. The easiest way to pass | ||
arguments to the functions is via a config file, which contains input | ||
settings required for prediction, and the package offers two methods, | ||
navigate_to_config() which points the user to the configuration file, | ||
and re_predict() for starting the fit-predict process. | ||
Razvan G. Romanescu et al. (2023) <doi:10.1016/j.epidem.2023.100708>. | ||
Imports: yaml, config, zoo, grDevices, utils | ||
License: GPL (>= 2) | ||
Encoding: UTF-8 | ||
RoxygenNote: 7.2.3 | ||
Collate: 'prediction_model.v16.R' 'executions.v16.R' | ||
NeedsCompilation: no | ||
Packaged: 2024-01-31 18:14:33 UTC; gobs3 | ||
Author: Razvan Romanescu [aut, cre], | ||
Songdi Hu [aut], | ||
Md Ashiqul Haque [aut], | ||
Olivier Tremblay-Savard [aut] | ||
Repository: CRAN | ||
Date/Publication: 2024-02-02 18:30:02 UTC |
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,22 @@ | ||
5eeab009739343dbd99cb2d1e100af20 *DESCRIPTION | ||
0c79430589fc8375fa283c0b2a700212 *NAMESPACE | ||
e778b86e78e9398f7e47cb8162af93d8 *R/executions.v16.R | ||
2b4ed4b7ebb4197bc64f93029ce1cc9f *R/prediction_model.v16.R | ||
ace2b074ff852bd1b8d6aaf095fa1984 *inst/config.yml | ||
3280b6d9de50b546717c20bb93a3bd47 *inst/extdata/NY_OCT_4_2022.csv | ||
07601b5a14538a8542eabc6bcf863607 *man/c_helper.Rd | ||
2954881c32139660e1f2ba43651a1d00 *man/ci.curve.Rd | ||
710dd855d6bbb2ec96a06afe8fff9c5e *man/estimate.mle.Rd | ||
5ae616ca3469d67a1bc911563ee036a8 *man/find_ends.Rd | ||
8308d8a4941e57846739f16fce05642e *man/find_starts.Rd | ||
25527169ff8d23ea143dbd6ae7dc11da *man/load_config.Rd | ||
1d42025363b2d2fc72c8ccb86d9ddaed *man/log_lklh.Rd | ||
4277b6b452c4ee5e7bf151b118b4a78a *man/modif.helper.Rd | ||
b8d3f8315181bc4596ab6485637fd84b *man/navigate_to_config.Rd | ||
01b6259a012f0a4165489fb9e9a4680f *man/plot_outputs.Rd | ||
3477bcd035d8c1fc2ab8aa692e381812 *man/pred.curve.Rd | ||
07a4f0fb02de208a907cded1e3ad6e3d *man/ranges_to_waves.Rd | ||
02a4eb334b0d2fdca285d960a801fe34 *man/re_predict.Rd | ||
779993d869916312b0f76a7a2a197426 *man/rt_empirical.Rd | ||
7c4bc9bee71464512a36b71d1989bf4c *man/serial.helper.Rd | ||
c443136f1d32cfb1dae090f9585bb8f7 *man/waves_1d_list.Rd |
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,32 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(c_helper) | ||
export(ci.curve) | ||
export(estimate.mle) | ||
export(find_ends) | ||
export(find_starts) | ||
export(load_config) | ||
export(log_lklh) | ||
export(navigate_to_config) | ||
export(plot_outputs) | ||
export(pred.curve) | ||
export(ranges_to_waves) | ||
export(re_predict) | ||
export(rt_empirical) | ||
export(waves_1d_list) | ||
import(config) | ||
import(yaml) | ||
importFrom(grDevices,colorRampPalette) | ||
importFrom(grDevices,dev.off) | ||
importFrom(graphics,abline) | ||
importFrom(graphics,axis) | ||
importFrom(graphics,lines) | ||
importFrom(graphics,points) | ||
importFrom(graphics,rect) | ||
importFrom(graphics,title) | ||
importFrom(stats,dlnorm) | ||
importFrom(stats,dnorm) | ||
importFrom(stats,optim) | ||
importFrom(utils,data) | ||
importFrom(utils,read.csv) | ||
importFrom(zoo,as.Date) |
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,211 @@ | ||
##################################### MAIN ##################################### | ||
# includes underreporting estimation | ||
#' @import yaml | ||
#' @import config | ||
#' @importFrom zoo as.Date | ||
#' @importFrom grDevices dev.off | ||
#' @importFrom utils data read.csv | ||
#' @include prediction_model.v16.R | ||
NULL | ||
|
||
#' @title Navigate to the config file | ||
#' @description Prints the path to the config file and opens the config file. | ||
#' @returns The path to the configuration file. | ||
#' @export | ||
navigate_to_config <- function() { | ||
path_to_config <- system.file("config.yml", package = "REffectivePred") | ||
system(path_to_config) | ||
output <- path_to_config | ||
} | ||
|
||
#' @title Load configuration file | ||
#' @description Load the configuration file as an object in the global | ||
#' environment. This can be passed to the main functions instead of the | ||
#' individual arguments within, for user convenience. | ||
#' @returns A ’config’ object, which is a list that stores input parameters and | ||
#' settings from config.yml. Variable names are imported exactly. See the | ||
#' configuration file for details. | ||
#' @export | ||
load_config <- function(){ | ||
path_to_config <- system.file("config.yml", package = "REffectivePred") | ||
cfg <- config::get(file = path_to_config) | ||
output <- cfg | ||
} | ||
|
||
|
||
#' @title Demo of main functions | ||
#' @description Fits the model to an example case data and predicts the epidemic curves and plots the outputs. | ||
#' @details | ||
#' Please modify the config file before invoking this method. | ||
#' The config file contains all the settings and initial parameter values | ||
#' necessary for the algorithm to run. Path to the dataset (in csv format) | ||
#' is also set in the config file. This file should be updated to the desired | ||
#' specifications before running this demo. To open it, execute | ||
#' REffectivePred::navigate_to_config(). | ||
#' @usage NULL | ||
#' @param path_to_data Absolute path to the dataset in csv format. | ||
#' @returns No return value. | ||
#' @export | ||
re_predict <- function(path_to_data = NULL) { | ||
path_to_config <- system.file("config.yml", package = "REffectivePred") | ||
cfg <- config::get(file = path_to_config) | ||
|
||
if (is.null(path_to_data)) { | ||
path_to_data <- system.file("extdata/NY_OCT_4_2022.csv", package = "REffectivePred") | ||
} | ||
|
||
data <- read.csv(path_to_data) | ||
cases <- diff(c(0, data$cases)) # Convert cumulative cases into daily cases | ||
Time <- as.Date(data$date, tryFormats = c("%d-%m-%Y", "%d/%m/%Y")) | ||
population <- cfg$population # Population size | ||
|
||
lt <- length(cases) # Length of cases | ||
window_size <- cfg$window.size # Window size for Instantaneous Rt | ||
rho <- eval(parse(text = cfg$rho)) # Under-reporting fraction (ref Irons, Raftery, 2021) | ||
serial_mean <- cfg$serial_mean | ||
serial_var <- cfg$serial_var | ||
adj.period <- cfg$adj.period # Assume that psi shifts linearly to the new value over this period, to account for delays in society adjusting, and reporting delays | ||
|
||
fit.t.pred <- cfg$fit.t.pred #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Time of prediction | ||
not.predict <- cfg$not.predict | ||
rt.func.num <- cfg$rt.func.num | ||
num.iter <- cfg$num.iter | ||
silence.errors <- cfg$silence.errors | ||
predict.beyond <- cfg$predict.beyond | ||
|
||
curve_params <- as.double(unlist(cfg$curve_params)) | ||
|
||
vt_params <- as.double(unlist(cfg$vt_params)) # The vt initial values, starting at wave 2 | ||
|
||
restriction_levels <- as.double(unlist(cfg$restriction_levels)) # Psi | ||
|
||
betas <- as.double(unlist(cfg$betas)) # betas | ||
|
||
ini_params <- c(curve_params, vt_params, restriction_levels, betas) | ||
|
||
restrictions_params <- cfg$restrictions_params | ||
restriction_st_params <- cfg$restriction_st_params | ||
param_scale <- abs(ini_params) / 10 | ||
waves_list <- ranges_to_waves(cfg$waves_list) | ||
params_limits <- cfg$params_limits | ||
num_waves <- cfg$num_waves | ||
|
||
waves <- waves_1d_list(num_waves, waves_list) | ||
|
||
rho <- eval(parse(text = cfg$rho)) | ||
infections <- cases / rho # Estimated time series of total infections | ||
|
||
# ============================================================================== | ||
|
||
est <- estimate.mle( | ||
ini_params = ini_params, | ||
params_limits = params_limits, | ||
restrictions = restrictions_params, | ||
restriction.starts = restriction_st_params, | ||
ranges = waves, | ||
rt_func = rt.func.num, | ||
silence.errors = silence.errors, | ||
fit.t.pred = fit.t.pred, | ||
param_scale = param_scale, | ||
num.iter = num.iter, | ||
cases = cases, | ||
scenario = NULL, | ||
H.E = NULL, | ||
H.W = NULL, | ||
adj.period = adj.period, | ||
population = population, | ||
rho = rho, | ||
serial_mean = serial_mean, | ||
serial_var = serial_var, | ||
lt = lt, | ||
window_size = window_size, | ||
hessian = T | ||
) | ||
|
||
print(est) | ||
|
||
a1 <- est$a1 | ||
a2 <- est$a2 | ||
a3 <- est$a3 | ||
a4 <- est$a4 | ||
nu <- est$nu | ||
vt <- c(1, est$vt_params_est) | ||
psi <- est$Psi | ||
betas <- est$betas | ||
|
||
|
||
# Result & Plot: Predictions are based on the function below | ||
|
||
r1 <- pred.curve( | ||
a1 = a1, | ||
a2 = a2, | ||
a3 = a3, | ||
a4 = a4, | ||
nu = nu, | ||
Psi = psi, | ||
betas = betas, | ||
use.actual.not.predicted = not.predict, | ||
restrictions = restrictions_params, | ||
restriction.starts = restriction_st_params, | ||
ranges = waves, | ||
variant.transm = vt, | ||
rt_func = rt.func.num, | ||
fit.t.pred = fit.t.pred, | ||
cases = cases, | ||
scenario = NULL, | ||
H.E = NULL, | ||
H.W = NULL, | ||
adj.period = adj.period, | ||
population = population, | ||
rho = rho, | ||
serial_mean = serial_mean, | ||
serial_var = serial_var, | ||
lt = lt, | ||
window_size = window_size | ||
) | ||
|
||
print(r1) | ||
Rt.pr <- r1$`Predicted Rt` # Predicted Rt | ||
yt.pr1 <- abs(r1$`Predicted Infections`) | ||
|
||
# Rt | ||
range.rt <- 1:length(lt) | ||
|
||
### Plot for each Rt (1:4) | ||
range.points <- 1:(max(waves_list[[4]]) + 21) # Decide the range of points to plot | ||
|
||
# Rt | ||
plot_outputs(Time = Time, | ||
cases = cases, | ||
window_size = window_size, | ||
serial_mean = serial_mean, | ||
serial_var = serial_var, | ||
predict.beyond = predict.beyond, | ||
waves_list = waves_list, | ||
num_waves = num_waves, | ||
rt_func = rt.func.num, | ||
curve = r1, | ||
restrictions = restrictions_params, | ||
restriction.starts = restriction_st_params | ||
) | ||
|
||
# Confidence bounds | ||
bounds <- ci.curve(fit = est, | ||
restrictions = restrictions_params, | ||
restriction.starts = restriction_st_params, | ||
ranges = waves, | ||
rt_func = rt.func.num, | ||
fit.t.pred = fit.t.pred, | ||
cases = cases, | ||
scenario = NULL, | ||
H.E = NULL, | ||
H.W = NULL, | ||
adj.period = adj.period, | ||
population = population, | ||
rho = rho, | ||
serial_mean = serial_mean, | ||
serial_var = serial_var, | ||
lt = lt, | ||
window_size = window_size) | ||
print(bounds) | ||
} |
Oops, something went wrong.