Random generation for the PLN model with latent mean equal to mu, latent covariance matrix equal to Sigma and average depths (sum of counts in a sample) equal to depths

rPLN(
  n = 10,
  mu = rep(0, ncol(Sigma)),
  Sigma = diag(1, 5, 5),
  depths = rep(10000, n)
)

Arguments

n

the sample size

mu

vectors of means of the latent variable

Sigma

covariance matrix of the latent variable

depths

Numeric vector of target depths. The first is recycled if there are not n values

Value

a n * p count matrix, with row-sums close to depths, with an attribute "offsets" corresponding to the true generated offsets (in log-scale).

Details

The default value for mu and Sigma assume equal abundances and no correlation between the different species.

Examples

## 10 samples of 5 species with equal abundances, no covariance and target depths of 10,000
rPLN()
#>       Y1   Y2   Y3   Y4   Y5
#> S1   554 1417 2449 1443  447
#> S2   187 1078  585  326 1542
#> S3  1009 2634  627 2245  853
#> S4  2637  372  192  783 1349
#> S5   494  716 2682  539  647
#> S6  7127  889  793 1584  967
#> S7   525 1022 5516 1368 5607
#> S8  1607 1085  167 1113  552
#> S9  1488  594 2125  887 1204
#> S10 1174 1418  431 1496  224
#> attr(,"offsets")
#>           [,1]     [,2]     [,3]     [,4]     [,5]
#>  [1,] 7.100902 7.100902 7.100902 7.100902 7.100902
#>  [2,] 7.100902 7.100902 7.100902 7.100902 7.100902
#>  [3,] 7.100902 7.100902 7.100902 7.100902 7.100902
#>  [4,] 7.100902 7.100902 7.100902 7.100902 7.100902
#>  [5,] 7.100902 7.100902 7.100902 7.100902 7.100902
#>  [6,] 7.100902 7.100902 7.100902 7.100902 7.100902
#>  [7,] 7.100902 7.100902 7.100902 7.100902 7.100902
#>  [8,] 7.100902 7.100902 7.100902 7.100902 7.100902
#>  [9,] 7.100902 7.100902 7.100902 7.100902 7.100902
#> [10,] 7.100902 7.100902 7.100902 7.100902 7.100902
## 2 samples of 10 highly correlated species with target depths 1,000 and 100,000
## very different abundances
mu <- rep(c(1, -1), each = 5)
Sigma <- matrix(0.8, 10, 10); diag(Sigma) <- 1
rPLN(n=2, mu = mu, Sigma = Sigma, depths = c(1e3, 1e5))
#>      Y1   Y2   Y3   Y4    Y5  Y6   Y7   Y8  Y9  Y10
#> S1   69  209   79   53    87   7   12   13  20    7
#> S2 6775 7194 5423 4558 14735 511 1725 1069 985 1017
#> attr(,"offsets")
#>          [,1]     [,2]     [,3]     [,4]     [,5]     [,6]     [,7]     [,8]
#> [1,] 3.671389 3.671389 3.671389 3.671389 3.671389 3.671389 3.671389 3.671389
#> [2,] 8.276560 8.276560 8.276560 8.276560 8.276560 8.276560 8.276560 8.276560
#>          [,9]    [,10]
#> [1,] 3.671389 3.671389
#> [2,] 8.276560 8.276560