1
$\begingroup$

I am modeling the distribution of the sum of two dice throws as a TransformedDistribution

d1 = TransformedDistribution[x + y, {x, y}\[Distributed]DiscreteUniformDistribution[{1, 6}]]

and wanted to take random samples with

(* In[2] = *)
RandomVariate[d1]

(* Out[2] = RandomVariate[
       TransformedDistribution[\[FormalX]1 + \FormalX]2,
         {\[FormalX]1, \[FormalX]2} \[Distributed] DiscreteUniformDistribution[{1, 6}]
       ]
     ]*)

but instead of a sample i get the unevaluated expression back. If i define my distribution like this

d2 = TransformedDistribution[x + y,
       {x \[Distributed] DiscreteUniformDistribution[{1, 6}], 
        y \[Distributed] DiscreteUniformDistribution[{1, 6}]}
     ]

instead, it works as expected:

(* In[3] = *)
RandomVariate[d2]

(* Out[3] = 7 *)

Can someone explain where this difference in behaviour comes from and if it's intended or should behave the same?

$\endgroup$
3
  • 3
    $\begingroup$ d1 as you have defined does not evaluate as the distribution is univariate and you are asking it to be bivariate, You could use TransformedDistribution[ x + y, {x, y} \[Distributed] DiscreteUniformDistribution[{{1, 6}, {1, 6}}]] $\endgroup$
    – ubpdqn
    Commented Apr 8, 2016 at 11:50
  • $\begingroup$ oh, i see, thanks for the explanation! If you put this as an answer i would accept it! Thanks! $\endgroup$ Commented Apr 8, 2016 at 12:27
  • 2
    $\begingroup$ I don't think you will beat the simplicity of: RandomInteger[{1, 6}] + RandomInteger[{1, 6}] by using RandomVariate[ TransformedBlah ] ... especially if you need just one drawing at a time (rather than a million in advance). $\endgroup$
    – wolfies
    Commented Apr 8, 2016 at 15:00

1 Answer 1

3
$\begingroup$

d1 as defined does not evaluate as the distribution is univariate and you are asking it to be bivariate. You could use

TransformedDistribution[ x + y, {x, y} \[Distributed] DiscreteUniformDistribution[{{1, 6}, {1, 6}}]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.