stephens999 / ashr

An R package for adaptive shrinkage
GNU General Public License v3.0
80 stars 36 forks source link

issue in comp_cdf method for tnormalmix #142

Closed willwerscheid closed 6 months ago

willwerscheid commented 6 months ago

@pcarbo discovered issues in comp_cdf.tnormalmix while running the following:

library(ebnm)
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()`).

I believe that in these lines:

pnc = matrix(pnorm(YY[subset], MM[subset], SD[subset]), k, n)
pna = matrix(pnorm(A[subset], MM[subset], SD[subset], lower.tail), k, n)
pnb = matrix(pnorm(B[subset], MM[subset], SD[subset], lower.tail), k, n)

the ncol argument should be removed (i.e., it should read matrix(dat, k) instead of matrix(dat, k, n) since the number of columns is no longer n after subsetting).

pcarbo commented 6 months ago

Thanks @willwerscheid!