({{, (RefLink[MatrixNormalDistribution, paclet:ref/MatrixNormalDistribution])[(Subscript[Σ, row]),(Subscript[Σ, col])] 
represents zero mean matrix normal distribution with row covariance matrix (Subscript[Σ, row]) and column covariance matrix (Subscript[Σ, col]).}, {, (RefLink[MatrixNormalDistribution, paclet:ref/MatrixNormalDistribution])[μ,(Subscript[Σ, row]),(Subscript[Σ, col])]
represents matrix normal distribution with mean matrix μ.}})

OpenersNotesSection(Spacer1)Details

(RefLink[MatrixNormalDistribution, paclet:ref/MatrixNormalDistribution]) is a distribution of μ+(Subscript[Σ, row]^(1/2)).x.(Subscript[Σ, col]^(1/2)), where x is a matrix with independent identically distributed matrix elements that follow (RefLink[NormalDistribution, paclet:ref/NormalDistribution])[0,1].

The probability density for a matrix x in a matrix normal distribution is proportional to exp(-(1/2)Tr[(Overscript[(Subscript[Σ, col]), -1]).(((x-μ))^ᵀ).(Overscript[(Subscript[Σ, row]), -1]).(x-μ)]).

(RefLink[MatrixNormalDistribution, paclet:ref/MatrixNormalDistribution])[μ,c (Subscript[Σ, row]),(c^(-1)) (Subscript[Σ, col])] has the same distribution as (RefLink[MatrixNormalDistribution, paclet:ref/MatrixNormalDistribution])[μ,(Subscript[Σ, row]),(Subscript[Σ, col])] for any positive real constant c.

The covariance matrices (Subscript[Σ, row]) and (Subscript[Σ, col]) can be any symmetric positive definite matrices of real numbers of dimensions {n,n} and {m,m}, respectively, and the mean matrix μ can be any matrix of real numbers of dimensions {n,m}.

