gordy2x / ecoCopula

R package to find species interactions from co-occurrence data
14 stars 9 forks source link

cgr not working when BIC don't change for given lambda values #14

Open mattocci27 opened 3 years ago

mattocci27 commented 3 years ago

When BIC (or AIC) don't change for given lambda values (like below),

r$> sparse_fits$BIC
 [1] 221.1714 202.8500 202.8500 202.8500 202.8500 202.8500 202.8500 202.8500 202.8500 202.8500 202.8500

https://github.com/gordy2x/ecoCopula/blob/277ab698a00a90852d75e724890c74deb52c2a29/R/cgr.R#L101-L108

the above lines do not return sub_lam (i.e., sub_lam will be numeric(0)), and subsequent codes will not work properly. This happened some of my datasets.

Currently, I put large lambda values and make completely sparse matrices (identity matrix) for those bad estimates. Because most of the case, the target matrix become completely sparse at the beginning of changing lambda. https://github.com/mattocci27/ecoCopula/blob/4439a2f1575bcd486b641a9562780a9445932bee/R/cgr.R#L113-L116

I would be willing to start on a PR if maintainers support the idea. I would also appreciate if you could implement a more efficient way to search lambda values.

gordy2x commented 3 years ago

Thanks, I will look at it when I come back to work in mid Jan.