print.cArima: Printing method for object of class 'cArima'

View source: R/print_arima.R

print.cArimaR Documentation

Printing method for object of class 'cArima'

Description

Quick shortcut to see the results of a call to CausalArima, i.e., the estimated causal effects at each time point provided in horizon. If horizon = NULL (default), the function prints the estimated effects at the last date of the post-intervention period.

Usage

## S3 method for class 'cArima'
print(x, type = "norm", horizon = NULL)

Arguments

x

Object of class cArima.

type

Character string indicating the summary to be produced. Possible values in c("norm", "boot"). Defaults to "norm".

horizon

Optional vector with elements of class Date. If provided, the function summarizes the point, cumulative and temporal average effects at the given time horizon(s).

Value

An extract from the data.frame returned by cArima$norm$inf or cArima$boot$inf corresponding to the dates provided in horizon (if horizon = NULL, a single row corresponding to the last date of the post-intervention period) with the following columns:

tau

The estimated causal effect at the given time horizon or at the end of analysis period if is.null(horizon).

pvalue.tau

Left-sided (.l), bidirectional (.b) and right-sided (.r) p-values for tau.

sum.tau

The estimated cumulative causal effect up to the given time horizon or at the end of analysis period if is.null(horizon).

pvalue.sum

Left-sided (.l), bidirectional (.b) and right-sided (.r) p-values for sum.tau.

avg.tau

The estimated temporal average causal effect up to the given time horizon or at the end of analysis period if is.null(horizon).

pvalue.avg

Left-sided (.l), bidirectional (.b) and right-sided (.r) p-values for avg.tau.

Additional columns are provided with the estimated standard deviations for the point, cumulative and temporal average effects.

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, nboot = 1000)

# Print
print(ce, type = "norm")
print(ce, type = "boot", horizon = horizon)

## 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[, "Price"]

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

# Print
print(ce, horizon = horizon)
print(ce, type = "boot", horizon = horizon)


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