Skip to contents

Run simulation:

set.seed(42)
result = tekka("-y80 -l3 --sa 10,10 --sj 10,10") |> 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>
sample_family = result$sample_family[[1L]] |> print()
## # A tibble: 7,116 × 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,106 more rows

Extract kinship with degree≤4:

kinship = find_kinship(sample_family, 4L) |> print()
## # A tibble: 93 × 5
##     from    to path   degree label
##    <int> <int> <chr>   <int> <fct>
##  1     2    10 1100_1      4 HC   
##  2     2   102 110_1       3 HUN  
##  3     3    44 10_1        2 HS   
##  4     3    86 1100_1      4 HC   
##  5     3    90 1100_1      4 HC   
##  6     5    92 1100_1      4 HC   
##  7     6    43 1100_1      4 HC   
##  8     7    79 1100_1      4 HC   
##  9     7   111 1100_1      4 HC   
## 10     7   113 1100_1      4 HC   
## # ℹ 83 more rows
kinship |> dplyr::count(label, .drop = FALSE)
## # A tibble: 11 × 2
##    label     n
##    <fct> <int>
##  1 PO        1
##  2 HS       12
##  3 FS        0
##  4 GG        2
##  5 GGG       0
##  6 HUN      19
##  7 UN        0
##  8 HC       50
##  9 C         0
## 10 HGUN      9
## 11 GUN       0

Bind other information to kinship data.frame:

sampled = sample_family |>
  dplyr::filter(!is.na(capture_year)) |>
  dplyr::mutate(age = capture_year - birth_year) |>
  dplyr::select("id", "location", "capture_year", "age") |>
  print()
## # A tibble: 120 × 4
##       id location capture_year   age
##    <int>    <int>        <int> <int>
##  1     1        0           78     4
##  2     2        0           78     4
##  3     3        0           78     4
##  4     4        0           78     5
##  5     5        0           78     5
##  6     6        0           78     5
##  7     7        0           78     6
##  8     8        0           78     5
##  9     9        0           78     5
## 10    10        0           78     4
## # ℹ 110 more rows
kinship |>
  dplyr::left_join(sampled, by = c(from = "id")) |>
  dplyr::left_join(sampled, by = c(to = "id"), suffix = c("_from", "_to"))
## # A tibble: 93 × 11
##     from    to path   degree label location_from capture_year_from age_from
##    <int> <int> <chr>   <int> <fct>         <int>             <int>    <int>
##  1     2    10 1100_1      4 HC                0                78        4
##  2     2   102 110_1       3 HUN               0                78        4
##  3     3    44 10_1        2 HS                0                78        4
##  4     3    86 1100_1      4 HC                0                78        4
##  5     3    90 1100_1      4 HC                0                78        4
##  6     5    92 1100_1      4 HC                0                78        5
##  7     6    43 1100_1      4 HC                0                78        5
##  8     7    79 1100_1      4 HC                0                78        6
##  9     7   111 1100_1      4 HC                0                78        6
## 10     7   113 1100_1      4 HC                0                78        6
## # ℹ 83 more rows
## # ℹ 3 more variables: location_to <int>, capture_year_to <int>, age_to <int>