2019-12-17 15:52:59 +01:00
|
|
|
#' @title Generates random numbers
|
|
|
|
|
#' @return vector of length `nc` with r.v. realizations from Gamma(rate=1)
|
2023-08-09 09:36:15 +02:00
|
|
|
#' @examples rBAPS:::randdir(matrix(c(10, 30, 60), 3), 3)
|
2019-12-17 15:52:59 +01:00
|
|
|
#' @param counts shape parameter
|
|
|
|
|
#' @param nc number of rows on output
|
2025-01-15 11:07:44 +01:00
|
|
|
#' @importFrom stats rgamma
|
2021-11-10 14:02:35 +01:00
|
|
|
randdir <- function(counts, nc) {
|
|
|
|
|
svar <- zeros(nc, 1)
|
|
|
|
|
for (i in 1:nc) {
|
2025-01-15 11:07:44 +01:00
|
|
|
svar[i, 1] <- rgamma(1L, shape = counts[i, 1], rate = 1)
|
2021-11-10 14:02:35 +01:00
|
|
|
}
|
|
|
|
|
svar <- svar / sum(svar)
|
|
|
|
|
return(svar)
|
|
|
|
|
}
|