0

I'm trying to simulate 2 X 2 data that would yield a relatively strong negative phi coefficients.

I'm using the library GenOrd as follows:

library(GenOrd)

# Specify sample size N
N <- 40

# Marginal distribution
marginal <- list(c(.5), c(.5))

# Matrix
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 -.70.

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.

Help appreciated.

4

2 回答 2

0

我不确定“为什么”,但是,我发现模拟 2 X 2 数据没有问题,使用包中的generate.binary()函数会产生相对较强的负相关MultiOrd

例如,以下代码将适用于所有相关输入。该generate.binary()函数的文档表明指定的矩阵被解释为四色相关矩阵。

library(MultiOrd)

# Specify sample size N
N <- 40

# Marginal distribution for two variables as a vector for MultiOrd rather than a list
marginal <- c(.5, .5)

# Correlation (tetrachoric) 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 <- generate.binary(40, marginal, Sigma)
于 2018-04-16T22:32:53.530 回答
0

我将尝试将其作为编码问题来回答。错误指向包发现问题开始的位置:在您的 Sigma 入口处。鉴于您的边际分布,您的 corr 中有 -.71。矩阵超出范围,包裹警告您这一点。您可以通过更改 Sigma 中的符号来看到这一点:

Sigma <- matrix(c(1.0, .71, .71, 1.0), 2, 2, byrow=TRUE)
m <- ordsample(N, marginal, Sigma)
> m
       [,1] [,2]
  [1,]    1    1
  [2,]    1    2
  ....

至于为什么 -.71 无效,您可能希望将该统计问题定向到Cross Validated以获得简洁的答案。

于 2018-04-16T16:54:36.803 回答