plot.cArima | R Documentation |
Plotting method for object of class 'cArima'
## S3 method for class 'cArima'
plot(x, type = c("forecast", "impact", "residuals"), horizon = NULL, ...)
x |
Object of class |
type |
Character string indicating the plot to be produced. Possible values in c("forecast", "impact", "residuals"). |
horizon |
Optional vector with elements of class |
... |
Optional arguments passed to other methods. |
The option 'forecast' plots the observed time series as compared to the forecasted series. The option 'impact' plots the causal effect at each point in time after the intervention date, as resulting from the direct comparison between the observed and forecasted time series. Finally, the option 'residuals' draws the autocorrelation and partial autocorrelation functions of the residuals of the model fitted to the data in the pre-intervention period as well as the Normal QQ Plot.
## Example 1 (daily data, no predictors)
# Generating a time series of length 1000 and a vector of dates
y <- 0.5*seq(0.5, 250, by = 0.5) + rnorm(500, sd = 6)
dates <- seq.Date(from = as.Date("2014-01-05"), by = "days", length.out = 500)
# Adding a fictional intervention
int.date <- as.Date("2015-04-01")
horizon <- as.Date(c("2015-04-10", "2015-04-20"))
y.new <- y ; y.new[dates >= int.date] <- y.new[dates >= int.date]*1.25
# Causal effect estimation
ce <- CausalArima(y = y.new, auto = TRUE, ic = "aic", dates = dates, int.date = int.date)
# Plot
plot(ce, type = "forecast")
plot(ce, type = "impact", horizon = horizon)
plot(ce, type = "residuals")
## Example 2 (daily data, with predictors, log-linear model)
# Loading data and setting dates
data(sales)
y <- log(sales[, "Sales"])
dates <- as.Date(sales[, "Dates"])
int.date <- as.Date("2018-10-04")
horizon<- as.Date(c("2018-11-04","2019-01-04"))
xreg <- sales[, 4:12]
# Causal effect estimation
ce <- CausalArima(y = ts(y, frequency = 7), xreg = xreg, int.date = int.date,
dates = dates, nboot = 100)
# Plot
plot(ce, type = "forecast", horizon = horizon)
plot(ce, type = "impact", horizon = horizon)
plot(ce, type = "residuals")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.