chr1swallace / coloc

Repo for the R package coloc
144 stars 44 forks source link

Bug in code to set up sample size argument to pass to susie_rss #106

Open nshrine opened 1 year ago

nshrine commented 1 year ago

It looks like the code you introduced to add the sample size to the susie arguments has a bug i.e. this code in susie.R:

while(!converged) {
    message("running max iterations: ",maxit)
    ## at 0.12.6 susieR introduced need for n = sample size
    susie_args=c(list(n=d$N), susie_args)
    res=do.call(susie_rss,
                c(list(z=z, R=LD, max_iter=maxit), susie_args))
    converged=res$converged; #s_init=res; maxit=maxit*2
    message("\tconverged: ",converged)
    if(!converged && repeat_until_convergence==FALSE)
      stop("susie_rss() did not converge in ",maxit," iterations. Try running with run_until_convergence=TRUE")
    if(!converged)
      maxit=maxit * 100 # no point in half measures!
  }

The line

susie_args=c(list(n=d$N), susie_args)

needs to be outside the while loop otherwise if susie_rss does not converge the first time then next time round the loop another n gets appended to the susie_args and susie bombs out with this error:

Error in (function (z, R, n, bhat, shat, var_y, z_ld_weight = 0, estimate_residual_variance = FALSE,  : 
  formal argument "n" matched by multiple actual arguments

So any dataset that doesn't converge on the first set of iterations fails.

I wondered why I was getting so few results back.

jeffreypullin commented 11 months ago

@chr1swallace This issue was already fixed (in commit https://github.com/chr1swallace/coloc/commit/7646f8c1ae0dc2da2536d4c0a65b6b2721bf023d) so this issue can be closed.