我在stata中制作了variance-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 i的大多数矩阵已经在类似的stata命令中使用而没有问题... sigma1.csv的链接:
答案 0 :(得分:0)
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"
只需确保sigma是矩阵