Package 'RNGforGPD'

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

Help Index


Generates Univariate and Multivariate Generalized Poisson Variables

Description

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.

Details

Package: RNGforGPD
Type: Package
Version: 1.1.0
Date: 2020-11-17
License: GPL-2 | GPL-3

Author(s)

Hesen Li, Ruizhe Chen, Hai Nguyen, Yu-Che Chung, Ran Gao, Hakan Demirtas

Maintainer: Ruizhe Chen <[email protected]>

References

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.


Computes Intermediate Correlation Matrix

Description

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.

Usage

CmatStarGpois(corMat, theta.vec, lambda.vec, verbose = TRUE)

Arguments

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.

Value

Intermediate correlation matrix.

References

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.

Examples

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

Computes the Lower and Upper Correlation Bounds

Description

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).

Usage

ComputeCorrGpois(theta.vec, lambda.vec, verbose = TRUE)

Arguments

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.

Value

Lower and upper correlation bounds.

References

Demirtas, H. and Hedeker, D. (2011). A practical way for computing approximate lower and upper correlation bounds. The American Statistician, 65(2), 104-109.

Examples

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)

Adjusts the Target Correlation

Description

CorrNNGpois adjusts the actual/realized correlation to the target correlation bounds for a pair of generalized Poisson variables.

Usage

CorrNNGpois(theta.vec, lambda.vec, r)

Arguments

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.

Value

The adjusted target correlation.

References

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.

Examples

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)

Generates Data from Multivariate Generalized Poisson Distribution

Description

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.

Usage

GenMVGpois(
  sample.size,
  no.gpois,
  cmat.star,
  theta.vec,
  lambda.vec,
  details = TRUE
)

Arguments

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.

Value

Data that follow multivariate generalized Poisson distribution.

References

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.

Examples

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

Generates Univariate Generalized Poisson Variates

Description

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.

Usage

GenUniGpois(theta, lambda, n, details = TRUE, method)

Arguments

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".

Details

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.

Value

A list that includes generated data, specified and empirical values of theta and lambda, and the specified method.

References

Demirtas, H. (2017). On accurate and precise generation of generalized Poisson variates. Communications in Statistics - Simulation and Computation, 46(1), 489-499.

Examples

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)

Computes Quantiles

Description

QuantileGpois computes the quantile for the generalized Poisson distribution for specified values of percentile, rate, and dispersion parameters.

Usage

QuantileGpois(p, theta, lambda, details = FALSE)

Arguments

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.

Value

Quantile of the specified distribution if the parameter details is set to FALSE, detailed information of probabilities and cumulative probabilities otherwise.

References

Demirtas, H. (2017). On accurate and precise generation of generalized Poisson variates. Communications in Statistics - Simulation and Computation, 46(1), 489-499.

Examples

QuantileGpois(0.98, 1, -0.2, details = TRUE)
 QuantileGpois(0.80, 2, 0.025, details = FALSE)

Validates Pairwise Correlations

Description

ValidCorrGpois checks the validity of the values of pairwise correlations including positive definiteness, symmetry, and correctness of the dimensions.

Usage

ValidCorrGpois(corMat, theta.vec, lambda.vec, verbose = TRUE)

Arguments

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.

Value

TRUE or FALSE.

References

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.

Examples

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)