-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix_tdist.jl
38 lines (27 loc) · 1005 Bytes
/
matrix_tdist.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module location_scale_tdist
using LinearAlgebra
using Distributions
using SpecialFunctions
export LocationScaleT, pdf, logpdf, params, dimensions
mutable struct LocationScaleT <: ContinuousUnivariateDistribution
ν ::Real
μ ::Real
σ ::Real
function LocationScaleT(ν::Float64, μ::Float64, σ::Float64)
if ν <= 0.0; error("Degrees of freedom parameter must be positive."); end
if σ <= 0.0; error("Scale parameter must be positive."); end
return new(ν, μ, σ)
end
end
function params(p::LocationScaleT)
return p.ν, p.μ, p.σ
end
function pdf(p::LocationScaleT, x)
ν, μ, σ = params(p)
return gamma( (ν+1)/2 ) / ( gamma(ν/2) *sqrt(πν)*σ ) * ( 1 + (x-μ)^2/(ν*σ^2) )^( -(ν+1)/2 )
end
function logpdf(p::LocationScaleT, x)
ν, μ, σ = params(p)
return loggamma( (ν+1)/2 ) - loggamma(ν/2) - 1/2*log(πν) - log(σ) + ( -(ν+1)/2 )*log( 1 + (x-μ)^2/(ν*σ^2) )
end
end