plot.cArima: Plotting method for object of class 'cArima'

View source: R/plot_arima.R

plot.cArimaR Documentation

Plotting method for object of class 'cArima'

Description

Plotting method for object of class 'cArima'

Usage

## S3 method for class 'cArima'
plot(x, type = c("forecast", "impact", "residuals"), horizon = NULL, ...)

Arguments

x

Object of class cArima.

type

Character string indicating the plot to be produced. Possible values in c("forecast", "impact", "residuals").

horizon

Optional vector with elements of class Date. If provided, the function plots the pointwise causal effect (for type = "impact") or the forecasted time series (for type = "forecast") up to the required time horizon(s).

...

Optional arguments passed to other methods.

Details

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.

Examples

## 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")


FMenchetti/CausalArima documentation built on May 14, 2024, 10:14 p.m.