 # How to generate truncated Dirichlet distribution

I am interested in generating numbers from a truncated Dirichlet distribution, upperly bounded by a certain value. As a simple example:

``````library(DirichletReg)

ub=0.2
DirichletReg::rdirichlet(1,alpha=rep(1,times=10))
``````

This code generates 10 random numbers from the Dirichlet distribution with all concentration parameters set to 1.

Does anyone know how could I do the same, truncating the distribution by an upper bound `ub`?

Thanks in advance for any help!

Thanks for your answer. I have worked in a more elaborated example:

``````library(DirichletReg)

Bmax = 0.05 #Upper bound
nvar = 100 #Vector length
niter = 500 #Number of generations
p = 0.10
smax = 3 #Max shape parameter

b = rep(Bmax, length.out=nvar) #Vector of upper bounds

s1 = rev(rep(smax, length.out=p*nvar))
s2 = rep(1, times=(1-p)*nvar)
s = c(s1,s2) #Vector of shape parameters

r = DirichletReg::rdirichlet(niter, alpha=s) #Stochastic matrix generation
``````

Basically, what I want is to build an stochastic matrix, in which no element exceeds the upper bound. However, I am not sure how can I truncate the results in an efficient way, especially because when `smax` is bigger, more and more rejection of samples is needed.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.