rnorta {SimCorMultRes} | R Documentation |
Simulating Random Vectors using the NORTA Method
Description
Utility function to simulate random vectors with predefined marginal distributions via the NORTA method.
Usage
rnorta(R = R, cor.matrix = cor.matrix, distr = distr,
qparameters = NULL)
Arguments
R |
integer indicating the sample size. |
cor.matrix |
matrix indicating the correlation matrix of the multivariate normal distribution employed in the NORTA method. |
distr |
character string vector of length |
qparameters |
list of |
Details
Checks are made to ensure that cor.matrix
is a positive definite
correlation matrix. The positive definiteness of cor.matrix
is
assessed via eigenvalues.
The t
-th character string in distr
indicates the quantile
function of the t
-th marginal distribution. See
Distributions
for the most common distributions. Quantile
functions supported by other R packages are allowed provided that these
packages have been uploaded first. However, note that no checks are made to
ensure that the character strings in distr
correspond to valid names
of quantile functions.
If qparameters = NULL
then the default parameter values for the
quantile functions specified by distr
are used. Otherwise,
qparameters
should be provided as a list of ncol(cor.matrix)
lists such that the t
-th list contains the desired parameter values of
the t
-th quantile function.
Value
Returns R
random vectors of size ncol(cor.matrix)
with
marginal distributions specified by distr
(and qparameters
).
Author(s)
Anestis Touloumis
References
Cario, M. C. and Nelson, B. L. (1997) Modeling and generating random vectors with arbitrary marginal distributions and correlation matrix. Technical Report, Department of Industrial Engineering and Management Sciences, Northwestern University, Evanston, Illinois.
Li, S. T. and Hammond, J. L. (1975) Generation of pseudorandom numbers with specified univariate distributions and correlation coefficients. IEEE Transactions on Systems, Man and Cybernetics 5, 557–561.
Touloumis, A. (2016) Simulating Correlated Binary and Multinomial Responses under Marginal Model Specification: The SimCorMultRes Package. The R Journal 8, 79–91.
Examples
## An example with standard logistic as marginal distribution.
set.seed(1)
sample_size <- 1000
latent_correlation_matrix <- toeplitz(c(1, rep(0.8, 2)))
latent_correlation_matrix
common_marginal_distribution <- rep("qlogis", 3)
simulated_logistic_responses <- rnorta(R = sample_size,
cor.matrix = latent_correlation_matrix,
distr = common_marginal_distribution)
## The following lines exemplify the NORTA method.
set.seed(1)
simulated_normal_responses <- rsmvnorm(R = sample_size,
cor.matrix = latent_correlation_matrix)
norta_simulated <- qlogis(pnorm(simulated_normal_responses))
all(simulated_logistic_responses == norta_simulated)
## Change the marginal distributions to standard normal, standard
## logistic and standard extreme value distribution.
set.seed(1)
different_marginal_distributions <- c("qnorm", "qlogis", "qgumbel")
simulated_logistic_responses <- rnorta(R = sample_size,
cor.matrix = latent_correlation_matrix,
distr = different_marginal_distributions)
cor(simulated_logistic_responses)
colMeans(simulated_logistic_responses)
apply(simulated_logistic_responses, 2, sd)
## Same as above but using parameter values other than the default ones.
set.seed(1)
qpars <- list(c(mean = 1, sd = 9), c(location = 2, scale = 1),
c(loc = 3, scale = 1))
simulated_logistic_responses <- rnorta(R = sample_size,
cor.matrix = latent_correlation_matrix,
distr = different_marginal_distributions, qparameters = qpars)
cor(simulated_logistic_responses)
colMeans(simulated_logistic_responses)
apply(simulated_logistic_responses, 2, sd)