(RefLink[MatrixNormalDistribution, paclet:ref/MatrixNormalDistribution]) can be used with such functions as (RefLink[MatrixPropertyDistribution, paclet:ref/MatrixPropertyDistribution]), (RefLink[EstimatedDistribution, paclet:ref/EstimatedDistribution]), and (RefLink[RandomVariate, paclet:ref/RandomVariate]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (18)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Sample from matrix normal distribution:

RandomVariate[MatrixNormalDistribution[{{3,1,1},{1,2,-1},{1,-1,4}},{{1,-1/2},{-1/2,2}}]]

Mean and variance:

Mean[MatrixNormalDistribution[{{1,4},{6,8},{10,2}},DiagonalMatrix[{2,1,3}],{{2,1},{1,3}}]]//MatrixForm

Variance[MatrixNormalDistribution[{{1,4},{6,8},{10,2}},DiagonalMatrix[{2,1,3}],{{2,1},{1,3}}]]//MatrixForm

OpenersExampleSection1(Spacer1)Scope  (7)

Generate a single pseudorandom matrix:

RandomVariate[MatrixNormalDistribution[{{1,1/3},{1/3,1}},IdentityMatrix[3]]]

Generate a single pseudorandom matrix with nonzero mean:

RandomVariate[MatrixNormalDistribution[{{1,2,3},{4,5,6}},{{1,1/3},{1/3,1}},IdentityMatrix[3]]]

Generate a set of pseudorandom matrices:

RandomVariate[MatrixNormalDistribution[{{1,1/3},{1/3,1}},IdentityMatrix[3]],3]

Sample at extended precision:

RandomVariate[MatrixNormalDistribution[{{1,1/3},{1/3,1}},IdentityMatrix[3]],WorkingPrecision->20]

Distribution parameters estimation:

dist=MatrixNormalDistribution[{{3,1},{1,2}},ToeplitzMatrix[{4,2,1}]];sample=RandomVariate[dist,10^3];

Estimate the distribution parameters from sample data:

edist=EstimatedDistribution[sample,MatrixNormalDistribution[Array[row,{2,2}],Array[col,{3,3}]]]

Compare (RefLink[LogLikelihood, paclet:ref/LogLikelihood]) for both distributions:

LogLikelihood[#,sample]&/@{edist,dist}

Find the probability that smallest eigenvalue (Abs[(Subscript[λ, min])])>0.1`:

NProbability[λmin>0.1,λmin\[Distributed]MatrixPropertyDistribution[Min[Abs[Eigenvalues[m]]],m\[Distributed]MatrixNormalDistribution[IdentityMatrix[10],IdentityMatrix[10]]]]

Probability density function:

dist=MatrixNormalDistribution[IdentityMatrix[2],DiagonalMatrix[{2,1}]];PDF[dist,{{1.,2.},{3,4.}}]

Plot PDF for a diagonal matrices:

Plot3D[PDF[dist,DiagonalMatrix[{a,b}]],{a,-3,3},{b,-3,3}]

Skewness and kurtosis:

Skewness[MatrixNormalDistribution[{{2,1},{1,3}},IdentityMatrix[3]]]//MatrixForm

Kurtosis[MatrixNormalDistribution[{{2,1},{1,3}},IdentityMatrix[3]]]//MatrixForm

OpenersExampleSection3(Spacer1)Applications  (2)

Visualize sample matrices from matrix normal distributions:

sigR=Covariance[ARProcess[{-0.95},1][Range[0,100]]];
sigC=KroneckerProduct[IdentityMatrix[100,SparseArray],{{1,1/2},{1/2,3}}];
vals=RandomVariate[MatrixNormalDistribution[sigR,sigC]];

MatrixPlot[vals,PlotTheme->"Minimal"]

sigR=Covariance[ARProcess[{0.95},1][Range[0,100]]];
sigC=KroneckerProduct[IdentityMatrix[100,SparseArray],{{1,1/2},{1/2,3}}];
vals=RandomVariate[MatrixNormalDistribution[sigR,sigC]];

MatrixPlot[vals,PlotTheme->"Minimal"]

Use matrix normal distribution to simulate a vector autoregressive process:

sigR=Covariance[ARProcess[{a},1][Range[0,100]]];
sigC={{s11,s12},{s12,s22}};

rules={a->1/2,s11->1,s12->1/2,s22->3};

dist=MatrixNormalDistribution[sigR,sigC]/.rules;

vals=RandomVariate[dist,10000];

Construct (RefLink[TemporalData, paclet:ref/TemporalData]) from sampled values:

td=TemporalData[vals,{0,Length[sigR]-1,1},ValueDimensions->2];

Estimate diagonal vector autoregressive process:

proc=ARProcess[{a IdentityMatrix[2]},{{s11,s12},{s12,s22}}];

sol=FindProcessParameters[td,proc]

Compare to the original values:

sol[[All,2]]-rules[[All,2]]

OpenersExampleSection4(Spacer1)Properties & Relations  (6)

Matrix normal distribution is defined up to a positive multiplicative constant:

sigr={{2,1},{1,4}};
sigc=ToeplitzMatrix[{9,3,1}];
𝒟1=MatrixNormalDistribution[sigr,sigc];

Equivalent distribution with row and column scale matrices multiplied and divided by a positive constant:

c=2;
𝒟2=MatrixNormalDistribution[c*sigr,sigc/c];

Compute the PDF of the distributions at a random point:

mat=RandomReal[{-10,10},{2,3}]

PDF[𝒟1,mat]==PDF[𝒟2,mat]

(RefLink[MatrixTDistribution, paclet:ref/MatrixTDistribution])[(Subscript[Σ, row]),(Subscript[Σ, col]),ν] is a parameter mixture of (RefLink[MatrixNormalDistribution, paclet:ref/MatrixNormalDistribution])[Σ,(Subscript[Σ, col])] with Σ following (RefLink[InverseWishartMatrixDistribution, paclet:ref/InverseWishartMatrixDistribution])[ν+n-1,(Subscript[Σ, row])]:

ν=5;
n=3;
Σr=IdentityMatrix[n];
Σc=IdentityMatrix[2];
invW=InverseWishartMatrixDistribution[ν+n-1,Σr];

Create a sample following the parameter mixture of (RefLink[MatrixNormalDistribution, paclet:ref/MatrixNormalDistribution]) with (RefLink[InverseWishartMatrixDistribution, paclet:ref/InverseWishartMatrixDistribution]):

sampleSize=10^3;
sigmas=RandomVariate[invW,10^3];
sample=Table[RandomVariate[MatrixNormalDistribution[s,Σc]],{s,sigmas}];

Fit the sample data to (RefLink[MatrixTDistribution, paclet:ref/MatrixTDistribution]):

edist=EstimatedDistribution[sample,MatrixTDistribution[Array[s1,{3,3}],Array[s2,{2,2}],nu]]

Compute log-likelihood ratio statistic against the appropriate (RefLink[MatrixTDistribution, paclet:ref/MatrixTDistribution]):

ratio=LogLikelihood[edist,sample]-LogLikelihood[MatrixTDistribution[Σr,Σc,ν],sample]

Log-likelihood ratio follows (RefLink[ChiSquareDistribution, paclet:ref/ChiSquareDistribution]) with the parameter equal to the number of degrees of freedom:

dof=(Length[Σr]+1)*Length[Σr]/2+(Length[Σc]+1)*Length[Σc]/2+1

Compute the p-value of log-likelihood ratio test:

pval=SurvivalFunction[ChiSquareDistribution[dof],2ratio]

Sample from matrix normal distribution with independent rows:

mat=RandomVariate[MatrixNormalDistribution[IdentityMatrix[10^3,SparseArray],{{1,-1/2},{-1/2,2}}]];

Test the hypothesis that rows follow multinormal distribution with the column covariance matrix:

BaringhausHenzeTest[mat,MultinormalDistribution[{0,0},{{1,-1/2},{-1/2,2}}],"TestConclusion"]

Sample from matrix normal distribution with independent rows:

mat=RandomVariate[MatrixNormalDistribution[IdentityMatrix[10^3,SparseArray],{{1,-1/2},{-1/2,2}}]];

Test the hypothesis that rows follow multinormal distribution with the column covariance matrix:

BaringhausHenzeTest[mat,MultinormalDistribution[{0,0},{{1,-1/2},{-1/2,2}}],"TestConclusion"]

Sample from matrix normal distribution with independent rows:

data=RandomVariate[MatrixNormalDistribution[IdentityMatrix[3],{{1,-1/2},{-1/2,2}}],10^5];

Computing sample inter-row covariances shows different rows are pairwise independent:

Round[Table[Covariance[data[[All,i]],data[[All,j]]],{i,3},{j,3}],0.05]//MatrixForm

Computing sample inter-column covariances shows different columns are dependent:

Round[Table[Covariance[data[[All,All,i]],data[[All,All,j]]],{i,2},{j,2}],0.05]//MatrixForm

By joining the rows of the matrix-valued random variable together, a matrix normal distribution can be regarded as a multivariate normal distribution:

(Subscript[Σ, r])={{2,1},{1,3}};
(Subscript[Σ, c])={{1,1/2},{1/2,3}};

mats=RandomVariate[MatrixNormalDistribution[(Subscript[Σ, r]),(Subscript[Σ, c])],5000];

vecs=Flatten[mats,{{1},{2,3}}];

The covariance matrix of the vectorized random matrix is the Kronecker product of (Subscript[Σ, r]) and (Subscript[Σ, c]):

DistributionFitTest[vecs,MultinormalDistribution[{0,0,0,0},KroneckerProduct[(Subscript[Σ, r]),(Subscript[Σ, c])]],{"TestDataTable",All}]

OpenersExampleSection5(Spacer1)Possible Issues  (1)

Matrix normal distribution is defined up to a multiplicative scaling constant. The estimated parameters may not be close to the ones that specify the underlying distribution:

sigr=ToeplitzMatrix[{4,2,1}];
sigc=DiagonalMatrix[{3,1}];
dist=MatrixNormalDistribution[sigr,sigc];

Sample from the matrix normal distribution:

sample=RandomVariate[dist,10^4];

Estimate the distribution:

edist=EstimatedDistribution[sample,MatrixNormalDistribution[Array[s1,{3,3}],Array[s2,{2,2}]]];

Compare the estimated scale parameters with the ones of the underlying distribution:

MatrixForm/@{esigr=First[edist],sigr}

MatrixForm/@{esigc=edist[[2]],sigc}

Kronecker products of the scale matrices are close to each other:

NumberForm[KroneckerProduct[sigr,sigc]-KroneckerProduct[esigr,esigc]//MatrixForm,4]

The (RefLink[LogLikelihood, paclet:ref/LogLikelihood]) of the distribution indicates that the estimate is good:

LogLikelihood[#,sample]&/@{dist,edist}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[MatrixTDistribution, paclet:ref/MatrixTDistribution])  ▪  (RefLink[WishartMatrixDistribution, paclet:ref/WishartMatrixDistribution])  ▪  (RefLink[GaussianOrthogonalMatrixDistribution, paclet:ref/GaussianOrthogonalMatrixDistribution])  ▪  (RefLink[MatrixPropertyDistribution, paclet:ref/MatrixPropertyDistribution])  ▪  (RefLink[MultinormalDistribution, paclet:ref/MultinormalDistribution])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Matrix Distributions, paclet:guide/MatrixDistributions])}})}})