4
$\begingroup$

I would like to set up a transformed distribution as below:

For each draw from this transformed distribution, I would do the following:

  1. Draw x1 from X ~ U(0,1)
  2. Draw and output y1 from Y ~ U(0,x1)

I tried setting up transformed distribution using:

TransformedDistribution[x2,
  {
    x1 \[Distributed] UniformDistribution[{min1, max1}], 
    x2 \[Distributed] UniformDistribution[{min2, x1  }]
   }]

But the above uses a fixed value for the second draw from the uniform distribution.

The corresponding R code for making draws is below where n is the number of draws needed:

draw.rand <- function(n) {
    list.rand <- lapply(1:n, function(i) {
                            vec.max <- runif(1)
                            vec.rand <- runif(1, min = 0, max = vec.max)
                            vec.rand})
    unlist(list.rand)}

draw.rand(100)

Edit: I would like to evaluate the CDF, PDF of the new distribution.

$\endgroup$

1 Answer 1

6
$\begingroup$

Solution

You are after ParameterMixtureDistribution.

ClearAll[dist];
dist[min2_, min1_, max1_] := ParameterMixtureDistribution[
   UniformDistribution[{min2, x1}]
   , x1 \[Distributed] UniformDistribution[{min1, max1}]
   ];

Your example

PDF[dist[0, 0, 1], x]

enter image description here

CDF[dist[0, 0, 1], x]

Mathematica graphics

Plot[
 Evaluate@PDF[dist[0, 0, 1], x]
 , {x, 0, 1.2}
 , PlotTheme -> "Scientific"
 , PlotRange -> {0, 5}
 ]

Mathematica graphics

Another example

PDF[dist[1, 2, 3]]

Mathematica graphics

Plot[
 Evaluate@PDF[dist[1, 2, 3], x]
 , {x, 0, 5}
 , PlotTheme -> "Scientific"
 ]

Mathematica graphics

$\endgroup$
0

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.