Description Usage Arguments Details Value Author(s) Examples
'rcounts' is used to sample high-dimensional correlated count random variables with approximate prespecified Pearson correlation and exact margins.
1 2 3 |
N |
number of observations to be generated per margin (should be at least 500). |
margins |
Vector of margin tokens. Its length T is the dimension. See details. |
mu |
Vector of length T of means for the Poisson, GP, ZIP, ZIGP and NB margins. |
phi |
Vector of length T of dispersion parameters for the GP, and ZIGP margins. For Poisson, ZIP and NB margins, an 'NA' can be provided. |
omega |
Vector of length T of zero-inflation parameters for the ZIP and ZIGP margins. For Poisson, GP and NB margins, an 'NA' can be provided. |
psi |
Vector of length T of size parameters for the NB margins. For Poisson, GP, ZIP and ZIGP margins, an 'NA' can be provided. |
corstr |
Correlation structure. Can be 'ex' for exchangeable, 'AR1' for AR(1) and 'unstr' for unstructured. |
corpar |
Correlation parameter. Scalar correlation for 'ex' and 'AR1' and matrix of dimension TxT for 'unstr'. |
conv |
Convergence criterion |
The entries in 'margins' can be specified as 'Poi' for Poisson, 'GP' for generalized Poisson, 'ZIP' for zero-inflated Poisson, 'ZIGP' for zero-inflated generalized Poisson and 'NB' for negative-binomial.
The function will return a matrix of counts of dimension N x T.
Vinzenz Erhardt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | N <- 5000
# high precision in dimension 2
margins <- c("ZIGP","GP")
mu <- c(10, 15)
phi <- c(1.5, 3.5)
omega <- c(.25, NA)
corstr <- "ex"
corpar <- .5
Y <- rcounts(N=N, margins=margins, mu=mu, phi=phi, omega=omega, corstr=corstr,
corpar=corpar, conv=0.0001)
cor(Y)
# five-dimensional examples
margins <- c("ZIGP","GP","Poi","NB","ZIP")
mu <- c(10, 25, 12, 20, 28)
phi <- c(1.5, 2, NA, NA, NA)
omega <- c(.25, NA, NA, NA, .2)
psi <- c(NA, NA, NA, 7, NA)
# Exchangeable structure with correlation of 0.5
corstr <- "ex"
corpar <- .5
Y <- rcounts(N=N, margins=margins, mu=mu, phi=phi, omega=omega, psi=psi,
corstr=corstr, corpar=corpar)
cor(Y)
# AR(1) structure with correlation of corr(Y(t1), Y(t2)) = .8 ^ |t1-t2|
corstr <- "AR1"
corpar <- .8
Y <- rcounts(N=N, margins=margins, mu=mu, phi=phi, omega=omega, psi=psi,
corstr=corstr, corpar=corpar)
cor(Y)
# Unstructured correlation. Create random symmetric positive definite
# matrix using function 'unstructured'
corstr <- "unstr"
corpar <- unstructured(5)
corpar
Y <- rcounts(N=N, margins=margins, mu=mu, phi=phi, omega=omega, psi=psi,
corstr=corstr, corpar=corpar)
cor(Y)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.