【问题标题】:Correlated binary variables with heterogeneous marginal probabilities具有异质边际概率的相关二元变量
【发布时间】:2013-09-30 09:37:09
【问题描述】:

我想创建 50 个相关的二元变量,其中不同的变量具有不同的边际概率:

首先我创建我的相关矩阵:

cor.mat=matrix(.9,nrow=50,ncol=50)
cor.mat[,9:11]=.1 
cor.mat[9:11,]=.1  
diag(cor.mat)=1 

然后我使用 'rmvbin' 生成数据:

library(bindata)
marg=rep(c(0.4,0.6),c(25,25))
a<-rmvbin(100, margprob=marg, bincorr=cor.mat)

但是,我收到以下错误:

Error in commonprob2sigma(commonprob, simulvals) : 
  Matrix commonprob not admissible.

我也试过用 commonprob 代替 margprob:

common=rep(c(0.4,0.6),c(25,25))
a<-rmvbin(100, commonprob=common, bincorr=cor.mat)

但我明白了:

Error in if (n != dim(commonprob)[2]) { : argument is of length zero
> 

我做错了什么?

【问题讨论】:

    标签: r correlation


    【解决方案1】:

    将“.9”更改为“.4”或更低

    cor.mat=matrix(0.4, nrow=50, ncol=50)
    cor.mat[,9:11]=.1 
    cor.mat[9:11,]=.1  
    diag(cor.mat)=1 
    

    现在应该运行:

    library(bindata)
    marg=rep(c(0.4,0.6),c(25,25))
    a<-rmvbin(100, margprob=marg, bincorr=cor.mat)
    

    第二个错误:

    1。 commonprob 需要是一个矩阵。

    2。只能指定参数commonprobbincorrsigma 之一。默认是不相关的组件。

    m <- cbind(c(1/2,1/5,1/6),c(1/5,1/2,1/6),c(1/6,1/6,1/2))
    m
    check.commonprob(m)
    rmvbin(10,commonprob=m)
    ## or
    ## same as the example above, but faster if the same probabilities are
    ## used repeatedly (commonprob2sigma rather slow)
    sigma <- commonprob2sigma(m)
    rmvbin(10,margprob=diag(m),sigma=sigma)
    

    来源:rmvbin 帮助文件中的示例

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-26
      • 1970-01-01
      • 2017-10-17
      • 2023-03-03
      • 2011-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多