privefl / bigsnpr

R package for the analysis of massive SNP arrays.
https://privefl.github.io/bigsnpr/
183 stars 43 forks source link

"NA or NaN values in the resulting correlation matrix." #443

Closed JNajar closed 8 months ago

JNajar commented 10 months ago

Hi!

I have used your script for LDPred2 several times with good results. However, now that i want to create a PRS for diabetes type 2, for some reason i get this warning during the LD calculations: "Warning message: NA or NaN values in the resulting correlation matrix." I have already removed NAs in a previous step:

# a lot of NAs for hg38 variable 
sumstats <- na.omit(sumstats)

And when i check for NAs i dont find any. 

If i continue with the script i get this: 
> ## We assume the fam order is the same across different chromosomes
> fam.order <- as.data.table(obj.bigSNP$fam)
>
> ## Rename fam order
> setnames(fam.order,
+         c("family.ID", "sample.ID"),
+         c("FID", "IID"))
>
> # 6. Perform LD score regression
>   df_beta <- info_snp[,c("beta", "beta_se", "n_eff", "_NUM_ID_")]
>
>   ldsc <- snp_ldsc(   ld,
+                       length(ld),
+                       chi2 = (df_beta$beta / df_beta$beta_se)^2,
+                       sample_size = df_beta$n_eff,
+                       blocks = NULL)
Error in if (max(abs(pred - pred0)) < 1e-06) break :
  missing value where TRUE/FALSE needed
>
>   h2_est <- ldsc[["h2"]]
Error: object 'ldsc' not found

Do you know what might be the problem? Or how I can troubleshoot?

All the best, Jenna

privefl commented 10 months ago

Have you searched for similar issues? I think that has been reported a few times here already.

privefl commented 10 months ago

Please make sure to post your issues in the bigsnpr repo.

JNajar commented 10 months ago

Pretty new to Github, sorry :) I am not sure how?

privefl commented 10 months ago

howtoissue

Minta821 commented 9 months ago

I have also used your script for LDPred2 several times, I also got the same error now .

privefl commented 9 months ago

Yes, the change appeared in v1.9.5 (cf. https://privefl.github.io/bigsnpr/news/):

snp_cor() and bed_cor() now return NaNs when e.g. the standard deviation is 0 (and warn about it). Before, these values were not reported (i.e. treated as 0).

So, yes, it "worked" before, but for wrong reasons. Please make sure to do some proper QC on very small MAF and this warning will disappear.

privefl commented 8 months ago

Any update on this?

Minta821 commented 8 months ago

Any update on this?

Sorry for the late responses, yes, it's working after SNP filtering..