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:
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.314 0.008 0.324Viewing 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 7965.572Creating 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 7927.9520 279.29474 7443.6070 8549.7916
#> impact 0.0000 0.00000 0.0000 0.0000
#> maturation 0.0000 0.00000 0.0000 0.0000
#> natural_mort 146.0604 5.14558 137.1371 157.5168Time 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
#> 23.442 0.189 23.671More 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.