set_timestamps: Add dummy variables for weekdays and day parts

View source: R/set_timestamps.r

set_timestampsR Documentation

Add dummy variables for weekdays and day parts

Description

This function adds dummy columns for weekdays (named Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday) and day parts (morning, afternoon) to the given subset of the specified data set. These are used by var_main to find better models by removing cyclicity from the data set.

Usage

set_timestamps(
  av_state,
  subset_id = 1,
  date_of_first_measurement,
  measurements_per_day = 1,
  log_level = 0,
  first_measurement_index = 1,
  add_days_as_exogenous = TRUE,
  add_dayparts_as_exogenous = TRUE,
  add_weekend_as_exogenous = FALSE
)

Arguments

av_state

an object of class av_state

subset_id

either an integer subset index or the the value for the id_field column that was used in the group_by function. The subset_id argument is required if the data set is grouped into multiple data sets (i.e., if the group_by function was used), in which case the function works on the specified data subset.

date_of_first_measurement

the date of the first measurement. This argument should be given in the format: "yyyy-mm-dd", e.g., "2004-03-28".

measurements_per_day

how many measurements were taken per day. This default is 1. It is assumed that every day has exactly this amount of measurements, and that the first measurement in the dataset was the first measurement on that day.

log_level

sets the minimum level of output that should be shown (a number between 0 and 3). A lower level means more verbosity. Specify a log_level of 3 to hide messages about the exogenous columns being added.

first_measurement_index

is used to specify that the first day of measurements has fewer than measurements_per_day measurements. Here, we assume that the measurements in the data set still form a connected sequence. In other words, the assumption is that the missing measurements of the first day precede the first measurement in the data set. For example, by specifying measurements_per_day = 3, first_measurement_index = 2, the first measurement in the data set will be treated as the second measurement of that day. So the first two measurements in the data set will be tagged with Afternoon and Evening, and the third measurement in the data set will be tagged with Morning of the next day.

add_days_as_exogenous

adds days as exogenous dummy variables to VAR models.

add_dayparts_as_exogenous

adds day parts as exogenous dummy variables to VAR models.

add_weekend_as_exogenous

adds one exogenous variable named Weekend to the VAR models. This variable is 1 for weekend days (Saturday and Sunday) and 0 otherwise. By specifying add_days_as_exogenous = FALSE and add_weekend_as_exogenous = TRUE, the weekend is used instead of day dummies in the evaluation of models.

Value

This function returns the modified av_state object.

Examples

## Not run: 
av_state <- load_file("../data/input/pp4 nieuw compleet met 140min.sav",log_level=3)
av_state <- set_timestamps(av_state,date_of_first_measurement="2010-04-14")

# an example with multiple measurements per day:
av_state <- load_file("../data/input/ID68 basisbestand.sav",log_level=3)
av_state <- set_timestamps(av_state,date_of_first_measurement="2012-07-12",
                           measurements_per_day=3)

# same data set, but one extra day because the first day only has one measurement
av_state <- load_file("../data/input/ID68 basisbestand.sav",log_level=3)
av_state <- set_timestamps(av_state,date_of_first_measurement="2012-07-12",
                           measurements_per_day=3,first_measurement_index=3)

## End(Not run)

roqua/autovar documentation built on Jan. 21, 2023, 7:37 p.m.