# -*- coding: utf-8 -*- """examples for multivariate normal and t distributions Created on Fri Jun 03 16:00:26 2011 @author: josef for comparison I used R mvtnorm version 0.9-96 """ import numpy as np from numpy.testing import assert_array_almost_equal import matplotlib.pyplot as plt import statsmodels.api as sm import statsmodels.distributions.mixture_rvs as mix import statsmodels.sandbox.distributions.mv_normal as mvd cov3 = np.array([[ 1. , 0.5 , 0.75], [ 0.5 , 1.5 , 0.6 ], [ 0.75, 0.6 , 2. ]]) mu = np.array([-1, 0.0, 2.0]) #************** multivariate normal distribution *************** mvn3 = mvd.MVNormal(mu, cov3) #compare with random sample x = mvn3.rvs(size=1000000) xli = [[2., 1., 1.5], [0., 2., 1.5], [1.5, 1., 2.5], [0., 1., 1.5]] xliarr = np.asarray(xli).T[None,:, :] #from R session #pmvnorm(lower=-Inf,upper=(x[0,.]-mu)/sqrt(diag(cov3)),mean=rep(0,3),corr3) r_cdf = [0.3222292, 0.3414643, 0.5450594, 0.3116296] r_cdf_errors = [1.715116e-05, 1.590284e-05, 5.356471e-05, 3.567548e-05] n_cdf = [mvn3.cdf(a) for a in xli] assert_array_almost_equal(r_cdf, n_cdf, decimal=4) print(n_cdf) print('') print((x