forestgeo/fgeo.analyze

Helper to pick sufficiently abundant species

maurolepore opened this issue · 3 comments

Sabrina Russo said:

... I guess there’s a wrapper function in which the user can pick what minimum tree abundance they wish to use and that then subsets the data so that only the species meeting the minimum abundance criterion are run for the TT? If not, then there should be one.

@srusso2,

RE: "I guess there’s a wrapper function in which the user can pick what minimum tree abundance they wish..."

filter(add_count(...), n > ...) does the trick, and I show it in the examples of tt_test(). I'm inclined to now wrap it because this is is a useful, common pattern and I would like to encourage people to learn it so they can use it in other contexts.

suppressPackageStartupMessages({
  library(dplyr)
  library(fgeo.analyze)
})

census <- fgeo.data::luquillo_tree6_1ha %>% 
  filter(status == "A", dbh >= 10)
census
#> # A tibble: 2,319 x 19
#>    treeID stemID tag   StemTag sp    quadrat    gx    gy MeasureID CensusID
#>     <int>  <int> <chr> <chr>   <chr> <chr>   <dbl> <dbl>     <int>    <int>
#>  1     50 165123 1000~ 178258  PSYB~ 921      165.  418.    618386        6
#>  2     67     92 1000~ 100043  CORB~ 921      163.  420.    617072        6
#>  3     82    112 1000~ 100061  CASS~ 921      161.  416.    617074        6
#>  4     85    115 1000~ 100064  MANB~ 921      161.  418.    617075        6
#>  5    102    141 1000~ 100088  SCHM~ 921      163.  411.    617058        6
#>  6    111    150 1000~ 100098  CECS~ 921      162.  410.    617059        6
#>  7    115    154 1001~ 100100  CECS~ 921      163.  410.    617060        6
#>  8    119    158 1001~ 100104  MYRS~ 1021     183.  410.    578696        6
#>  9    120    159 1001~ 100105  OCOL~ 1021     182.  410.    578697        6
#> 10    130    169 1001~ 100114  OCOL~ 1021     181.  409.    578682        6
#> # ... with 2,309 more rows, and 9 more variables: dbh <dbl>, pom <chr>,
#> #   hom <dbl>, ExactDate <date>, DFstatus <chr>, codes <chr>,
#> #   nostems <dbl>, status <chr>, date <dbl>

census %>% 
  count(sp)
#> # A tibble: 70 x 2
#>    sp         n
#>    <chr>  <int>
#>  1 ALCFLO    11
#>  2 ALCLAT    15
#>  3 ANDINE     1
#>  4 ANTOBT     1
#>  5 ARDGLA     1
#>  6 BUCTET    11
#>  7 BYRSPI    25
#>  8 CALCAL     2
#>  9 CASARB   489
#> 10 CASSYL    58
#> # ... with 60 more rows

# Pick species with over 50 individuals
sufficiently_abundant <- census %>% 
  add_count(sp) %>% 
  filter(n > 50)

sufficiently_abundant %>% 
  count(sp)
#> # A tibble: 11 x 2
#>    sp         n
#>    <chr>  <int>
#>  1 CASARB   489
#>  2 CASSYL    58
#>  3 CECSCH    76
#>  4 INGLAU    89
#>  5 MANBID   113
#>  6 OCOLEU    85
#>  7 PREMON   507
#>  8 PSYBER   125
#>  9 PSYBRA    66
#> 10 SCHMOR   151
#> 11 SLOBER    61

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