dust_data: Process data for dust

View source: R/data.R

dust_dataR Documentation

Process data for dust

Description

Prepare data for use with the $set_data() method. This is not required for use but tries to simplify the most common use case where you have a data.frame with some column indicating "model step" (name_step), and other columns that might be use in your data_compare function. Each row will be turned into a named R list, which your dust_data function can then work with to get this time-steps values. See Details for use with multi-pars objects.

Usage

dust_data(object, name_step = "step", multi = NULL)

Arguments

object

An object, at this point must be a data.frame

name_step

The name of the data column within object; this column must be integer-like and every integer must be nonnegative and unique

multi

Control how to interpret data for multi-parameter dust object; see Details

Details

The data object as accepted by data_set must be a list and each element must itself be a list with two elements; the model step at which the data applies and any R object that corresponds to data at that point. We expect that most of the time this second element will be a key-value list with scalar keys, but more flexibility may be required.

For multi-data objects, the final format is a bit more awkward; each time step we have a list with elements step, data_1, data_2, ..., data_n for n parameters. There are two ways of creating this that might be useful: sharing the data across all parameters and using some column as a grouping value.

The behaviour here is driven by the multi argument;

  • NULL: (the default) do nothing; this creates an object that is suitable for use with a pars_multi = FALSE dust object.

  • <integer> (e.g., multi = 3); share the data across 3 sets of parameters. This number must match the number of parameter sets that your dust object is created with

  • <column_name> (e.g., multi = "country"); the name of a column within your data to split the data at. This column must be a factor, and that factor must have levels that map to integers 1, 2, ..., n (e.g., unique(as.integer(object[[multi]])) returns the integers 1:n).

Value

A list of dust time/data pairs that will be used for the compare function in a compiled model. Each element is a list of length two or more where the first element is the time step and the subsequent elements are data for that time step.

Examples

d <- data.frame(step = seq(0, 50, by = 10), a = runif(6), b = runif(6))
dust::dust_data(d)

mrc-ide/dust documentation built on May 21, 2022, 7:57 a.m.