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

SuSiE can crash when run in small samples #219

Open
william-denault opened this issue Feb 22, 2024 · 1 comment
Open

SuSiE can crash when run in small samples #219

william-denault opened this issue Feb 22, 2024 · 1 comment

Comments

@william-denault
Copy link
Collaborator

william-denault commented Feb 22, 2024

Hello,

As suggested by @stephens999 , I am opening an issue about that.

If you run the script below for a couple of minutes it will crash and output

Error in init_finalize(s) : 
  Residual variance sigma2 must be positive (is your var(Y) zero)
library(susieR
        )


N <- 20
set.seed(123)

res <- list( )
data(N3finemapping)
h=1
for ( i in (length(res)+1):10000){
 
  L <- sample (1:10, size=1)

  X <- N3finemapping$X
  X <- N3finemapping$X[sample (1:nrow(X), size=N, replace=FALSE),]
  true_pos <- sample( 1:ncol(X), L)
  if( L==1){
    if (var( X[,true_pos])==0) next
    y <- X[, true_pos]
  }else{
    y <- apply( X[, true_pos],1, sum)
  }
 
  y <- y + rnorm( N, sd=  1*( sd(y)))
 
 
 
  out <-  susie(X,y, L=1 )  
  out$sets
    if(!is.null(out$sets$cs)){
     
    n_true_cs <-   Reduce("+",sapply(1:length(out$sets$cs), function(k)
        ifelse( length(which(true_pos%in%out$sets$cs[[k]] ))==0, 0,1)
      ))
    n_cs   <-    length(  out$sets$cs  )
    n_effect <- length(true_pos)
     
      res [[h]] <- c( n_true_cs ,   n_cs,n_effect   )
                       
        print( res[[h]])
       
      h=h+1
    }
 
 
} 
@william-denault william-denault changed the title SuSiE can crashe when run in small samples SuSiE can crash when run in small samples Feb 22, 2024
@pcarbo
Copy link
Member

pcarbo commented Feb 22, 2024

@william-denault The error message says to check that the variance of y is zero, and indeed it is zero in your example:

> i
[1] 429
> var(y)
[1] 0

One issue perhaps is that this step has no effect when y has no variance:

y <- y + rnorm( N, sd= 1*( sd(y)))

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