gordy2x / ecoCopula

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

Large memory overhead for duplicating the stackedsdm object in the "simulate.res.S" function #19

Open ch16S opened 2 years ago

ch16S commented 2 years ago

Hey guys

I noted a very large memory overhead in the simulate.res.S helper function.

The function calls: many.obj = list(obj)[rep(1, n.res)] This create many lists of the same stackedsdm object. Unfortunately the LM and GLM models have quite a large memory foot print - and so if you working with 1000's of samples and 1000's of species then memory requirements become enormous in this step you in effect multiple the memory usage by the number of simulations. I propose you run the following instead: res = lapply(1:n.res,function(x) residuals(obj)) This achieves the desired outcome to produce the residuals but without the unnecessary memory usage.

Cheers, Chris

gordy2x commented 1 year ago

Yes the code is very inefficient, thanks for the suggestion, I'll try to find some time to test and implement.