R coda "The leading minor of order 3 is not positive definite"



有人能向我解释一下这个错误消息的含义吗?

我有一个名为hitandrun的MCMC采样方法(在未完成的包中https://github.com/davidkane9/kmatching)这给了我一个矩阵列表,其中有列作为单个样本的多变量输出,这里有一个例子:

> A = matrix(1, ncol = 3)
> b = 1
> ## gives me solutions of Ax = b (a.k.a x + y + z = 1)
> h = hitandrun(A,b, n=10, chains = 2)
> h
[[1]]
          [,1]      [,2]      [,3]      [,4]      [,5]       [,6]      [,7]      [,8]      [,9]
[1,] 0.1804431 0.3340590 0.4195820 0.2061222 0.3591085 0.09984353 0.6707110 0.3926639 0.1283919
[2,] 0.6135745 0.4256909 0.3619727 0.2918238 0.5057426 0.81919629 0.2368842 0.1178713 0.2666737
[3,] 0.2059824 0.2402501 0.2184453 0.5020541 0.1351489 0.08096018 0.0924048 0.4894647 0.6049344
         [,10]
[1,] 0.1322112
[2,] 0.4736057
[3,] 0.3941831
[[2]]
           [,1]      [,2]      [,3]      [,4]       [,5]       [,6]      [,7]       [,8]      [,9]
[1,] 0.32883534 0.1284182 0.1735151 0.2005726 0.94511422 0.61653717 0.5130324 0.33228224 0.2088865
[2,] 0.65868549 0.3066952 0.5182009 0.3065610 0.01214334 0.07007548 0.1191157 0.01137002 0.3311197
[3,] 0.01247917 0.5648866 0.3082840 0.4928664 0.04274244 0.31338735 0.3678519 0.65634774 0.4599938
          [,10]
[1,] 0.61412223
[2,] 0.32289039
[3,] 0.06298738

我想看看Gelman-Rubin对这些数据的诊断,看看我需要对它进行多少精简,但当我把它放在函数中时,我得到了一个模糊的错误,我不知道它意味着什么。这是:

> mclist = lapply(h, function(x) mcmc(t(x), thin = 5))
> gelman.diag(mclist)
Error in chol.default(W) : 
  the leading minor of order 1 is not positive definite

(我想现在是第1顺序,但之前是第3顺序)SO上有密码专家吗?我试过调试它,但它导致我找到了一个内部函数La_chol,我不知道该怎么办。

获得Gelman-Rubin诊断的多变量估计似乎有问题。设置multivariate = FALSE可以解决问题,并为每个变量输出单个变量估计值。然而,由于我试图解决的问题的性质,我的大多数变量都是相关的,所以我想知道(也希望)这会让我高估诊断结果。

我最近在我的模型中遇到了这个问题——我发现我的矩阵不是对称的,因为它是一个不对称的GRM矩阵。我用这个函数使它对称,问题就解决了(取自创建对称矩阵的最有效方法):

symmetrise <- function(mat){   rowscols <- which(lower.tri(mat), arr.ind=TRUE)   sparseMatrix(i=rowscols[,1], 
               j=rowscols[,2], 
               x=mat[lower.tri(mat)], 
               symmetric=TRUE, 
               dims=c(nrow(mat),ncol(mat)) )   }

这将左下部分复制到右上部分。

相关内容

最新更新