What is Vector Autoregressions in the StatsModels library?

The recipe explains Vector Autoregressions, a feature inside the StatsModels library

Recipe Objective - What is Vector Autoregressions in the StatsModels library?

The statsmodels.tsa.vector_ar contains methods that are useful for simultaneous modeling and analysis of multiple time series using vector autoregressive (VAR) and vector error correction models (VECM).

Build a Multi Touch Attribution Model in Python with Source Code 

For more related projects -

https://www.dezyre.com/projects/data-science-projects/deep-learning-projects
https://www.dezyre.com/projects/data-science-projects/neural-network-projects

Example:

# Importing libraries
import statsmodels.api as sm
from statsmodels.tsa.api import VAR
import numpy as np
import pandas

# Importing macrodata dataset from statsmodel library in the form of pandas dataframe
data = sm.datasets.macrodata.load_pandas()

# Storing data
X = data.data

# Filtering columns
X = X[['realgdp','realcons','realinv']]

# Taking log
X = np.log(X).diff().dropna()

# Creating a VAR model
model = VAR(X)

# Fitting the model
model_summary = model.fit()

# Summary
model_summary.summary()

Output - 
  Summary of Regression Results   
==================================
Model:                         VAR
Method:                        OLS
Date:           Mon, 22, Nov, 2021
Time:                     18:36:41
--------------------------------------------------------------------
No. of Equations:         3.00000    BIC:                   -27.7388
Nobs:                     201.000    HQIC:                  -27.8562
Log likelihood:           1963.94    FPE:                7.37174e-13
AIC:                     -27.9360    Det(Omega_mle):     6.94859e-13
--------------------------------------------------------------------
Results for equation realgdp
==============================================================================
                 coefficient       std. error           t-stat            prob
------------------------------------------------------------------------------
const               0.003580         0.000911            3.928           0.000
L1.realgdp         -0.338056         0.172084           -1.964           0.049
L1.realcons         0.746283         0.130411            5.723           0.000
L1.realinv          0.057939         0.025349            2.286           0.022
==============================================================================

Results for equation realcons
==============================================================================
                 coefficient       std. error           t-stat            prob
------------------------------------------------------------------------------
const               0.006286         0.000775            8.114           0.000
L1.realgdp         -0.134053         0.146285           -0.916           0.359
L1.realcons         0.327751         0.110859            2.956           0.003
L1.realinv          0.042521         0.021549            1.973           0.048
==============================================================================

Results for equation realinv
==============================================================================
                 coefficient       std. error           t-stat            prob
------------------------------------------------------------------------------
const              -0.015808         0.004756           -3.324           0.001
L1.realgdp         -2.220857         0.898064           -2.473           0.013
L1.realcons         4.585966         0.680582            6.738           0.000
L1.realinv          0.300989         0.132290            2.275           0.023
==============================================================================

Correlation matrix of residuals
             realgdp  realcons   realinv
realgdp     1.000000  0.607456  0.759286
realcons    0.607456  1.000000  0.142791
realinv     0.759286  0.142791  1.000000

In this way, we can perform Vector Autoregressions in the StatsModels library.

What Users are saying..

profile image

Savvy Sahai

Data Science Intern, Capgemini
linkedin profile url

As a student looking to break into the field of data engineering and data science, one can get really confused as to which path to take. Very few ways to do it are Google, YouTube, etc. I was one of... Read More

Relevant Projects

AWS MLOps Project for ARCH and GARCH Time Series Models
Build and deploy ARCH and GARCH time series forecasting models in Python on AWS .

LLM Project to Build and Fine Tune a Large Language Model
In this LLM project for beginners, you will learn to build a knowledge-grounded chatbot using LLM's and learn how to fine tune it.

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

Personalized Medicine: Redefining Cancer Treatment
In this Personalized Medicine Machine Learning Project you will learn to classify genetic mutations on the basis of medical literature into 9 classes.

Build Real Estate Price Prediction Model with NLP and FastAPI
In this Real Estate Price Prediction Project, you will learn to build a real estate price prediction machine learning model and deploy it on Heroku using FastAPI Framework.

Create Your First Chatbot with RASA NLU Model and Python
Learn the basic aspects of chatbot development and open source conversational AI RASA to create a simple AI powered chatbot on your own.

Build a Churn Prediction Model using Ensemble Learning
Learn how to build ensemble machine learning models like Random Forest, Adaboost, and Gradient Boosting for Customer Churn Prediction using Python

Recommender System Machine Learning Project for Beginners-1
Recommender System Machine Learning Project for Beginners - Learn how to design, implement and train a rule-based recommender system in Python

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.