stephenslab / susieR

R package for "sum of single effects" regression.
https://stephenslab.github.io/susieR
Other
174 stars 44 forks source link

susie_get_posterior_mean error #121

Closed cindywen96 closed 3 years ago

cindywen96 commented 3 years ago

84 this thread was very helpful. Thanks. However, I had a question when using the function susie_get_posterior_mean. When include_idx is a single number, I got an error

> colSums((susie_object$alpha * susie_object$mu)[1,])
Error in base::colSums(x, na.rm = na.rm, dims = dims, ...) :
  'x' must be an array of at least two dimensions

Any idea on this?

stephens999 commented 3 years ago

i'm not sure what the issue is - this doesn't seem to be anything specific to susie but you are trying to apply colSums to a vector? That isn't allowed by colSums.

If it helps, you can avoid R automatically turning a matrix with one row into a vector by using drop=FALSE.

eg:

> x = matrix(0,nrow=1,ncol=10)
> colSums(x)
 [1] 0 0 0 0 0 0 0 0 0 0
> colSums(x[1,])
Error in colSums(x[1, ]) : 
  'x' must be an array of at least two dimensions
> colSums(x[1,,drop=FALSE])
 [1] 0 0 0 0 0 0 0 0 0 0
stephens999 commented 3 years ago

oh sorry, i think i see now: you are saying susie_get_posterior_mean error has this problem when include_idx is a single number? I'll fix this.

cindywen96 commented 3 years ago

Thank you for your reply! Yes that is exactly what I meant

gaow commented 3 years ago

@cindywen96 could you try the current master? I just pushed a patch for that line ...

gaow commented 3 years ago

@stephens999 oops sorry our emails crossed. Hopefully that patch solves the problem. @cindywen96 please let us know!

cindywen96 commented 3 years ago

@gaow Thank you-it works! It could be added to function susie_get_posteriror_sd as well