forestgeo / fgeo.analyze

[R-package on CRAN] Analyze fgeo data.
https://forestgeo.github.io/fgeo.analyze/
GNU General Public License v3.0
2 stars 3 forks source link

tt_test returns Error when I use a file with a single species (with relatively low sample size) #103

Open DanielZuleta opened 4 years ago

DanielZuleta commented 4 years ago

@maurolepore When I use a dataset with a single species, I get an error message related to the issue https://github.com/forestgeo/fgeo.analyze/issues/40. The Error can be reproduced using the example data in the tt_test function:

# Using the same example of tt_test
library(fgeo.tool, warn.conflicts = FALSE)
assert_is_installed("fgeo.x")
tree <- fgeo.x::tree6_3species
elevation <- fgeo.x::elevation

# Pick alive trees, of 10 mm or more
census <- filter(tree, status == "A", dbh >= 10)

# Selecting CASARB species
w <- which(census$sp == "CASARB")
census.CASARB <- census[w,]

# An error occur with any of the following codes when you use a file with a single species
fgeo.analyze::tt_test(census.CASARB, fgeo.x::habitat)
#> Using `plotdim = c(320, 500)`. To change this value see `?tt_test()`.Using
#> `gridsize = 20`. To change this value see `?tt_test()`.
#> Error:   Every quadrat in the dataset must have at lease one tree.
#>   For more information see https://github.com/forestgeo/fgeo.analyze/issues/40.
fgeo.analyze::tt_test(census.CASARB, fgeo.x::habitat, sp = "CASARB")
#> Using `plotdim = c(320, 500)`. To change this value see `?tt_test()`.Using
#> `gridsize = 20`. To change this value see `?tt_test()`.
#> Error:   Every quadrat in the dataset must have at lease one tree.
#>   For more information see https://github.com/forestgeo/fgeo.analyze/issues/40.

# I think it doesn't have to do with the low sample size issue and the error is being incorrectly reported because no error is returned when the species is included along with other species
fgeo.analyze::tt_test(census, fgeo.x::habitat, sp = "CASARB")
#> Using `plotdim = c(320, 500)`. To change this value see `?tt_test()`.Using
#> `gridsize = 20`. To change this value see `?tt_test()`.
#> [[1]]
#>        N.Hab.1 Gr.Hab.1 Ls.Hab.1 Eq.Hab.1 Rep.Agg.Neut.1 Obs.Quantile.1
#> CASARB      29     1242      356        2              0        0.77625
#>        N.Hab.2 Gr.Hab.2 Ls.Hab.2 Eq.Hab.2 Rep.Agg.Neut.2 Obs.Quantile.2
#> CASARB      20      390     1206        4              0        0.24375
#>        N.Hab.3 Gr.Hab.3 Ls.Hab.3 Eq.Hab.3 Rep.Agg.Neut.3 Obs.Quantile.3
#> CASARB      12      778      817        5              0        0.48625
#>        N.Hab.4 Gr.Hab.4 Ls.Hab.4 Eq.Hab.4 Rep.Agg.Neut.4 Obs.Quantile.4
#> CASARB       5      932      658       10              0         0.5825
maurolepore commented 4 years ago

Thanks @DanielZuleta for reporting the bug (:1st_place_medal: for sharing a reprex).

Would you be willing to try fix the bug and submit a pull request?

As I no longer work at ForestGEO I have little time to fix it myself but I'm more than happy to guide you through the process. If you prefer, we could set a call, share screens and set up the "plumbing" you need to submit the pull request.

As usual it will help to have up-to-date Git, R, RStudio, and R packages. If you get stuck, this website can help you: https://happygitwithr.com/.

DanielZuleta commented 4 years ago

Hi @maurolepore , Sure! I will work on this and let you know. Thanks, DZ