Learn R Programming

NORTARA (version 1.0.0)

genNORTARA: Generates samples with specified input correlation matrix and marginal distributions.

Description

The function simulates a data set with specified input correlation matrix cor_matrix and pre-specified marignals invcdfnames using bounding RA and NORTA methods.

Usage

genNORTARA(n, cor_matrix, invcdfnames, paramslists = NULL, defaultindex = NULL, m1 = 60, c1 = 2, c2 = 1, delta1 = 1e-04, sigma0 = 0.01, epsilon = 1e+50, maxit = 1000)

Arguments

n
Number of observations.
cor_matrix
specified input correlation matrix.
invcdfnames
A character sequence of the marginals' inverse cdf(cumulative distribution function) names.
paramslists
A list contains lists of params of the marginals excluded the index(es) in defaultindex meanwhile as the same order as invcdfnames, the names of the arguments of the inner lists should keep the same with the function arguments matching rules with the arguments of invcdfnames functions.
defaultindex
The index number sequence which indicates the corresponding inverse cdfs use the default argument values.
m1
The initial sample size.
c1
The sample-size multiplier(c1>1).
c2
The step-size multiplier(c2>0).
delta1
The initial step size(detla1>0).
sigma0
The standard error tolerance.
epsilon
The initial error tolerance.
maxit
The maximum number of numerical searches.

Value

A matrix of size n * (ncol(cor_matrix)) from pre-specified marignals which also have an asymptotically correlation matrix to specified input correlation matrix cor_matrix.

Details

The function simulates a date set with varibles from arbitrary(continuous or discrete) marginal distributions which have a correlation matrix cor_matrix. The pre-specified marignals are described by invcdfnames,paramslists,defaultindex, the later two arguments will be combined into a full paramslists which has the same length as invcdfnames. The function uses result of the function BoundingRA which is an implementation of a specific RA(Retrospective Approximation) algorithm called bounding RA. With the result, the function uses the NORTA(NORmal To Anything) approach which generates a standard normal random vector and then transforms it into a random vector with specified marginal to generates the wanted samples.

References

Huifen Chen, (2001) Initialization for NORTA: Generation of Random Vectors with Specified Marginals and Correlations. INFORMS Journal on Computing 13(4):312-331.'

See Also

BoundingRA, valid_input_cormat, check_input_cormat

Examples

Run this code
## Not run: 
# invcdfnames <- c("qt","qpois","qnorm","qweibull","qunif")
# # The following usage :
# # a <- qt; b <- qnorm; f <- stats::qweibull (It is also the way you can use functions
# # from other packages)
# # invcdfnames <- c("a","qpois","b","f","qunif") will also be ok!
# paramslists <- list(
#                m1 = list(df = 3),
#                m2 = list(lambda = 5),
#                m4 = list(shape = 1)
#                  )
# defaultindex <- c(3,5)
# #It means the 3rd and 5th invcdf should use its default arguments.
# #That means qnorm using mean = 0, sd = 1, qunif using min =0 ,max =1 and so on.
# cor_matrix <- matrix(c(1.0,-0.4,0.1,0.7,-0.2,-0.4,
#                       1.0,0.4,0.4,0.9,0.1,0.4,1.0,
#                       0.5,0.5,0.7, 0.4,0.5,1.0,
#                       0.7,-0.2,0.9,0.5,0.7,1.0),5,5)
# 
# res <- genNORTARA(10000,cor_matrix,invcdfnames,paramslists,defaultindex)
# #May get warning message indicating nearest positive definite is used,It's
# #normal but the cor(res) may not very close to cor_matrix.
# cor(res)
# invcdfnames <- c("qt","qpois","qnorm")
# paramslists <- list(
#                m1 = list(df = 3),
#                m2 = list(lambda = 5)
#                  )
# defaultindex <- 3
# cor_matrix <- matrix(c(1,0.5,-0.3,0.5,1,0.4,-0.3,0.4,1), 3)
# res <- genNORTARA(10000,cor_matrix,invcdfnames,paramslists,defaultindex)
# cor(res) #This time cor(res) may very close to cor_matrix.
# ## End(Not run)

Run the code above in your browser using DataLab