Welcome to Robust_CI_Acf’s documentation!
This package provides a Python implementation of the HAC robust confidence interval for autocorrelation function by the working paper titled “An Estimating Equation Approach for Robust Confidence Intervals for Autocorrelations of Stationary Time Series” (Hwang and Vogelsang, 2023).
For details about the theory and its empirical applications, please refer to our working paper, available here: [PaperLink]
- class robust.HAC_robust_conf_int(data, lag, null_imp=True, method='fixedb', bandwidth='SPJ', time_trend=False, diff=False, alpha=0.05)[source]
Bases:
object
The base class for the implementation of the heteroskedasticity and autocorrelation consistent (HAC) robust confidence intervals for autocorrelation functions across lags for (covariance) stationary time series in Hwang and Vogelsang (2023). Our method provides valid inference for autocorrelation functions. It is pointed out that Bartlett formula on which the widely used statistical packages (Stata, SAS, R, Matlab and etc..) are relying for inference for autocorrelation function is no longer valid when the assumption of i.i.d innovations is relaxed. In contrast, our method implemented here is robust in three ways: innovations can be weak white noise (relaxation of the i.i.d innovations assumption), innovations can have asymmetric distributions, and inference does not require a specific model of serial correlation.
We provide vaild confidence intervals and confidence bands for inference about autocorrelation function in this Python package. This class and following methods provide a graph of autocorrelogram with the estimated autocorrelation functions and the valid confidence intervals by Hwang and Vogelsang (2023) across multiple lags for your time series data so that empirical practitioners can easily obtain valid confidence intervals (and confidence bands) for empirical anaylsis of time series data.
- Parameters:
data (array-like) – The input time series data.
lag (int) – The maximum lag to be considered for autocorrelation functions.
null_imp (bool, default=True) – If true, the null imposed variance estimator is used for inference. If false, then it uses the null not imposed variance estimator. For null imposed and null not imposed estimators, see Lazarus, Lewis, Stock and Watson (2018).
method ({"fixedb", "OS", "normal"}, default='fixedb') – The asymptotics and the following critical values used for estimation.
bandwidth ({"SPJ", "AD"}, default="SPJ") – Specifies the data dependent bandwidth selection method used in the estimation. “SPJ” is a testing optimal data depdendent bandwidth selection method suggested in Sun, Phillips and Jin (2008). “AD” is a MSE optimal method by Andrews (1991).
time_trend (bool, default=False) – If True, a time trend is considered in the estimating equation. To be able to obtain bandwidth by the data dependent selection methods, we use Frisch–Waugh–Lovell theorem to partial out the time trend and obtain the residuals for the bandwidth calculation, instead of full regression. If false, the usual regression is used for the estimating equation.
diff (bool, default=False) – If True, the time series data is differenced and the differenced time series is used for autocorrelogram and output.
alpha (float, default=0.05) – Significance level for the confidence intervals and the confidence bands.
Note
The provided options may need further refinement.
- __init__(data, lag, null_imp=True, method='fixedb', bandwidth='SPJ', time_trend=False, diff=False, alpha=0.05)[source]
- plot_acf(CI_HAC=True, CB_HAC=False, CB_stata=False, CB_bart=False, title='Autocorrelogram with HAC robust CI', save_as_pdf=False, filename='autocorrelogram.pdf')[source]
Plot the autocorrelation functions (ACF).
- Parameters:
CI_HAC (bool, default=True) – Whether to plot HAC robust confidence intervals.
CB_HAC (bool, default=False) – Whether to plot HAC robust confidence bands.
CB_stata (bool, default=False) – Whether to plot the Stata confidence bands.
CB_bart (bool, default=False) – Whether to plot the Bartlett confidence bands.
title (str, default='Autocorrelogram with HAC robust CI') – Title for the plot.
save_as_pdf (bool, default=False) – If True, save the plot as a PDF, otherwise display it.
filename (str, default='autocorrelogram.pdf') – Filename for saving the plot if save_as_pdf is True.
- Returns:
fig – The Matplotlib figure object containing the ACF plot.
- Return type:
matplotlib.figure.Figure
Notes
This method plots autocorrelogram with confidence intervals and confidence bands
- get_estimated_acf()[source]
Retrieve the estimated autocorrelation function values by the estimating equation approach in Hwang and Vogelsang (2023).
- Returns:
List of estimated ACF values.
- Return type:
list of float
- get_confidence_interval()[source]
Compute the confidence intervals for the ACF values by the estimating equation approach with the options pre-defined in the class.
- Returns:
Lower and upper confidence interval bounds for each ACF value.
- Return type:
tuple of list of float
- get_confidence_band()[source]
Compute the confidence bands around zero for the ACF values by the estimating equation approach with the options pre-defined in the class.
- Returns:
Lower and upper confidence band bounds for each ACF value.
- Return type:
tuple of list of float
- get_null_imp_index()[source]
Retrieve the index values (indicating the solution types of the quadractic equation across lags) if the null is imposed.
- Returns:
List of index values if null is imposed; otherwise, print a message and return None.
- Return type:
list of int or None
- get_cb_stata()[source]
Compute the confidence bands suggested by Stata for the sample ACF values.
- Returns:
Lower and upper confidence band bounds by Stata for each sample ACF value.
- Return type:
tuple of list of float