USDAForestService / FIESTA

FIESTA (Forest Inventory ESTimation and Analysis) is a research estimation tool for analysts that work with sample-based inventory data from the U.S. Department of Agriculture, Forest Service, Forest Inventory and Analysis (FIA) Program. Follow the link below for more information:
https://usdaforestservice.github.io/FIESTA/
24 stars 11 forks source link

adding modMAratio + function documentation #23

Closed joshyam-k closed 1 year ago

joshyam-k commented 1 year ago

These changes rely on FIESTAutils#15

joshyam-k commented 1 year ago

note: any example using modMAratio within this fork of FIESTA won't pass any R CMD check because it can't use the updated version of MAest.pbar until that has been merged into FIESTAutils, so here's an example of it's usage:

# have to do it in this order to ensure we use my dev version of FIESTAutils
devtools::install_github("joshyam-k/FIESTA")
devtools::install_github("joshyam-k/FIESTAutils")

MApopdat <- FIESTA::modMApop(popTabs = list(tree = FIESTA::WYtree,
                                    cond = FIESTA::WYcond),
                     pltassgn = FIESTA::WYpltassgn,
                     pltassgnid = "CN",
                     unitarea = FIESTA::WYunitarea,
                     unitvar = "ESTN_UNIT",
                     unitzonal = FIESTA::WYunitzonal,
                     prednames = c("dem", "tcc", "tpi", "tnt"),
                     predfac = "tnt")
#> INTENSITY not in dataset.. assuming single intensity plots
#> DESIGNCD not in dataset.. assuming DESIGNCD = 1 (annual inventory)
#> For FIA estimation, adjustment factors are calculated to account for plots with partial nonresponse.
#> ...there are 14 nonsampled forest conditions in the dataset.
#> filter removed 14 records: COND_STATUS_CD != 5

out <- FIESTA::modMAratio(MApopdat,
                          estvarn = "VOLCFNET",
                          estvarn.filter = "STATUSCD == 1",
                          rowvar = "STDSZCD",
                          prednames = c("dem", "tcc", "tpi"))
#> filter removed 2620 records: COND_STATUS_CD == 1
#> multiplying VOLCFNET by TPA
#> using the following predictors...dem, tcc, tpi
#> getting output...

