# Multivariate Student's T distribution?

**URL:** <https://discourse.julialang.org/t/multivariate-students-t-distribution/119676>\
**Category:** Statistics\
**Tags:** question, distributions, probability\
**Created:** [September 21, 2024, 2:01pm UTC](https://discourse.julialang.org/t/multivariate-students-t-distribution/119676 "2024-09-21T14:01:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rsenne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rsenne/32/212973_2.png) [@rsenne](https://discourse.julialang.org/u/rsenne)\
**Post date:** [September 21, 2024, 2:01pm UTC](https://discourse.julialang.org/t/multivariate-students-t-distribution/119676/1 "2024-09-21T14:01:18Z")

</div>

Does there exist any active implementations of a multivariate Student’s T distribution? I need one for a model I am implementing but the only information I could find was from a multi year old issue on the Distributions.jl package that had no follow up:

> <https://github.com/JuliaStats/Distributions.jl/issues/1812>
>
> I am looking for the multi-variate t distribution, which is commonly used for Ba…yesian linear regression (see eqn. 8 \[here\](https://ams206-winter19-01.courses.soe.ucsc.edu/system/files/attachments/banerjee-bayesian-linear-model-details.pdf)).
> 
> I found \`AbstractMvTDist\` in the source code \[here\](https://github.com/JuliaStats/Distributions.jl/blob/master/src/multivariate/mvtdist.jl), but it isn't documented, exported, and the constructor \`Distributions.AbstractMvTDist(rand(3), Symmetric(rand(3, 3)))\` doesn't work as I'd anticipate.
> 
> is this distribution accessible for sampling via \`Distributions.jl\`? thanks.

Seems, that the code exists but is not exported?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 21, 2024, 5:54pm UTC](https://discourse.julialang.org/t/multivariate-students-t-distribution/119676/3 "2024-09-21T17:54:56Z")

</div>

The code does not exist in that package, it looks like. An “abstract” type is not something you can instantiate.

In a pinch, you could use PyCall.jl or PythonCall.jl to call the scipy implementation: [scipy.stats.multivariate\_t — SciPy v1.14.1 Manual](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.multivariate_t.html)

---

<div class="post-metadata">

**Author:** ![andreasnoack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andreasnoack/32/27_2.png) [@andreasnoack](https://discourse.julialang.org/u/andreasnoack)\
**Post date:** [September 23, 2024, 6:38am UTC](https://discourse.julialang.org/t/multivariate-students-t-distribution/119676/4 "2024-09-23T06:38:30Z")

</div>

Which functionality specifically do you need, `pdf`, `cdf`, `rand`? How large, just two and three dimensional or larger?

---

<div class="post-metadata">

**Author:** ![rsenne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rsenne/32/212973_2.png) [@rsenne](https://discourse.julialang.org/u/rsenne)\
**Post date:** [September 23, 2024, 3:27pm UTC](https://discourse.julialang.org/t/multivariate-students-t-distribution/119676/5 "2024-09-23T15:27:20Z")

</div>

I mostly need to be able to sample from the distribution so `rand` and evaluate the ‘pdf’ / ‘logpdf’ . The size of the distribution could be quite large, though unlikely. I would expect most applications to be less than 10 dimensions though can’t necessarily say _a priori_.

here is a few examples of something I could potentially want the distribution for:

> **[A Novel Robust Student's t-Based Kalman Filter](https://ieeexplore.ieee.org/document/7814285)**
>
> A novel robust Student's t-based Kalman filter is proposed by using the variational Bayesian approach, which provides a Gaussian approximation to the posterior distribution. Simulation results for a manoeuvring target tracking example illustrate that...

> **[Signal Modeling and Classification Using a Robust Latent Space Model Based on...](https://ieeexplore.ieee.org/document/4451278)**
>
> Factor analysis is a statistical covariance modeling technique based on the assumption of normally distributed data. A mixture of factor analyzers can be hence viewed as a special case of Gaussian (normal) mixture models providing a mathematically...

---

<div class="post-metadata">

**Author:** ![andreasnoack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andreasnoack/32/27_2.png) [@andreasnoack](https://discourse.julialang.org/u/andreasnoack)\
**Post date:** [September 23, 2024, 3:55pm UTC](https://discourse.julialang.org/t/multivariate-students-t-distribution/119676/6 "2024-09-23T15:55:45Z")

</div>

It seems like what is in [Distributions.jl/src/multivariate/mvtdist.jl at b219803a0d03a7c75d7aef7c0bab6cd0d79997dc · JuliaStats/Distributions.jl · GitHub](https://github.com/JuliaStats/Distributions.jl/blob/b219803a0d03a7c75d7aef7c0bab6cd0d79997dc/src/multivariate/mvtdist.jl) covers what you need but unfortunately it is not documented. You can do

```julia
julia> X = MvTDist(4.5, Matrix{Float64}(I, 3, 3))
Distributions.GenericMvTDist{Float64, PDMats.PDMat{Float64, Matrix{Float64}}, FillArrays.Zeros{Float64, 1, Tuple{Base.OneTo{Int64}}}}(
df: 4.5
dim: 3
μ: Zeros(3)
Σ: [1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0]
)

julia> pdf(X, rand(X))
0.0104628664698684

```

though.

---

<div class="post-metadata">

**Author:** ![rsenne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rsenne/32/212973_2.png) [@rsenne](https://discourse.julialang.org/u/rsenne)\
**Post date:** [September 23, 2024, 4:05pm UTC](https://discourse.julialang.org/t/multivariate-students-t-distribution/119676/7 "2024-09-23T16:05:47Z")

</div>

Ah great! Cheers, thank you!
