[R-meta] Non-positive definite variance-covariance matrix

James Pustejovsky jepu@to @end|ng |rom gm@||@com
Tue Aug 27 17:01:03 CEST 2019


Erik,

Please keep the listserv cc'd in your replies.

How is the example that you sent formatted? If I read it in as a matrix,
then it does not appear to be a feasible covariance matrix because the
off-diagonal entries are all larger than the diagonals. Example below.

James

V <- matrix(c(.00825680, .00994727,
              .00959348, .01321687,
              .01290479, .01133872,
              .00994727, .00825568,
              .00937481, .01966662,
              .01270540, .01118369,
              .00959348, .00937481,
              .00824400, .01269867,
              .01964920, .01392237,
              .01321687, .01966662,
              .01269867, .00826429,
              .00938956, .03499702,
              .01290479, .01270540,
              .01964920, .00938956,
              .00826134, .01393701,
              .01133872, .01118369,
              .01392237, .03499702,
              .01393701, .00818451), 6, 6)

cov2cor(V)


On Sat, Aug 24, 2019 at 3:26 PM E. van der Meulen <E.vdrMeulen_1 using uvt.nl>
wrote:

> Dear James (and others),
>
> Thank you for your assistance. Especially using the matrixcalc package, it
> resolved the problem so far that the problem appears to be related to the
> proces I used to formulate by matrices, and probably not content wise. This
> because all matrices with 6 dimensions were off, and none of the others.
> However, when I check these matrices I simply can't see what is wrong with
> them. The data is correctly sorted by ID. I tried using sapply, but this
> did not change much. Under here is an example matrix with 6 dimensions,
> does anybody else see why it is not positive definite?
>
>
> .00825680 .00994727 .00959348 .01321687 .01290479 .01133872
> .00994727 .00825568 .00937481 .01966662 .01270540 .01118369
> .00959348 .00937481 .00824400 .01269867 .01964920 .01392237
> .01321687 .01966662 .01269867 .00826429 .00938956 .03499702
> .01290479 .01270540 .01964920 .00938956 .00826134 .01393701
> .01133872 .01118369 .01392237 .03499702 .01393701 .00818451
>
> Thanks again!
>
> Kind regards,
>
> Erik
> ------------------------------
> *Van:* James Pustejovsky [jepusto using gmail.com]
> *Verzonden:* maandag 19 augustus 2019 3:39
> *Aan:* E. van der Meulen
> *CC:* r-sig-meta-analysis using r-project.org
> *Onderwerp:* Re: [R-meta] Non-positive definite variance-covariance matrix
>
> Erik,
>
> A few possibilities occur to me:
> 1) Is the data frame sorted by ID? If not, then the split-calculate-bldiag
> calculations will return a matrix that is not in the same order as the
> original data frame.
> 2) Why do you use sapply rather than lapply in creating the
> remove_zero_mat object? Perhaps it makes no difference.
> 3) To further isolate the problem, it might be useful to check for
> positive-definiteness of the component covariance matrices. The matrixcalc
> package provides a handy function for doing so:
> library(matrixcalc)
> lapply(remove_zero_mat, is.positive.definite)
>
> James
>
> On Sun, Aug 18, 2019 at 12:42 PM E. van der Meulen <E.vdrMeulen_1 using uvt.nl>
> wrote:
>
>> Dear all,
>>
>> I am trying to run a multivariate meta-analysis for a review. For this
>> review I included multiple effect sizes from single studies into my
>> analysis. The number of effect sizes from a single study range from 1 to
>> 36. To account for covariance between effect sizes extracted from the same
>> sample, I created a variance-covariance matrix for each study with multiple
>> effect sizes (which is the majority). I am using a syntax I have used
>> before, in the previous attempt it worked perfectly. However, in this new
>> study I am continuously ending up with the same error message:
>>
>> Error in .ll.rma.mv(opt.res$par, reml = reml, Y = Y, M = V, A = A, X.fit
>> = X,  :
>>   Final variance-covariance matrix not positive definite.
>> In addition: Warning message:
>> In rma.mv(dat$ESP, V, mods = ~1, random = list(~1 | id/nummer),  :
>>   'V' appears to be not positive definite.
>>
>> In which V is the variance-covariance matrix I made. As far as I know an
>> error due to 'non-positive definite matrices' can occur in cases in which
>> negative or exactly zero eigenvalues appear anywhere in any of the
>> matrices. As far as I can determine this is not the case. What could be the
>> problem? If it helps this is full the syntax:
>>
>>
>> library(metafor) # For meta-analysis
>> library(clubSandwich) # For cluster-robust variance-covariance matrix
>> library(foreign)
>>
>> dat<- read.spss("TEST.sav", to.data.frame= TRUE)
>>
>> list_mat<- split(dat[ ,c("v1p", "v2p", "v3p", "v4p", "v5p", "v6p")],
>> dat$id)
>>
>> remove_zero<- lapply(list_mat, function(x) x[ ,colSums(x) != 0])
>>
>> remove_zero_mat<- sapply(remove_zero, as.matrix)
>>
>> V<- bldiag(remove_zero_mat)
>>
>> PTSD<- rma.mv(dat$ESP, V, mods= ~ 1, random= list(~ 1| id/nummer),
>> data=dat)
>>
>> summary (PTSD,digits=3)
>>
>> In which:
>> V = the covariance-variance matrices
>> ESP = the effect size
>> v1p to v6p = dimensions of the variance-covariance matrices
>>
>> Thanks in advance.
>>
>> Kind regards,
>>
>> Erik van der Meulen
>>
>>
>>
>>
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-meta-analysis mailing list
>> R-sig-meta-analysis using r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis
>>
>

	[[alternative HTML version deleted]]



More information about the R-sig-meta-analysis mailing list