# rdiric: The Dirichlet distribution In VGAM: Vector Generalized Linear and Additive Models

## Description

Generates Dirichlet random variates.

## Usage

 `1` ```rdiric(n, shape, dimension = NULL, is.matrix.shape = FALSE) ```

## Arguments

 `n` number of observations. Note it has two meanings, see `is.matrix.shape` below. `shape` the shape parameters. These must be positive. If `dimension` is specifed, values are recycled if necessary to length `dimension`. `dimension` the dimension of the distribution. If `dimension` is not numeric then it is taken to be `length(shape)` (or `ncol(shape)` if `is.matrix.shape == TRUE`). `is.matrix.shape` Logical. If `TRUE` then `shape` must be a matrix, and then `n` is no longer the number of rows of the answer but the answer has `n * nrow(shape)` rows. If `FALSE` (the default) then `shape` is a vector and each of the `n` rows of the answer have `shape` as its shape parameters.

## Details

This function is based on a relationship between the gamma and Dirichlet distribution. Random gamma variates are generated, and then Dirichlet random variates are formed from these.

## Value

A `n` by `dimension` matrix of Dirichlet random variates. Each element is positive, and each row will sum to unity. If `shape` has names then these will become the column names of the answer.

Thomas W. Yee

## References

Lange, K. (2002). Mathematical and Statistical Methods for Genetic Analysis, 2nd ed. New York: Springer-Verlag.

`dirichlet` is a VGAM family function for fitting a Dirichlet distribution to data.

## Examples

 ```1 2 3 4``` ```ddata <- data.frame(rdiric(n = 1000, shape = c(y1 = 3, y2 = 1, y3 = 4))) fit <- vglm(cbind(y1, y2, y3) ~ 1, dirichlet, data = ddata, trace = TRUE) Coef(fit) coef(fit, matrix = TRUE) ```

### Example output

```Loading required package: stats4
VGLM    linear loop  1 :  loglikelihood = 927.09911
VGLM    linear loop  2 :  loglikelihood = 5336.2899
VGLM    linear loop  3 :  loglikelihood = 13146.094
VGLM    linear loop  4 :  loglikelihood = 18059.793
VGLM    linear loop  5 :  loglikelihood = 18738.503
VGLM    linear loop  6 :  loglikelihood = 18747.169
VGLM    linear loop  7 :  loglikelihood = 18747.17
VGLM    linear loop  8 :  loglikelihood = 18747.17
shape1    shape2    shape3
2.9442795 0.9920767 4.0897905
loge(shape1) loge(shape2) loge(shape3)
(Intercept)     1.079864 -0.007954892     1.408494
```

VGAM documentation built on Jan. 16, 2021, 5:21 p.m.