ENMTools icon indicating copy to clipboard operation
ENMTools copied to clipboard

Set up models to work with categorical variables

Open danlwarren opened this issue 5 years ago • 3 comments

danlwarren avatar May 08 '19 11:05 danlwarren

I actually took a stab at this for glms today, and it turns out to be a surprising amount of trouble. In large part this is because of the widespread use of the "extract" function from the raster package, which doesn't seem to want to extract factor layers as factors. I've played around with the "factors = TRUE" argument and it still seems to export them as numeric, which bungs up the predict functions and evaluate functions down the line. Not sure what's going on here, but we're not going to be able to use factors in models until we figure it out.

danlwarren avatar May 10 '21 22:05 danlwarren

Oh yeah, okay:

Description Factors are categorical variables. These functions allow for defining a RasterLayer as a categorical variable. This feature is under development, and whether a RasterLayer is defined as a factor or not is currently ignored by all other functions.

I think if we want to implement this we're going to have to roll our own extract code or do some post-processing to deal with the fact that factor layers don't really work right now.

danlwarren avatar May 11 '21 04:05 danlwarren

Jamie Kass pointed me to the factorValues stuff and associated sample code, which only partially works on my machine. Honestly it seems like less of a pain in the ass to just have a "factors" argument with a list of names of factor layers, and just pass that to all of the associated functions that use "extract". At some point we should just move all of this to terra instead of raster, where it is (presumably) significantly easier.

danlwarren avatar May 11 '21 06:05 danlwarren