Skip to content
Snippets Groups Projects
Commit 0ee5a661 authored by Facundo Muñoz's avatar Facundo Muñoz :registered:
Browse files

Adopt "age" as a term for "days since release event".

parent 22ecc553
No related branches found
No related tags found
No related merge requests found
......@@ -1353,8 +1353,9 @@ Depending on the needs and hypotheses, the calculation could also aggregate days
# the package will have to perform. Only, using data extractors
# as mrr_surveys() et al.
## Days since release event for each surveyed population
surveys_days <-
## Days since release event (age) for each surveyed
## population of sterile males.
surveys_ages <-
cub_adult_data_raw |>
select(
survey = `Survey date`,
......@@ -1367,9 +1368,29 @@ surveys_days <-
pivot_longer(
cols = yellow:pink,
names_to = "population",
values_to = "day"
values_to = "age"
) |>
filter(!is.na(day))
filter(!is.na(age))
captures_by_age <-
cub_adult_data_clean |>
inner_join(
## Implicitly filters sterile males
surveys_ages,
by = c("survey", "population")
) |>
select(-sex) |>
mutate(
species = factor(species),
population = factor(population)
) |>
## Keep observations up to the last age for which there is at least one
## observation of a sterile male.
group_by(age) |>
filter(sum(n) > 0) |>
ungroup()
## Use reported distances (based on rings) to the single
## release point
......@@ -1378,32 +1399,19 @@ traps_distances <-
select(trap = `Trap Id`, d_m = `Distance (m)`) |>
unique()
## Mean dispersal distances by day and release
## Captures by trap, age and population
cub_dispersal_dat <-
cub_adult_data_clean |>
filter(
sex == "male",
# species == "aeg", # This is redundant with not wild next
population != "wild"
) |>
select(-species, -sex, -duration) |>
captures_by_age |>
left_join(
traps_distances,
by = "trap"
) |>
inner_join(
surveys_days,
by = c("survey", "population")
) |>
select(-survey) |>
select(-survey, -species, -duration) |>
mutate(
population = fct_inorder(population)
) |>
## Keep observations up to the last day for which there is at least one
## observation of a sterile male.
group_by(day) |>
filter(sum(n) > 0) |>
ungroup()
)
```
......@@ -1412,12 +1420,12 @@ cub_dispersal_dat <-
## of MRR_template.xls.
cub_dispersal_dat |>
filter(day == 7, population == "pink") |>
filter(age == 7, population == "pink") |>
print(n = 21)
## MDD by day and population
## MDD by age and population
cub_dispersal_dat |>
group_by(day, population) |>
group_by(age, population) |>
## We have 21 surveys in each group (1 for each trap)
summarise(
mdd = ifelse(sum(n) > 0, sum(n * d_m)/sum(n), NA),
......@@ -1429,7 +1437,7 @@ cub_dispersal_dat |>
)
## MDD by population, across days.
## MDD by population, across ages.
cub_dispersal_dat |>
group_by(population) |>
## We have 21 surveys in each group (1 for each trap)
......@@ -1438,15 +1446,15 @@ cub_dispersal_dat |>
.groups = "drop"
)
## MDD by day, across populations.
## MDD by ages, across populations.
cub_dispersal_dat |>
group_by(day) |>
group_by(age) |>
summarise(
mdd = sum(n * d_m)/sum(n),
.groups = "drop"
)
## MDD across days and populations.
## MDD across ages and populations.
cub_dispersal_dat |>
summarise(
mdd = sum(n * d_m)/sum(n),
......@@ -1457,15 +1465,15 @@ cub_dispersal_dat |>
Define a function `mrr_dispersal()` which computes the MDD estimates by day and population.
Define a function `mrr_dispersal()` which computes the MDD estimates by age and population.
Input:
```{r}
print_variable_table(
"x", "Either a `mrrsit` object or the outcome of a `adult_surveys()` call.",
"pool", "Character or NULL (default). Any of `populations`, `days` or `all`.",
"by", "Character or NULL. Any of `populations`, `days` or `all` (default). Alternative to `pool`.",
"pool", "Character or NULL (default). Any of `populations`, `ages` or `all`.",
"by", "Character or NULL. Any of `populations`, `ages` or `all` (default). Alternative to `pool`.",
header = FALSE
)
```
......@@ -1479,7 +1487,7 @@ Only one of either the dual arguments `pool` or `by` should be implemented. I th
```{r}
cub_dispersal_dat |>
group_by(day, population) |>
group_by(age, population) |>
## We have 21 surveys in each group (1 for each trap)
summarise(
mdd = ifelse(sum(n) > 0, sum(n * d_m)/sum(n), NA),
......@@ -1487,11 +1495,11 @@ Only one of either the dual arguments `pool` or `by` should be implemented. I th
)
```
For `by = days` or `pool = populations` counts are pooled across populations and MDDs are computed by days alone :
For `by = ages` or `pool = populations` counts are pooled across populations and MDDs are computed by ages alone :
```{r}
cub_dispersal_dat |>
group_by(day) |>
group_by(age) |>
## We have 21 surveys in each group (1 for each trap)
summarise(
mdd = ifelse(sum(n) > 0, sum(n * d_m)/sum(n), NA),
......@@ -1499,7 +1507,7 @@ Only one of either the dual arguments `pool` or `by` should be implemented. I th
)
```
For `by = populations` or `pool = days` counts are pooled across days and MDDs are computed by populations alone :
For `by = populations` or `pool = ages` counts are pooled across ages and MDDs are computed by populations alone :
```{r}
cub_dispersal_dat |>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment