Estimated total population based on monthly population totals, grouped by species

results %>%
  filter(ModelType == "yearly imputed index: Total ~ Year + Month") %>%
  transmute(
    area = LocationGroup,
    species = scientific_name,
    genus = str_replace(scientific_name, "([[:alpha:]]*) .*", "\\1"),
    year = as.integer(as.character(Parameter)),
    p05 = p_population(Estimate, SE, 0.05),
    p10 = p_population(Estimate, SE, 0.1),
    p30 = p_population(Estimate, SE, 0.3),
    p50 = p_population(Estimate, SE, 0.5),
    p70 = p_population(Estimate, SE, 0.7),
    p90 = p_population(Estimate, SE, 0.9),
    p95 = p_population(Estimate, SE, 0.95),
    Order
  ) %>%
  arrange(genus, Order, area) %>%
  group_by(genus, species) %>%
  nest() %>%
  mutate(
    id = species,
    Previous = lag(genus),
    Title = ifelse(
      is.na(Previous) | Previous != genus,
      sprintf("## %s\n\n### %s", genus, species),
      sprintf("### %s", species)
    )
  ) -> monthly_population
monthly_population %>%
  pull(id) %>%
  sapply(
    function(id) {
      knit_expand("_species_area_montly_total.Rmd", id = id)
    }
  ) %>%
  paste(collapse = "\n\n") -> rmd
knit(text = rmd, quiet = TRUE) %>%
  cat()


inbo/watervogelanalysis documentation built on Oct. 10, 2024, 7:17 a.m.