Skip to content
Snippets Groups Projects
Commit 8e877450 authored by Christina Azodi's avatar Christina Azodi
Browse files

fixed merge errors in plot function

parents e1e1da6c a8c57298
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@
#' @param return_df In effect only when method == "weekly", if TRUE returns
#' also the dataframe used for plotting as well as the ggplot object.
#' @param comp_remove Compartments to remove. Suggest c(s.num, r.num)
#' @param time_lim Number of steps (days) to plot.
#' @param time_limit Number of steps (days) to plot.
#' @param ci T/F to include 95\% confidence intervals in sirplus plot.
#' @param sep_compartments T/F use faceting to show each compartment in a
#' separate plot, only works if plotting a single simulation.
......@@ -38,7 +38,7 @@
#' @export
plot.seiqhrf <- function(x, method = NULL,
comp_remove = "none",
time_lim = 90,
time_limit = 90,
ci = TRUE,
sep_compartments = FALSE,
trans = FALSE,
......@@ -54,7 +54,7 @@ plot.seiqhrf <- function(x, method = NULL,
if(is.null(method)){
plot_sirplus(x, comp_remove = comp_remove,
time_lim = time_lim,
time_limit = time_limit,
ci = ci,
sep_compartments = sep_compartments,
trans = trans,
......@@ -75,7 +75,7 @@ plot.seiqhrf <- function(x, method = NULL,
icu_percent = icu_percent,
start_date = start_date,
show_start_date = show_start_date,
time_lim = time_lim,
time_limit = time_limit,
total_population = total_population)
if(return_df){
return(ret)
......@@ -89,7 +89,7 @@ plot.seiqhrf <- function(x, method = NULL,
#'
#' @param x A list of seiqhrf objects returned from \code{\link{seiqhrf}}.
#' @param comp_remove Compartments to remove. Suggest c(s.num, r.num)
#' @param time_lim Number of steps (days) to plot.
#' @param time_limit Number of steps (days) to plot.
#' @param ci T/F to include 95\% confidence intervals in sirplus plot.
#' @param sep_compartments T/F use faceting to show each compartment in a
#' separate plot, only works if plotting a single simulation.
......@@ -110,7 +110,7 @@ plot.seiqhrf <- function(x, method = NULL,
#' @import ggplot2
#' @export
plot.list <- function(x, comp_remove = "none",
time_lim = 90,
time_limit = 90,
ci = TRUE,
sep_compartments = FALSE,
trans = FALSE,
......@@ -120,7 +120,7 @@ plot.list <- function(x, comp_remove = "none",
plot_title = 'SEIQHRF', ...){
plot_sirplus(x, comp_remove = comp_remove,
time_lim = time_lim,
time_limit = time_limit,
ci = ci,
sep_compartments = sep_compartments,
trans = trans,
......@@ -143,7 +143,7 @@ plot.list <- function(x, comp_remove = "none",
#' @param x A seiqhrf object (or list of multiple seiqhrf objects) returned
#' from \code{\link{seiqhrf}}.
#' @param comp_remove Compartments to remove. Suggest c(s.num, r.num)
#' @param time_lim Number of steps (days) to plot.
#' @param time_limit Number of steps (days) to plot.
#' @param ci T/F to include 95\% confidence intervals in sirplus plot.
#' @param sep_compartments T/F use faceting to show each compartment in a
#' separate plot, only works if plotting a single simulation.
......@@ -165,7 +165,7 @@ plot.list <- function(x, comp_remove = "none",
#' @import ggplot2
#' @export
plot_sirplus <- function(x, comp_remove,
time_lim,
time_limit,
ci,
sep_compartments,
trans,
......@@ -175,7 +175,7 @@ plot_sirplus <- function(x, comp_remove,
plot_title, ...){
# Convert from seiqhrf object to dataframe
plot_df <- format_sims(x, time_lim = time_lim, start_date = start_date)
plot_df <- format_sims(x, time_limit = time_limit, start_date = start_date)
reo_exp <- function(x) {factor(x, levels = unique(plot_df$experiment))}
# Get Confidence Intervals
......@@ -201,7 +201,7 @@ plot_sirplus <- function(x, comp_remove,
# Filter compartments
comp_plot <- setdiff(comps, comp_remove)
plot_df <- plot_df %>% filter(compartment %in% c(comp_plot)) %>%
filter(time <= time_lim)
filter(time <= time_limit)
# Plot with options
p <- ggplot(plot_df, aes(x = Date, y = count, colour = compartment,
......@@ -335,7 +335,7 @@ get_weekly_local <- function(sim,
icu_percent = icu_percent,
start_date = start_date,
show_start_date = show_start_date,
time_lim = time_lim,
time_limit = time_limit,
total_population = total_population){
# Get h.num and 95% quantile CIs
......@@ -344,7 +344,7 @@ get_weekly_local <- function(sim,
hosp <- data.frame('h.num' = sim_mean$h.num, 'ci5' = ci_info$qntCI.1,
'ci95' = ci_info$qntCI.2)
hosp[is.na(hosp)] <- 0
hosp <- hosp[1: time_lim, ]
hosp <- hosp[1: time_limit, ]
hosp$date <- start_date + as.numeric(row.names(hosp))
if(class(show_start_date) == "Date"){
......@@ -395,13 +395,13 @@ get_weekly_local <- function(sim,
#' Format seiqhrf objects into dataframe for ggplot
#'
#' @param x An seiqhrf object returned from function \code{\link{seiqhrf}}.
#' @param time_lim Number of steps (days) to plot.
#' @param time_limit Number of steps (days) to plot.
#' @param start_date Date for day 0. Default: ymd("2020-03-21"),
#'
#' @return dataframe
#'
#' @export
format_sims <- function(x, time_lim, start_date){
format_sims <- function(x, time_limit, start_date){
# Merge models to plot together
if(class(x) == "seiqhrf"){
......@@ -424,7 +424,7 @@ format_sims <- function(x, time_lim, start_date){
}
}
plot_df <- plot_df %>% filter(time <= time_lim) %>%
plot_df <- plot_df %>% filter(time <= time_limit) %>%
pivot_longer(-c(time, experiment),
names_to = "compartment",
values_to = "count") %>%
......
......@@ -6,12 +6,20 @@
\usage{
get_weekly_local(
sim,
<<<<<<< HEAD
market.share = market.share,
icu_percent = icu_percent,
start_date = start_date,
show_start_date = show_start_date,
time_lim = time_lim,
total_population = total_population
=======
market.share,
icu_percent,
start_date,
time_lim,
total_population
>>>>>>> a8c57298caf1bdc80ae8ae8f15fc65d70d4b2b86
)
}
\arguments{
......@@ -27,14 +35,16 @@ ICU among the ones that need hospitalization}
plot week numbers, if provided will plot the first day (Sunday) of the
week.}
<<<<<<< HEAD
\item{show_start_date}{First date to show in plots. Use ymd format. If FALSE,
shows from step 1. Default: FALSE}
=======
\item{time_lim}{Number of days to include. Default = 90.}
>>>>>>> a8c57298caf1bdc80ae8ae8f15fc65d70d4b2b86
\item{total_population}{True population size, needed only if simulation size
is smaller than the true population size due to computational cost
etc.}
\item{time_limit}{Number of days to include. Default = 90.}
}
\value{
\itemize{
......
......@@ -41,12 +41,12 @@ See Tim Churches's [blog post](https://timchurches.github.io/blog/posts/2020-03-
![](model_diagram.png)
| trasitions | Description | Parameters (with default values) |
| trasnitions | Description | Parameters (with default values) |
|-------------|----------------| ------------------------------------------------------------------|
| **inf** | Infection due to contact | `act.rate.*` and `inf.prob.*`, where `*` = `i`, `e`, `q` |
| **prog** | Progress from asymptomatic to symptomatic | `prog.rand = FALSE`, `prog.rate`, `prog.dist.scale = 5`, `prog.dist.shape = 1.5` |
| **quar** | From infectious to quaritine | `quar.rand = TRUE`, `quar.rate = 1/30` |
| **hosp** | From infected (both before and during quarintine) to require hospitalisation | `quar.rand = TRUE`, `quar.rate = 1/30` |
| **quar** | From infectious to quarantine | `quar.rand = TRUE`, `quar.rate = 1/30` |
| **hosp** | From infected (both before and during quarantine) to require hospitalisation | `quar.rand = TRUE`, `quar.rate = 1/30` |
| **rec** | From infected to recovered without hospitalization | `rec.rand = FALSE`, `prog.dist.scale = 35`, `prog.dist.shape = 1.5` |
| **arec** | Exposed individuals recovered before symptomatic | `arec.rand = TRUE`, `arec.rate = 0.05` |
| **disch** | recovery after hospitalization | `disch.rand = TRUE`, `disch.rate = 1/15` |
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment