Skip to contents
## Error in get(paste0(generic, ".", class), envir = get_method_env()) : 
##   object 'type_sum.accel' not found
library(ggplot2)
grDevices::palette("Okabe-Ito")
options(
  ggplot2.continuous.colour = "viridis",
  ggplot2.continuous.fill = "viridis",
  ggplot2.discrete.colour = grDevices::palette()[-1],
  ggplot2.discrete.fill = grDevices::palette()[-1]
)

Run simulation:

set.seed(42)
result = tekka("-y80 -l3") |> print()
## # A tibble: 1 × 17
##   carrying_capacity fishing_coef fishing_mortality  last migration_matrices
##               <dbl> <list>       <list>            <int> <list>            
## 1              2000 <list [0]>   <dbl [84]>            3 <dbl [9 × 4 × 4]> 
## # ℹ 12 more variables: natural_mortality <list>, origin <int>, outdir <chr>,
## #   overdispersion <dbl>, recruitment <dbl>, sample_size_adult <list>,
## #   sample_size_juvenile <list>, seed <int>, weight_for_age <list>,
## #   years <int>, sample_family <list>, demography <list>

A result is a nested tibble with two columns: sample_family and demography:

sample_family = result$sample_family[[1L]] |> print()
## # A tibble: 7,273 × 6
##       id father_id mother_id birth_year location capture_year
##    <int>     <int>     <int>      <int>    <int>        <int>
##  1   132         0         0         -4       NA           NA
##  2   131       132       132          0       NA           NA
##  3   133       132       132          0       NA           NA
##  4   130       131       133          5       NA           NA
##  5   136       132       132          0       NA           NA
##  6   137       132       132          0       NA           NA
##  7   135       136       137          4       NA           NA
##  8   139       132       132          0       NA           NA
##  9   140       132       132          0       NA           NA
## 10   138       139       140          4       NA           NA
## # ℹ 7,263 more rows
demography = result$demography[[1L]] |> print()
## # A tibble: 6,783 × 5
##     year season location   age count
##    <dbl>  <dbl>    <dbl> <dbl> <dbl>
##  1     0      0        0     0  2000
##  2     0      1        0     0  1220
##  3     0      2        0     0   788
##  4     0      3        0     0   467
##  5     4      0        0     0  1057
##  6     4      0        0     4    19
##  7     4      1        0     0   652
##  8     4      1        0     4    13
##  9     4      2        0     0   394
## 10     4      2        0     4    13
## # ℹ 6,773 more rows

Here is an example of visualizing demography:

df = demography |>
  dplyr::mutate(time = year + 0.25 * season) |>
  dplyr::mutate(age = ifelse(age > 4, "adult", "juvenile")) |>
  dplyr::summarize(count = sum(count), .by = c(time, location, age))

ggplot(df) +
  aes(time, count) +
  geom_path(aes(colour = age, group = age)) +
  facet_grid(vars(location)) +
  theme_bw() +
  theme(legend.position = "top")