Generate 3 random number that sum to 1 in R

前端 未结 6 1151
花落未央
花落未央 2020-12-16 18:15

I am hoping to create 3 (non-negative) quasi-random numbers that sum to one, and repeat over and over.

Basically I am trying to partition something into three rand

6条回答
  •  囚心锁ツ
    2020-12-16 18:53

    When you want to randomly generate numbers that add to 1 (or some other value) then you should look at the Dirichlet Distribution.

    There is an rdirichlet function in the gtools package and running RSiteSearch('Dirichlet') brings up quite a few hits that could easily lead you to tools for doing this (and it is not hard to code by hand either for simple Dirichlet distributions).

提交回复
热议问题