merge_add_projections: Add data of different projections objects

View source: R/merge_add_projections.R

merge_add_projectionsR Documentation

Add data of different projections objects

Description

This function adds counts from several projections objects, making sure that they all use the same dates, adding rows of '0' where needed. Simulations (columns) are recycled when needed if some objects have less simulations than others. The same operation is implemented by the + operator.

Usage

merge_add_projections(x)

## S3 method for class 'projections'
a + b

Arguments

x

A list of projections objects to be added.

a

A projections object.

b

A projections object.

Author(s)

Thibaut Jombart

Examples


if (require(incidence)) {

  ## make toy data and projections 
  set.seed(1)
  i <- incidence::incidence(as.Date('2020-01-01') +
                          sample(1:20, 50, replace = TRUE))
  si <- c(0.2, 0.5, 0.2, 0.1)

  x_1 <- project(x = i[1:10],
                 si = si,
                 R = 3.5,
                 n_sim = 200,
                 n_days = 5)

  x_2 <- project(x = i[11:20],
                 si = si,
                 R = 1.8,
                 n_sim = 300,
                 n_days = 10
                 )

  ## check simulations
  x_1 # first type
  x_2 # other simulations
  y <- x_1 + x_2 # add simulations
  plot(y)

}

reconhub/projections documentation built on March 24, 2023, 4:36 a.m.