Skip to contents
library(tekkamaki)
library(conflicted)
library(dplyr)
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:

result = tekka("--seed=42 -y100 -l3") |> print()
## # A tibble: 1 × 13
##   carrying_capacity infile  last origin outdir        overdispersion recruitment
##               <dbl> <chr>  <int>  <dbl> <chr>                  <dbl>       <dbl>
## 1              1000 ""         3    0.2 /var/folders…             -1           2
## # ℹ 6 more variables: sample_size_adult <list>, sample_size_juvenile <list>,
## #   seed <int>, 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,045 × 6
##       id father_id mother_id birth_year location capture_year
##    <int>     <int>     <int>      <int>    <int>        <int>
##  1    95         0         0         -4       NA           NA
##  2    96         0         0         -4       NA           NA
##  3    94        95        96          1       NA           NA
##  4    98         0         0         -4       NA           NA
##  5    99         0         0         -4       NA           NA
##  6    97        98        99          1       NA           NA
##  7    93        94        97          6       NA           NA
##  8   102         0         0         -4       NA           NA
##  9   103         0         0         -4       NA           NA
## 10   101       102       103          1       NA           NA
## # ℹ 7,035 more rows
demography = result$demography[[1L]] |> print()
## # A tibble: 8,862 × 5
##     year season location   age count
##    <dbl>  <dbl>    <dbl> <dbl> <dbl>
##  1     0      3        0     4   200
##  2     1      0        0     0 13515
##  3     1      1        0     0  8388
##  4     1      2        0     0  5343
##  5     1      3        0     0  3243
##  6     2      0        2     1  1459
##  7     2      1        2     1  1050
##  8     2      2        2     1   765
##  9     2      3        2     1   653
## 10     3      0        2     2   266
## # ℹ 8,852 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")