A Time Series List (tsl
for short) is a list of zoo time series. This type of object, not defined as a class, is used throughout the distantia
package to contain time series data ready for processing and analysis.
The structure and values of a tsl
must fulfill several general conditions:
Structure:
The list names match the attributes "name" of the zoo time series
All zoo time series must have at least one shared column name.
Data in univariate zoo time series (as extracted by
zoo::coredata(x)
) must be of the class "matrix". Univariate zoo time series are often represented as vectors, but this breaks several subsetting and transformation operations implemented in this package.
Values (optional, when full = TRUE
):
All time series have at least one shared numeric column.
There are no NA, Inf, or NaN values in the time series.
This function analyzes a tsl
, and tries to fix all possible issues to make it comply with the conditions listed above without any user input. Use with care, as it might defile your data.
See also
Other tsl_management:
tsl_colnames_clean()
,
tsl_colnames_get()
,
tsl_colnames_set()
,
tsl_count_NA()
,
tsl_diagnose()
,
tsl_handle_NA()
,
tsl_names_clean()
,
tsl_names_get()
,
tsl_names_set()
,
tsl_names_test()
,
tsl_ncol()
,
tsl_nrow()
,
tsl_split()
,
tsl_subset()
,
tsl_time()
,
tsl_time_class_set()
,
tsl_to_df()
Examples
#creating three zoo time series
#one with NA values
x <- zoo_simulate(
name = "x",
cols = 1,
na_fraction = 0.1
)
#with different number of columns
#wit repeated name
y <- zoo_simulate(
name = "x",
cols = 2
)
#with different time class
z <- zoo_simulate(
name = "z",
cols = 1,
time_range = c(1, 100)
)
#adding a few structural issues
#changing the column name of x
colnames(x) <- c("b")
#converting z to vector
z <- zoo::zoo(
x = runif(nrow(z)),
order.by = zoo::index(z)
)
#storing zoo objects in a list
#with mismatched names
tsl <- list(
a = x,
b = y,
c = z
)
#running full diagnose
tsl <- tsl_diagnose(
tsl = tsl,
full = TRUE
)
#> distantia::tsl_diagnose(): Structural issues:
#> -------------------------------------------
#>
#> - core data of univariate zoo time series must be of class 'matrix': use lapply(tsl, distantia::zoo_vector_to_matrix) to fix this issue.
#>
#> - list and time series names must match and be unique: reset names with distantia::tsl_names_set().
#>
#> - missing column names in zoo time series: use distantia::tsl_colnames_set() to rename columns as needed.
#>
#> - no shared column names across time series: use distantia::tsl_colnames_get() and distantia::ts_colnames_set() to identify and rename columns as needed.
#>
#> - time in all time series must be of the same class: use lapply(tsl, function(x) class(zoo::index(x))) to identify and remove or modify the objects with a mismatching class.
#>
#>
#> Value-related issues:
#> -------------------------
#>
#> - there are NA, Inf, -Inf, or NaN cases in the time series: interpolate or remove them with distantia::tsl_handle_NA().
tsl <- tsl_repair(tsl)
#> Structural repairs:
#> --------------------------
#>
#> - converted univariate zoo vectors to matrix.
#>
#> - fixed naming issues.
#>
#> - REPAIR FAILED: cannot repair missing column names in zoo time series.
#>
#> - REPAIR FAILED: no valid shared column names found across all time series.
#>
#>
#> Value-related repairs:
#> --------------------------
#>
#> - interpolated NA cases in zoo objects with distantia::tsl_handle_NA().
#>
#> Re-diagnosing 'tsl':
#> distantia::tsl_diagnose(): Structural issues:
#> -------------------------------------------
#>
#> - no shared column names across time series: use distantia::tsl_colnames_get() and distantia::ts_colnames_set() to identify and rename columns as needed.
#>
#> - time in all time series must be of the same class: use lapply(tsl, function(x) class(zoo::index(x))) to identify and remove or modify the objects with a mismatching class.