From 52ee617252e482d674faca7691ba4d7791cce0ac Mon Sep 17 00:00:00 2001 From: Amelie Lucker <amelie.lucker@itwm.fraunhofer.de> Date: Thu, 26 May 2022 14:11:13 +0200 Subject: [PATCH] use of commas and tidyverse style updated --- vignettes/contacts.Rmd | 50 ++++++------- vignettes/contagious_period.Rmd | 33 +++++---- vignettes/future_infections.Rmd | 12 ++-- vignettes/infection_period.Rmd | 72 +++++++++---------- .../risk_assessment_group_quarantine.Rmd | 36 +++++----- 5 files changed, 100 insertions(+), 103 deletions(-) diff --git a/vignettes/contacts.Rmd b/vignettes/contacts.Rmd index 56db027..b105606 100644 --- a/vignettes/contacts.Rmd +++ b/vignettes/contacts.Rmd @@ -45,7 +45,7 @@ knitr::knit_hooks$set( ``` -```{r setup, echo=FALSE, message=FALSE} +```{r setup, echo = FALSE, message = FALSE} library(smidm) library(ggplot2) library(dplyr) @@ -66,7 +66,7 @@ Therefore, only the symptom begin date of the infected person is needed. Further Multiple arguments are needed for the function `get_serial_interval_density()`: -First of all, the `symptom_begin_date` has to be specified, which is defined as the date, when the person started to show symptoms. +First of all, the `symptom_begin_date` has to be specified, which is defined as the date when the person started to show symptoms. Furthermore, the `max_serial_interval_days` is needed, which defines the interval length of the distribution output. @@ -89,14 +89,14 @@ serial_in_df_v1 <- get_serial_interval_density(symptom_begin_date, The default values of the parameters for the distribution, when the infected contacts will show symptoms, are from the paper Zhang et al [1], in which a gamma distribution for the serial interval between symptom onsets of infected persons and the symptom onset of infected contacts was estimated. -For the second generation of contacts, the probability equals the summation of random variables because we assume that the infection from infected person to the first contact generation is independent from the first to the second generation. Thus, a convolution of two identical gamma distributions has to be conducted. For gamma distributions, the convolutions of gamma distributions equals the summation of their first parameters [2]. Thus, the density for the second generation of infected persons showing symptoms is given by a gamma distribution with $2 \cdot$ `shape_serial` and the same `rate_serial`. In general, the serial interval for the $i$-th generation of contacts can be calculated with a gamma distribution with parameters $i \cdot$ `shape_serial` and `rate_serial`. This holds in an analogous way for the third generation. +For the second generation of contacts the probability equals the summation of random variables because we assume that the infection from infected person to the first contact generation is independent from the first to the second generation. Thus, a convolution of two identical gamma distributions has to be conducted. For gamma distributions the convolutions of gamma distributions equals the summation of their first parameters [2]. Thus, the density for the second generation of infected persons showing symptoms is given by a gamma distribution with $2 \cdot$ `shape_serial` and the same `rate_serial`. In general, the serial interval for the $i$-th generation of contacts can be calculated with a gamma distribution with parameters $i \cdot$ `shape_serial` and `rate_serial`. This holds in an analogous way for the third generation. ### Output The function call returns the following data set: -```{r get_serial_interval_density_result, echo=FALSE, message=FALSE} -knitr::kable(serial_in_df_v1[100:109,], +```{r get_serial_interval_density_result, echo = FALSE, message = FALSE} +knitr::kable(serial_in_df_v1[100:109, ], caption = "values 100 to 109 of resulting data frame") ``` @@ -106,18 +106,18 @@ The data frame shows for each hour beginning at `symptom_begin_date` until `max_ ```{r get_serial_interval_density_v2} symptom_begin_date = as.Date("2021-12-28") max_serial_interval_days = 20 -shape_serial = 2*2.39 +shape_serial = 2 * 2.39 rate_serial = 0.48 serial_in_df_v2 <- get_serial_interval_density(symptom_begin_date, - max_serial_interval_days, - shape_serial, - rate_serial) + max_serial_interval_days, + shape_serial, + rate_serial) ``` -```{r get_serial_interval_density_v2_table, echo=FALSE, message=FALSE} -knitr::kable(serial_in_df_v2[100:109,], +```{r get_serial_interval_density_v2_table, echo = FALSE, message = FALSE} +knitr::kable(serial_in_df_v2[100:109, ], caption = "values 100 to 109 of resulting data frame") ``` @@ -126,18 +126,18 @@ knitr::kable(serial_in_df_v2[100:109,], The following code generates a plot with the gamma distribution of the illness probability of the first contact generation and the 80% and 95% high density intervals. In addition, the illness probability for the second generation is plotted in violet. -```{r .calculate_qstart_qend, foldcode=TRUE} +```{r .calculate_qstart_qend, foldcode = TRUE} .calculate_qstart_qend <- function(probability, df) { - hdr_df <- hdr(den=data.frame(x=1:length(df$distribution), y=df$distribution), - p=probability*100)$hdr - qstart <- (hdr_df[1,1] - 1)/24 - qend <- (hdr_df[1,2] - 1)/24 + hdr_df <- hdr(den = data.frame(x = 1:length(df$distribution), y = df$distribution), + p = probability * 100)$hdr + qstart <- (hdr_df[1, 1] - 1) / 24 + qend <- (hdr_df[1, 2] - 1) / 24 return(list("qstart" = qstart, "qend" = qend)) } ``` -```{r .shade_curve, foldcode=TRUE} +```{r .shade_curve, foldcode = TRUE} .shade_curve <- function(df, qstart, qend, fill = "red", alpha = 0.4) { subset_df <- df[floor(qstart * 24):ceiling(qend * 24), ] geom_area(data = subset_df, @@ -149,7 +149,7 @@ The following code generates a plot with the gamma distribution of the illness p ``` -```{r parameters for visualization of get_infection_date_density, foldcode=TRUE} +```{r parameters for visualization of get_infection_date_density, foldcode = TRUE} symptom_begin_date = as.Date("2021-12-28") df <- get_serial_interval_density(symptom_begin_date, @@ -163,24 +163,24 @@ The following code generates a plot with the gamma distribution of the illness p df_2 <- get_serial_interval_density(symptom_begin_date, max_serial_interval_days = 20, - shape_serial = 2*2.39, + shape_serial = 2 * 2.39, rate_serial = 0.48) symp_date_posixct_start <- as.POSIXct(format(as.POSIXct(symptom_begin_date, tz = "CET"), "%Y-%m-%d")) symp_date_posixct_end <- as.POSIXct(format(as.POSIXct(symptom_begin_date + 1, tz = "CET"), "%Y-%m-%d")) symp_date_posixct_mid <- symp_date_posixct_start - as.numeric(difftime(symp_date_posixct_start, - symp_date_posixct_end, units = "hours"))/2*3600 + symp_date_posixct_end, units = "hours")) / 2 * 3600 ``` -```{r visualization of get_infection_date_density, foldcode=TRUE} +```{r visualization of get_infection_date_density, foldcode = TRUE} g <- ggplot() + scale_x_datetime(breaks = scales::date_breaks("1 days"), labels = scales::date_format("%d-%m-%Y")) + theme(axis.text.x = element_text(angle = 90)) + # scale_x_continuous(breaks = x_tick, # labels = x_label) + - # theme(axis.ticks.x = element_line(color = c(rbind(rep("black", length(x_label)/2), rep(NA, length(x_label)/2))), linetype = 2, size = 1))+ + # theme(axis.ticks.x = element_line(color = c(rbind(rep("black", length(x_label) / 2), rep(NA, length(x_label) / 2))), linetype = 2, size = 1)) + geom_path(aes(x = df$dates, y = df$distribution), color = "red", size = 1) + geom_path(aes(x = df_2$dates, y = df_2$distribution), color = "purple", size = 1) + .shade_curve(df = data.frame(x = df$dates, y = df$distribution), @@ -196,13 +196,13 @@ The following code generates a plot with the gamma distribution of the illness p ymax = Inf), aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax), fill = "brown", alpha = 0.3) + - geom_label(aes(x = symp_date_posixct_mid, y = 0.9*max(df$distribution), label = "Symptom\nbeginn"), + geom_label(aes(x = symp_date_posixct_mid, y = 0.9 * max(df$distribution), label = "Symptom\nbeginn"), colour = "brown", fill = "white", size = 5, label.size = NA) + ylab("Wahrscheinlichkeit") + xlab("Zeitverlauf") + labs(color = 'Verteilung') + - # ggtitle("Visualization of get_infection_date_density ") + - theme(legend.position = "none", text = element_text(size = 16*5/5)) + + # ggtitle("Visualization of get_infection_date_density") + + theme(legend.position = "none", text = element_text(size = 16 * 5 / 5)) + theme(axis.text.x = element_text(colour = "black", face = "bold", angle = 30, hjust = 1)) + theme(axis.title.x = element_text(colour = "black", face = "bold")) + theme(axis.text.y = element_text(colour = "gray50")) + diff --git a/vignettes/contagious_period.Rmd b/vignettes/contagious_period.Rmd index 7a49a4f..66ce465 100644 --- a/vignettes/contagious_period.Rmd +++ b/vignettes/contagious_period.Rmd @@ -45,7 +45,7 @@ knitr::knit_hooks$set( ``` -```{r setup, echo=FALSE, message=FALSE} +```{r setup, echo = FALSE, message = FALSE} library(smidm) library(ggplot2) library(dplyr) @@ -66,7 +66,7 @@ The function `get_infectiousness_density()` creates a dataframe containing the i The following input arguments are needed for the function `get_infectiousness_density()`: -The `symptom_begin_date` is the date, when the person started to have symptoms. +The `symptom_begin_date` is the date when the person started to have symptoms. Then, the `max_infectious_days` is needed, which defines the interval length of the distribution output. @@ -89,14 +89,14 @@ infectious_df_v1 <- get_infectiousness_density(symptom_begin_date, ### Methodology -The default values of the gamma distribution are taken from the paper He et al [1]. In this paper, an analysis of COVID-19 viral shedding and transmissibility was conducted and a gamma distribution for the infectious period of cases was estimated based on their symptom onset dates. +The default values of the gamma distribution are taken from the paper He et al [1]. In this paper an analysis of COVID-19 viral shedding and transmissibility was conducted and a gamma distribution for the infectious period of cases was estimated based on their symptom onset dates. ### Output The function call returns the following data frame: -```{r get_infectiousness_density_result, echo=FALSE, message=FALSE} -knitr::kable(infectious_df_v1[100:109,], +```{r get_infectiousness_density_result, echo = FALSE, message = FALSE} +knitr::kable(infectious_df_v1[100:109, ], caption = "values 100 to 109 of resulting data frame") ``` @@ -107,11 +107,11 @@ The function `get_infectiousness_density()` creates an interval of length `max_i The following code generates a plot with the gamma distribution of the infectiousness profile and the 80% and 95% high density intervals. -```{r .calculate_qstart_qend, foldcode=TRUE} +```{r .calculate_qstart_qend, foldcode = TRUE} .calculate_qstart_qend <- function(probability, df) { - hdr_df <- hdr(den=data.frame(x=1:length(df$distribution), y=df$distribution), p=probability*100)$hdr - qstart <- (hdr_df[1,1] - 1)/24 - qend <- (hdr_df[1,2] - 1)/24 + hdr_df <- hdr(den = data.frame(x = 1:length(df$distribution), y = df$distribution), p = probability * 100)$hdr + qstart <- (hdr_df[1, 1] - 1) / 24 + qend <- (hdr_df[1, 2] - 1) / 24 return(list("qstart" = qstart, "qend" = qend)) } @@ -120,7 +120,7 @@ period_95 <- .calculate_qstart_qend(0.95, infectious_df_v1) ``` -```{r .shade_curve, foldcode=TRUE} +```{r .shade_curve, foldcode = TRUE} .shade_curve <- function(df, qstart, qend, fill = "red", alpha = 0.4) { subset_df <- df[floor(qstart * 24):ceiling(qend * 24), ] geom_area(data = subset_df, @@ -132,7 +132,7 @@ period_95 <- .calculate_qstart_qend(0.95, infectious_df_v1) ``` -```{r parameters for visualization of get_infection_density, foldcode=TRUE} +```{r parameters for visualization of get_infection_density, foldcode = TRUE} symptom_begin_date = as.Date("2021-12-28") df <- infectious_df_v1 @@ -140,18 +140,17 @@ period_95 <- .calculate_qstart_qend(0.95, infectious_df_v1) symp_date_posixct_start <- as.POSIXct(format(as.POSIXct(symptom_begin_date, tz = "CET"), "%Y-%m-%d")) symp_date_posixct_end <- as.POSIXct(format(as.POSIXct(symptom_begin_date + 1, tz = "CET"), "%Y-%m-%d")) symp_date_posixct_mid <- symp_date_posixct_start - as.numeric(difftime(symp_date_posixct_start, - symp_date_posixct_end, units = "hours"))/2*3600 + symp_date_posixct_end, units = "hours")) / 2 * 3600 ``` -```{r visualization of get_infection_density, foldcode=TRUE} +```{r visualization of get_infection_density, foldcode = TRUE} g <- ggplot() + - scale_x_datetime(breaks = scales::date_breaks("1 days"), labels = scales::date_format("%d-%m-%Y")) + theme(axis.text.x = element_text(angle = 90)) + # scale_x_continuous(breaks = x_tick, # labels = x_label) + - # theme(axis.ticks.x = element_line(color = c(rbind(rep("black", length(x_label)/2), rep(NA, length(x_label)/2))), linetype = 2, size = 1))+ + # theme(axis.ticks.x = element_line(color = c(rbind(rep("black", length(x_label) / 2), rep(NA, length(x_label) / 2))), linetype = 2, size = 1))+ geom_path(aes(x = df$dates, y = df$distribution, color = "red")) + .shade_curve(df = data.frame(x = df$dates, y = df$distribution), period_80$qstart, @@ -166,13 +165,13 @@ period_95 <- .calculate_qstart_qend(0.95, infectious_df_v1) ymax = Inf), aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax), fill = "brown", alpha = 0.3) + - geom_label(aes(x = symp_date_posixct_mid, y = 0.9*max(df$distribution), label = "Symptom\nbeginn"), + geom_label(aes(x = symp_date_posixct_mid, y = 0.9 * max(df$distribution), label = "Symptom\nbeginn"), colour = "brown", fill = "white", size = 5, label.size = NA) + ylab("Wahrscheinlichkeit") + xlab("Zeitverlauf") + labs(color = 'Verteilung') + # ggtitle("Visualization of get_infection_density") + - theme(legend.position = "none", text = element_text(size = 16*5/5)) + + theme(legend.position = "none", text = element_text(size = 16 * 5 / 5)) + theme(axis.text.x = element_text(colour = "black", face = "bold", angle = 30, hjust = 1)) + theme(axis.title.x = element_text(colour = "black", face = "bold")) + theme(axis.text.y = element_text(colour = "gray50")) + diff --git a/vignettes/future_infections.Rmd b/vignettes/future_infections.Rmd index 95210be..2837240 100644 --- a/vignettes/future_infections.Rmd +++ b/vignettes/future_infections.Rmd @@ -45,7 +45,7 @@ knitr::knit_hooks$set( ``` -```{r setup, echo=FALSE, message=FALSE} +```{r setup, echo = FALSE, message = FALSE} library(smidm) library(ggplot2) @@ -109,7 +109,7 @@ Finally, `meanlog` and `sdlog` are the mean and standard deviation parameters of The function `predict_future_infections()` uses the function `get_incubation_day_distribution()` to get a vector of day-specific probabilities of symptom onset, given that a person will develop symptoms. Default values of the log-normal distribution for the incubation time used in that function are taken from the paper Xin et al. [2]. -Starting on the first day after the `last_day_reported_infection`, the probability of symptom onset on a particular day given that no symptoms occurred so far is multiplied by the number of further expected infections and rounded upwards to receive the expected number of people starting to show symptoms on that day. +Starting on the first day after the `last_day_reported_infection`, the probability of symptom onset on a particular day, given that no symptoms occurred so far, is multiplied by the number of further expected infections and rounded upwards to receive the expected number of people starting to show symptoms on that day. The probability that no symptoms occurred so far can be calculated by 1 minus the sum of symptom onset probabilities for all previous days. The number of further expected infections is simply `total_expected_infections` minus `total_reported_infections`. The latter is afterwards raised by the predicted number of people with symptom onset on the day currently looked at, so that afterwards the next day can be treated. @@ -134,10 +134,10 @@ The function `predict_future_infections()` creates a vector with values represen ## An example for visualizing the output of \newline `predict_future_infections` -```{r libraries, foldcode=TRUE, message=FALSE} +```{r libraries, foldcode = TRUE, message = FALSE} data <- data.frame("Erkrankungsdatum" = as.Date("2022-03-15") + 0:3, - "Neue_Faelle" = c(0,0,1,3)) -expected <- data.frame("Erkrankungsdatum" = as.Date("2022-03-15") + 0:(length(predicted_daily_infections)-1), + "Neue_Faelle" = c(0, 0, 1, 3)) +expected <- data.frame("Erkrankungsdatum" = as.Date("2022-03-15") + 0:(length(predicted_daily_infections) - 1), "ErwarteteWeitereFaelle" = predicted_daily_infections) g <- ggplot(expected) + geom_bar( @@ -164,7 +164,7 @@ g <- ggplot(expected) + ylab("Erkrankte") + xlab("Zeitverlauf") + labs(fill = 'Art der Fälle') + - theme(legend.position = c(0.75,0.85), text = element_text(size = 16), + theme(legend.position = c(0.75, 0.85), text = element_text(size = 16), axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) return(g) diff --git a/vignettes/infection_period.Rmd b/vignettes/infection_period.Rmd index 2c4938e..b19891f 100644 --- a/vignettes/infection_period.Rmd +++ b/vignettes/infection_period.Rmd @@ -45,7 +45,7 @@ knitr::knit_hooks$set( ``` -```{r setup, echo=FALSE, message=FALSE} +```{r setup, echo = FALSE, message = FALSE} library(smidm) library(ggplot2) library(dplyr) @@ -59,7 +59,7 @@ One or several persons start to show symptoms of COVID-19. When did the person b ## Generating a data frame with dates and infection probability using \newline `get_infection_density` for one person -The function `get_infection_density()` can be used to calculate a data frame containing the infection probability, when the person shows symptoms. +The function `get_infection_density()` can be used to calculate a data frame containing the infection probability when the person shows symptoms. ### Inputs @@ -86,14 +86,14 @@ infec_date_df_v1 <- get_infection_density(symptom_begin_date, ### Methodology -The default values of log-normal distribution are taken from the paper Xin et al [1]. In this paper, the authors made a systematic review of the current literature and estimated those parameters based on their meta-analysis. +The default values of log-normal distribution are taken from the paper Xin et al [1]. In this paper the authors made a systematic review of the current literature and estimated those parameters based on their meta-analysis. ### Output The data frame shows for each hour from the earliest potential start of infection up to the symptom begin date the resulting density of the log-normal distribution. This density can be used for calculating the most probable period of the infection. -```{r get_infection_density_result, echo=FALSE, message=FALSE} -knitr::kable(infec_date_df_v1[100:109,], +```{r get_infection_density_result, echo = FALSE, message = FALSE} +knitr::kable(infec_date_df_v1[100:109, ], caption = "values 100 to 109 of resulting data frame") ``` @@ -106,20 +106,20 @@ The function `get_misc_infection_density()` creates a data frame containing the The following arguments are needed for using the function `get_misc_infection_density()`: -The first parameter `symptom_begin_dates` contains the dates, when the persons got symptoms. +The first parameter `symptom_begin_dates` contains the dates when the persons got symptoms. The second parameter `persons` contains the number of persons having symptoms on each date. The remaining inputs are the same as in `get_infection_density`. ```{r get_misc_infection_date_density} -symptom_begin_dates = c(as.Date("2021-12-24"),as.Date("2021-12-28")) -persons <- c(1,2) +symptom_begin_dates = c(as.Date("2021-12-24"), as.Date("2021-12-28")) +persons <- c(1, 2) max_incubation_days = 18 infec_date_df_v2 <- get_misc_infection_density(symptom_begin_dates, - persons, - max_incubation_days) + persons, + max_incubation_days) ``` @@ -131,26 +131,26 @@ This function uses the `get_infection_density` function and generates a mixture The data shows the mixture log-normal distribution and thus gives an overview over the potential infection time points for all considered persons. -```{r get_mic_infection_density_result, echo=FALSE, message=FALSE} -knitr::kable(infec_date_df_v2[100:109,], +```{r get_mic_infection_density_result, echo = FALSE, message = FALSE} +knitr::kable(infec_date_df_v2[100:109, ], caption = "values 100 to 109 of resulting data frame") ``` ## Visualization example of the data frame of \newline `get_infection_density` -```{r .calculate_qstart_qend, foldcode=TRUE} +```{r .calculate_qstart_qend, foldcode = TRUE} .calculate_qstart_qend <- function(probability, df) { - hdr_df <- hdr(den=data.frame(x=1:length(df$distribution), y=df$distribution), - p=probability*100)$hdr - qstart <- (hdr_df[1:(length(hdr_df)/2)*2] - 1)/24 - qend <- (hdr_df[1:(length(hdr_df)/2)*2-1] - 1)/24 + hdr_df <- hdr(den = data.frame(x = 1:length(df$distribution), y = df$distribution), + p = probability * 100)$hdr + qstart <- (hdr_df[1:(length(hdr_df) / 2) * 2] - 1) / 24 + qend <- (hdr_df[1:(length(hdr_df) / 2) * 2 - 1] - 1) / 24 return(list("qstart" = qstart, "qend" = qend)) } ``` -```{r .shade_curve, foldcode=TRUE} +```{r .shade_curve, foldcode = TRUE} .shade_curve <- function(df, qstart, qend, fill = "red", alpha = 0.4) { subset_df <- df[floor(qstart * 24):ceiling(qend * 24), ] geom_area(data = subset_df, @@ -162,7 +162,7 @@ knitr::kable(infec_date_df_v2[100:109,], ``` -```{r parameters for visualization of get_infection_density, foldcode=TRUE} +```{r parameters for visualization of get_infection_density, foldcode = TRUE} symptom_begin_date = as.Date("2021-12-28") df <- infec_date_df_v1 @@ -172,17 +172,17 @@ knitr::kable(infec_date_df_v2[100:109,], symp_date_posixct_start <- as.POSIXct(format(as.POSIXct(symptom_begin_date, tz = "CET"), "%Y-%m-%d")) symp_date_posixct_end <- as.POSIXct(format(as.POSIXct(symptom_begin_date + 1, tz = "CET"), "%Y-%m-%d")) symp_date_posixct_mid <- symp_date_posixct_start - as.numeric(difftime(symp_date_posixct_start, - symp_date_posixct_end, units = "hours"))/2*3600 + symp_date_posixct_end, units = "hours")) / 2 * 3600 ``` -```{r visualization of get_infection_density, foldcode=TRUE} +```{r visualization of get_infection_density, foldcode = TRUE} g <- ggplot() + scale_x_datetime(breaks = scales::date_breaks("1 days"), labels = scales::date_format("%d-%m-%Y")) + theme(axis.text.x = element_text(angle = 90)) + # scale_x_continuous(breaks = x_tick, # labels = x_label) + - # theme(axis.ticks.x = element_line(color = c(rbind(rep("black", length(x_label)/2), rep(NA, length(x_label)/2))), linetype = 2, size = 1))+ + # theme(axis.ticks.x = element_line(color = c(rbind(rep("black", length(x_label) / 2), rep(NA, length(x_label) / 2))), linetype = 2, size = 1))+ geom_path(aes(x = df$dates, y = df$distribution, color = "red")) + .shade_curve(df = data.frame(x = df$dates, y = df$distribution), period_80$qstart, @@ -192,18 +192,18 @@ knitr::kable(infec_date_df_v2[100:109,], period_95$qend, alpha = 0.2) + geom_rect(data = data.frame(xmin = symp_date_posixct_start, - xmax = symp_date_posixct_end, - ymin = -Inf, - ymax = Inf), - aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax), - fill = "brown", alpha = 0.3) + - geom_label(aes(x = symp_date_posixct_mid, y = 0.9*max(df$distribution), label = "Symptom\nbeginn"), + xmax = symp_date_posixct_end, + ymin = -Inf, + ymax = Inf), + aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax), + fill = "brown", alpha = 0.3) + + geom_label(aes(x = symp_date_posixct_mid, y = 0.9 * max(df$distribution), label = "Symptom\nbeginn"), colour = "brown", fill = "white", size = 5, label.size = NA) + ylab("Wahrscheinlichkeit") + xlab("Zeitverlauf") + labs(color = 'Verteilung') + - # ggtitle("Visualization of get_infection_density ") + - theme(legend.position = "none", text = element_text(size = 16*5/5)) + + # ggtitle("Visualization of get_infection_density") + + theme(legend.position = "none", text = element_text(size = 16 * 5 / 5)) + theme(axis.text.x = element_text(colour = "black", face = "bold", angle = 30, hjust = 1)) + theme(axis.title.x = element_text(colour = "black", face = "bold")) + theme(axis.text.y = element_text(colour = "gray50")) + @@ -215,7 +215,7 @@ knitr::kable(infec_date_df_v2[100:109,], ## Visualization example of the data frame of \newline `get_misc_infection_density` -```{r parameters for visualization of get_misc_infection_density, foldcode=TRUE} +```{r parameters for visualization of get_misc_infection_density, foldcode = TRUE} df <- infec_date_df_v2 period_80 <- .calculate_qstart_qend(0.8, df) @@ -224,18 +224,18 @@ knitr::kable(infec_date_df_v2[100:109,], symp_date_posixct_start <- as.POSIXct(format(as.POSIXct(symptom_begin_date, tz = "CET"), "%Y-%m-%d")) symp_date_posixct_end <- as.POSIXct(format(as.POSIXct(symptom_begin_date + 1, tz = "CET"), "%Y-%m-%d")) symp_date_posixct_mid <- symp_date_posixct_start - as.numeric(difftime(symp_date_posixct_start, - symp_date_posixct_end, units = "hours"))/2*3600 + symp_date_posixct_end, units = "hours")) / 2 * 3600 ``` -```{r visualization of get_misc_infection_density, foldcode=TRUE} +```{r visualization of get_misc_infection_density, foldcode = TRUE} g <- ggplot() + scale_x_datetime(breaks = scales::date_breaks("1 days"), labels = scales::date_format("%d-%m-%Y")) + theme(axis.text.x = element_text(angle = 90)) + # scale_x_continuous(breaks = x_tick, # labels = x_label) + - # theme(axis.ticks.x = element_line(color = c(rbind(rep("black", length(x_label)/2), rep(NA, length(x_label)/2))), linetype = 2, size = 1))+ + # theme(axis.ticks.x = element_line(color = c(rbind(rep("black", length(x_label) / 2), rep(NA, length(x_label) / 2))), linetype = 2, size = 1))+ geom_path(aes(x = df$dates, y = df$distribution, color = "red")) + .shade_curve(df = data.frame(x = df$dates, y = df$distribution), period_80$qstart, @@ -247,8 +247,8 @@ knitr::kable(infec_date_df_v2[100:109,], ylab("Wahrscheinlichkeit") + xlab("Zeitverlauf") + labs(color = 'Verteilung') + - # ggtitle("Visualization of get_infection_density ") + - theme(legend.position = "none", text = element_text(size = 16*5/5)) + + # ggtitle("Visualization of get_infection_density") + + theme(legend.position = "none", text = element_text(size = 16 * 5 / 5)) + theme(axis.text.x = element_text(colour = "black", face = "bold", angle = 30, hjust = 1)) + theme(axis.title.x = element_text(colour = "black", face = "bold")) + theme(axis.text.y = element_text(colour = "gray50")) + diff --git a/vignettes/risk_assessment_group_quarantine.Rmd b/vignettes/risk_assessment_group_quarantine.Rmd index 5baf6c8..65795df 100644 --- a/vignettes/risk_assessment_group_quarantine.Rmd +++ b/vignettes/risk_assessment_group_quarantine.Rmd @@ -45,7 +45,7 @@ knitr::knit_hooks$set( ``` -```{r setup, echo=FALSE, message=FALSE} +```{r setup, echo = FALSE, message = FALSE} library(smidm) library(ggplot2) library(dplyr) @@ -67,11 +67,11 @@ How likely is it that the two cases did not transmit COVID-19 and that no furthe The function `calculate_posterior_no_infections()` calculates the probability that nobody is infected given the negative tests. To that end, the following input values are required: -The input `negativ_person` denotes the number of people without the infectious persons and `infected_person` denotes the number of primary COVID-19 cases in the school class. Furthermore, the event type `event` describes the setting of the meeting. In the package, the event types `school` (school class) and `kita` (daycare center) were modeled. +The input `negativ_person` denotes the number of people without the infectious persons and `infected_person` denotes the number of primary COVID-19 cases in the school class. Furthermore, the event type `event` describes the setting of the meeting. In the package the event types `school` (school class) and `kita` (daycare center) were modeled. -In addition, the information about the conducted tests `test_infos`, the conducted test types `test_types` and the number of persons which were tested at each days `day_size` are needed. Each row of `test_infos`, `test_types` and each entry of `day_size` describes one group of persons which were tested in the same way on the same dates. `test_infos` describes in the first column how many tests and the following columns on which days after the event they were conducted, and `test_types` contains in each column which kind of test was conducted at the corresponding date. +In addition, the information about the conducted tests `test_infos`, the conducted test types `test_types` and the number of persons which were tested at each days `day_size` are needed. Each row of `test_infos`, `test_types` and each entry of `day_size` describes one group of persons, which were tested in the same way on the same dates. `test_infos` describes in the first column how many tests and the following columns on which days after the event they were conducted, and `test_types` contains in each column which kind of test was conducted at the corresponding date. -Beside this, `distribution` as well as `info` are optional inputs, which can be set to use an own, custom prior distribution and own custom tests. `distribution` should be a probability vector, containing the probabilities that one COVID-19 case infects 0, ..., `negativ_person` persons.For `info`, a data frame with one column containing the day-specific sensitivities of the considered test after infection has to be created and the column should have the name of the considered tests. The specificity of the test is not affecting the likelihood, since no positive tests results are assumed. +Beside this, `distribution` as well as `info` are optional inputs, which can be set to use an own, custom prior distribution and own custom tests. `distribution` should be a probability vector, containing the probabilities that one COVID-19 case infects 0, ..., `negativ_person` persons. For `info` a data frame with one column containing the day-specific sensitivities of the considered test after infection has to be created and the column should have the name of the considered tests. The specificity of the test is not affecting the likelihood, since no positive tests results are assumed. ### Methodology @@ -188,13 +188,13 @@ The output vector shows the prior probabilities that 0, ..., 23 persons are infe ## Visualization example of all date inputs on a time scale -```{r foldcode=TRUE} +```{r foldcode = TRUE} date <- as.Date("2021-10-05") -tests_df <- data.frame(c("2021-10-06 PCR-test", "2021-10-07 antigen-test", "2021-10-07 antigen-test", "2021-10-08 antigen-test", "2021-10-10 antigen-test"), c(2,2,3,5,1), c(1,2,2,3,5)) +tests_df <- data.frame(c("2021-10-06 PCR-test", "2021-10-07 antigen-test", "2021-10-07 antigen-test", "2021-10-08 antigen-test", "2021-10-10 antigen-test"), c(2, 2, 3, 5, 1), c(1, 2, 2, 3, 5)) ``` -```{r foldcode=TRUE} +```{r foldcode = TRUE} # Convert test data frame into arrays test_dates <- c() test_colors <- c() @@ -204,8 +204,7 @@ tests_df <- data.frame(c("2021-10-06 PCR-test", "2021-10-07 antigen-test", "2021 test_label_positions_x <- c(date) test_label_positions_y <- c(0.6) test_label_colours <- c("1") - if (nrow(tests_df > 0)) - { + if (nrow(tests_df > 0)) { for (i in 1:nrow(tests_df)) { test_list <- strsplit(tests_df[i, 1], ", ")[[1]] dates_group <- c() @@ -213,26 +212,25 @@ tests_df <- data.frame(c("2021-10-06 PCR-test", "2021-10-07 antigen-test", "2021 test <- strsplit(test_list[j], " ")[[1]] test_dates <- c(test_dates, test[1]) dates_group <- c(dates_group, as.Date(test[1])) - test_colors <- c(test_colors, as.character(i+1) ) - test_positions <- c(test_positions, i*0.9/nrow(tests_df)) - test_text_positions <- c(test_text_positions, i*0.9/nrow(tests_df) + 0.1) + test_colors <- c(test_colors, as.character(i + 1) ) + test_positions <- c(test_positions, i * 0.9 / nrow(tests_df)) + test_text_positions <- c(test_text_positions, i * 0.9 / nrow(tests_df) + 0.1) } test_label <- paste(as.character(tests_df[i, 2]), " Personen") - if(tests_df[i, 2] == 1) - { + if (tests_df[i, 2] == 1) { test_label <- "1 Person" } test_labels <- c(test_labels, test_label) test_label_positions_x <- c(test_label_positions_x, mean.Date(dates_group)) - test_label_positions_y <- c(test_label_positions_y, i*0.9/nrow(tests_df) + 0.1) + test_label_positions_y <- c(test_label_positions_y, i * 0.9 / nrow(tests_df) + 0.1) test_label_colours <- c(test_label_colours, as.character(i+1) ) } } - df_label <- data.frame( Date = test_label_positions_x, - Position = test_label_positions_y, - Label = test_labels, - col = test_label_colours) + df_label <- data.frame(Date = test_label_positions_x, + Position = test_label_positions_y, + Label = test_labels, + col = test_label_colours) df <- data.frame(Date = c(date, test_dates), Position = c(0.5, test_positions), Text_pos = c(0.6, test_text_positions), -- GitLab