gennortaRA: Generates samples with specified input correlation matrix and...

Description Usage Arguments Details Value Note Author(s) References See Also Examples

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

1
2
3
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.

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 processed an combined into a full paramslists which has the same length as invcdfnames, then it will be passed as input arguments to function valid_input_cormat and check_input_cormat and so on. 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.

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.

Note

  1. The inverse cdf functions should have its first argument as a vector.

  2. The inverse cdf functions like qweibull should not use default values because the shape argument does not has a default value.So we should not put its index in invcdfnames into defaultindex.

  3. The function won't accept the invcdfnames all be 'qnorm", you can generate multi-normal varibles by other packages.The function will give you a error message, but if you use a = qnorm, then using new name, the function won't find it, just be careful.

  4. You may get a warning message indicate the Nearest positive definite matrix is used. It happens when your inputs won't generate a positive definite intermediate normal correlation matrix. And in this case, the cor(res) may not very close to cor_matrix.

Author(s)

Po Su

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

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

superdesolator/NORTARA documentation built on May 30, 2019, 8:40 p.m.