Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/distrs/ntdist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

# R implementations
using .RFunctions:
ntdistpdf,
ntdistlogpdf,
ntdistcdf,
ntdistccdf,
ntdistlogcdf,
Expand All @@ -12,3 +10,20 @@ using .RFunctions:
ntdistinvccdf,
ntdistinvlogcdf,
ntdistinvlogccdf

using SpecialFunctions: gamma

function ntdistpdf(k::Real, λ::Real, x::Real)
return exp(ntdistlogpdf(k, λ, x))
end

ntdistlogpdf(k::Real, λ::Real, x::Real) = ntdistlogpdf(promote(k, λ, x)...)

function ntdistlogpdf(k::T, λ::T, x::T) where {T<:Real}
ONE = one(T)
Av = _₁F₁((k + 1) / 2, ONE / 2, (λ * x)^2 / (2 * muladd(x, x, k)))
Bv = sqrt(2*ONE) * λ * x * gamma(k/2 +1) / (sqrt(muladd(x, x, k)) * gamma((k+1)/2)) *
_₁F₁(k/2 + 1, 3*ONE/2, (λ * x)^2 / (2 * muladd(x, x, k)))
tdistlogpdf(k, x) - λ^2 / 2 +
log(Av + Bv)
end
Loading