Create signal object
to_signal.Rd
This function creates an object of the S3 class "signal". The user can conditionally specify either a "forecast" or "observed" signal.
Arguments
- input
Data to be converted to signal; see "Details" for more information
- outcome
Name of the outcome column in the input data
- type
Signal type; must be one of "observed" or "forecast"; default is "observed"
- resolution
The temporal resolution of the signal; data can be aggregated daily, weekly, or monthly; default is
"weeks"
; see "Details" for more information- horizon
Number of time steps ahead for forecast signals; only used if
type="forecast"
; default isNULL
Value
An object of the class signal
. The object will have a second class of either observed
or forecast
depending on the value passed to the "type" argument.
Details
The input signal data may be either "observed" or "forecast" data. Depending on the type, the input data must conform to certain format prior to submission. In both cases, the data must be passed as a data frame.
For "observed" data the data frame must at minimum include columns for location (geographic unit such as FIPS code) and date (date of reported value; must be date
class). The data should also include a column that contains the outcome (e.g., case count).
For "forecast" data the data frame must include columns for location (geographic unit such as FIPS code), date (date corresponding to forecast horizon; must be date
class or character formatted as 'YYYY-MM-DD'), horizon (forecast horizon), lower (the lower limit of the prediction interval for the forecast), point (the point estimate for the forecast), and upper (the upper limit of the prediction interval for the forecast). Note that the read_forecast function returns data in this format.
The input data must at the daily, weekly, or monthly resolution. The "resolution" parameter is designed to use string matching. This allows flexibility for the user, such that, for example, an input of "day", "days", or "daily" would all resolve to a resolution of days. The same rules apply for designating weekly or monthly resolution.
Examples
hosp <- read.csv(system.file("extdata/observed/hdgov_hosp_weekly.csv", package = "rplanes"))
to_signal(hosp, outcome = "flu.admits", type = "observed", resolution = "weeks")
fp <- system.file("extdata/forecast/2022-10-31-SigSci-TSENS.csv", package = "rplanes")
ex_forecast <- read_forecast(fp)
to_signal(ex_forecast, outcome = "flu.admits", type = "forecast", horizon = 4, resolution = "weeks")