Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in if (max(abs(pred - pred0)) < 1e-06) break #414

Closed
Mahantesh-Biradar opened this issue Mar 9, 2023 · 7 comments
Closed

Error in if (max(abs(pred - pred0)) < 1e-06) break #414

Mahantesh-Biradar opened this issue Mar 9, 2023 · 7 comments

Comments

@Mahantesh-Biradar
Copy link

Mahantesh-Biradar commented Mar 9, 2023

I'm using the ‘1.12.1’ version of bigsnpr. I have seem to have trouble in the LD calculation step. How can I address this issue?

# calculate LD
> for (chr in 1:22) {
+   # Extract SNPs that are included in the chromosome
+   ind.chr <- which(info_snp$chr == chr)
+   ind.chr2 <- info_snp$`_NUM_ID_`[ind.chr]
+   # Calculate the LD
+   corr0 <- snp_cor(
+     genotype2,
+     ind.col = ind.chr2,
+     ncores = NCORES,
+     infos.pos = POS2[ind.chr2],
+     size = 3 / 1000
+   )
+   if (chr == 1) {
+     ld <- Matrix::colSums(corr0^2)
+     corr <- as_SFBM(corr0, tmp)
+   } else {
+     ld <- c(ld, Matrix::colSums(corr0^2))
+     corr$add_columns(corr0, nrow(corr))
+   }
+ }

There were 11 warnings (use warnings() to see them)

> warnings()
Warning messages:
1: NA or NaN values in the resulting correlation matrix.
2: NA or NaN values in the resulting correlation matrix.
3: NA or NaN values in the resulting correlation matrix.
4: NA or NaN values in the resulting correlation matrix.
5: NA or NaN values in the resulting correlation matrix.
6: NA or NaN values in the resulting correlation matrix.
7: NA or NaN values in the resulting correlation matrix.
8: NA or NaN values in the resulting correlation matrix.
9: NA or NaN values in the resulting correlation matrix.
10: NA or NaN values in the resulting correlation matrix.
11: NA or NaN values in the resulting correlation matrix.
> # 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"))
> #4. 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
> h2_est #[1] 0.457358
Error: object 'h2_est' not found
@privefl
Copy link
Owner

privefl commented Mar 10, 2023

NA or NaN values in the resulting correlation matrix

This has already been discussed in other issues here. Please have a look at them by searching through the issues.

Please close the issue if you find an answer to your question.
Otherwise, please provide more details on why your problem is different from those already reported.

@Mahantesh-Biradar
Copy link
Author

Thanks Florian. I'm looking into this and let me update this asap.

@Mahantesh-Biradar
Copy link
Author

Hi Florian,

I have already excluded rare variants (MAF < 0.01) and I have tried to run this step without imputing missing values and also imputation using genotype2 <- snp_fastImputeSimple(genotype).

In both the cases, I see the following error: NA or NaN values in the resulting correlation matrix.

@privefl
Copy link
Owner

privefl commented Mar 10, 2023

You should be able to locate missing values with something like Matrix::which(is.na(corr0), arr.ind = TRUE).

@Mahantesh-Biradar
Copy link
Author

Thanks Florian

@privefl
Copy link
Owner

privefl commented Mar 12, 2023

So, what was the problem?

@Mahantesh-Biradar
Copy link
Author

Mahantesh-Biradar commented Mar 12, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants