rmaia / pavo

tools for the analysis of color data in R
http://pavo.colrverse.com
GNU General Public License v2.0
69 stars 17 forks source link

bootcoldist() doesn't like the hexagon #221

Closed thomased closed 3 years ago

thomased commented 3 years ago
data(flowers)
vis.flowers <- vismodel(flowers,
                        visual = "apis", qcatch = "Ei", relative = FALSE,
                        vonkries = TRUE, achromatic = "l", bkg = "green"
)
flowers.hex <- colspace(vis.flowers, space = "hexagon")
pop_group <- c(rep('pop_1', nrow(flowers.hex)/2), rep('pop_2', nrow(flowers.hex)/2))
bootcoldist(flowers.hex, by = pop_group)
Error in log(x[x > 0]) : non-numeric argument to mathematical function

It gets tangled up in the internal gmean function in bootcoldist() (line 62).

thomased commented 3 years ago

So I think I've fixed it, but it was two separate issues.

a2cc1c6c32e81cce51bc79b9432e584dca25fdc8 - strips non-numeric data (which, for example, the hexagon & categorical models return) which would cause failure. 06e28a52ec9c61d8f482cc1300f1a5607e8f1b4a - rescales the coordinate systems of colourspace data by adding a constant, because they're often negative and you can't calculate the geometric mean of a negative value, so it'd cause problems and/or uninformative failure.

Just to double-check my logic since my maths is crap, does that second solution make sense to you @Bisaloo? For colspace objects bootcoldist() calculates distances using their coordinates. As part of the bootstrapping though we need to take the geometric mean, so it causes problems when coordinates are negative, as they often are. So I've just...added 100 to all colspace x-y-z coordinates since that won't affect the resulting distances calculations (right?). My quick testing says no, but just want to be sure...

It's not an issue for vismodel()/receptor-noise calculations since bootcoldist() uses qcatch values for that, which are basically never negative.