There is a package in R that already does this test and it is called MVN
The first thing you have to do is to import MVN into python as described in here
Then go to your jupyter notebook and fit the VAR(1) model to your data as so
# Fit VAR(1) Model
results = Model.fit(1)
results.summary()
Store the residuals as resi
resi=results.resid
Then
# Call function from R
import os
os.environ['R_USER'] = '...\Lib\site-packages\rpy2'
import rpy2.robjects as robjects
from rpy2.robjects import pandas2ri
pandas2ri.activate()
from rpy2.robjects.packages import importr
MVN = importr("MVN", lib_loc = "C:/.../R/win-library/3.3")
After importing MVN you can simply do the normality test as so
MVNresult =MVN.hzTest(resi, qqplot = 0)
If you press on
type(MVNresult)
you will find that it is an
rpy2.robjects.methods.RS4
Therefore, in this case you will find this link a very powerful in explaining the details
Then afterwards
tuple(MVNresult.slotnames())
This will show you the observations
('HZ', 'p.value', 'dname', 'dataframe')
Then you may get the values as so
np.array(MVNresult.slots[tuple(MVNresult.slotnames())[i]])[0]
where i
stands for 0, 1, 2, 3
as 'HZ', 'p-value',...
So in case the p-value i.e. i=1
is less than 0.05 then residuals (resi) are not multivariate normal at 5% confidence level.