Construct Distribution Histogram From Random Variable
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
Given a Beta Random Variable $X$ with parameters $alpha, beta$ and a positive constant $n$, suppose I am interested in the distribution of:
$$Y:=lfloor nXrfloor$$
Suppose I want a histogram showing the distribution of $Y$ in Mathematica. How can I go about plotting this histogram? Is it necessary that I generate many samples to approximate it first, or can Mathematica calculate it perfectly? Would you please provide some example code showing how you can obtain and plot this distribution?
plotting probability-or-statistics random distributions histograms
add a comment |Â
up vote
4
down vote
favorite
Given a Beta Random Variable $X$ with parameters $alpha, beta$ and a positive constant $n$, suppose I am interested in the distribution of:
$$Y:=lfloor nXrfloor$$
Suppose I want a histogram showing the distribution of $Y$ in Mathematica. How can I go about plotting this histogram? Is it necessary that I generate many samples to approximate it first, or can Mathematica calculate it perfectly? Would you please provide some example code showing how you can obtain and plot this distribution?
plotting probability-or-statistics random distributions histograms
2
You'll get more help if you show what you've tried and when you get a good answer consider upvoting it or accepting it. (You haven't accepted an answer since December 2017.)
– JimB
Sep 4 at 2:27
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
Given a Beta Random Variable $X$ with parameters $alpha, beta$ and a positive constant $n$, suppose I am interested in the distribution of:
$$Y:=lfloor nXrfloor$$
Suppose I want a histogram showing the distribution of $Y$ in Mathematica. How can I go about plotting this histogram? Is it necessary that I generate many samples to approximate it first, or can Mathematica calculate it perfectly? Would you please provide some example code showing how you can obtain and plot this distribution?
plotting probability-or-statistics random distributions histograms
Given a Beta Random Variable $X$ with parameters $alpha, beta$ and a positive constant $n$, suppose I am interested in the distribution of:
$$Y:=lfloor nXrfloor$$
Suppose I want a histogram showing the distribution of $Y$ in Mathematica. How can I go about plotting this histogram? Is it necessary that I generate many samples to approximate it first, or can Mathematica calculate it perfectly? Would you please provide some example code showing how you can obtain and plot this distribution?
plotting probability-or-statistics random distributions histograms
asked Sep 4 at 0:39
ereHsaWyhsipS
31118
31118
2
You'll get more help if you show what you've tried and when you get a good answer consider upvoting it or accepting it. (You haven't accepted an answer since December 2017.)
– JimB
Sep 4 at 2:27
add a comment |Â
2
You'll get more help if you show what you've tried and when you get a good answer consider upvoting it or accepting it. (You haven't accepted an answer since December 2017.)
– JimB
Sep 4 at 2:27
2
2
You'll get more help if you show what you've tried and when you get a good answer consider upvoting it or accepting it. (You haven't accepted an answer since December 2017.)
– JimB
Sep 4 at 2:27
You'll get more help if you show what you've tried and when you get a good answer consider upvoting it or accepting it. (You haven't accepted an answer since December 2017.)
– JimB
Sep 4 at 2:27
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
If you are interested in the distribution of $Y$, you don't want a histogram of counts. $Y$ is a discrete random variable. You want the vertical axis to be the estimated probability for the values of $Y$.
A DiscretePlot
is what you want. One way to get the appropriate plot is to use HistogramList
to get the probabilities.
data = Floor /@ (20 RandomVariate[BetaDistribution[4, 3], 1000]);
probability = HistogramList[data, Min[data] - 1/2, Max[data] + 1/2, 1, "PDF"]
(* 3/2, 5/2, 7/2, 9/2, 11/2, 13/2, 15/2, 17/2, 19/2, 21/2, 23/2, 25/2,
27/2, 29/2, 31/2, 33/2, 1/500, 13/500, 21/1000, 51/1000, 29/500,
23/250, 93/1000, 1/8, 97/1000, 57/500, 19/200, 9/100, 31/500, 57/1000, 17/1000 *)
DiscretePlot[probability[[2, i - Min[data] + 1]], i, Min[data], Max[data]]
If you really have to have something that looks like a histogram (like if you boss insists on it or you're stuck in the 20th century), then you need to make sure that the bars are centered on the integer values:
Histogram[data, Min[data] - 1/2, Max[data] + 1/2, 1, "PDF"]
If you don't include Min[data] - 1/2, Max[data] + 1/2, 1
, then the default will have the bars centered on 0.5, 1.5, 2.5, etc., which are values that $Y$ can't take on.
add a comment |Â
up vote
2
down vote
ClearAll[td]
td[n_, α_, β_] := TransformedDistribution[Floor[n x],
Distributed[x, BetaDistribution[α, β]]]
sample = RandomVariate[td[10, 2, 4], 500] ;
Histogram[sample]
Histogram[sample, Automatic, "PDF"]
Expectation[x, x [Distributed] td[10, 2, 4]]
5667/2000
Maybe it's my use of Mathematica 10.4 but unless I explicitly ask for the bins to be centered on integers, I get the integers being on the bin boundaries.
– JimB
Sep 4 at 3:05
@JimB, the picture is obtained in version 11.3 (Wolfram Cloud). I also get integers bin boundaries in version 9.
– kglr
Sep 4 at 3:08
add a comment |Â
up vote
1
down vote
Histogram[Floor /@ (20 RandomVariate[BetaDistribution[4, 3], 1000])]
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
If you are interested in the distribution of $Y$, you don't want a histogram of counts. $Y$ is a discrete random variable. You want the vertical axis to be the estimated probability for the values of $Y$.
A DiscretePlot
is what you want. One way to get the appropriate plot is to use HistogramList
to get the probabilities.
data = Floor /@ (20 RandomVariate[BetaDistribution[4, 3], 1000]);
probability = HistogramList[data, Min[data] - 1/2, Max[data] + 1/2, 1, "PDF"]
(* 3/2, 5/2, 7/2, 9/2, 11/2, 13/2, 15/2, 17/2, 19/2, 21/2, 23/2, 25/2,
27/2, 29/2, 31/2, 33/2, 1/500, 13/500, 21/1000, 51/1000, 29/500,
23/250, 93/1000, 1/8, 97/1000, 57/500, 19/200, 9/100, 31/500, 57/1000, 17/1000 *)
DiscretePlot[probability[[2, i - Min[data] + 1]], i, Min[data], Max[data]]
If you really have to have something that looks like a histogram (like if you boss insists on it or you're stuck in the 20th century), then you need to make sure that the bars are centered on the integer values:
Histogram[data, Min[data] - 1/2, Max[data] + 1/2, 1, "PDF"]
If you don't include Min[data] - 1/2, Max[data] + 1/2, 1
, then the default will have the bars centered on 0.5, 1.5, 2.5, etc., which are values that $Y$ can't take on.
add a comment |Â
up vote
2
down vote
If you are interested in the distribution of $Y$, you don't want a histogram of counts. $Y$ is a discrete random variable. You want the vertical axis to be the estimated probability for the values of $Y$.
A DiscretePlot
is what you want. One way to get the appropriate plot is to use HistogramList
to get the probabilities.
data = Floor /@ (20 RandomVariate[BetaDistribution[4, 3], 1000]);
probability = HistogramList[data, Min[data] - 1/2, Max[data] + 1/2, 1, "PDF"]
(* 3/2, 5/2, 7/2, 9/2, 11/2, 13/2, 15/2, 17/2, 19/2, 21/2, 23/2, 25/2,
27/2, 29/2, 31/2, 33/2, 1/500, 13/500, 21/1000, 51/1000, 29/500,
23/250, 93/1000, 1/8, 97/1000, 57/500, 19/200, 9/100, 31/500, 57/1000, 17/1000 *)
DiscretePlot[probability[[2, i - Min[data] + 1]], i, Min[data], Max[data]]
If you really have to have something that looks like a histogram (like if you boss insists on it or you're stuck in the 20th century), then you need to make sure that the bars are centered on the integer values:
Histogram[data, Min[data] - 1/2, Max[data] + 1/2, 1, "PDF"]
If you don't include Min[data] - 1/2, Max[data] + 1/2, 1
, then the default will have the bars centered on 0.5, 1.5, 2.5, etc., which are values that $Y$ can't take on.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
If you are interested in the distribution of $Y$, you don't want a histogram of counts. $Y$ is a discrete random variable. You want the vertical axis to be the estimated probability for the values of $Y$.
A DiscretePlot
is what you want. One way to get the appropriate plot is to use HistogramList
to get the probabilities.
data = Floor /@ (20 RandomVariate[BetaDistribution[4, 3], 1000]);
probability = HistogramList[data, Min[data] - 1/2, Max[data] + 1/2, 1, "PDF"]
(* 3/2, 5/2, 7/2, 9/2, 11/2, 13/2, 15/2, 17/2, 19/2, 21/2, 23/2, 25/2,
27/2, 29/2, 31/2, 33/2, 1/500, 13/500, 21/1000, 51/1000, 29/500,
23/250, 93/1000, 1/8, 97/1000, 57/500, 19/200, 9/100, 31/500, 57/1000, 17/1000 *)
DiscretePlot[probability[[2, i - Min[data] + 1]], i, Min[data], Max[data]]
If you really have to have something that looks like a histogram (like if you boss insists on it or you're stuck in the 20th century), then you need to make sure that the bars are centered on the integer values:
Histogram[data, Min[data] - 1/2, Max[data] + 1/2, 1, "PDF"]
If you don't include Min[data] - 1/2, Max[data] + 1/2, 1
, then the default will have the bars centered on 0.5, 1.5, 2.5, etc., which are values that $Y$ can't take on.
If you are interested in the distribution of $Y$, you don't want a histogram of counts. $Y$ is a discrete random variable. You want the vertical axis to be the estimated probability for the values of $Y$.
A DiscretePlot
is what you want. One way to get the appropriate plot is to use HistogramList
to get the probabilities.
data = Floor /@ (20 RandomVariate[BetaDistribution[4, 3], 1000]);
probability = HistogramList[data, Min[data] - 1/2, Max[data] + 1/2, 1, "PDF"]
(* 3/2, 5/2, 7/2, 9/2, 11/2, 13/2, 15/2, 17/2, 19/2, 21/2, 23/2, 25/2,
27/2, 29/2, 31/2, 33/2, 1/500, 13/500, 21/1000, 51/1000, 29/500,
23/250, 93/1000, 1/8, 97/1000, 57/500, 19/200, 9/100, 31/500, 57/1000, 17/1000 *)
DiscretePlot[probability[[2, i - Min[data] + 1]], i, Min[data], Max[data]]
If you really have to have something that looks like a histogram (like if you boss insists on it or you're stuck in the 20th century), then you need to make sure that the bars are centered on the integer values:
Histogram[data, Min[data] - 1/2, Max[data] + 1/2, 1, "PDF"]
If you don't include Min[data] - 1/2, Max[data] + 1/2, 1
, then the default will have the bars centered on 0.5, 1.5, 2.5, etc., which are values that $Y$ can't take on.
answered Sep 4 at 3:03
JimB
15.1k12456
15.1k12456
add a comment |Â
add a comment |Â
up vote
2
down vote
ClearAll[td]
td[n_, α_, β_] := TransformedDistribution[Floor[n x],
Distributed[x, BetaDistribution[α, β]]]
sample = RandomVariate[td[10, 2, 4], 500] ;
Histogram[sample]
Histogram[sample, Automatic, "PDF"]
Expectation[x, x [Distributed] td[10, 2, 4]]
5667/2000
Maybe it's my use of Mathematica 10.4 but unless I explicitly ask for the bins to be centered on integers, I get the integers being on the bin boundaries.
– JimB
Sep 4 at 3:05
@JimB, the picture is obtained in version 11.3 (Wolfram Cloud). I also get integers bin boundaries in version 9.
– kglr
Sep 4 at 3:08
add a comment |Â
up vote
2
down vote
ClearAll[td]
td[n_, α_, β_] := TransformedDistribution[Floor[n x],
Distributed[x, BetaDistribution[α, β]]]
sample = RandomVariate[td[10, 2, 4], 500] ;
Histogram[sample]
Histogram[sample, Automatic, "PDF"]
Expectation[x, x [Distributed] td[10, 2, 4]]
5667/2000
Maybe it's my use of Mathematica 10.4 but unless I explicitly ask for the bins to be centered on integers, I get the integers being on the bin boundaries.
– JimB
Sep 4 at 3:05
@JimB, the picture is obtained in version 11.3 (Wolfram Cloud). I also get integers bin boundaries in version 9.
– kglr
Sep 4 at 3:08
add a comment |Â
up vote
2
down vote
up vote
2
down vote
ClearAll[td]
td[n_, α_, β_] := TransformedDistribution[Floor[n x],
Distributed[x, BetaDistribution[α, β]]]
sample = RandomVariate[td[10, 2, 4], 500] ;
Histogram[sample]
Histogram[sample, Automatic, "PDF"]
Expectation[x, x [Distributed] td[10, 2, 4]]
5667/2000
ClearAll[td]
td[n_, α_, β_] := TransformedDistribution[Floor[n x],
Distributed[x, BetaDistribution[α, β]]]
sample = RandomVariate[td[10, 2, 4], 500] ;
Histogram[sample]
Histogram[sample, Automatic, "PDF"]
Expectation[x, x [Distributed] td[10, 2, 4]]
5667/2000
edited Sep 4 at 4:35
answered Sep 4 at 3:02
kglr
159k8183382
159k8183382
Maybe it's my use of Mathematica 10.4 but unless I explicitly ask for the bins to be centered on integers, I get the integers being on the bin boundaries.
– JimB
Sep 4 at 3:05
@JimB, the picture is obtained in version 11.3 (Wolfram Cloud). I also get integers bin boundaries in version 9.
– kglr
Sep 4 at 3:08
add a comment |Â
Maybe it's my use of Mathematica 10.4 but unless I explicitly ask for the bins to be centered on integers, I get the integers being on the bin boundaries.
– JimB
Sep 4 at 3:05
@JimB, the picture is obtained in version 11.3 (Wolfram Cloud). I also get integers bin boundaries in version 9.
– kglr
Sep 4 at 3:08
Maybe it's my use of Mathematica 10.4 but unless I explicitly ask for the bins to be centered on integers, I get the integers being on the bin boundaries.
– JimB
Sep 4 at 3:05
Maybe it's my use of Mathematica 10.4 but unless I explicitly ask for the bins to be centered on integers, I get the integers being on the bin boundaries.
– JimB
Sep 4 at 3:05
@JimB, the picture is obtained in version 11.3 (Wolfram Cloud). I also get integers bin boundaries in version 9.
– kglr
Sep 4 at 3:08
@JimB, the picture is obtained in version 11.3 (Wolfram Cloud). I also get integers bin boundaries in version 9.
– kglr
Sep 4 at 3:08
add a comment |Â
up vote
1
down vote
Histogram[Floor /@ (20 RandomVariate[BetaDistribution[4, 3], 1000])]
add a comment |Â
up vote
1
down vote
Histogram[Floor /@ (20 RandomVariate[BetaDistribution[4, 3], 1000])]
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Histogram[Floor /@ (20 RandomVariate[BetaDistribution[4, 3], 1000])]
Histogram[Floor /@ (20 RandomVariate[BetaDistribution[4, 3], 1000])]
edited Sep 4 at 2:41
answered Sep 4 at 2:21


David G. Stork
21.3k11646
21.3k11646
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181175%2fconstruct-distribution-histogram-from-random-variable%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
You'll get more help if you show what you've tried and when you get a good answer consider upvoting it or accepting it. (You haven't accepted an answer since December 2017.)
– JimB
Sep 4 at 2:27