impact: Function to create a table of the estimated model...

View source: R/table_arima.R

impactR Documentation

Function to create a table of the estimated model coefficients from a call to CausalArima

Description

Function to create a table of the estimated model coefficients from a call to CausalArima

Usage

impact(
  x,
  format = "numeric",
  horizon = NULL,
  style = kable_styling,
  digits = 3,
  ...
)

Arguments

x

Object of class cArima.

format

Required format for the table. Possible values in c("numeric", "html", "latex").

horizon

Optional vector with elements of class Date. If provided, the function returns the estimated effects at the given time horizons.

style

Function to pass to knitr_kable objects to customize the style of the table. Defaults to kable_styling. Alternative themes for html tables include kable_classic, or kable_minimal. For the full list of alternatives, see package kableExtra documentation.

digits

Number of digits in table columns.

...

Optional arguments passed to other methods.

Value

A list with the following components:

impact_norm

Estimated point, cumulative and temporal average effect assuming Normality of the error terms.

impact_boot

Estimated point, cumulative and temporal average effect by bootstrap.

arima

Arima order, coefficient estimates and accuracy measures for the estimated model in the pre-intervention period.

Examples

## Example 1 (weekly data, no predictors)
# Generating a time series with weekly seasonality and a vector of dates
y <- simulate(Arima(ts(rnorm(100),freq=4), order=c(1,0,1), seasonal=c(1,0,1)),
              nsim=800)
dates <- seq.Date(from = as.Date("2005-01-01"), by = "week", length.out = 800)

# Adding a fictional intervention
int.date <- as.Date("2019-05-11")
horizon <- as.Date(c("2019-12-07", "2020-02-15", "2020-04-25"))
y.new <- y ; y.new[dates >= int.date] <- y.new[dates >= int.date]*1.40

# Causal effect estimation
ce <- CausalArima(y = ts(y.new, frequency = 4), dates = dates, int.date = int.date)

# Table of the estimated effects (numeric and latex)
impact(ce)
impact(ce, horizon = horizon)
tab_latex <- impact(ce, format = "latex", horizon = horizon, digits = 3, latex_options = "striped")
tab_latex$impact_norm$average

## Example 2 (daily data, with predictors)
# Loading data and setting dates
data(sales)
y <- sales[, "Sales"]
dates <- as.Date(sales[, "Dates"])
int.date <- as.Date("2018-10-04")
horizon<- as.Date(c("2018-11-04","2019-01-04","2019-04-30"))
xreg <- sales[, 4:12]

# Causal effect estimation
ce <- CausalArima(y = ts(y, frequency = 7), xreg = xreg, int.date = int.date,
                  dates = dates, nboot = 100)

# Table of the estimated effects (html)
tab_html <- impact(ce, format = "html", horizon = horizon)
tab_html$arima$param
tab_html <- impact(ce, format = "html", horizon = horizon, style = kable_classic,
                   html_font = "Cambria")
tab_html$arima$param


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