View source: R/ResidualOutliers.R
ResidualOutliers | R Documentation |
ResidualOutliers is an automated time series outlier detection function that utilizes tsoutliers and auto.arima. It looks for five types of outliers: "AO" Additive outliter - a singular extreme outlier that surrounding values aren't affected by; "IO" Innovational outlier - Initial outlier with subsequent anomalous values; "LS" Level shift - An initial outlier with subsequent observations being shifted by some constant on average; "TC" Transient change - initial outlier with lingering effects that dissapate exponentially over time; "SLS" Seasonal level shift - similar to level shift but on a seasonal scale.
ResidualOutliers(
data,
DateColName = NULL,
TargetColName = NULL,
PredictedColName = NULL,
TimeUnit = "day",
Lags = 5,
Diff = 1,
MA = 5,
SLags = 0,
SDiff = 1,
SMA = 0,
tstat = 2,
FixedParams = FALSE
)
data |
the source residuals data.table |
DateColName |
The name of your data column to use in reference to the target variable |
TargetColName |
The name of your target variable column |
PredictedColName |
The name of your predicted value column. If you supply this, you will run anomaly detection of the difference between the target variable and your predicted value. If you leave PredictedColName NULL then you will run anomaly detection over the target variable. |
TimeUnit |
The time unit of your date column: hour, day, week, month, quarter, year |
Lags |
the largest lag or moving average (seasonal too) values for the arima fit |
Diff |
The largest d value for differencing |
MA |
Max moving average |
SLags |
Max seasonal lags |
SDiff |
The largest d value for seasonal differencing |
SMA |
Max seasonal moving averages |
tstat |
the t-stat value for tsoutliers |
FixedParams |
Set to TRUE or FALSE. If TRUE, a stats::Arima() model if fitted with those parameter values. If FALSE, then an auto.arima is built with the parameter values representing the max those values can be. |
A named list containing FullData = original data.table with outliers data and ARIMA_MODEL = the arima model object
Adrian Antico
Other Unsupervised Learning:
GenTSAnomVars()
## Not run:
data <- data.table::data.table(
DateTime = as.Date(Sys.time()),
Target = as.numeric(
stats::filter(
rnorm(1000, mean = 50, sd = 20),
filter=rep(1,10),
circular=TRUE)))
data[, temp := seq(1:1000)][, DateTime := DateTime - temp][, temp := NULL]
data.table::setorderv(x = data, cols = 'DateTime', 1)
data[, Predicted := as.numeric(
stats::filter(
rnorm(1000, mean = 50, sd = 20),
filter=rep(1,10),
circular=TRUE))]
Output <- ResidualOutliers(
data = data,
DateColName = "DateTime",
TargetColName = "Target",
PredictedColName = NULL,
TimeUnit = "day",
Lags = 5,
Diff = 1,
MA = 5,
SLags = 0,
SDiff = 0,
SMA = 0,
tstat = 4)
data <- Output[['FullData']]
model <- Output[['ARIMA_MODEL']]
outliers <- data[type != "<NA>"]
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.