2

I am trying to calculate the density function of a continuos random variable in range in Julia using Distributions, but I am not able to define the range. I used Truncator constructor to construct the distribution, but I have no idea how to define the range. By density function I mean P(a

Would appreciate any help. The distribution I'm using is Gamma btw!

Thanks

2 Answers2

3

To get the maximum and minimum of the support of distribution d just write maximum(d) and minimum(d) respectively. Note that for some distributions this might be infinity, e.g. maximum(Normal()) is Inf.

Bogumił Kamiński
  • 66,844
  • 3
  • 80
  • 107
  • My questing is about continuos random variables not discrete and this works fine for discrete, but of course it wont work for continuos that's why I'm using truncation – Chris Martin Nov 22 '18 at 23:09
  • This works both for continuous and discrete random variables. But I see that you have changed your question now - you have the answer to it in the comment by 张实唯 below. – Bogumił Kamiński Nov 23 '18 at 07:42
0

What version of Julia and Distributions du you use? In Distribution v0.16.4, it can be easily defined with the second and third arguments of Truncated.

julia> a = Gamma()
Gamma{Float64}(α=1.0, θ=1.0)

julia> b = Truncated(a, 2, 3)
Truncated(Gamma{Float64}(α=1.0, θ=1.0), range=(2.0, 3.0))

julia> p = rand(b, 1000);

julia> extrema(p)
(2.0007680527633305, 2.99864177354943)

You can see the document of Truncated by typing ?Truncated in REPL and enter.

张实唯
  • 2,836
  • 13
  • 25