Lapack routine dgesv: system is exactly singular

38 views
Skip to first unread message

Tomas Gomes

unread,
Apr 18, 2024, 11:26:04 AMApr 18
to Genomic SEM Users
Hello!

I'm having trouble running common factor GWAS on some neurodegenerative traits as it keeps throwing back a matrix singularity error. I've successfully replicated the Wightman et al. 2023 publication using Alzheimer's, ALS, Lewy Body Dementia and Parkinson's, but when I try to exclude LBD or substitute it for Multiple Sclerosis instead, it fails in parts despite the model without SNP's working. Here is the error (the task number and U[,] values vary)

Error in { :
  task 8 failed - "Lapack routine dgesv: system is exactly singular: U[7,7] = 0"


I've split the task into batches of 1000SNP so I know where the problems are occurring (batches 9,14,23,25,194,195,206,270,393,447,567,709,etc.) but I can't seem to find anything suspicious about these particular groups of SNP's. The rest of the batches all work fine. The original sumstats files contain rows with Betas or SE's = 0 (never both), but these are all removed by post sumstats() anyway. Here's my code:

length=nrow(RUN_7_SNPmodel)
n=length/1000                       #
5612.628
for(i in 1:n){
  index1 = i*1000+1
  index2 = i*1000+1000
  print(paste0("Batch number: ",i+1, " Running"))
  outputGWAS_batch2 <- commonfactorGWAS(covstruc = LDSCoutput, SNPs = RUN_7_SNPmodel[index1:index2,], estimation = "DWLS", cores = 20, toler = 1e-70, SNPSE = FALSE, parallel = TRUE,GC="standard",MPI=FALSE,smooth_check=TRUE)

  saveRDS(outputGWAS_batch2,file = paste0("OutputGWAS_RUN_7_toler_batch",i+1,".RData") )
}


All included GWAS have a Heritability Z-score > 4 and the smallest has a sample size of 26,723. I think I've explored all other solutions for similar errors in this group but I may be wrong! Here's the LDSCoutput for the run with AD, ALS, MS and PD included:

$V
               [,1]         [,2]          [,3]          [,4]         [,5]
 [1,]  6.485030e-05 3.002846e-06 -1.666858e-06 -4.112997e-06 1.677034e-06
 [2,]  3.002846e-06 3.682346e-06  7.168059e-07  1.259315e-06 7.261583e-07
 [3,] -1.666858e-06 7.168059e-07  1.480481e-05  7.564524e-07 1.756760e-07
 [4,] -4.112997e-06 1.259315e-06  7.564524e-07  3.018949e-05 4.376101e-07
 [5,]  1.677034e-06 7.261583e-07  1.756760e-07  4.376101e-07 3.051818e-06
 [6,] -1.160472e-06 4.047893e-07  1.745293e-06 -1.218710e-06 8.718427e-08
 [7,]  2.633134e-06 3.430578e-07  4.999136e-07  1.455192e-06 9.321648e-07
 [8,]  1.378374e-05 3.918891e-06  4.748670e-06  1.018749e-05 2.477197e-06
 [9,]  2.235910e-06 8.672565e-07  1.809971e-06  6.681371e-06 4.940327e-07
[10,]  1.722475e-05 2.559956e-06  1.989956e-06  3.666518e-06 1.535065e-06
               [,6]          [,7]          [,8]         [,9]         [,10]
 [1,] -1.160472e-06  2.633134e-06  1.378374e-05 2.235910e-06  1.722475e-05
 [2,]  4.047893e-07  3.430578e-07  3.918891e-06 8.672565e-07  2.559956e-06
 [3,]  1.745293e-06  4.999136e-07  4.748670e-06 1.809971e-06  1.989956e-06
 [4,] -1.218710e-06  1.455192e-06  1.018749e-05 6.681371e-06  3.666518e-06
 [5,]  8.718427e-08  9.321648e-07  2.477197e-06 4.940327e-07  1.535065e-06
 [6,]  6.988151e-06 -4.716473e-07 -4.667419e-06 1.684793e-06 -4.118639e-06
 [7,] -4.716473e-07  1.224719e-05  6.762582e-06 2.070561e-06  5.606182e-06
 [8,] -4.667419e-06  6.762582e-06  1.160256e-04 1.150625e-05  3.258666e-05
 [9,]  1.684793e-06  2.070561e-06  1.150625e-05 5.127326e-05  1.887847e-05
[10,] -4.118639e-06  5.606182e-06  3.258666e-05 1.887847e-05  2.292578e-04

$S
          AD_2021         ALS           MS  PD_noproxy
[1,]  0.039078315 0.008454464 -0.003234379 0.011873066
[2,]  0.008454464 0.015641720  0.001365194 0.007969419
[3,] -0.003234379 0.001365194  0.119938037 0.008371002
[4,]  0.011873066 0.007969419  0.008371002 0.153429643

$I
             [,1]         [,2]         [,3]         [,4]
[1,]  1.039005277 -0.001888624  0.016065851 -0.007650786
[2,] -0.001888624  1.027053159 -0.005457264  0.020401443
[3,]  0.016065851 -0.005457264  1.027321318 -0.007544079
[4,] -0.007650786  0.020401443 -0.007544079  0.973303850

$N
         [,1]     [,2]     [,3]     [,4]     [,5]     [,6]     [,7]     [,8]
[1,] 111607.8 94357.87 57029.97 44861.54 79539.38 48158.18 37931.51 29063.96
         [,9]    [,10]
[1,] 22915.45 18022.58

$m
[1] 1173569


Hoping you may know what's going wrong

Thank you!
Tomas

agro...@gmail.com

unread,
Apr 18, 2024, 10:44:41 PMApr 18
to Genomic SEM Users
Hi Tomas, 

Thanks for providing all of these details! You've checked the typical issues that would cause this to pop-up so I'm not sure what may be causing the issue. I'm happy to take a closer look if you e-mail me at andrew.g...@colorado.edu with: 
1.  The LDSC output as a .RData file 
2. The sumstats output for one of the chunks of 1,000 SNPs that threw the error
3. The full set of code you ran to implement the multivariate GWAS 

Best, 
  Andrew

agro...@gmail.com

unread,
May 10, 2024, 12:44:37 PMMay 10
to Genomic SEM Users
Hi Tomas, 

Just sent an e-mail response but also wanted to reply here in case others see a similar error in the future. I get a few warnings about negative residual variances for these two batches of 1,000 SNPs you sent, but none of them pertaining specifically to the matrix singularity error. I realize that isn’t the most helpful as far as your own troubleshooting but since I can’t seem to reproduce the error on my end I would suggest the following three steps to help further tease apart what may be going on for you:

  1. Ensure that you have the most up-to-date version of GenomicSEM your cluster. GenomicSEM uses lavaan for the model estimation, and there are frequent updates to this package that sometimes change the estimation procedure and could lead to you getting the error even if it is just a few lavaan versions behind.
  1. Try running this subset of SNPs locally on your computer to see if this error is something you are just seeing on your cluster.
  1. The warnings I get are about negative residual variances, which may be the same SNPs that are throwing the matrix singularity errorr on your end. You could try running the model with userGWAS and add in constraints on the residuals to see if it gets you the same error. In theory, there’s no reason that we should be getting different errors/warnings for SNPs if we are using the same package version, so I would prefer to get to a point where we are both seeing the same thing before moving forward, which is why I would use this suggestion as a sort of last resort for troubleshooting.

Hope this helps!

Best,

   Andrew


Reply all
Reply to author
Forward
0 new messages