The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
This vignette file conveys certain ideas behind the generalized Poisson distribution and some examples of applying the functions in this package (RNGforGPD).
GenUniGpois
We choose different data generation methods according to different parameter values because restrictions apply when the rate parameter or the dispersion parameter of the generalized Poisson is within certain ranges. For example, the normal approximation method does not work well for theta < 10.
GenUniGpois(2, 0.9, 5000, method = "Branching")
#> [1] "Specified theta is 2, empirical theta is 2.048134, specified lambda is 0.9, empirical lambda is 0.903048."
GenUniGpois(5, -0.4, 5000, method = "Inversion")
#> [1] "Specified theta is 5, empirical theta is 5.034962, specified lambda is -0.4, empirical lambda is -0.405001."
GenUniGpois(12, 0.5, 5000, method = "Normal-Approximation")
#> [1] "Specified theta is 12, empirical theta is 12.258253, specified lambda is 0.5, empirical lambda is 0.49197."
= GenUniGpois(3, 0.9, 10, method = "Build-Up", details = FALSE)
data
data#> $data
#> [1] 9 27 26 4 26 3 0 4 63 1
#>
#> $specified.theta
#> [1] 3
#>
#> $empirical.theta
#> [1] 3.329447
#>
#> $specified.lambda
#> [1] 0.9
#>
#> $empirical.lambda
#> [1] 0.795739
#>
#> $method
#> [1] "Build-Up"
= GenUniGpois(10, 0.4, 10, method = "Chop-Down", details = FALSE)
data
data#> $data
#> [1] 30 38 10 9 13 16 22 32 29 9
#>
#> $specified.theta
#> [1] 10
#>
#> $empirical.theta
#> [1] 8.767553
#>
#> $specified.lambda
#> [1] 0.4
#>
#> $empirical.lambda
#> [1] 0.578483
#>
#> $method
#> [1] "Chop-Down"
ComputeCorrGpois
From a practical perspective, correlation bounds among variables are typically narrower than between −1 and 1 (the theoretical maximum and minimum correlation bounds) because different correlation upper and lower bounds may be imposed by the marginal distributions. A simple sorting technique can be used to obtain approximate correlation bounds and this approach works regardless of the data type or the distributional assumption (Demirtas, Hedeker 2011).
Using the sorting technique, we wrote the function ValidCorrGpois
that computes the lower and upper correlation bounds between a pair of generalized Poisson variables. Besides, this function serves as an integral part of the ValidCorrGpois
function, which examines whether values of pairwise correlation matrices fall within the limits imposed by the marginal distributions.
set.seed(3406)
ComputeCorrGpois(c(3, 2, 5, 4), c(0.3, 0.2, 0.5, 0.6), verbose = FALSE)
#> $min
#> [,1] [,2] [,3] [,4]
#> [1,] NA -0.8456559 -0.8514953 -0.8069000
#> [2,] -0.8456559 NA -0.8361494 -0.7897626
#> [3,] -0.8514953 -0.8361494 NA -0.7978223
#> [4,] -0.8069000 -0.7897626 -0.7978223 NA
#>
#> $max
#> [,1] [,2] [,3] [,4]
#> [1,] NA 0.9837440 0.9935450 0.9873062
#> [2,] 0.9837440 NA 0.9867560 0.9818077
#> [3,] 0.9935450 0.9867560 NA 0.9948798
#> [4,] 0.9873062 0.9818077 0.9948798 NA
ComputeCorrGpois(c(4, 5), c(-0.45, -0.11), verbose = FALSE)
#> $min
#> [,1] [,2]
#> [1,] NA -0.9487209
#> [2,] -0.9487209 NA
#>
#> $max
#> [,1] [,2]
#> [1,] NA 0.9527313
#> [2,] 0.9527313 NA
ValidCorrGpois
This function checks the required conditions of the values of pairwise correlations, which include positive definiteness, symmetry, correctness of dimensions, and whether the correlations fall within the correlation bounds. ValidCorrGpois
ensures that the supplied correlation matrix is valid for simulating multivariate generalized Poisson distributions using GenMVGpois
.
ValidCorrGpois(matrix(c(1, 0.9, 0.9, 1), byrow = TRUE, nrow = 2), c(0.5, 0.5), c(0.1, 0.105), verbose = TRUE)
#> ..
#> ..
#> ...
#> [1] TRUE
ValidCorrGpois(matrix(c(1, 0.9, 0.9, 1), byrow = TRUE, nrow = 2), c(3, 2), c(-0.3, -0.2), verbose = TRUE)
#> ..
#> ..
#> ...
#> [1] TRUE
QuantileGpois
This function computes quantiles for generalized Poisson distribution. We guarantee that there will be at least five classes if lambda is negative by forcing \(m \geq 4\).
QuantileGpois(0.98, 1, -0.2, details = TRUE)
#> x = 0, P(X = x) = 0.3678794, P(X <= x) = 0.3678794
#> x = 1, P(X = x) = 0.449329, P(X <= x) = 0.8172084
#> x = 2, P(X = x) = 0.1646435, P(X <= x) = 0.9818519
#> When lambda is negative, we need to account for truncation error. The adjusted CDF are: 0.3746792 0.8323133 1
#> [1] 2
QuantileGpois(0.80, 2, 0.025, details = FALSE)
#> [1] 3
CorrNNGpois
This function applies the method proposed by Yahav, Shmueli 2011. They found that the relationship between the desired correlation matrix and the actual correlation matrix of a generalized Poisson distribution can be approximated by an exponential function. Following their simple and empirical approximation method we can correct our actual correlation matrix to the desired correlation matrix. Note that some desired correlations might be infeasible.
set.seed(3406)
CorrNNGpois(c(0.1,10), c(0.1, 0.2),0.5)
#> [1] 0.8016437
= c(-0.2, 0.2, -0.3)
lambda.vec = c(1, 3, 4)
theta.vec = c(0.352, 0.265, 0.342)
M = diag(3)
N lower.tri(N)] = M
N[= N + t(N)
TV diag(TV) = 1
= CmatStarGpois(TV, theta.vec, lambda.vec, verbose = TRUE)
cstar #> ......
#> ......
#> ......
#> ...
cstar#> [,1] [,2] [,3]
#> [1,] 1.0000000 0.3943785 0.2946171
#> [2,] 0.3943785 1.0000000 0.3601862
#> [3,] 0.2946171 0.3601862 1.0000000
GenMVGpois
GenMVGPois
(the engine function) is the most important function in this package (RNGforGPD). It depends on all the other functions in this package and three external packages: mvtnorm, corpcor, and VGAM. The major difference between the univariate generalized Poisson variables generating function and the multivariate one is the consideration of pairwise correlations between variables. These correlations can be verified using ValidCorrGpois
and corrected by CorrNNGpois
.
set.seed(3406)
= c(-0.2, 0.2, -0.3)
lambda.vec = c(1, 3, 4)
theta.vec = c(0.352, 0.265, 0.342)
M = diag(3)
N lower.tri(N)] = M
N[= N + t(N)
TV diag(TV) = 1
= CmatStarGpois(TV, theta.vec, lambda.vec, verbose = TRUE)
cstar #> ......
#> ......
#> ......
#> ...
= 10000; no.gpois = 3
sample.size = GenMVGpois(sample.size, no.gpois, cstar, theta.vec, lambda.vec, details = FALSE)
data apply(data, 2, mean) # empirical means
#> [1] 0.8242 3.7577 3.0820
/ (1 - lambda.vec) # theoretical means
theta.vec #> [1] 0.8333333 3.7500000 3.0769231
apply(data, 2, var) # empirical variances
#> [1] 0.5871531 5.9281835 1.8334593
/ (1 - lambda.vec)^3 # theoretical variances
theta.vec #> [1] 0.5787037 5.8593750 1.8206645
cor(data) # empirical correlation matrix
#> [,1] [,2] [,3]
#> [1,] 1.0000000 0.3552436 0.2713530
#> [2,] 0.3552436 1.0000000 0.3413526
#> [3,] 0.2713530 0.3413526 1.0000000
# specified correlation matrix
TV #> [,1] [,2] [,3]
#> [1,] 1.000 0.352 0.265
#> [2,] 0.352 1.000 0.342
#> [3,] 0.265 0.342 1.000
Amatya, A. and Demirtas, H. (2015). Simultaneous generation of multivariate mixed data with Poisson and normal marginals. Journal of Statistical Computation and Simulation, 85(15), 3129-3139.
Amatya, A. and Demirtas, H. (2017). PoisNor: An R package for generation of multivariate data with Poisson and normal marginals. Communications in Statistics - Simulation and Computation, 46(3), 2241-2253.
Demirtas, H. (2017). On accurate and precise generation of generalized Poisson variates. Communications in Statistics - Simulation and Computation, 46(1), 489-499.
Demirtas, H. and Hedeker, D. (2011). A practical way for computing approximate lower and upper correlation bounds. The American Statistician, 65(2), 104-109.
Yahav, I. and Shmueli, G. (2012). On generating multivariate Poisson data in management science applications. Applied Stochastic Models in Business and Industry, 28(1), 91-102.
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.