str(out)
#> List of 4
#>  $ est    :'data.frame': 5 obs. of  3 variables:
#>   ..$ Stand-size class      : chr [1:5] "1" "2" "3" "5" ...
#>   ..$ Estimate              : chr [1:5] "17665.1" "14011.4" "1907.7" "129.7" ...
#>   ..$ Percent Sampling Error: chr [1:5] "4.34" "10.4" "8.62" "8.32" ...
#>  $ raw    :List of 15
#>   ..$ unit_totest   :'data.frame':   23 obs. of  16 variables:
#>   .. ..$ ESTN_UNIT : num [1:23] 1 3 5 7 9 11 13 15 17 19 ...
#>   .. ..$ rhat      : num [1:23] 346.6 336.6 69.1 1060.3 259.7 ...
#>   .. ..$ rhat.var  : num [1:23] 2559 92075 2546 8214 6048 ...
#>   .. ..$ NBRPLT    : int [1:23] 24 12 14 36 18 26 53 NA 8 22 ...
#>   .. ..$ NBRPLT.gt0: int [1:23] 23 9 12 34 14 26 46 NA 5 21 ...
#>   .. ..$ ACRES     : num [1:23] 2757613 2021729 3072988 5096959 2729653 ...
#>   .. ..$ AREAUSED  : num [1:23] 2757613 2021729 3072988 5096959 2729653 ...
#>   .. ..$ rhat.se   : num [1:23] 50.6 303.4 50.5 90.6 77.8 ...
#>   .. ..$ rhat.cv   : num [1:23] 0.146 0.9015 0.7307 0.0855 0.2994 ...
#>   .. ..$ pse       : num [1:23] 14.6 90.15 73.07 8.55 29.94 ...
#>   .. ..$ CI99left  : num [1:23] 216.3 0 0 826.9 59.4 ...
#>   .. ..$ CI99right : num [1:23] 477 1118 199 1294 460 ...
#>   .. ..$ CI95left  : num [1:23] 247 0 0 883 107 ...
#>   .. ..$ CI95right : num [1:23] 446 931 168 1238 412 ...
#>   .. ..$ CI68left  : num [1:23] 296.3 34.8 18.9 970.2 182.4 ...
#>   .. ..$ CI68right : num [1:23] 397 638 119 1150 337 ...
#>   ..$ totest        :'data.frame':   1 obs. of  14 variables:
#>   .. ..$ TOTAL     : num 1
#>   .. ..$ rhat      : num 12985
#>   .. ..$ rhat.var  : num 247783
#>   .. ..$ NBRPLT.gt0: int 459
#>   .. ..$ AREAUSED  : num 62600430
#>   .. ..$ rhat.se   : num 498
#>   .. ..$ rhat.cv   : num 0.0383
#>   .. ..$ pse       : num 3.83
#>   .. ..$ CI99left  : num 11703
#>   .. ..$ CI99right : num 14267
#>   .. ..$ CI95left  : num 12009
#>   .. ..$ CI95right : num 13961
#>   .. ..$ CI68left  : num 12490
#>   .. ..$ CI68right : num 13480
#>   ..$ unit_rowest   :'data.frame':   73 obs. of  17 variables:
#>   .. ..$ ESTN_UNIT       : num [1:73] 1 1 1 1 3 3 3 3 5 5 ...
#>   .. ..$ Stand-size class: Factor w/ 4 levels "1","2","3","5": 1 2 3 4 1 2 3 4 1 3 ...
#>   .. ..$ rhat            : num [1:73] 649 2070 181 NA 1060 ...
#>   .. ..$ rhat.var        : num [1:73] 13950 1692805 322 NA 308078 ...
#>   .. ..$ NBRPLT          : int [1:73] 24 24 24 NA 12 NA NA NA 14 14 ...
#>   .. ..$ NBRPLT.gt0      : int [1:73] 9 6 6 NA 8 NA NA NA 8 2 ...
#>   .. ..$ ACRES           : num [1:73] 2757613 2757613 2757613 2757613 2021729 ...
#>   .. ..$ AREAUSED        : num [1:73] 2757613 2757613 2757613 2757613 2021729 ...
#>   .. ..$ rhat.se         : num [1:73] 118.1 1301.1 17.9 NA 555 ...
#>   .. ..$ rhat.cv         : num [1:73] 0.1819 0.6286 0.0993 NA 0.5235 ...
#>   .. ..$ pse             : num [1:73] 18.19 62.86 9.93 NA 52.35 ...
#>   .. ..$ CI99left        : num [1:73] 345 0 134 0 0 ...
#>   .. ..$ CI99right       : num [1:73] 954 5421 227 NA 2490 ...
#>   .. ..$ CI95left        : num [1:73] 418 0 146 0 0 ...
#>   .. ..$ CI95right       : num [1:73] 881 4620 216 NA 2148 ...
#>   .. ..$ CI68left        : num [1:73] 532 776 163 0 508 ...
#>   .. ..$ CI68right       : num [1:73] 767 3364 199 NA 1612 ...
#>   ..$ rowest        :'data.frame':   4 obs. of  14 variables:
#>   .. ..$ Stand-size class: Factor w/ 4 levels "1","2","3","5": 1 2 3 4
#>   .. ..$ rhat            : num [1:4] 17665 14011 1908 130
#>   .. ..$ rhat.var        : num [1:4] 588535 2122472 27032 116
#>   .. ..$ NBRPLT.gt0      : int [1:4] 244 92 88 4
#>   .. ..$ AREAUSED        : num [1:4] 62600430 44542176 45447111 50085619
#>   .. ..$ rhat.se         : num [1:4] 767.2 1456.9 164.4 10.8
#>   .. ..$ rhat.cv         : num [1:4] 0.0434 0.104 0.0862 0.0832
#>   .. ..$ pse             : num [1:4] 4.34 10.4 8.62 8.32
#>   .. ..$ CI99left        : num [1:4] 15689 10259 1484 102
#>   .. ..$ CI99right       : num [1:4] 19641 17764 2331 158
#>   .. ..$ CI95left        : num [1:4] 16162 11156 1585 109
#>   .. ..$ CI95right       : num [1:4] 19169 16867 2230 151
#>   .. ..$ CI68left        : num [1:4] 16902 12563 1744 119
#>   .. ..$ CI68right       : num [1:4] 18428 15460 2071 140
#>   ..$ domdat        :'data.frame':   590 obs. of  19 variables:
#>   .. ..$ PLT_CN          : chr [1:590] "40404729010690" "40404730010690" "40404737010690" "40404738010690" ...
#>   .. ..$ CONDID          : num [1:590] 1 1 2 1 1 1 2 1 1 1 ...
#>   .. ..$ CONDPROP_UNADJ  : num [1:590] 1 1 0.25 1 1 ...
#>   .. ..$ SUBPPROP_UNADJ  : num [1:590] 1 1 0.25 1 1 ...
#>   .. ..$ MICRPROP_UNADJ  : num [1:590] 1 1 0.25 1 1 1 0.5 1 1 1 ...
#>   .. ..$ MACRPROP_UNADJ  : logi [1:590] NA NA NA NA NA NA ...
#>   .. ..$ ESTN_UNIT       : int [1:590] 1 1 1 1 1 1 1 1 1 1 ...
#>   .. ..$ dem             : int [1:590] 2382 2274 2576 2434 2202 2177 2011 1861 2161 2124 ...
#>   .. ..$ tcc             : int [1:590] 5 45 16 27 1 16 5 19 0 3 ...
#>   .. ..$ tpi             : num [1:590] 0.75 -12.12 2.5 -0.75 -8.62 ...
#>   .. ..$ tnt2            : num [1:590] 1 0 0 0 1 1 1 0 1 1 ...
#>   .. ..$ cadjfac         : num [1:590] 1 1 1 1 1 ...
#>   .. ..$ ADJ_FACTOR_SUBP : num [1:590] 1 1 1 1 1 ...
#>   .. ..$ ADJ_FACTOR_MACR : num [1:590] 0 0 0 0 0 0 0 0 0 0 ...
#>   .. ..$ ADJ_FACTOR_MICR : num [1:590] 1 1 1 1 1 ...
#>   .. ..$ CONDPROP_ADJ    : num [1:590] 1 1 0.25 1 1 ...
#>   .. ..$ STDSZCD         : int [1:590] 1 1 5 3 3 1 1 1 1 5 ...
#>   .. ..$ TOTAL           : num [1:590] 1 1 1 1 1 1 1 1 1 1 ...
#>   .. ..$ VOLCFNET_TPA_ADJ: num [1:590] 41.8 1563 14.9 137.5 448.7 ...
#>   ..$ estvarn       : chr "VOLCFNET"
#>   ..$ estvarn.filter: chr "STATUSCD == 1"
#>   ..$ estvard       : chr "CONDPROP_ADJ"
#>   ..$ module        : chr "MA"
#>   ..$ esttype       : chr "RATIO"
#>   ..$ MAmethod      : chr "gregRatio"
#>   ..$ predselect    : chr [1:3] "dem" "tcc" "tpi"
#>   ..$ rowvar        : chr "STDSZCD"
#>   ..$ colvar        : chr "NONE"
#>   ..$ areaunits     : chr "acres"
#>  $ statecd: int 56
#>  $ invyr  : int [1:3] 2011 2012 2013

out$est
#>   Stand-size class Estimate Percent Sampling Error
#> 1                1  17665.1                   4.34
#> 2                2  14011.4                   10.4
#> 3                3   1907.7                   8.62
#> 4                5    129.7                   8.32
#> 5            Total  12984.9                   3.83