The MAARTS (Merger and Acquisition Autoregressive Time-Series Models) package provides a comprehensive framework for analyzing M&A time-series data using autoregressive models. This vignette demonstrates the key features and functionality of the package.
# Install from local directory
install.packages("path/to/MAARTS", repos = NULL, type = "source")library(MAARTS)## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
The package includes a sample M&A time-series dataset for demonstration:
data(ma_sample_data)
head(ma_sample_data)## Qtr1 Qtr2 Qtr3 Qtr4
## 2000 12.34568 13.21457 14.12346 13.87654
## 2001 14.54321 15.23457
plot(ma_sample_data, type = "l", main = "Sample M&A Time-Series",
xlab = "Time", ylab = "M&A Activity")Calculate comprehensive descriptive statistics:
desc_stats <- ma_descriptive_stats(ma_sample_data)
print(desc_stats)## Descriptive Statistics for M&A Time-Series
## ===========================================
## Sample Size: 200
## Mean: 49.917
## Sum: 9983.404
## Variance: 459.8718
## Standard Deviation: 21.4446
## Standard Error (Mean): 1.5164
## Minimum: 12.3457
## Maximum: 86.7654
## Range: 74.4198
## Q1 (25%): 31.5432
## Median (50%): 49.8888
## Q3 (75%): 68.3827
## IQR: 36.8395
## MAD: 27.5105
## Skewness: -0.0013
## Kurtosis: 1.8017
## Coeff. of Variation: 42.9605%
##
## Normality Diagnostic Tests
## --------------------------
## Shapiro-Wilk W: 0.9551 (p-value: 0) [Non-normal]
## Jarque-Bera X-sq: 11.9658 (p-value: 0.0025) [Non-normal]
## Anderson-Darling A: 2.1806 (p-value: 0) [Non-normal]
## Cramer-von Mises W-sq:0.2984 (p-value: 3e-04)
## Pearson chi-square: 23.89 (p-value: 0.0472)
## Shapiro-Francia W': 0.9601 (p-value: 1e-04)
## Overall Conclusion: Strong evidence against normality (all p-values < 0.05)
Perform stationarity tests to ensure the time-series is suitable for AR modeling:
stationarity <- ma_stationarity_tests(ma_sample_data)## Warning in tseries::adf.test(ts_y, alternative = "stationary"): p-value smaller
## than printed p-value
## Warning in tseries::pp.test(ts_y, alternative = "stationary"): p-value smaller
## than printed p-value
print(stationarity)## Stationarity Tests for M&A Time-Series
## ======================================
##
## Augmented Dickey-Fuller (ADF) Test
## ----------------------------------
## Statistic: -7.0156
## P-value: 0.01
## Interpretation: Reject null: Series is stationary
##
## Phillips-Perron (PP) Test
## -------------------------
## Statistic: -235.4583
## P-value: 0.01
## Interpretation: Reject null: Series is stationary
##
## KPSS Test
## ---------
## Statistic: 4.0989
## Critical Values: 10%= 0.347 , 5%= 0.463 , 1%= 0.739
## Interpretation: Reject null: Series is non-stationary
##
## DF-GLS Test
## -----------
## Statistic: 0.2847
## Critical Values: 10%= -1.62 , 5%= -1.94 , 1%= -2.58
## Interpretation: Fail to reject null: Series is non-stationary
##
## Overall Summary: Moderate evidence for stationarity (ADF and PP support stationarity, KPSS disagrees)
Examine autocorrelation structure to determine appropriate AR order:
acf_pacf <- ma_acf_pacf(ma_sample_data, plot = TRUE)print(acf_pacf)## ACF and PACF Analysis for M&A Time-Series
## ==========================================
##
## Sample size: 200
## Max lag: 23.0103
## 95% significance bound: +/- 0.1386
##
## Significant ACF lags: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
## Significant PACF lags: 1
## Suggested AR order: 1
Fit an AR model to the data:
ar_model <- ma_ar_fit(ma_sample_data, order = 2)
print(ar_model)## AR Model Fit for M&A Time-Series
## ================================
## Order: 2
## Method: OLS
## Sample Size: 200
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## [1,] 0.5050 0.05793 8.717 1.177e-15
## [2,] 0.4946 0.05829 8.486 5.102e-15
##
## Intercept: 49.917
## Variance of Prediction: 0.1444
##
## Information Criteria:
## AIC: 184.7332
## BIC: 194.598
## HQIC: 188.7261
##
## Model Stability:
## Stable: TRUE
## Persistence: 0.9996
## F-statistic: 302482.2
## F-pvalue: 0
Generate forecasts with multiple confidence intervals:
forecast <- ma_forecast(ar_model, h = 12, confidence = c(0.80, 0.90, 0.95, 0.99))
print(forecast)## Forecast for M&A AR Time-Series
## ================================
## Forecast Horizon: 12
##
## Point Forecasts and Confidence Intervals:
## Period 1: 136.3167 (SE = 0.3800) CI_80% [135.8297, 136.8037] CI_90% [135.6917, 136.9418] CI_95% [135.5719, 137.0615] CI_99% [135.3379, 137.2955]
## Period 2: 161.6674 (SE = 0.4257) CI_80% [161.1219, 162.2130] CI_90% [160.9672, 162.3676] CI_95% [160.8331, 162.5018] CI_99% [160.5709, 162.7639]
## Period 3: 198.9781 (SE = 0.5122) CI_80% [198.3216, 199.6345] CI_90% [198.1356, 199.8206] CI_95% [197.9742, 199.9820] CI_99% [197.6587, 200.2974]
## Period 4: 230.3574 (SE = 0.5651) CI_80% [229.6332, 231.0817] CI_90% [229.4279, 231.2870] CI_95% [229.2498, 231.4650] CI_99% [228.9018, 231.8131]
## Period 5: 264.6576 (SE = 0.6227) CI_80% [263.8596, 265.4556] CI_90% [263.6334, 265.6818] CI_95% [263.4372, 265.8780] CI_99% [263.0537, 266.2615]
## Period 6: 297.4988 (SE = 0.6710) CI_80% [296.6389, 298.3588] CI_90% [296.3951, 298.6026] CI_95% [296.1837, 298.8140] CI_99% [295.7704, 299.2273]
## Period 7: 331.0481 (SE = 0.7181) CI_80% [330.1279, 331.9683] CI_90% [329.8670, 332.2292] CI_95% [329.6407, 332.4555] CI_99% [329.1985, 332.8977]
## Period 8: 364.2332 (SE = 0.7613) CI_80% [363.2577, 365.2088] CI_90% [362.9811, 365.4854] CI_95% [362.7412, 365.7253] CI_99% [362.2724, 366.1941]
## Period 9: 397.5847 (SE = 0.8025) CI_80% [396.5562, 398.6132] CI_90% [396.2647, 398.9048] CI_95% [396.0118, 399.1577] CI_99% [395.5175, 399.6519]
## Period 10: 430.8401 (SE = 0.8416) CI_80% [429.7616, 431.9186] CI_90% [429.4558, 432.2244] CI_95% [429.1907, 432.4896] CI_99% [428.6724, 433.0079]
## Period 11: 464.1292 (SE = 0.8790) CI_80% [463.0028, 465.2557] CI_90% [462.6835, 465.5750] CI_95% [462.4065, 465.8520] CI_99% [461.8652, 466.3933]
## Period 12: 497.3879 (SE = 0.9147) CI_80% [496.2156, 498.5602] CI_90% [495.8833, 498.8925] CI_95% [495.5950, 499.1807] CI_99% [495.0317, 499.7441]
plot(forecast)Check for residual autocorrelation:
diagnostics <- ma_diagnostic_tests(ar_model)
print(diagnostics)## Diagnostic Tests for M&A AR Model Residuals
## ============================================
##
## Number of residuals: 198
## Model order (fitdf): 2
##
## Ljung-Box Test
## --------------
## Lag 6: Q = 578.8614, df = 4, p-value = 0.0000 [Significant autocorrelation detected]
## Lag 12: Q = 1140.4877, df = 10, p-value = 0.0000 [Significant autocorrelation detected]
## Lag 18: Q = 1684.3114, df = 16, p-value = 0.0000 [Significant autocorrelation detected]
## Lag 24: Q = 2210.3785, df = 22, p-value = 0.0000 [Significant autocorrelation detected]
##
## Box-Pierce Test
## ---------------
## Lag 6: Q = 561.5396, df = 4, p-value = 0.0000 [Significant autocorrelation detected]
## Lag 12: Q = 1089.5213, df = 10, p-value = 0.0000 [Significant autocorrelation detected]
## Lag 18: Q = 1584.4539, df = 16, p-value = 0.0000 [Significant autocorrelation detected]
## Lag 24: Q = 2047.4461, df = 22, p-value = 0.0000 [Significant autocorrelation detected]
Comprehensive residual analysis including normality and heteroscedasticity tests:
resid_diag <- ma_residual_diagnostics(ar_model, plot = FALSE)## Warning in nortest::cvm.test(data): p-value is smaller than 7.37e-10, cannot be
## computed more accurately
print(resid_diag)## Residual Diagnostics for M&A AR Model
## ======================================
##
## Residual Summary Statistics:
## Mean: 0
## Std Dev: 0.381
## Min: -0.475
## Max: 0.7677
## Skewness: 0.0567
## Kurtosis: 1.5363
##
## Normality Tests on Residuals:
## Shapiro-Wilk: p = 0 [ Non-normal ]
## Jarque-Bera: p = 1e-04 [ Non-normal ]
## Anderson-Darling: p = 0 [ Non-normal ]
## Conclusion: Strong evidence against normality (all p-values < 0.05)
##
## Heteroscedasticity Tests:
## Breusch-Pagan: stat = NA , p = NA [ Heteroscedasticity detected ]
## ARCH LM: stat = 192.9985 , p = 0 [ ARCH effects detected ]
Analyze model stability and persistence:
stability <- ma_stability_analysis(ar_model)
print(stability)## Stability Analysis for M&A AR Model
## ====================================
##
## AR Order: 2
##
## Characteristic Roots:
## Root 1: 1.0003 + -0.0000i (modulus = 1.0003)
## Root 2: -2.0211 + 0.0000i (modulus = 2.0211)
##
## All roots outside unit circle: TRUE
## Model is: STABLE (stationary)
##
## Persistence (sum of AR coefficients): 0.9996
## Mean Reversion Speed: 4e-04
## Half-life of shocks: 2499.1 periods
## Long-run Mean: 120418.1
Analyze shock transmission and dynamic effects:
irf <- ma_impulse_response(ar_model, n_periods = 20, plot = FALSE)
print(irf)## Impulse Response Function for M&A AR Model
## ============================================
##
## Periods computed: 20
## Long-run multiplier: 2412.365
## Innovation std dev: 0.38
##
## IRF values (first 10 periods):
## Period IRF Cumulative
## 0 1.000000 1.000000
## 1 0.504950 1.504950
## 2 0.749610 2.254560
## 3 0.628282 2.882842
## 4 0.688035 3.570876
## 5 0.658194 4.229070
## 6 0.672681 4.901751
## 7 0.665236 5.566987
## 8 0.668643 6.235630
## 9 0.666681 6.902311
Compare multiple AR models using information criteria:
ar1 <- ma_ar_fit(ma_sample_data, order = 1)
ar2 <- ma_ar_fit(ma_sample_data, order = 2)
ar3 <- ma_ar_fit(ma_sample_data, order = 3)
comparison <- ma_model_comparison(ar1, ar2, ar3)
print(comparison)## Model Comparison for M&A AR Models
## ===================================
##
## Model Order AIC BIC HQIC LogLik Sigma2
## Model_1 1 240.0 246.5 242.6 -117.98 0.191639
## Model_2 2 184.7 194.6 188.7 -89.37 0.144398
## Model_3 3 -780.7 -767.5 -775.4 394.33 0.001069
##
## Best Model by AIC: Model_3
## Best Model by BIC: Model_3
## Best Model by HQIC: Model_3
Detect structural breaks in the time-series:
breaks <- ma_structural_break(ma_sample_data)
print(breaks)## Structural Break Analysis for M&A Time-Series
## ===============================================
##
## Bai-Perron Multiple Breakpoint Analysis
## Estimated breakpoints: 34, 68, 101, 134, 167
##
## CUSUM Test
## Statistic: 0.2522
## P-value: 1
## Result: No structural instability
Identify cyclical components in the frequency domain:
spectral <- ma_spectral_analysis(ma_sample_data, plot = FALSE)
print(spectral)## Spectral Analysis for M&A Time-Series
## =====================================
##
## Sample Size: 200
## Dominant Frequency: 0.335
## Dominant Period: 2.99 observations
Evaluate estimator performance using simulation:
set.seed(123)
sim_results <- ma_monte_carlo_simulation(
true_coefficients = c(0.6, -0.2),
intercept = 10,
n = 100,
n_sim = 500,
sigma = 2
)
print(sim_results)## Monte Carlo Simulation Results for M&A AR Model
## =================================================
##
## Simulations: 500 / 500 (successful)
## Sample size: 100
## Confidence level: 95 %
##
## Parameter Estimation Performance:
## Parameter True Mean_Est Bias MSE RMSE Coverage
## AR1 0.6 0.5851 -0.014939 0.008932 0.0945 0.868
## AR2 -0.2 -0.2012 -0.001157 0.005661 0.0752 0.954
Calculate forecast accuracy measures:
# Create actual vs predicted for demonstration
actual <- ma_sample_data[1:150]
predicted <- ma_sample_data[2:151]
accuracy <- ma_accuracy(actual, predicted)
print(accuracy)## Forecast Accuracy Measures
## ==========================
## MSE: 0.332109
## RMSE: 0.5763
## MAE: 0.5377
## MAPE: 1.6428%
## SMAPE: 1.6248%
## MASE: 0.9964
## Theil's U: 1.0679
## R-squared: 0.9987
## Observations: 150
A complete analysis workflow:
# 1. Load and examine data
data(ma_sample_data)
plot(ma_sample_data, type = "l", main = "M&A Time-Series")# 2. Descriptive statistics
desc_stats <- ma_descriptive_stats(ma_sample_data)
# 3. Check stationarity
stationarity <- ma_stationarity_tests(ma_sample_data)## Warning in tseries::adf.test(ts_y, alternative = "stationary"): p-value smaller
## than printed p-value
## Warning in tseries::pp.test(ts_y, alternative = "stationary"): p-value smaller
## than printed p-value
# 4. Examine ACF/PACF
acf_pacf <- ma_acf_pacf(ma_sample_data, plot = FALSE)
# 5. Fit models of different orders
models <- list()
for (p in 1:4) {
models[[p]] <- ma_ar_fit(ma_sample_data, order = p)
}
# 6. Compare models
comparison <- do.call(ma_model_comparison, models)
print(comparison)## Model Comparison for M&A AR Models
## ===================================
##
## Model Order AIC BIC HQIC LogLik Sigma2
## Model_1 1 240.0 246.5 242.6 -117.98 1.916e-01
## Model_2 2 184.7 194.6 188.7 -89.37 1.444e-01
## Model_3 3 -780.7 -767.5 -775.4 394.33 1.069e-03
## Model_4 4 -1374.4 -1358.0 -1367.8 692.20 5.012e-05
##
## Best Model by AIC: Model_4
## Best Model by BIC: Model_4
## Best Model by HQIC: Model_4
# 7. Select best model
best_model <- models[[comparison$Order[1]]]
# 8. Forecast
forecast <- ma_forecast(best_model, h = 12)
# 9. Diagnostics
diagnostics <- ma_diagnostic_tests(best_model)
resid_diag <- ma_residual_diagnostics(best_model, plot = FALSE)## Warning in nortest::cvm.test(data): p-value is smaller than 7.37e-10, cannot be
## computed more accurately
# 10. Stability analysis
stability <- ma_stability_analysis(best_model)
# 11. Impulse response
irf <- ma_impulse_response(best_model, n_periods = 20, plot = FALSE)
# Summary
cat("\n=== Analysis Summary ===\n")##
## === Analysis Summary ===
cat("Best Model: AR", comparison$Order[1], "\n")## Best Model: AR 1
cat("AIC:", round(comparison$AIC[1], 4), "\n")## AIC: 239.9612
cat("BIC:", round(comparison$BIC[1], 4), "\n")## BIC: 246.5478
cat("Stable:", stability$is_stable, "\n")## Stable: TRUE
cat("Persistence:", round(stability$persistence, 4), "\n")## Persistence: 0.9995
The MAARTS package provides a comprehensive toolkit for M&A time-series analysis. All major aspects of AR modeling are covered, from descriptive statistics and stationarity testing to forecasting and advanced diagnostic analysis.