Title: | Random Number Generation for Generalized Poisson Distribution |
---|---|
Description: | Generation of univariate and multivariate data that follow the generalized Poisson distribution. The details of the univariate part are explained in Demirtas (2017) <doi: 10.1080/03610918.2014.968725>, and the multivariate part is an extension of the correlated Poisson data generation routine that was introduced in Yahav and Shmueli (2012) <doi: 10.1002/asmb.901>. |
Authors: | Hesen Li, Ruizhe Chen, Hai Nguyen, Yu-Che Chung, Ran Gao, Hakan Demirtas |
Maintainer: | Ruizhe Chen <[email protected]> |
License: | GPL-2 | GPL-3 |
Version: | 1.1.0 |
Built: | 2024-11-25 03:53:21 UTC |
Source: | https://github.com/cran/RNGforGPD |
This package is about generating univariate and multivariate data that follow the generalized
Poisson distribution.There are seven functions in the package: GenUniGpois
and GenMVGpois
are the data generation functions that simulate univariate and multivariate Poisson variables, respectively;
ValidCorrGpois
checks the validity of the values of pairwise correlations;
ComputeCorrGpois
computes the lower and upper correlation bounds of a pairwise correlation between a pair of generalized Poisson variables;
CorrNNGpois
adjusts the target correlation for a pair of generalized Poisson variables;
QuantileGpois
computes the quantile of a given generalized Poisson distribution;
CmatStarGpois
computes an intermediate correlation matrix. To learn more about this package please refer to both the reference manual and the vignette file.
Package: | RNGforGPD |
Type: | Package |
Version: | 1.1.0 |
Date: | 2020-11-17 |
License: | GPL-2 | GPL-3 |
Hesen Li, Ruizhe Chen, Hai Nguyen, Yu-Che Chung, Ran Gao, Hakan Demirtas
Maintainer: Ruizhe Chen <[email protected]>
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.
CmatStarGpois
computes an intermediate correlation matrix that will be used to obtain
the target correlation matrix using the inverse CDF transformation method in GenMVGpois
.
If the intermediate correlation matrix is not positive definite, the nearest positive definite
matrix is used.
CmatStarGpois(corMat, theta.vec, lambda.vec, verbose = TRUE)
CmatStarGpois(corMat, theta.vec, lambda.vec, verbose = TRUE)
corMat |
target correlation matrix. |
theta.vec |
rate parameters in the generalized Poisson distribution. It is assumed that the length of the vector is at least two, and each value has to be a positive number. |
lambda.vec |
dispersion parameters in the generalized Poisson distribution. It is assumed that the length of the vector is at least two. All lambda values have to be less than 1. For lambda < 0, lambda must be greater than or equal to -theta/4. |
verbose |
logical variable that determines whether to display the traces. Default is set to TRUE. |
Intermediate correlation matrix.
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.
lambda.vec = c(-0.2, 0.2, -0.3) theta.vec = c(1, 3, 4) M = c(0.352, 0.265, 0.342) N = diag(3) N[lower.tri(N)] = M TV = N + t(N) diag(TV) = 1 cstar = CmatStarGpois(TV, theta.vec, lambda.vec, verbose = TRUE) cstar
lambda.vec = c(-0.2, 0.2, -0.3) theta.vec = c(1, 3, 4) M = c(0.352, 0.265, 0.342) N = diag(3) N[lower.tri(N)] = M TV = N + t(N) diag(TV) = 1 cstar = CmatStarGpois(TV, theta.vec, lambda.vec, verbose = TRUE) cstar
ComputeCorrGpois
computes the lower and upper correlation bounds of pairwise
correlations between any pair of generalized Poisson variables using the Generate, Sort,
and Correlate (GSC) algorithm described in Demirtas and Hedeker (2011).
ComputeCorrGpois(theta.vec, lambda.vec, verbose = TRUE)
ComputeCorrGpois(theta.vec, lambda.vec, verbose = TRUE)
theta.vec |
rate parameters in the generalized Poisson distribution. It is assumed that the length of the vector is at least two, and each value has to be a positive number. |
lambda.vec |
dispersion parameters in the generalized Poisson distribution. It is assumed that the length of the vector is at least two. All lambda values have to be less than 1. For lambda < 0, lambda must be greater than or equal to -theta/4. |
verbose |
logical variable that determines whether to display the traces. Default is set to TRUE. |
Lower and upper correlation bounds.
Demirtas, H. and Hedeker, D. (2011). A practical way for computing approximate lower and upper correlation bounds. The American Statistician, 65(2), 104-109.
ComputeCorrGpois(c(3, 2, 5, 4), c(0.3, 0.2, 0.5, 0.6), verbose = TRUE) ComputeCorrGpois(c(4, 5), c(-0.45, -0.11), verbose = TRUE)
ComputeCorrGpois(c(3, 2, 5, 4), c(0.3, 0.2, 0.5, 0.6), verbose = TRUE) ComputeCorrGpois(c(4, 5), c(-0.45, -0.11), verbose = TRUE)
CorrNNGpois
adjusts the actual/realized correlation to the target correlation bounds for
a pair of generalized Poisson variables.
CorrNNGpois(theta.vec, lambda.vec, r)
CorrNNGpois(theta.vec, lambda.vec, r)
theta.vec |
rate parameters in the generalized Poisson distribution. It is assumed that the length of the vector is at least two, and each value has to be a positive number. |
lambda.vec |
dispersion parameters in the generalized Poisson distribution. It is assumed that the length of the vector is at least two. All lambda values have to be less than 1. For lambda < 0, lambda must be greater than or equal to -theta/4. |
r |
desired target correlation. |
The adjusted target correlation.
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.
CorrNNGpois(c(0.1, 10), c(0.1, 0.2), 0.5) CorrNNGpois(c(0.1, 10), c(-0.01, -0.02), 0.5) CorrNNGpois(c(4, 2.3), c(-0.32,-0.3), 0.7) CorrNNGpois(c(14, 10), c(-0.8, -0.3), 0.9)
CorrNNGpois(c(0.1, 10), c(0.1, 0.2), 0.5) CorrNNGpois(c(0.1, 10), c(-0.01, -0.02), 0.5) CorrNNGpois(c(4, 2.3), c(-0.32,-0.3), 0.7) CorrNNGpois(c(14, 10), c(-0.8, -0.3), 0.9)
GenMVGpois
simulates a sample of size sample.size from a set of multivariate generalized
Poisson variables with correlation matrix cmat.star and pre-specified marginals.
GenMVGpois( sample.size, no.gpois, cmat.star, theta.vec, lambda.vec, details = TRUE )
GenMVGpois( sample.size, no.gpois, cmat.star, theta.vec, lambda.vec, details = TRUE )
sample.size |
desired sample size (number of rows) for the multivariate generalized Poisson data |
no.gpois |
dimension of the multivariate generalized Poisson distribution. |
cmat.star |
intermediate correlation matrix. |
theta.vec |
rate parameters in the generalized Poisson distribution. It is assumed that the length of the vector is at least two, and each value has to be a positive number. |
lambda.vec |
dispersion parameters in the generalized Poisson distribution. It is assumed that the length of the vector is at least two. All lambda values have to be less than 1. For lambda < 0, lambda must be greater than or equal to -theta/4. |
details |
index of whether to display the specified and empirical values of parameters. Default is set to TRUE. |
Data that follow multivariate generalized Poisson distribution.
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.
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.
sample.size = 10000; no.gpois = 3 lambda.vec = c(-0.2, 0.2, -0.3); theta.vec = c(1, 3, 4) M = c(0.352, 0.265, 0.342); N = diag(3); N[lower.tri(N)] = M TV = N + t(N); diag(TV) = 1 cstar = CmatStarGpois(TV, theta.vec, lambda.vec, verbose = TRUE) data = GenMVGpois(sample.size, no.gpois, cstar, theta.vec, lambda.vec, details = FALSE) apply(data, 2, mean) # empirical means theta.vec/(1 - lambda.vec) # theoretical means apply(data, 2, var) # empirical variances theta.vec/(1 - lambda.vec)^3 # theoretical variances cor(data) # empirical correlation matrix TV # specified correlation matrix
sample.size = 10000; no.gpois = 3 lambda.vec = c(-0.2, 0.2, -0.3); theta.vec = c(1, 3, 4) M = c(0.352, 0.265, 0.342); N = diag(3); N[lower.tri(N)] = M TV = N + t(N); diag(TV) = 1 cstar = CmatStarGpois(TV, theta.vec, lambda.vec, verbose = TRUE) data = GenMVGpois(sample.size, no.gpois, cstar, theta.vec, lambda.vec, details = FALSE) apply(data, 2, mean) # empirical means theta.vec/(1 - lambda.vec) # theoretical means apply(data, 2, var) # empirical variances theta.vec/(1 - lambda.vec)^3 # theoretical variances cor(data) # empirical correlation matrix TV # specified correlation matrix
GenUniGpois
generates univariate random variables from the generalized Poisson
distribution using one of the five methods including Inversion, Branching, Normal-Approximation, Build-Up, and Chop-Down.
GenUniGpois(theta, lambda, n, details = TRUE, method)
GenUniGpois(theta, lambda, n, details = TRUE, method)
theta |
the rate parameter in the generalized Poisson distribution. It has to be a positive number. |
lambda |
the dispersion parameter in the generalized Poisson distribution. It has to be less than 1. For lambda < 0, lambda must be greater than or equal to -theta/4. |
n |
number of data points that is to be generated. |
details |
index to indicate whether to print out the estimates of parameters. Default is set to TRUE. |
method |
index to specify one of the five methods for generating univariate GPD variable: "Inversion", "Branching", "Normal-Approximation", "Build-Up" or "Chop-Down". |
All five methods come from Demirtas (2017). When lambda equals to 0, it is the ordinary Poisson distribution, so there is no need to specify the method. "Branching" only works when lambda is positive. When theta is less than 10, the "Normal-Approximation" may not be reliable.
A list that includes generated data, specified and empirical values of theta and lambda, and the specified method.
Demirtas, H. (2017). On accurate and precise generation of generalized Poisson variates. Communications in Statistics - Simulation and Computation, 46(1), 489-499.
GenUniGpois(5, -0.4, 100, method = "Inversion") GenUniGpois(2, 0.9, 100, method = "Branching") GenUniGpois(12, 0.5, 100, method = "Normal-Approximation") data <- GenUniGpois(3, 0.9, 10000, method = "Build-Up", details = FALSE) data <- GenUniGpois(10, 0.4, 10, method = "Chop-Down", details = FALSE)
GenUniGpois(5, -0.4, 100, method = "Inversion") GenUniGpois(2, 0.9, 100, method = "Branching") GenUniGpois(12, 0.5, 100, method = "Normal-Approximation") data <- GenUniGpois(3, 0.9, 10000, method = "Build-Up", details = FALSE) data <- GenUniGpois(10, 0.4, 10, method = "Chop-Down", details = FALSE)
QuantileGpois
computes the quantile for the generalized Poisson distribution
for specified values of percentile, rate, and dispersion parameters.
QuantileGpois(p, theta, lambda, details = FALSE)
QuantileGpois(p, theta, lambda, details = FALSE)
p |
percentile of the generalized Poisson distribution, p should be between 0 and 1. |
theta |
the rate parameter in the generalized Poisson distribution. It has to be a positive number. |
lambda |
the dispersion parameter in the generalized Poisson distribution. It has to be less than 1. For lambda < 0, lambda must be greater than or equal to -theta/4. |
details |
index of whether to display the probabilities and cumulative probabilities. Default is set to FALSE. |
Quantile of the specified distribution if the parameter details is set to FALSE, detailed information of probabilities and cumulative probabilities otherwise.
Demirtas, H. (2017). On accurate and precise generation of generalized Poisson variates. Communications in Statistics - Simulation and Computation, 46(1), 489-499.
QuantileGpois(0.98, 1, -0.2, details = TRUE) QuantileGpois(0.80, 2, 0.025, details = FALSE)
QuantileGpois(0.98, 1, -0.2, details = TRUE) QuantileGpois(0.80, 2, 0.025, details = FALSE)
ValidCorrGpois
checks the validity of the values of pairwise correlations including
positive definiteness, symmetry, and correctness of the dimensions.
ValidCorrGpois(corMat, theta.vec, lambda.vec, verbose = TRUE)
ValidCorrGpois(corMat, theta.vec, lambda.vec, verbose = TRUE)
corMat |
a positive definite target correlation matrix whose entries are within the valid correlation bounds. |
theta.vec |
rate parameters in the generalized Poisson distribution. It is assumed that the length of the vector is at least two, and each value has to be a positive number. |
lambda.vec |
dispersion parameters in the generalized Poisson distribution. It is assumed that the length of the vector is at least two. All lambda values have to be less than 1. For lambda < 0, lambda must be greater than or equal to -theta/4. |
verbose |
logical variable that determines whether to display the traces. Default is set to TRUE. |
TRUE or FALSE.
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. and Hedeker, D. (2011). A practical way for computing approximate lower and upper correlation bounds. The American Statistician, 65(2), 104-109.
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) ValidCorrGpois(matrix(c(1, 0.9, 0.9, 1), byrow = TRUE, nrow = 2), c(3, 2), c(-0.3, -0.2), verbose = TRUE)
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) ValidCorrGpois(matrix(c(1, 0.9, 0.9, 1), byrow = TRUE, nrow = 2), c(3, 2), c(-0.3, -0.2), verbose = TRUE)