# Wolfram 语言™

## Wishart 和逆 Wishart 分布

Wishart 分布是从独立多维正态随机向量中所抽取样本的协方差矩阵的分布. 它是 分布的多维推广. 该分布在诸如回归、协方差等多元统计中自然出现.

In[1]:=
`\[CapitalSigma] = DiagonalMatrix[RandomReal[10, 5]];`

In[2]:=
```dist = WishartMatrixDistribution[30, \[CapitalSigma]]; mat = RandomVariate[dist];```
In[3]:=
`SymmetricMatrixQ[mat] && PositiveDefiniteMatrixQ[mat]`
Out[3]=

In[4]:=
```invdist = InverseWishartMatrixDistribution[30, Inverse[\[CapitalSigma]]]; invmat = RandomVariate[invdist];```

In[5]:=
`SymmetricMatrixQ[invmat] && PositiveDefiniteMatrixQ[invmat]`
Out[5]=

In[6]:=
```eigs = Flatten[ RandomVariate[ MatrixPropertyDistribution[Eigenvalues[x], x \[Distributed] dist], 10^4]]; inveigs = Flatten[RandomVariate[ MatrixPropertyDistribution[Eigenvalues[x]^-1, x \[Distributed] invdist], 10^4]];```

In[7]:=
```SmoothHistogram[{eigs, inveigs}, PlotLegends -> {"Wishart", "Inverse Wishart"}, Filling -> Axis, ImageSize -> Medium, PlotTheme -> "Scientific"]```
Out[7]=

In[8]:=
```y = #/Sqrt[#.\[CapitalSigma].#] &[RandomReal[1, 5]]; data = RandomVariate[ MatrixPropertyDistribution[y.w.y, w \[Distributed] WishartMatrixDistribution[30, \[CapitalSigma]]], 10^4];```
In[9]:=
```Show[Histogram[data, Automatic, PDF, PlotTheme -> "Detailed"], Plot[PDF[ChiSquareDistribution[30], x], {x, 0, 80}], ImageSize -> Medium]```
Out[9]=