r-pmvnorm错误;西格玛而非协方差矩阵



我有在stata中制作的方差cov矩阵,我想在pmvtnorm中的R中使用,例如:

library(mvtnorm)
library(matrixcalc)
sigma = read.csv(file="c:/Users/../sigma1.csv", header=F, sep=",")
sigma <- as.matrix(sigma) 
is.symmetric.matrix(sigma)
is.positive.definite(sigma)
m = nrow(sigma)
Fn = pmvnorm(lower=rep(-Inf, m), upper=rep(0, m), mean=rep(0, m), sigma=sigma)

当我运行这个序列时,我得到错误消息:

Error in checkmvArgs(lower = lower, upper = upper, mean = mean, corr = corr,  : 
  ‘sigma’ is not a covariance matrix

检查正定性和对称性都显示为真,并且我导入到R的大多数矩阵我已经在类似的stata命令中使用过了,没有问题。。。sigma1.csv:的链接

sigma1.csv 的链接

sigma <- read.csv(file = "data/sigma.csv", header = F, sep = ",")
mat <- matrix(0, nrow = nrow(sigma), ncol = ncol(sigma))
sigma <- as.matrix(sigma)
attributes(sigma) <- attributes(mat)
# str(sigma)
# is.symmetric.matrix(sigma)
# is.positive.definite(sigma)
m <- nrow(sigma)
Fn <- pmvnorm(
  lower = rep(-Inf, m), upper = rep(0, m),
  mean = rep(0, m), sigma = sigma
)
Fn
[1] 6.747892e-29
attr(,"error")
[1] 2.005038e-31
attr(,"msg")
[1] "Normal Completion"

只需确保西格玛是一个矩阵

相关内容

  • 没有找到相关文章

最新更新