Experimenting with joint dependent distributions via the TransformedDistribution
function, I used the following to derive a distribution where the second variate is distributed dependent on the value of the first variate (very simplified & contrived example follows).
distA = TransformedDistribution[{b,
If[b == 1, d1, d2]}, {b \[Distributed]
DiscreteUniformDistribution[{1, 2}],
d1 \[Distributed] UniformDistribution[{1, 2}],
d2 \[Distributed] UniformDistribution[{2, 3}]}]
distB = TransformedDistribution[{b,
Piecewise[{{d1, b == 1}, {d2, b == 2}}]}, {b \[Distributed]
DiscreteUniformDistribution[{1, 2}],
d1 \[Distributed] UniformDistribution[{1, 2}],
d2 \[Distributed] UniformDistribution[{2, 3}]}]
distC = TransformedDistribution[{b,
Switch[b, 1, d1, 2, d2]}, {b \[Distributed]
DiscreteUniformDistribution[{1, 2}],
d1 \[Distributed] UniformDistribution[{1, 2}],
d2 \[Distributed] UniformDistribution[{2, 3}]}]
distD = TransformedDistribution[{b,
Which[b == 1, d1, b == 2, d2]}, {b \[Distributed]
DiscreteUniformDistribution[{1, 2}],
d1 \[Distributed] UniformDistribution[{1, 2}],
d2 \[Distributed] UniformDistribution[{2, 3}]}]
The first two behave as I'd expect: Mean, Var, RandomVariate
all do what they're supposed to. The latter two, while behaving as expected for the simple probability functions (e.g. Mean
), puke on any attempt to sample with RandomVariate
, with the message
TransformedDistribution::nnbprm: The valid numeric parameters of distribution TransformedDistribution[{\FormalX]1,Switch[\FormalX]1,1,\FormalX]2,2,\FormalX]3]},\FormalX]1,\FormalX]2,\FormalX]3}\Distributed]ProductDistribution[DiscreteUniformDistribution[{1,2}],UniformDistribution[{1,2}],UniformDistribution[{2,3}]]] are expected. Use DistributionParameterAssumptions to obtain the parameter assumptions. >>
I'm a bit puzzled by this, seems the forms in this case should result in equivalent behavior. Any insights?
If
,Switch
etc. are not equivalent to begin with. For example, trySwitch[b, 1, d1, _, d2]
if you want something almost equivalent to yourIf
. (It is equivalent on numericb
). $\endgroup$ – Michael E2 Jan 26 '14 at 0:38Switch
andWhich
should (could) be setup to return a result at all times. In addition to the use ofBlank[]
inSwitch
you could tryWhich[test1, ...,test2, ..., True, output if all tests fail]
$\endgroup$ – Mike Honeychurch Jan 26 '14 at 3:34switch
andwhich
never see the evaluated form of the test value. $\endgroup$ – ciao Jan 26 '14 at 3:42Simplify[ Switch[b, 1, d1, 2, d2] == If[b == 1, d1, d2], b == 1 || b == 2 ]
does not returnTrue
. (It does returnTrue
under the assumptionb == 1
, orb == 2
, but not their disjunction.) $\endgroup$ – Michael E2 Jan 26 '14 at 5:17