forestgeo/fgeo.analyze

tt_test() errs with relatively high number of habitats

maurolepore opened this issue · 1 comments

library(tidyverse)
#> Warning: package 'purrr' was built under R version 3.5.3
library(fgeo)
#> -- Attaching packages -------------------------------------------- fgeo 1.1.2.9000 --
#> v fgeo.analyze 1.1.4          v fgeo.tool    1.2.2     
#> v fgeo.plot    1.1.3.9000     v fgeo.x       1.1.2
#> -- Conflicts ---------------------------------------------------- fgeo_conflicts() --
#> x fgeo.tool::filter() masks dplyr::filter(), stats::filter()
#> x dplyr::intersect()  masks base::intersect()
#> x dplyr::lag()        masks stats::lag()
#> x dplyr::setdiff()    masks base::setdiff()
#> x dplyr::setequal()   masks base::setequal()
#> x dplyr::union()      masks base::union()
set.seed(1)

# Small dataset from Luquillo
cns_luq <- fgeo.x::tree6_3species
hab_luq <- fgeo.x::habitat
sp_top3_luq <- unique(fgeo.x::tree6_3species$sp)
pdim_luq <- c(320, 500)
gsize_luq <- 20

# Passes
hab <- fgeo_habitat(fgeo.x::elevation, 20, 8)
as_tibble(tt_test(cns_luq, hab))
#> Using `plotdim = c(320, 500)`. To change this value see `?tt_test()`.
#> Using `gridsize = 20`. To change this value see `?tt_test()`.
#> # A tibble: 24 x 8
#>    habitat sp     N.Hab Gr.Hab Ls.Hab Eq.Hab Rep.Agg.Neut Obs.Quantile
#>  * <chr>   <chr>  <dbl>  <dbl>  <dbl>  <dbl>        <dbl>        <dbl>
#>  1 1       CASARB    11    587   1012      1            0        0.367
#>  2 2       CASARB    16   1433    163      4            0        0.896
#>  3 3       CASARB     2   1200    368     32            0        0.75 
#>  4 4       CASARB    14    886    710      4            0        0.554
#>  5 5       CASARB     6    223   1365     12            0        0.139
#>  6 6       CASARB     6    418   1177      5            0        0.261
#>  7 7       CASARB     5    932    658     10            0        0.582
#>  8 8       CASARB     6   1423    171      6            0        0.889
#>  9 1       PREMON    49   1223    374      3            0        0.764
#> 10 2       PREMON    37    627    968      5            0        0.392
#> # ... with 14 more rows
autoplot(hab)

# Errs
hab <- fgeo_habitat(fgeo.x::elevation, 20, 16)
as_tibble(tt_test(cns_luq, hab))
#> Using `plotdim = c(320, 500)`. To change this value see `?tt_test()`.
#> Using `gridsize = 20`. To change this value see `?tt_test()`.
#> Error in if (spprophab[i] > Torspprophab[i]) {: missing value where TRUE/FALSE needed

autoplot(hab)

Created on 2019-03-22 by the reprex package (v0.2.1)

Relates to #40 (comment)

The issue is not a given empty quadrat, but empty habitats (set of quadrats) that perfectly match with a habitat of one of the translated maps

library(tidyverse)
library(fgeo)
#> -- Attaching packages ------------------------------------------- fgeo 1.1.2 --
#> v fgeo.analyze 1.1.4.9000     v fgeo.tool    1.2.2     
#> v fgeo.plot    1.1.3.9000     v fgeo.x       1.1.2
#> -- Conflicts ---------------------------------------------- fgeo_conflicts() --
#> x fgeo.tool::filter() masks dplyr::filter(), stats::filter()
#> x dplyr::intersect()  masks base::intersect()
#> x dplyr::lag()        masks stats::lag()
#> x dplyr::setdiff()    masks base::setdiff()
#> x dplyr::setequal()   masks base::setequal()
#> x dplyr::union()      masks base::union()

cns_luq <- fgeo.x::tree6_3species
hab <- fgeo_habitat(fgeo.x::elevation, 20, 16)
as_tibble(tt_test(cns_luq, hab))
#> Using `plotdim = c(320, 500)`. To change this value see `?tt_test()`.
#> Using `gridsize = 20`. To change this value see `?tt_test()`.
#>   Every quadrat in the dataset must have at lease one tree.
#>   For more information see https://github.com/forestgeo/fgeo.analyze/issues/40.

Created on 2019-04-26 by the reprex package (v0.2.1)