Skip to content

Instantly share code, notes, and snippets.

View thibautjombart's full-sized avatar

Thibaut Jombart thibautjombart

View GitHub Profile
@thibautjombart
thibautjombart / simulate_occupancy.R
Created April 6, 2020 10:34
Simulator for projecting bed occupancy
#' Simulator for projecting bed occupancy
#'
#' This function predits bed occupancy from admission data (dates, and numbers
#' of admissions on these days). Duration of hospitalisation is provided by a
#' function returning `integer` values for the number of days in hospital.
#'
#' @param dates A vector of dates, ideally as `Date` but `integer` should work too.
#'
#' @param n_admissions An `integer` vector giving the number of admissions
#' predicted for each date in `dates`.
@thibautjombart
thibautjombart / project_beds.R
Created April 6, 2020 10:37
Project bed occupancy from admissions
#' Project bed occupancy from admissions
#'
#' This projects bed occupancy using admission incidence stored as a
#' `projections` object, and a distribution of length of stay (los). This is a
#' wrapper around `simulate_occupancy`, which essentially applies this function
#' to different admission trajectories and collects outputs into a single
#' `projections` object.
#'
#' @param x a `projections` object storing forecast of daily admissions
@thibautjombart
thibautjombart / linelist_class.R
Last active June 18, 2020 08:43
Basic idea for a linelist class
library(outbreaks)
library(tidyverse)
make_linelist <- function(x, date, interval = 1L, date_start = NULL, date_stop = NULL) {
## TODO: add tests on inputs
x <- tibble::as_tibble(x)
#' Calculate force of infection
#'
#' This function calculates the force of infection at time t+1, generated by
#' cases with onset at time 1, 2, ..., t, with reproduction numbers R_1, R_2,
#' ..., R_t. Calculations use matrices where independent simulations are stored
#' as separate columns.
#'
#' @param w a `numeric` containing numbers representing the PMF of the serial
#' interval, starting at day 1, i.e. one day after symptom onset; the vector
## Source: color palettes come from https://personal.sron.nl/~pault/#sec:qualitative
## They exclude 'grey', which will be reserved for missing data.
col_vibrant <- c(
"#0077BB",
"#33BBEE",
"#009988",
"#EE7733",
"#CC3311",
@thibautjombart
thibautjombart / prop_ci.R
Last active July 10, 2020 08:33
Function prop_ci() to calculate Binomial confidence intervals for proportions
#' Binomial confidence intervals for proportions
#'
#' This function uses `binom.test` to derive estimates of the confidence interval
#' for proportions.
#'
#' @param k number of successes
#'
#' @param n number of trials
#'
#' @param conf confidence level (1 - alpha), defaults to 0.95