format.timestamps {bsts} | R Documentation |
Tools for checking if a series of timestamps is 'regular' meaning that
it has no duplicates, and no gaps. Checking for regularity can be
tricky. For example, if you have monthly observations with
Date
or POSIXt
timestamps then gaps
between timestamps can be 28, 29, 30, or 31 days, but the series is
still "regular".
NoDuplicates(timestamps) NoGaps(timestamps) IsRegular(timestamps) HasDuplicateTimestamps(bsts.object)
timestamps |
A set of (possibly irregular or non-unique)
timestamps. This could be a set of integers (like 1, 2, , 3...), a
set of numeric like (1945, 1945.083, 1945.167, ...) indicating years
and fractions of years, a |
bsts.object |
A bsts model object. |
All four functions return scalar logical values. NoDuplicates
returns TRUE
if all elements of timestamps
are unique.
NoGaps
examines the smallest nonzero gap between time points.
As long as no gaps between time points are more than twice as wide as
the smallest gap, it returns TRUE
, indicating that there are no
missing timestamps. Otherwise it returns FALSE
.
IsRegular
returns TRUE
if NoDuplicates
and
NoGaps
both return TRUE
.
HasDuplicateTimestamps
returns FALSE
if the data used to
fit bsts.model either has NULL timestamps, or if the timestamps
contain no duplicate values.
Steven L. Scott steve.the.bayesian@gmail.com
first <- as.POSIXct("2015-04-19 08:00:04") monthly <- seq(from = first, length.out = 24, by = "month") IsRegular(monthly) ## TRUE skip.one <- monthly[-8] IsRegular(skip.one) ## FALSE has.duplicates <- monthly has.duplicates[1] <- has.duplicates[2] IsRegular(has.duplicates) ## FALSE