Skip to contents

This function samples the k-dimensional probability simplex \(\Delta^{(k-1)}=\left\{ \langle x_1, \ldots x_k \rangle \in \mathbb{R}_{\geq 0}^k\, |\, \sum_{i=1}^k x_i = 1\right\}\) using the uniform probability distribution.

Arguments

k

The dimension of the probability simplex to be sampled.

Value

A sample of \(\Delta^{(k-1)}\) taken according the uniform probability distribution.

Examples

# sample the 5-dimensional probability simplex
sample_prob_simplex(5)
#> [1] 0.17058011 0.40188304 0.17388162 0.19960926 0.05404597

# successive calls may produce different results
sample_prob_simplex(5)
#> [1] 0.30827330 0.01997969 0.20885237 0.32390207 0.13899258

# setting the random seed before the call guarantee repeatability
set.seed(1)
sample_prob_simplex(5)
#> [1] 0.05830519 0.15783181 0.55531351 0.01952378 0.20902571

set.seed(1)
sample_prob_simplex(5)
#> [1] 0.05830519 0.15783181 0.55531351 0.01952378 0.20902571