not positive definite and NA errors

4 replies [Last post]
yahmed's picture
Offline
Joined: 06/24/2014

Hi Mike,

I am currently trying to fit a multivariate metaSEM model. I am getting a non-positive definite matrix when fitting a random effects model, and this is likely expected due to a lot missing data in the attached datafile. Would you agree that this is the reason behind the non-positive definite error? Please also note that I tried running the model with fewer studies that provided more data (the number of studies went from 108 to 44) but the errors were the same.

Additionally, I can’t seem to fit the fixed effects model. Given that I am new to R, I was hoping you could look at my code below and let me know how you have handled “NA” or missing values in metaSEM. Below is all the code I have used, as well as the errors.

Thanks in advance,

Yusra

#importing the dataset with a matrix for each sample
my.full <- readFullMat("T:/matrix.dat")

#creating an object with the sample sizes
n <- ("100 100 100 100 100 100 241 45 70 122 119 119 447 56 41 38 103 57 192 105 62 48 56 123 56 123 121 103 300 128 106 20 17 75 10 19 21 492 153 107 71 123 23 15 14 22 131 727 30 297 60 125 37 140 88 182 735 45 300 300 77 136 162 65 166 60 75 87 59 57 97 129 242 83 54 78 75 30 60 105 65 64 92 101 120 88 144 120 464 104 296 120 121 95 76 60 256 251 317 52 622 80 297 171 98 354 690 88")

#random effects model
> random.full <- tssem1(my.full, n, method = "REM", RE.type="Symm", RE.startvalues=0.1, RE.lbound=1e-10, I2="I2q", model.name=NULL,suppressWarnings=TRUE)
Error in function (x, n, cor.analysis = TRUE, dropNA = FALSE, as.matrix = TRUE, :
x is not positive definite!

#fixed effects model
> fixed1 <- tssem1(my.full$data, n$n, method = "FEM", cor.analysis = TRUE, cluster = NULL, RE.type= "Symm", suppressWarnings=FALSE)
Error in !all.equal(my.range[1], my.range[2]) : invalid argument type
In addition: Warning messages:
1: In min(x, na.rm = na.rm) :
no non-missing arguments to min; returning Inf
2: In max(x, na.rm = na.rm) :
no non-missing arguments to max; returning -Inf

AttachmentSize
matrix.dat62.18 KB
Mike Cheung's picture
Offline
Joined: 10/08/2009
Hi, Yusra. Many of the

Hi, Yusra.

Many of the matrices are non-positive definite. You may check the matrices with "FALSE".
> is.pd(my.full)
1 2 3 4 5 6 7 8 9 10 11 12 13
NA NA NA NA NA NA FALSE TRUE NA FALSE FALSE NA TRUE
14 15 16 17 18 19 20 21 22 23 24 25 26
TRUE TRUE NA NA NA TRUE NA NA NA NA NA TRUE TRUE
27 28 29 30 31 32 33 34 35 36 37 38 39
TRUE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE TRUE TRUE NA FALSE
40 41 42 43 44 45 46 47 48 49 50 51 52
NA TRUE TRUE NA TRUE TRUE NA NA TRUE NA NA TRUE FALSE
53 54 55 56 57 58 59 60 61 62 63 64 65
FALSE NA TRUE TRUE FALSE TRUE TRUE NA NA FALSE NA TRUE TRUE
66 67 68 69 70 71 72 73 74 75 76 77 78
FALSE NA NA NA NA TRUE NA FALSE FALSE TRUE TRUE TRUE TRUE
79 80 81 82 83 84 85 86 87 88 89 90 91
NA NA FALSE FALSE TRUE TRUE NA NA NA TRUE NA TRUE TRUE
92 93 94 95 96 97 98 99 100 101 102 103 104
NA TRUE FALSE FALSE FALSE FALSE NA NA NA NA TRUE FALSE FALSE
105 106 107 108
TRUE TRUE TRUE TRUE

For example, the correlation between x5 and x12 in my.full[7] is 1.47.
> my.full[7]
$`7`
x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13
x1 1.00 NA NA NA 0.99 0.95 NA NA NA NA NA 0.93 0.44
x2 NA NA NA NA NA NA NA NA NA NA NA NA NA
x3 NA NA NA NA NA NA NA NA NA NA NA NA NA
x4 NA NA NA NA NA NA NA NA NA NA NA NA NA
x5 0.99 NA NA NA 1.00 1.00 NA NA NA NA NA 1.47 0.25
x6 0.95 NA NA NA 1.00 1.00 NA NA NA NA NA 0.78 0.20
x7 NA NA NA NA NA NA NA NA NA NA NA NA NA
x8 NA NA NA NA NA NA NA NA NA NA NA NA NA
x9 NA NA NA NA NA NA NA NA NA NA NA NA NA
x10 NA NA NA NA NA NA NA NA NA NA NA NA NA
x11 NA NA NA NA NA NA NA NA NA NA NA NA NA
x12 0.93 NA NA NA 1.47 0.78 NA NA NA NA NA 1.00 0.26
x13 0.44 NA NA NA 0.25 0.20 NA NA NA NA NA 0.26 1.00

Mike

yahmed's picture
Offline
Joined: 06/24/2014
Hi Mike, Thanks for pointing

Hi Mike,

Thanks for pointing it out! The correlations were in Fisher's z metric but once I changed the correlations to the r metric, I still get the same errors ("not positive definite" for the random effects model, and "In min(x, na.rm = na.rm) :
no non-missing arguments to min; returning Inf error" for the fixed effects model). I'm also getting the following error when checking if the matrices are positive definite:

is.pd(my.full3)
Error in eigen(x, only.values = TRUE) : infinite or missing values in 'x'

I've attached the dataset once again. Is the problem related to how missing values are being handled? Thanks again for all your help!

Yusra

AttachmentSize
rmatrix.dat 60.82 KB
Mike Cheung's picture
Offline
Joined: 10/08/2009
Hi, Yusra. There are still

Hi, Yusra.

There are still problems in your data.

> my.full3 <- readFullMat("rmatrix.dat")
> is.pd(my.full3)
1 2 3 4 5 6 7 8 9 10 11 12 13
NA NA NA NA NA NA FALSE TRUE NA FALSE FALSE NA TRUE
14 15 16 17 18 19 20 21 22 23 24 25 26
TRUE TRUE NA NA NA TRUE NA NA NA NA NA TRUE TRUE
27 28 29 30 31 32 33 34 35 36 37 38 39
TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUE FALSE TRUE TRUE NA TRUE
40 41 42 43 44 45 46 47 48 49 50 51 52
NA TRUE TRUE NA TRUE TRUE NA NA TRUE NA NA TRUE TRUE
53 54 55 56 57 58 59 60 61 62 63 64 65
TRUE NA TRUE TRUE TRUE TRUE TRUE NA NA TRUE NA TRUE TRUE
66 67 68 69 70 71 72 73 74 75 76 77 78
FALSE NA NA NA NA TRUE NA FALSE TRUE TRUE TRUE TRUE TRUE
79 80 81 82 83 84 85 86 87 88 89 90 91
NA NA FALSE TRUE TRUE TRUE NA NA NA TRUE NA TRUE TRUE
92 93 94 95 96 97 98 99 100 101 102 103 104
NA TRUE TRUE TRUE TRUE TRUE NA NA NA NA TRUE TRUE TRUE
105 106 107 108
TRUE TRUE TRUE TRUE

For example, the 7th matrix is not positive definite. The correlation between x5 and x6 is 1.
> index.na <- is.na(diag(my.full3[[7]]))
> my.full3[[7]][!index.na, !index.na]
x1 x5 x6 x12 x13
x1 1.00 0.76 0.74 0.73 0.41
x5 0.76 1.00 1.00 0.90 0.24
x6 0.74 1.00 1.00 0.65 0.20
x12 0.73 0.90 0.65 1.00 0.25
x13 0.41 0.24 0.20 0.25 1.00

Regards,
Mike

yahmed's picture
Offline
Joined: 06/24/2014
Thanks! I will look into

Thanks! I will look into this.