I'm trying to simulate 2 X 2 data that would yield a relatively strong negative correlation.
I'm using the
GenOrd and the
ordsample() function as follows below. The
ordsample() function requires that you specify (a) the sample size you'd like to simulate, (b) the marginal probabilities as a list that is the length of the number of variables being simulated (in this case 2), and (c) the target correlation matrix (i.e., called sigma in the
library(GenOrd) # Specify sample size N N <- 40 # Marginal distribution for two variables marginal <- list(c(.5), c(.5)) # Correlation (Pearson) matrix as target for simulated relationship between variables Sigma <- matrix(c(1.0, -.71, -.71, 1.0), 2, 2, byrow=TRUE) # Generate a sample of the categorical variables with specified parameters m <- ordsample(N, marginal, Sigma)
However, I'm getting the following error whenever I input a correlation larger than
Error in contord(list(marginal[[q]], marginal[[r]]), matrix(c(1, Sigma[q, : Correlation matrix not valid!
I'm clearly specifying something untenable somewhere - but I don't know what it is. Specifying any value between
+1.00 works fine such that it generates two variables with the correlation requested, given sampling error.
It's just values below
-.70 that crash the script.
I'm thinking I'm misunderstanding the specification of the marginal distribution, but am confused because it works for values that are not less than
Here is the help info for the marginal argument in the
ordsample() function (R documentation):
a list of k elements, where k is the number of variables. The i-th element of marginal is the vector of the cumulative probabilities defining the marginal distribution of the i-th component of the multivariate variable. If the i-th component can take k_i values, the i-th element of marginal will contain k_i-1 probabilities (the k_i-th is obviously 1 and shall not be included).