Range for continuos distribution in Julia












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










share|improve this question





























    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










    share|improve this question



























      2












      2








      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










      share|improve this question
















      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







      julia probability distribution julia-jump






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 4:05







      Chris Martin

















      asked Nov 22 '18 at 22:10









      Chris MartinChris Martin

      253




      253
























          2 Answers
          2






          active

          oldest

          votes


















          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.






          share|improve this answer
























          • 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 7: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.






          share|improve this answer
























          • Thanks for the response! But I don't think my question was understood properly (I edited it btw). What I am trying to calculate is the probability of x being between two values. So for example in your example, I want something like P(2<x<3). I think what you did is just defining x in that range but that's not the probability. I'm using Julia 0.6.2

            – Chris Martin
            Nov 23 '18 at 4:06








          • 2





            Then, why not simply cdf(x, 3) - cdf(x, 2).

            – 张实唯
            Nov 23 '18 at 6:56






          • 1





            Exactly. With one small note that cdf evaluates P(X<= a) not P(X<a) (which in case of continuous distributions is the same, but not in general).

            – Bogumił Kamiński
            Nov 23 '18 at 7:40











          • I have no idea why this didn't cross my mind! But yeah you're right, it works well now

            – Chris Martin
            Nov 23 '18 at 16:50











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438515%2frange-for-continuos-distribution-in-julia%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          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.






          share|improve this answer
























          • 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 7:42
















          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.






          share|improve this answer
























          • 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 7:42














          3












          3








          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 22:23









          Bogumił KamińskiBogumił Kamiński

          14.3k21322




          14.3k21322













          • 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 7:42



















          • 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 7:42

















          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





          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 7:42





          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 7: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.






          share|improve this answer
























          • Thanks for the response! But I don't think my question was understood properly (I edited it btw). What I am trying to calculate is the probability of x being between two values. So for example in your example, I want something like P(2<x<3). I think what you did is just defining x in that range but that's not the probability. I'm using Julia 0.6.2

            – Chris Martin
            Nov 23 '18 at 4:06








          • 2





            Then, why not simply cdf(x, 3) - cdf(x, 2).

            – 张实唯
            Nov 23 '18 at 6:56






          • 1





            Exactly. With one small note that cdf evaluates P(X<= a) not P(X<a) (which in case of continuous distributions is the same, but not in general).

            – Bogumił Kamiński
            Nov 23 '18 at 7:40











          • I have no idea why this didn't cross my mind! But yeah you're right, it works well now

            – Chris Martin
            Nov 23 '18 at 16:50
















          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.






          share|improve this answer
























          • Thanks for the response! But I don't think my question was understood properly (I edited it btw). What I am trying to calculate is the probability of x being between two values. So for example in your example, I want something like P(2<x<3). I think what you did is just defining x in that range but that's not the probability. I'm using Julia 0.6.2

            – Chris Martin
            Nov 23 '18 at 4:06








          • 2





            Then, why not simply cdf(x, 3) - cdf(x, 2).

            – 张实唯
            Nov 23 '18 at 6:56






          • 1





            Exactly. With one small note that cdf evaluates P(X<= a) not P(X<a) (which in case of continuous distributions is the same, but not in general).

            – Bogumił Kamiński
            Nov 23 '18 at 7:40











          • I have no idea why this didn't cross my mind! But yeah you're right, it works well now

            – Chris Martin
            Nov 23 '18 at 16:50














          0












          0








          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 2:02









          张实唯张实唯

          1,742822




          1,742822













          • Thanks for the response! But I don't think my question was understood properly (I edited it btw). What I am trying to calculate is the probability of x being between two values. So for example in your example, I want something like P(2<x<3). I think what you did is just defining x in that range but that's not the probability. I'm using Julia 0.6.2

            – Chris Martin
            Nov 23 '18 at 4:06








          • 2





            Then, why not simply cdf(x, 3) - cdf(x, 2).

            – 张实唯
            Nov 23 '18 at 6:56






          • 1





            Exactly. With one small note that cdf evaluates P(X<= a) not P(X<a) (which in case of continuous distributions is the same, but not in general).

            – Bogumił Kamiński
            Nov 23 '18 at 7:40











          • I have no idea why this didn't cross my mind! But yeah you're right, it works well now

            – Chris Martin
            Nov 23 '18 at 16:50



















          • Thanks for the response! But I don't think my question was understood properly (I edited it btw). What I am trying to calculate is the probability of x being between two values. So for example in your example, I want something like P(2<x<3). I think what you did is just defining x in that range but that's not the probability. I'm using Julia 0.6.2

            – Chris Martin
            Nov 23 '18 at 4:06








          • 2





            Then, why not simply cdf(x, 3) - cdf(x, 2).

            – 张实唯
            Nov 23 '18 at 6:56






          • 1





            Exactly. With one small note that cdf evaluates P(X<= a) not P(X<a) (which in case of continuous distributions is the same, but not in general).

            – Bogumił Kamiński
            Nov 23 '18 at 7:40











          • I have no idea why this didn't cross my mind! But yeah you're right, it works well now

            – Chris Martin
            Nov 23 '18 at 16:50

















          Thanks for the response! But I don't think my question was understood properly (I edited it btw). What I am trying to calculate is the probability of x being between two values. So for example in your example, I want something like P(2<x<3). I think what you did is just defining x in that range but that's not the probability. I'm using Julia 0.6.2

          – Chris Martin
          Nov 23 '18 at 4:06







          Thanks for the response! But I don't think my question was understood properly (I edited it btw). What I am trying to calculate is the probability of x being between two values. So for example in your example, I want something like P(2<x<3). I think what you did is just defining x in that range but that's not the probability. I'm using Julia 0.6.2

          – Chris Martin
          Nov 23 '18 at 4:06






          2




          2





          Then, why not simply cdf(x, 3) - cdf(x, 2).

          – 张实唯
          Nov 23 '18 at 6:56





          Then, why not simply cdf(x, 3) - cdf(x, 2).

          – 张实唯
          Nov 23 '18 at 6:56




          1




          1





          Exactly. With one small note that cdf evaluates P(X<= a) not P(X<a) (which in case of continuous distributions is the same, but not in general).

          – Bogumił Kamiński
          Nov 23 '18 at 7:40





          Exactly. With one small note that cdf evaluates P(X<= a) not P(X<a) (which in case of continuous distributions is the same, but not in general).

          – Bogumił Kamiński
          Nov 23 '18 at 7:40













          I have no idea why this didn't cross my mind! But yeah you're right, it works well now

          – Chris Martin
          Nov 23 '18 at 16:50





          I have no idea why this didn't cross my mind! But yeah you're right, it works well now

          – Chris Martin
          Nov 23 '18 at 16:50


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438515%2frange-for-continuos-distribution-in-julia%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          RAC Tourist Trophy