Skip to content

J-Ch-n/cwtCensus

Repository files navigation

cwtCensus

R-CMD-check codecov

The goal of cwtCensus is to provide a fast and memory efficient tool for cohort reconstruction using point and bootstrapped estimates. Writing efficient code for cohort reconstruction can be challenging, so we developed cwtCensus to abstract away the details of tweaking lines of R and designing algorithms. With this package, you can generate bootstrapped and non-bootstrapped cohort reconstructions with just one click!

Installation

You can install the latest stable version of cwtCensus from CRAN with:

install.packages("cwtCensus")

You can install the development version of cwtCensus from GitHub with:

install.packages("devtools")
devtools::install_github("J-Ch-n/cwtCensus")

Example

This is a basic example showing you how to solve a common cohort reconstruction problem:

library(cwtCensus)
set.seed(998784)

Creating a cohort reconstruction with point estimates:

result = cohort_reconstruct(release, recovery, birth_month = 4L,
  bootstrap = FALSE, last_month = 12L, iter = 10L,
  level = 0.95, detail = FALSE, sex = "both", verbose = FALSE)

Time spent on generating point estimate cohort reconstruction:

cohort_reconstruct(release, recovery, birth_month = 4L,
  bootstrap = FALSE, last_month = 12L, iter = 10L,
  level = 0.95, detail = FALSE, sex = "both", verbose = FALSE) |> system.time()
#>    user  system elapsed 
#>   0.315   0.008   0.327

Viewing the 1998 brood year age 3 cohort in June:

result[result$by == 2007 & result$age == 3 & result$month == 6] |> unlist()
#>              by             age           month ocean_abundance 
#>        2007.000           3.000           6.000        8436.809

Creating a bootstrapped cohort reconstruction with 1000 iterations:

result = cohort_reconstruct(release, recovery, birth_month = 4L,
  bootstrap = TRUE, last_month = 12L, iter = 1000L,
  level = 0.95, detail = TRUE, sex = "both", verbose = FALSE)

Viewing the bootstrapped summary of 2007 brood year age 3 cohort in June:

result[["2007"]][["3"]][["6"]][["summary"]]
#>                    median       sd   CrI_low  CrI_high
#> ocean_abundance 8407.3850 286.6125 7888.9955 9003.7356
#> impact             0.0000   0.0000    0.0000    0.0000
#> maturation         0.0000   0.0000    0.0000    0.0000
#> natural_mort     154.8932   5.2804  145.3427  165.8801

Time spent on generating bootstrapped cohort reconstruction with 1000 iterations:

cohort_reconstruct(release, recovery, birth_month = 4L,
  bootstrap = TRUE, last_month = 12L, iter = 1000L,
  level = 0.95, detail = TRUE, sex = "both", verbose = FALSE) |> system.time()
#>    user  system elapsed 
#>  28.819   0.515  30.398

More Information

You can find a more detailed tutorial at https://J-Ch-n.github.io/cwtCensus.

Getting Help

If you encounter a clear bug, please file a minimal reproducible example on GitHub.

About

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •