Mice() imputation using 2l.norm method gives Error in chol.default() leading minor of order 1 is not positive

13 Views Asked by At

Having an issue with imputation using mice. I'm testing a few ways to impute on a longitudinal dataset, however using the 2l.norm method gives me an error in almost every case I try (as a separate issue, when it does not show this error no imputation actually occurs). Am I setting up my predictor matrix wrong? I do not get this error for the 2l.pan method. Here is an example:

tds <- structure(list(id = c(11122L, 12898L, 13753L, 15217L, 18733L, 
19735L, 19761L, 48571L, 58693L, 58920L, 11122L, 12898L, 13753L, 
15217L, 18733L, 19735L, 19761L, 48571L, 58693L, 58920L), cohort= c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L), wave = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), sex = c(1L, 1L, 2L, 
2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 
1L), age_v1 = c(52.0164383561644, 50.8493150684931, 52.7753424657534, 
53.0739726027397, 48.9616438356164, 52.0219178082192, 53.2054794520548, 
46.0904109589041, 40.7479452054795, 46.9972602739726, 67.7424657534247, 
71.1479452054794, 68.5506849315069, NA, 64.8575342465753, 68.2904109589041, 
NA, NA, NA, 56.6794520547945), traila_tm = c(24, 30, 15, 36, 
33, 26, 23, 17.4, 25.5, 29.3, 25.03, 27.601, 32.18, NA, 46.34, 
35.81, NA, NA, NA, 22.72), acc_1b_ltr = c(0.285714285714286, 
0.214285714285714, 0.196428571428571, 0.392857142857143, 0.321428571428571, 
0.0892857142857143, 0.267857142857143, NA, NA, NA, 0.0178571428571429, 
0.339285714285714, 0.0714285714285714, NA, 0.0535714285714286, 
0.125, NA, NA, NA, 0), r_prs_er = c(4L, 5L, 5L, NA, 7L, 4L, 6L, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), const = c(1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), row.names = c(26L, 
368L, 487L, 646L, 1128L, 1258L, 1262L, 1607L, 1789L, 1793L, 1831L, 
2173L, 2292L, 2451L, 2933L, 3063L, 3067L, 3397L, 3563L, 3566L
), class = "data.frame")

> i <- mice(tds, maxit = 0)
Warning message:
Number of logged events: 1 
> p <- i$predictorMatrix
> me <- i$method
> me["r_prs_er"] <- ""        # don't impute r_prs_er, wasn't collected in wave 2
> me[me=="pmm"] <- "2l.norm"  # predict using 2l.nrom method   
> me
        id       wave        sex     age_v1  traila_tm acc_1b_ltr   r_prs_er      const 
        ""         ""         ""  "2l.norm"  "2l.norm"  "2l.norm"         ""         "" 
> p[, "wave"] <- -2          # wave is our grouping variable   
> p[, c("id", "const")] <- 2
> p[,"cohort"] <- 0
> p[, c("r_prs_er")] <- 0    # when r_prs is set to be a predictor, mice() runs but no imputation occurs
> p["r_prs_er",] <- 0
> p[c("id","wave", "const"), ] <- 0      
> p
           id cohort wave sex age_v1 traila_tm acc_1b_ltr r_prs_er const
id          0    0    0   0      0         0          0        0     0
cohort      2    0   -2   1      1         1          1        0     2
wave        0    0    0   0      0         0          0        0     0
sex         2    0   -2   0      1         1          1        0     2
age_v1      2    0   -2   1      0         1          1        0     2
traila_tm   2    0   -2   1      1         0          1        0     2
acc_1b_ltr  2    0   -2   1      1         1          0        0     2
r_prs_er    0    0    0   0      0         0          0        0     0
const       0    0    0   0      0         0          0        0     0

> test <- mice(tds, m = 1, maxit = 1, method = me, predictorMatrix = p)

 iter imp variable
  1   1  age_v1Error in chol.default(vv) : the leading minor of order 1 is not positive
In addition: Warning message:
In rchisq(p, df:(df - p + 1)) : NAs produced

I'm not sure what this error means or how to resolve it. Any insight would be helpful!

0

There are 0 best solutions below