stephenslab / ebnm

R package to fit Empirical Bayes Normal Means model.
https://stephenslab.github.io/ebnm/
12 stars 9 forks source link

Bug in plot.ebnm for ebnm_generalized_binary with negative mode #132

Closed pcarbo closed 2 months ago

pcarbo commented 2 months ago

This works:

set.seed(1)
res <- ebnm_generalized_binary(rnorm(1000),scale = 1,mode = 0.5)
plot(res,incl_cdf = TRUE,incl_pm = FALSE)

But this does not:

set.seed(1)
res <- ebnm_generalized_binary(rnorm(1000),scale = 1,mode = -0.5)
plot(res,incl_cdf = TRUE,incl_pm = FALSE)
# Warning messages:
# 1: In pnorm(YY[subset], MM[subset], SD[subset]) : NaNs produced
# 2: In matrix(pnorm(YY[subset], MM[subset], SD[subset]), k, n) :
#   data length [468] is not a sub-multiple or multiple of the number of columns [300]
# 3: In pnorm(A[subset], MM[subset], SD[subset], lower.tail) : NaNs produced
# 4: In matrix(pnorm(A[subset], MM[subset], SD[subset], lower.tail),  :
#   data length [468] is not a sub-multiple or multiple of the number of columns [300]
# 5: In pnorm(B[subset], MM[subset], SD[subset], lower.tail) : NaNs produced
# 6: In matrix(pnorm(B[subset], MM[subset], SD[subset], lower.tail),  :
#   data length [468] is not a sub-multiple or multiple of the number of columns [300]
# 7: In tmp[subset] <- (pnc - pna)/(pnb - pna) :
#   number of items to replace is not a multiple of replacement length
# 8: Removed 168 rows containing missing values or values outside the scale range
# (`geom_line()`).
willwerscheid commented 2 months ago

these warnings are coming from comp_cdf.tnormalmix -- i am going to transfer this issue to ashr

willwerscheid commented 2 months ago

another issue (which does belong here) is a negative mode results in a negative sd due to the way scale is interpreted. we should just ensure that sd is positive by setting sd = abs(mode * scale)

willwerscheid commented 2 months ago

@pcarbo It now works for me with the latest PRs both here and in ashr. Could you please verify?

pcarbo commented 2 months ago

@willwerscheid The errors are gone, but I still get warnings:

set.seed(1)
res <- ebnm_generalized_binary(rnorm(1000),scale = 1,mode = -0.5)
plot(res,incl_cdf = TRUE,incl_pm = FALSE)
# Warning messages:
# 1: In pnorm(YY[subset], MM[subset], SD[subset]) : NaNs produced
# 2: In pnorm(A[subset], MM[subset], SD[subset], lower.tail) : NaNs produced
# 3: In pnorm(B[subset], MM[subset], SD[subset], lower.tail) : NaNs produced
# 4: Removed 168 rows containing missing values or values outside the scale range
# (`geom_line()`).

Also, the plot doesn't look right.

Do you get the same warnings?

willwerscheid commented 2 months ago

@pcarbo make sure to use the changes in the latest pull request for ebnm. The NaNs are coming from the old behavior that set sd = scale mode (which is negative when mode is negative). This was updated so that sd = abs(scale mode).

pcarbo commented 2 months ago

I see! With pull request #134, it works fine.

willwerscheid commented 2 months ago

awesome, thanks for checking