# Wolfram言語™

## 行列正規分布と行列T分布

In[1]:=
```Subscript[\[CapitalSigma], row] = {{1, 0.9}, {0.9, 1}}; Subscript[\[CapitalSigma], col] = {{1, -0.9}, {-0.9, 1}};```
In[2]:=
```RandomVariate[ MatrixNormalDistribution[Subscript[\[CapitalSigma], row], Subscript[\[CapitalSigma], col]]]```
Out[2]=

In[3]:=
```sample = RandomVariate[ MatrixNormalDistribution[Subscript[\[CapitalSigma], row], Subscript[\[CapitalSigma], col]], 10^4]; firstrows = sample[[All, 1]];```

In[4]:=
```Show[ContourPlot[ PDF[MultinormalDistribution[{0, 0}, Subscript[\[CapitalSigma], col] ], {x, y}], {x, -4.5, 4.5}, {y, -4.5, 4.5}, PlotPoints -> 30, PlotTheme -> "Detailed", ImageSize -> Medium], ListPlot[firstrows, ImageSize -> Medium, PlotTheme -> "Detailed", PlotStyle -> Black]]```
Out[4]=

In[5]:=
`firstcols = sample[[All, All, 1]];`

In[6]:=
```Show[Histogram3D[firstcols, Automatic, "PDF", ImageSize -> Medium, PlotTheme -> "Detailed", ChartStyle -> "Pastel"], Plot3D[PDF[ MultinormalDistribution[{0, 0}, Subscript[\[CapitalSigma], row] ], {x, y}], {x, -5, 5}, {y, -5, 5}, PlotRange -> All, ImageSize -> Medium, PlotTheme -> "Detailed", PlotLegends -> None]]```
Out[6]=

スチューデントの 分布，多変量 分布と同様に，行列 分布は行列正規分布に逆ウィシャート分布の尺度母数を混ぜたものである．行列 分布からサンプルを抽出する．

In[7]:=
```RandomVariate[ MatrixTDistribution[Subscript[\[CapitalSigma], row], Subscript[\[CapitalSigma], col], 3]]```
Out[7]=

In[8]:=
```sample = RandomVariate[ MatrixTDistribution[Subscript[\[CapitalSigma], row], Subscript[\[CapitalSigma], col], 3], 10^4];```

In[9]:=
```v = {1, 2}; vecs = sample.v;```
In[10]:=
```DistributionFitTest[vecs, MultivariateTDistribution[ Subscript[\[CapitalSigma], row] (v.Subscript[\[CapitalSigma], col].v)/3, 3]]```
Out[10]=

In[11]:=
```Show[ContourPlot[ PDF[MultivariateTDistribution[ Subscript[\[CapitalSigma], row] (v.Subscript[\[CapitalSigma], col].v)/3, 3], {x, y}], {x, -5, 5}, {y, -5, 5}, PlotPoints -> 30, PlotTheme -> "Detailed", ImageSize -> Medium], ListPlot[vecs, ImageSize -> Medium, PlotTheme -> "Detailed", PlotStyle -> Black]]```
Out[11]=