Problem
I like Mathematica. I think it is awesome for a lot of things (and symbolic notation is nifty). Rather than doing things manually, I would like to take advantage of Mathematica's internal objects for handling probability and statistics. However, I find that doing so is very unintuitive -- at least to me.
For example, if I want to specify the PDF of a die, I need to be specific about the ProbabilityDistribution[... {x,1,6,1}]
For example what is below works great:
Die = ProbabilityDistribution[PDF[UniformDistribution[{0, 6}], x], {x, 1, 6, 1}];
Roll[die_] := RandomVariate[die, 1];
So what about the probability that the sum of two dice rolls is less than 8, given that the sum of the two dice is odd?
Probability[Subscript[x, 1] + Subscript[x, 2] < 8 \[Conditioned] Mod[Subscript[x, 1] + Subscript[x, 2], 2] != 0, {Subscript[x, 1] \[Distributed] Die, Subscript[x, 2] \[Distributed] Die}]
This works. Yet, the more intuitive (to me) way to have programmed this would have been:
Probability[Subscript[x, 1] + Subscript[x, 2] < 8 \[Conditioned] OddQ[Subscript[x, 1] + Subscript[x, 2]], {Subscript[x, 1] \[Distributed] Die, Subscript[x, 2] \[Distributed] Die}]
Which doesnt work.
Ok, so let's get a bit more tricky. What about the classical drawing marbles from a bag? Using the same format as above, I can get no results: (Probably should just copy-paste this into a notebook...)
BagOfMarbles[redMarbles_, blueMarbles_] := ProbabilityDistribution[PDF[\!\(\* TagBox[GridBox[{{"\[Piecewise]", GridBox[{{FractionBox["redMarbles", RowBox[{"redMarbles", "+","blueMarbles"}]], "Red"},{FractionBox["blueMarbles", RowBox[{"redMarbles", "+", "blueMarbles"}]], "Blue"}},AllowedDimensions->{2, Automatic},Editable->True,GridBoxAlignment->{"Columns" -> {{Left}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},GridBoxItemSize->{"Columns" -> {{Automatic}}, "ColumnsIndexed" -> {}, "Rows" -> {{1.}}, "RowsIndexed" -> {}},GridBoxSpacings->{"Columns" -> {Offset[0.27999999999999997`], {Offset[0.84]}, Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {Offset[0.2], {Offset[0.4]}, Offset[0.2]}, "RowsIndexed" -> {}},Selectable->True]}},GridBoxAlignment->{"Columns" -> {{Left}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},GridBoxItemSize->{"Columns" -> {{Automatic}}, "ColumnsIndexed" -> {}, "Rows" -> {{1.}}, "RowsIndexed" -> {}},GridBoxSpacings->{"Columns" -> {Offset[0.27999999999999997`], {Offset[0.35]}, Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {Offset[0.2], {Offset[0.4]}, Offset[0.2]}, "RowsIndexed" -> {}}],"Piecewise",DeleteWithContents->True,Editable->False,SelectWithContents->True,Selectable->False]\) , x], {x, Red, Blue}];
So far, it should in principle work...
Probability[x == Red , x \[Distributed] BagOfMarbles[3, 5]]
and then nothing.
So can someone please explain what qualifies as a valid PDF strucutre
ProbabilityDistribution[PDF[UniformDistribution[{0, 6}], x], {x, 1, 6, 1}];
is a very strange way to describe a dice. I am surprised it even works. You are using an inbuilt continuous Uniform distribution, taking the PDF of it, and then using that to manually construct a discrete Uniform distribution that describes a dice. What you want is:Die = DiscreteUniformDistribution[{1, 6}]
$\endgroup$OddQ
immediately givesFalse
if its argument is not already numeric, so your expression is effectivelySubscript[x, 1] + Subscript[x, 2] < 8 \[Conditioned] False
. Your second problem is because you shouldn't wrap the argument ofProbabilityDistribution
inPDF
, you should just give the PDF directly. For example, you could just have defineddie = ProbabilityDistribution[1/6, {x, 1, 6, 1}]
. $\endgroup$PDF
is a property of a distribution. Distributions have many properties:PDF
,CDF
,Mean
,Variance
,Moment
, and others. You useProbabilityDistribution
if you know thePDF
(orCDF
orSurvivalFunction
orHazardFunction
) to construct the associated distribution. Once constructed, the distribution can be used to calculate any of the other properties that Mathematica knows. $\endgroup$