sylvainschmitt / SSDM

Stacked Species Distribution Modelling R package
Other
41 stars 17 forks source link

Warning: In mean.default(corr, na.rm = TRUE) : argument is not numeric or logical: returning NA #89

Closed BettyBoyse closed 4 months ago

BettyBoyse commented 4 years ago

Dear Sylvain and Lukas,

I'm so sorry for all the questions... I also have started getting this warning message when running stack_modelling: In mean.default(corr, na.rm = TRUE) : argument is not numeric or logical: returning NA

and am unsure what it relates to within the code, I couldn't see object 'corr'.

Best wishes,

Betty

lukasbaumbach commented 4 years ago

Don't worry, the more bugs we are able to solve this way, the better for package stability!

I have also been receiving this error in the past and have narrowed it down to the use of uncertainty=TRUE. If this is activated, the ensemble function (run inside stack_modelling) tries to run an algorithm correlation. The error possibly occurs, because one of the rasters is lost along the way (likely because it's only stored temporarily) and corr becomes NA.

The error doesn't occur for ensemble_modelling if tmp=FALSE. So one of the problems may be, that if tmp=TRUE, the necessary files are lost due to a reset of the temporary folder when run in parallel. There seems to be an additional small bug for stack_modelling, however, which I think may be related to the esdm names, if they are incorrectly split by strsplit: https://github.com/sylvainschmitt/SSDM/blob/d8152bd234e2553d393df40fd40834e585090d20/R/stacking.R#L317-L320

For now, a workaround is to set uncertainty=FALSE. If really necessary, algorithm correlation may be computed by stacking the respective projections of the different algorithms and running raster::layerStats.

BettyBoyse commented 4 years ago

Dear Lukas,

Okay thank you, will make sure to set uncertainty=FALSE from now on.

Best wishes, Betty