Skip to contents

Applies stochastic variation to initial population size estimates (N0). If uncertainty columns are present, a new value of N0 is sampled for each row. When N.sd is provided, variation is sampled from either a Poisson distribution (if N.sd = sqrt(N0)) or a truncated Normal distribution. When N.lower and N.upper are provided, variation is sampled from a Uniform distribution bounded by those values. Sampled values are rounded to integers and constrained to any specified lower and upper bounds.

Usage

addN0Variation(popInfo, forceDataFrame = F)

Arguments

popInfo

numeric, list, or data.frame. Initial population size information. Must contain an N0 column or value. Optional columns N.sd, N.lower, and N.upper specify uncertainty in abundance estimates.

forceDataFrame

logical. If TRUE and the result is numeric, return a data frame with column N0. Default FALSE.

Value

A modified version of popInfo with updated N0 values. If no uncertainty columns are present, the input is returned unchanged.

Details

This function is intended to be called at the same stage of simulation and projection workflows as compositionBiasCorrection() so that uncertainty in abundance estimates is propagated through subsequent analyses.

Examples

addN0Variation(500)
#> [1] 500

addN0Variation(data.frame(PopulationName = rep("A", 10),
                          N0 = 500, N.sd = 50))
#>    PopulationName  N0
#> 1               A 430
#> 2               A 513
#> 3               A 378
#> 4               A 500
#> 5               A 531
#> 6               A 557
#> 7               A 409
#> 8               A 488
#> 9               A 488
#> 10              A 486

addN0Variation(data.frame(PopulationName = rep("A", 10),
                          N0 = 500,
                          N.lower = 400,
                          N.upper = 600))
#>    PopulationName  N0
#> 1               A 458
#> 2               A 536
#> 3               A 547
#> 4               A 439
#> 5               A 596
#> 6               A 548
#> 7               A 410
#> 8               A 506
#> 9               A 539
#> 10              A 538