R/rdirichlet.R

Defines functions rdirichlet

Documented in rdirichlet

## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
#     Copyright (C) 2017 - 2021  Reza Mohammadi                                |
#                                                                              |
#     This file is part of ssgraph package.                                    |
#                                                                              |
#     "bmixture" is free software: you can redistribute it and/or modify it    |
#     under the terms of the GNU General Public License as published by the    |
#     Free Software Foundation: <https://cran.r-project.org/web/licenses/GPL-3>|
#                                                                              |
#     Maintainer: Reza Mohammadi <a.mohammadi@uva.nl>                          |
## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
#     Random generator from Dirichlet distribution
## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

rdirichlet = function( n = 10, alpha = c( 1, 1 ) ) 
{
    length_alpha = length( alpha )
    
    sample = matrix( stats::rgamma( length_alpha * n, alpha ), 
                     ncol = length_alpha, byrow = TRUE )
    
    return( sample / apply( sample, 1, sum ) )
}
   
## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

Try the bmixture package in your browser

Any scripts or data that you put into this service are public.

bmixture documentation built on May 11, 2021, 5:08 p.m.