willwerscheid / flashier

A faster and angrier package for EBMF.
https://willwerscheid.github.io/flashier/
Other
10 stars 12 forks source link

Nullcheck error #104

Closed jean997 closed 1 month ago

jean997 commented 1 year ago

Hello! I am getting an error from flash_nullcheck:

flashier:::flash_nullcheck(flash_fit)
Error in if (obj.diff >= -tol) { : missing value where TRUE/FALSE needed
In addition: Warning message:
In log(tau) : NaNs produced

I am attaching the object that gives the error. Tracing back, it looks like nullcheck.factor is failing for factor 21 because update.R2.tau.and.obj(factor, flash) is assigning a negative tau value. flash_fit.RDS.gz

willwerscheid commented 1 month ago

Hi @jean997 , there is no way for me to figure out what happened here... at some point R2 became inaccurate and now when it updates k = 21 a negative value gets assigned to the expected sum of squared residuals for column 83. If however I reinitialize using the object you provided (which forces R2 to be calculated from scratch) and then do a nullcheck everything seems to works fine:

fit <- readRDS("flash_fit.RDS")
fl <- flash_init(fit$Y, S = sqrt(1 / fit$given.tau), var_type = fit$est.tau.dim)
fl <- fl |>
  flash_factors_init(fit)
fl <- fl |>
  flash_nullcheck()

I am going to close this because although there may still be an issue somewhere there is no way for me to track it down without being able to track the updates to R2 throughout the entire fitting process. I think you had some related issues though - could you please open a new issue for those?