MyNixOS website logo
Description

Nowcasting with Chain-Ladder Method.

Tools for performing nowcasting using the Chain-Ladder method <https://en.wikipedia.org/wiki/Chain-ladder_method>. It supports both non-cumulative delay-based estimation and model-based completeness fitting (e.g., using logistic or Gompertz curves) to predict final counts from partially reported data.

nowcastr

Lifecycle: experimental License: MIT R version

R package for nowcasting with non-cumulative chain-ladder method.

  • 1 main nowcast function
    • nowcast_cl() returns object with all intermediary results
  • 4 plots
    • plot_nc_input(option = "triangle") / plot(which = "data", option = "triangle")
    • plot_nc_input(option = "millipede") / plot(which = "data", option = "millipede")
    • plot_delays() / plot(which = "delays")
    • plot_nowcast() / plot(which = "results")
  • 3 utility functions
    • calculate_retro_score(): Calculate retro-scores for all groups
    • rm_repeated_values(): Remove duplicated reported values in reporting matrix
    • fill_future_reported_values(): Fill future reported values with last known values

Installation

pak::pak("whocov/nowcastr")

Quick Start

library(nowcastr)

# Run nowcast with built-in demo data
result <- nowcast_demo %>% 
  nowcast_cl(
    col_date_occurrence = date_occurrence,
    col_date_reporting = date_report,
    col_value = value,
    group_cols = "group"
  )

# View results
print(result@results)
plot(result, which = "results")

Data Requirements

Dataset with at least 2 date columns and a value column. The dataset can also have multiple group-by columns for batch processing.

Note that the delays (difference between the 2 dates) should have constant intervals, i.e., multiples of 1 day or 7 days.

print(nowcast_demo)

# # A tibble: 1,624 × 4
#     value date_occurrence date_report group        
#     <dbl> <date>         <date>      <chr>
#  1 251563 2024-12-16     2025-05-26  Syndromic ARI
#  2 219818 2024-12-23     2025-05-26  Syndromic ARI
#  3 219815 2024-12-23     2025-06-02  Syndromic ARI
#  4 253451 2024-12-30     2025-05-26  Syndromic ARI
#  5 253454 2024-12-30     2025-06-09  Syndromic ARI
#  6 311660 2025-01-06     2025-05-26  Syndromic ARI
#  7 311666 2025-01-06     2025-06-02  Syndromic ARI
#  8 311654 2025-01-06     2025-06-09  Syndromic ARI
#  9 311657 2025-01-06     2025-06-16  Syndromic ARI
# 10 313798 2025-01-13     2025-05-26  Syndromic ARI
# # ℹ 1,614 more rows

Usage

Data Preparation

## Visualize input data
nowcast_demo %>%
  plot_nc_input(
    option = "triangle",
    col_date_occurrence = date_occurrence,
    col_date_reporting = date_report,
    col_value = value,
    group_cols = "group"
  )

## Fill the missing (optional)
data <-
  nowcast_demo %>%
  fill_future_reported_values(
    col_date_occurrence = date_occurrence,
    col_date_reporting = date_report,
    col_value = value,
    group_cols = "group",
    max_delay = "auto"
  )

## Visualize the change
data %>%
  plot_nc_input(
    option = "triangle",
    col_date_occurrence = date_occurrence,
    col_date_reporting = date_report,
    col_value = value,
    group_cols = "group"
  )

Nowcast

nowcast <- data %>%
  nowcast_cl(
    col_date_occurrence = date_occurrence,
    col_date_reporting = date_report,
    col_value = value,
    group_cols = "group",
    time_units = "weeks",
    do_model_fitting = TRUE,
  )

Plotting Results

print(nowcast@delays)
nowcast %>% plot(which = "delays")
print(nowcast@results)
nowcast %>% plot(which = "results")

Output Object

nowcast_cl() returns an S7 object of class nowcast_results with the following properties:

PropertyTypeDescription
namecharacterTimestamp identifier for the run
paramslistParameters used for nowcasting (unevaluated call)
time_startPOSIXctSys time when function started
time_endPOSIXctSys time when function ended
n_groupsnumericNumber of groups processed
max_delaynumericMaximum delay used
datadata.frameOriginal input data (required columns only)
completenessdata.frameInput data with delays and completeness columns
delaysdata.frameAggregated completeness per delay (+ modelled column if fitted)
modelsdata.frameFitted models (empty if do_model_fitting = FALSE)
resultsdata.frameFinal nowcasting predictions

Access properties with $:

nowcast$delays
nowcast$results
nowcast$params

Available methods:

  • print(nowcast) - Summary of nowcast results
  • plot(nowcast, which = "delays") - Delay distribution
  • plot(nowcast, which = "results") - Nowcast time series

Methods

Summary:

  1. Input Data: Ensure three core columns: `observed_value` / `date_of_reporting` / `date_of_occurrence` (e.g. date_of_event / date_of_onset)
  2. Calculate the `reporting_delay` (= `date_of_reporting` - `date_of_occurrence`)
  3. Compute the `completeness` (= `observed_value` / `true_value` (approximated by `last_reported_value`))
  4. Aggregate the `avg_completeness` for each `reporting_delay`
  5. Optional: Fit a curve through that
  6. Apply Nowcast: `nowcast` = `observed_value` / `avg_completeness`
Metadata

Version

0.2.0

License

Unknown

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows