Code
knitr::opts_chunk$set(cache = TRUE)Nest and Chick Survival Modelling
knitr::opts_chunk$set(cache = TRUE)# a vector of all the packages needed in the project
packages_required_in_project <- c("tidyverse",
                                  "readxl",
                                  "RMark",
                                  "RColorBrewer",
                                  "patchwork",
                                  "mapview",
                                  "lubridate",
                                  "extrafont",
                                  "here",
                                  "DT",
                                  "leaflet",
                                  "sf",
                                  "leafpop",
                                  "tsibble",
                                  "corrplot",
                                  "gghalves",
                                  "gam",
                                  "pscl",
                                  "gamlss",
                                  "gt",
                                  "lme4",
                                  "timeDate",
                                  "circular",
                                  "openxlsx", 
                                  "fuzzyjoin")
                                  
# of the required packages, check if some need to be installed
new.packages <- 
  packages_required_in_project[!(packages_required_in_project %in% 
                                   installed.packages()[,"Package"])]
# install all packages that are not locally available
if(length(new.packages)) install.packages(new.packages)
# load all the packages into the current R session
lapply(packages_required_in_project, require, character.only = TRUE)
# set the home directory to where the project is locally based (i.e., to find 
# the relevant datasets to import, etc.
here::set_here()# Find fonts from computer that you want. Use regular expressions to do this
# For example, load all fonts that are 'verdana' or 'Verdana'
extrafont::font_import(pattern = "[V/v]erdana", prompt = FALSE) 
# check which fonts were loaded
extrafont::fonts()
extrafont::fonttable()
extrafont::loadfonts() # load these into R
# define the plotting theme to be used in subsequent ggplots
luke_theme <- 
  theme_bw() +
  theme(
    text = element_text(family = "Verdana"),
    legend.title = element_text(size = 10),
    legend.text = element_text(size = 8),
    axis.title.x = element_text(size = 10),
    axis.text.x  = element_text(size = 8), 
    axis.title.y = element_text(size = 10),
    axis.text.y = element_text(size = 8),
    strip.text = element_text(size = 10),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    axis.ticks = element_line(size = 0.5, colour = "grey40"),
    axis.ticks.length = unit(0.2, "cm"),
    panel.border = element_rect(linetype = "solid", colour = "grey"),
    legend.position = c(0.1, 0.9)
  )
region_names <- c(
  'FP' = "Fleurieu Peninsula",
  'MP' = "Mornington Peninsula",
  'BSC' = "Bellarine / Surf Coast",
  'PI' = "Phillip Island",
  'BC' = "Bass Coast" )
# set mapview to show satellite imagery
mapviewOptions(basemaps = c("Esri.WorldImagery"))The following custom functions are used to
%!in%This function simply does the opposite of %in%, which is used to test if elements on the left-hand side are members of the set defined by the right-hand side. %!in% returns a logical vector indicating whether each element on the left-hand side is not present in the right-hand side.
`%!in%` = Negate(`%in%`)nest_import()This function imports the HOPL nest survival data stored as Excel sheets into R, wrangles it into a single dataframe, and prepares it for subsequent analysis (e.g., specifies relevent date columns, etc.)
arguments:
year_1: first calender year of the focal data sheet (e.g., 2002)year_2: second calender year of the focal data set (i.e., always year_1 + 1)file_name: name of the Excel sheet to import data fromsite: site that the data describes (MP, FP, BSC, BC or PI)extra_text: the extra text associated with each sheet in the Excel file (i.e., besides from the year)first_found_date_col: the number of the column in the sheets that correspond to the first found datelast_alive_date_col: the number of the column in the sheets that correspond to the last alive datelast_checked_col: the number of the column in the sheets that correspond to the last checked datenest_import <-
  function(year_1, year_2, file_name, site, extra_text = NULL, Nest_ID_col_name = "Nest ID_2", 
           first_found_date_col, last_alive_date_col, last_checked_col) {
    if(is.null(extra_text)){
      file <- 
        read_excel(paste0("data/", file_name), 
                   sheet = paste0(site, " ", year_1, "_", str_sub(year_2, 3, 4)), 
                   col_types = "text", na = "n/a")
    }
    else{
      file <- 
        read_excel(paste0("data/", file_name), 
                   sheet = paste0(site, " ", year_1, "_", str_sub(year_2, 3, 4), extra_text), 
                   col_types = "text", na = "n/a")
    }
    file %>%
      # simplify column names
      rename(first_found = first_found_date_col,
             last_alive = last_alive_date_col,
             last_checked = last_checked_col,
             Fate = `Hatch?`,
             season = Season,
             # site = Site,
             site = `Suggested update to site name`,
             nest_ID = Nest_ID_col_name,
             nest_hab = `Nest habitat`,
             management_status = `Nest managed?`,
             management_type = `Nest management type`,
             nest_lat = `Nest latitude`,
             nest_lon = `Nest longitude`,
             chick_1st_ob = which(names(file) %in% c("Date chicks sighted", "Chicks first obsv date"))[1],
             clutch_comp = which(names(file) %in% c("Known clutch complete date", "Known laying date")),
             state_1st_ob = `Age stage first observed`,
             chick_management_status = which(names(file) %in% c("Chick manged?", "Chick managed?")),
             chick_management_type = `Chick management type`) %>% 
      # consolidate columns
      dplyr::select(season, site, nest_ID, first_found, last_alive, last_checked, Fate, nest_hab, 
                    management_status, management_type, nest_lat, nest_lon,
                    chick_1st_ob, clutch_comp, state_1st_ob, 
                    chick_management_status, chick_management_type) %>% 
      
      # wrangle: clean up Fate column for consistency
      mutate(Fate = ifelse(Fate == "?", "Unk", as.character(Fate))) %>% 
      mutate(Fate = toupper(Fate)) %>%
      # remove rows that have either an NA or numbers in the first_found column
      filter(is.na(first_found) | grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", first_found)) %>%
      # clean up the last_checked and last_alive columns so that non-number data are dropped to NA
      mutate(last_checked = ifelse(!is.na(last_checked) & 
                                     !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_checked), 
                                   NA, last_checked)) %>% 
      mutate(last_alive = ifelse(!is.na(last_alive) & 
                                   !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_alive), 
                                 NA, last_alive))%>% 
      # wrangle: if date last alive is "Unk." make it "NA"
      mutate(last_alive = ifelse(str_detect(last_alive, "Unk."), NA, last_alive),
             # change Fate to 1 or 0 (1 = failed, 0 = hatched, NA = unknown)
             Fate = ifelse(Fate == "Y", "0", 
                           ifelse(Fate == "N", "1", 
                                  ifelse(Fate == "UNK", NA, "XXX")))) %>%
      # remove nests without Fate information
      filter(Fate %in% c("0", "1")) %>% 
      # classify the chick_1st_ob and clutch_comp columns as.Date()
      mutate(chick_1st_ob = case_when(
          # Excel serial dates stored as numbers
          str_detect(chick_1st_ob, "^[0-9]+$") ~ as.Date(as.numeric(chick_1st_ob), origin = "1899-12-30"),
          
          # Dates with extra text in parentheses — extract only the date part
          str_detect(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
            dmy(str_extract(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
          ),
          
          # Everything else (including "Unk", "Failed during laying") → NA
          TRUE ~ as.Date(NA)
        ), 
             clutch_comp =  case_when(
          # Excel serial dates stored as numbers
          str_detect(clutch_comp, "^[0-9]+$") ~ as.Date(as.numeric(clutch_comp), origin = "1899-12-30"),
          
          # Dates with extra text in parentheses — extract only the date part
          str_detect(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
            dmy(str_extract(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
          ),
          
          # Everything else (including "Unk", "Failed during laying") → NA
          TRUE ~ as.Date(NA)
        )) %>%
      # if the clutch completion date is NA, then estimate it as 35 days before estimated hatch date - 28 days
      # using the date of first chick observation and the size of the chicks when seen
      mutate(clutch_comp = ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob),
                                        ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3 - 28,
                                               ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10 - 28,
                                                      ifelse(state_1st_ob == "2/3 adult size, mottled grey", chick_1st_ob - 19 - 28,
                                                             ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30 - 28,
                                                                    ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35 - 28,
                                                                           ifelse(state_1st_ob == "wet in nest", chick_1st_ob - 28, NA)))))), 
                                        ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob), NA, NA)) %>% as.Date()) %>%
      # specify the last_alive2 date for hatched nests as the estimated hatch date
      # using the date of first chick observation and the size of the chicks when seen
      mutate(last_alive2 = ifelse(Fate == "0" & !is.na(clutch_comp) & is.na(last_alive), clutch_comp + 28,
                                 ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob) & is.na(last_alive),
                                        ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3,
                                               ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10,
                                                      ifelse(state_1st_ob == "2/3 adult size, mottled grey", chick_1st_ob - 19,
                                                             ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30,
                                                                    ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35,
                                                                           ifelse(state_1st_ob == "wet in nest", chick_1st_ob, NA)))))), 
                                        ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob) & is.na(last_alive), NA, NA))) %>% as.Date()) %>% 
      # clean up the last_alive date given the new last_alive2 date extracted above
      mutate(last_alive = ifelse(!is.na(last_alive2), 
                                paste0(str_sub(as.character(last_alive2), 9, 10),
                                       str_sub(as.character(last_alive2), 6, 7),
                                       str_sub(as.character(last_alive2), 1, 4)), last_alive)) %>% 
      mutate(
        # wrangle: if last_alive has a date and last_checked is NA, then change 
        # last_checked to the date in last_alive
        last_checked = ifelse(!is.na(last_alive) & is.na(last_checked),
                              last_alive,
                              # if both last_alive and last_checked is "NA", then
                              # change last_checked to the first_found date
                              ifelse(is.na(last_alive) & is.na(last_checked),
                                     first_found,
                                     last_checked))) %>%
      mutate(
        # wrangle: if last_alive is NA and the nest hatched and last_checked has a
        # date, then specify last_alive as the date from last_checked
        last_alive = ifelse(is.na(last_alive) & Fate == "0" & !is.na(last_checked),
                            last_checked,
                            # if the last_alive is NA and the nest failed and 
                            # last_checked has a date, then specify last_alive as the
                            # date from first_found
                            ifelse(is.na(last_alive) & Fate == "1" & !is.na(last_checked),
                                   first_found,
                                   last_alive))) %>%
      # only keep rows that have 8 characters in the first_found, last_alive, and last_checked
      filter(nchar(first_found) == 8 & nchar(last_alive) == 8 & nchar(last_checked) == 8) %>%
      # specify date columns as a date string
      mutate(first_found2 = as.Date(paste(str_sub(first_found, 5, 8),
                                          str_sub(first_found, 3, 4),
                                          str_sub(first_found, 1, 2), sep = "-")),
             last_alive2 = as.Date(paste(str_sub(last_alive, 5, 8),
                                         str_sub(last_alive, 3, 4),
                                         str_sub(last_alive, 1, 2), sep = "-")),
             last_checked2 = as.Date(paste(str_sub(last_checked, 5, 8),
                                           str_sub(last_checked, 3, 4),
                                           str_sub(last_checked, 1, 2), sep = "-"))) %>%
      # if the found date is > days before the last alive date, and the clutch 
      # completion date is not NA and is < 40 days before the last alive date 
      # then replace the found date with the clutch completion date
      mutate(first_found2 = ifelse(!is.na(clutch_comp) & ((last_alive2 - first_found2) > 40 | (last_alive2 - first_found2) < 0)
                                                            & ((last_alive2 - clutch_comp) < 40 | (last_alive2 - clutch_comp) > 0), 
                                   clutch_comp, first_found2) %>% as.Date()) %>% 
      # if last checked date is before last alive date, then change it to the 
      # last alive date, if not then leave as is
      mutate(last_checked2 = ifelse(!is.na(last_alive2) & !is.na(last_checked2) & last_checked2 < last_alive2, 
                                    last_alive2, last_checked2) %>% as.Date()) %>% 
      # # julian dates
      # mutate(FirstFound = ((as.integer(format(first_found2, "%j")) -
      #                        as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
      #      replace(. == 0, 365),#as.numeric(format(first_found2 + 180, "%j")),
      #        LastPresent = ((as.integer(format(last_alive2, "%j")) -
      #                        as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
      #      replace(. == 0, 365),#as.numeric(format(last_alive2 + 180, "%j")),
      #        LastChecked = ((as.integer(format(last_checked2, "%j")) -
      #                        as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
      #      replace(. == 0, 365)) %>% #as.numeric(format(last_checked2 + 180, "%j"))) %>% 
      # julian dates
      mutate(FirstFound = as.numeric(format(first_found2 + 180, "%j")),
             LastPresent = as.numeric(format(last_alive2 + 180, "%j")),
             LastChecked = as.numeric(format(last_checked2 + 180, "%j"))) %>% 
      # remove all nests that have unknown fate
      # filter(!is.na(Fate)) %>% 
      # clean up the management_type column
      mutate(management_type = tolower(management_type)) %>% 
      mutate(management_type = str_replace(management_type, "acess", "access")) %>% 
      mutate(management_type = str_replace(management_type, "and", ",")) %>% 
      mutate(management_type = str_replace(management_type, "temporary", "")) %>% 
      mutate(management_type = str_replace_all(management_type, " ", "")) %>% 
      mutate(management_type = str_replace_all(management_type, "shelters", "")) %>% 
      mutate(management_type = str_replace_all(management_type, "banners", "")) %>% 
      mutate(management_type = str_replace_all(management_type, ",,", ",")) %>% 
      mutate(sign_access = ifelse(str_detect(management_type, "signaccess"), 1, 0)) %>%
      mutate(perm_fence = ifelse(str_detect(management_type, "permanentfence") | str_detect(management_type, "ringlockfence"), 1, 0)) %>%
      mutate(sign_nest = ifelse(str_detect(management_type, "signnest"), 1, 0)) %>% 
      mutate(rope_fence = ifelse(str_detect(management_type, "ropefence"), 1, 0)) %>% 
      mutate(wardens = ifelse(str_detect(management_type, "wardens"), 1, 0)) %>% 
      mutate(none = ifelse(str_detect(management_type, "none"), 1, 
                           ifelse(is.na(management_type) & management_status == "N", 1, 0))) %>% 
      mutate(other = ifelse(str_detect(management_type, "other"), 1, 0)) %>%
      mutate(nest_hab = tolower(nest_hab)) %>% 
                                        # Level 4 is Sign Nest, Rope fence, Wardens
      mutate(management_level = ifelse(rope_fence == 1 & wardens == 1, 4,
                                       # Level 3 is Sign Nest, Rope fence
                                       ifelse(rope_fence == 1, 3, 
                                              # Level 2 is Sign Nest
                                              ifelse(sign_nest == 1, 2,
                                                     # Level 1 is Sign Access or Permanent fence (but only if nest in dune)
                                                     ifelse((perm_fence == 1 & nest_hab == "dune") | sign_access == 1, 1,
                                                            ifelse(none == 1, 0, NA))))))
  }First we import the data and run a few checks to assess if there are any rows with the following issues:
found date is not 8 characters
last seen alive date is not 8 characters
last checked date is not 8 characters
found date missing
last seen alive date missing
last checked date missing
Nest managed? is not Y or N
Nest habitat is not Beach, Dune, Foredune/face, or Estuary/spit
Management type is not sufficient for making levels
Double check dates because incubation time greater than 35 days
Found date is after Last Alive date (should be greater or equal)
Found date is after Last Checked date (should be greater or equal)
Last Checked date is before Last Alive date (should be greater or equal)
MP_nest_data_issues <-
suppressMessages(
  bind_rows(
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2023", "_", str_sub("2024", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2022", "_", str_sub("2023", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2021", "_", str_sub("2022", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2020", "_", str_sub("2021", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2019", "_", str_sub("2020", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2018", "_", str_sub("2019", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2017", "_", str_sub("2018", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2016", "_", str_sub("2017", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2015", "_", str_sub("2016", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2014", "_", str_sub("2015", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2013", "_", str_sub("2014", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2012", "_", str_sub("2013", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2011", "_", str_sub("2012", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2010", "_", str_sub("2011", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2009", "_", str_sub("2010", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2008", "_", str_sub("2009", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2007", "_", str_sub("2008", 3, 4)), 
             col_types = "text", na = "n/a"), 
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2006", "_", str_sub("2007", 3, 4)), 
             col_types = "text", na = "n/a"))) %>%
    filter(!is.na(Season)) %>% 
  rename(first_found = 13,
         last_alive = 33,
         last_checked = 39,
         Fate = `Hatch?`,
         season = Season,
         # site = Site,
         site = `Suggested update to site name`,
         nest_ID = `Nest ID_2`,
         nest_hab = `Nest habitat`,
         management_status = `Nest managed?`,
         management_type = `Nest management type`,
         nest_lat = `Nest latitude`,
         nest_lon = `Nest longitude`,
         state_1st_ob = `Age stage first observed`) %>% 
  rename(
    chick_1st_ob = !!names(.)[which(names(.) %in% c("Date chicks sighted", "Chicks first obsv date"))][1],
    clutch_comp  = !!names(.)[which(names(.) %in% c("Known clutch complete date", "Known laying date"))][1]
  ) %>% 
  # chick_1st_ob = which(names(.) %in% c("Date chicks sighted", "Chicks first obsv date"))[1],
  # clutch_comp = which(names(.) %in% c("Known clutch complete date", "Known laying date"))) %>% 
  dplyr::select(season, site, nest_ID, first_found, last_alive, last_checked, Fate, nest_hab, 
                management_status, management_type, nest_lat, nest_lon, site,
                chick_1st_ob, clutch_comp, state_1st_ob) %>%
  mutate(Fate = ifelse(Fate == "?", "Unk", Fate)) %>% 
  mutate(Fate = toupper(Fate)) %>% 
  filter(
    is.na(first_found) | 
      grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", first_found)
  ) %>%
  mutate(last_checked = ifelse(!is.na(last_checked) & !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_checked), 
                               NA, last_checked)) %>% 
  mutate(last_alive = ifelse(!is.na(last_alive) & !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_alive), 
                             NA, last_alive)) %>% 
  mutate(last_alive = ifelse(str_detect(last_alive, "Unk."), NA, last_alive),
         Fate = ifelse(Fate == "Y", "0", 
                       ifelse(Fate == "N", "1", 
                              ifelse(Fate == "UNK", NA, "XXX")))) %>%
  # remove nests without Fate information
  filter(Fate %in% c("0", "1")) %>% 
  mutate(chick_1st_ob = case_when(
    # Excel serial dates stored as numbers
    str_detect(chick_1st_ob, "^[0-9]+$") ~ as.Date(as.numeric(chick_1st_ob), origin = "1899-12-30"),
    
    # Dates with extra text in parentheses — extract only the date part
    str_detect(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
      dmy(str_extract(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
    ),
    
    # Everything else (including "Unk", "Failed during laying") → NA
    TRUE ~ as.Date(NA)
  ), 
  clutch_comp =  case_when(
    # Excel serial dates stored as numbers
    str_detect(clutch_comp, "^[0-9]+$") ~ as.Date(as.numeric(clutch_comp), origin = "1899-12-30"),
    
    # Dates with extra text in parentheses — extract only the date part
    str_detect(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
      dmy(str_extract(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
    ),
    
    # Everything else (including "Unk", "Failed during laying") → NA
    TRUE ~ as.Date(NA)
  )) %>%
  # if the clutch completion date is NA, then estimate it as 35 days before estimated hatch date #28 days incubation length
  # using the date of first chick observation and the size of the chicks when seen
  mutate(clutch_comp = ifelse(!is.na(clutch_comp), clutch_comp, 
                              ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3 - 28,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10 - 28,
                                                   ifelse(state_1st_ob == "2/3 adult size, mottled grey", chick_1st_ob - 19 - 28,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30 - 28,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35 - 28,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob - 28, NA)))))), 
                                     ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob), NA, NA))) %>% as.Date()) %>% 
  mutate(last_alive2 = ifelse(Fate == "0" & !is.na(clutch_comp) & is.na(last_alive), clutch_comp + 28,
                              ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob) & is.na(last_alive),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10,
                                                   ifelse(state_1st_ob == "2/3 adult size, mottled grey", chick_1st_ob - 19,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob, NA)))))), 
                                     ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob) & is.na(last_alive), NA, NA))) %>% as.Date()) %>% 
  # mutate(last_alive2 = ifelse(Fate == "0" & !is.na(chick_1st_ob) & last_alive2 > chick_1st_ob, chick_1st_ob, last_alive2) %>% as.Date()) %>% 
  mutate(last_alive = ifelse(!is.na(last_alive2), 
                             paste0(str_sub(as.character(last_alive2), 9, 10),
                                    str_sub(as.character(last_alive2), 6, 7),
                                    str_sub(as.character(last_alive2), 1, 4)), last_alive)) %>% 
  mutate(
    last_checked = ifelse(!is.na(last_alive) & is.na(last_checked),
                          last_alive,
                          ifelse(is.na(last_alive) & is.na(last_checked),
                                 first_found, last_checked))) %>%
  mutate(
    last_alive = ifelse(is.na(last_alive) & Fate == "0" & !is.na(last_checked),
                        last_checked,
                        ifelse(is.na(last_alive) & Fate == "1" & !is.na(last_checked),
                               first_found,
                               last_alive))) %>%
  filter(
    (is.na(last_alive) | nchar(last_alive) == 8) &
      (is.na(first_found) | nchar(first_found) == 8) &
      (is.na(last_checked) | nchar(last_checked) == 8)
  ) %>% 
  mutate(first_found2 = as.Date(paste(str_sub(first_found, 5, 8),
                                      str_sub(first_found, 3, 4),
                                      str_sub(first_found, 1, 2), sep = "-")),
         last_alive2 = as.Date(paste(str_sub(last_alive, 5, 8),
                                     str_sub(last_alive, 3, 4),
                                     str_sub(last_alive, 1, 2), sep = "-")),
         last_checked2 = as.Date(paste(str_sub(last_checked, 5, 8),
                                       str_sub(last_checked, 3, 4),
                                       str_sub(last_checked, 1, 2), sep = "-"))) %>% 
  mutate(last_checked2 = ifelse(!is.na(last_alive2) & !is.na(last_checked2) & last_checked2 < last_alive2, 
                                last_alive2, last_checked2) %>% as.Date()) %>% 
  mutate(first_found2 = ifelse(!is.na(clutch_comp) & ((last_alive2 - first_found2) > 40 | (last_alive2 - first_found2) < 0)
                               & ((last_alive2 - clutch_comp) < 40 | (last_alive2 - clutch_comp) > 0), 
                               clutch_comp, first_found2) %>% as.Date()) %>% 
  mutate(FirstFound = as.numeric(format(first_found2 + 180, "%j")),
         LastPresent = as.numeric(format(last_alive2 + 180, "%j")),
         LastChecked = as.numeric(format(last_checked2 + 180, "%j"))) %>% 
  # mutate(FirstFound = ((as.integer(format(first_found2, "%j")) -
  #                         as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365),#as.numeric(format(first_found2 + 180, "%j")),
  #        LastPresent = ((as.integer(format(last_alive2, "%j")) -
  #                          as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365),#as.numeric(format(last_alive2 + 180, "%j")),
  #        LastChecked = ((as.integer(format(last_checked2, "%j")) -
  #                          as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365)) %>% #as.numeric(format(last_checked2 + 180, "%j"))) %>% 
  mutate(management_type = tolower(management_type)) %>%
  mutate(nest_hab = tolower(nest_hab)) %>%
  mutate(management_type = str_replace(management_type, "acess", "access")) %>%
  mutate(management_type = str_replace(management_type, "and", ",")) %>%
  mutate(management_type = str_replace(management_type, "temporary", "")) %>%
  mutate(management_type = str_replace_all(management_type, " ", "")) %>%
  mutate(management_type = str_replace_all(management_type, "shelters", "")) %>%
  mutate(management_type = str_replace_all(management_type, "banners", "")) %>%
  mutate(management_type = str_replace_all(management_type, ",,", ",")) %>%
  mutate(sign_access = ifelse(str_detect(management_type, "signaccess"), 1, 0)) %>%
  mutate(sign_nest = ifelse(str_detect(management_type, "signnest"), 1, 0)) %>%
  mutate(rope_fence = ifelse(str_detect(management_type, "ropefence"), 1, 0)) %>%
  mutate(perm_fence = ifelse(str_detect(management_type, "permanentfence"), 1, 0)) %>% # & nest_hab == "dune", 1, 0)) %>%
  mutate(wardens = ifelse(str_detect(management_type, "wardens"), 1, 0)) %>% 
  mutate(none = ifelse(str_detect(management_type, "none"), 1, 
                       ifelse(is.na(management_type) & management_status == "N", 1, 0))) %>%
  mutate(other = ifelse(str_detect(management_type, "other"), 1, 0)) %>%
  mutate(management_level = ifelse((sign_access == 1 | perm_fence == 1) & sign_nest == 1 & rope_fence == 1 & wardens == 1, 4,
                                   ifelse(rope_fence == 1, 3,
                                          ifelse(sign_nest == 1, 2,
                                                 ifelse(sign_access == 1 | perm_fence == 1, 1,
                                                        ifelse(none == 1, 0, NA)))))) %>%
  mutate(sign_nest_no_sign_access = ifelse(sign_access == 0 & sign_nest == 1, 1, 0)) %>%
  mutate(fence_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & rope_fence == 1, 1, 0)) %>%
  mutate(wardens_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & wardens == 1, 1, 0)) %>%
  mutate(wardens_no_fence = ifelse(rope_fence == 1 & wardens == 1, 1, 0)) %>%
  mutate(just_wardens = ifelse(rope_fence == 0 & sign_access == 0 & sign_nest == 0 & wardens == 1, 1, 0)) %>%
  dplyr::select(-other, -sign_nest_no_sign_access, -fence_no_sign, 
                -wardens_no_sign, -wardens_no_fence, -just_wardens) %>%
  group_by(season) %>%
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  mutate(region = "MP") %>%
  mutate(site = as.factor(site)) %>%
  mutate(issue1 = ifelse(nchar(first_found) != 8, "found date is not 8 characters; ", NA)) %>% 
  mutate(issue2 = ifelse(nchar(last_alive) != 8, "last seen alive date is not 8 characters; ", NA)) %>% 
  mutate(issue3 = ifelse(nchar(last_checked) != 8, "last checked date is not 8 characters; ", NA)) %>% 
  mutate(issue4 = ifelse(is.na(first_found), "found date missing; ", NA)) %>% 
  mutate(issue5 = ifelse(is.na(last_alive), "last seen alive date missing; ", NA)) %>% 
  mutate(issue6 = ifelse(is.na(last_checked), "last checked date missing; ", NA)) %>% 
  mutate(issue7 = ifelse(management_status %!in% c("Y", "N"), "Nest managed? is not Y or N; ", NA)) %>% 
  mutate(issue8 = ifelse(nest_hab %!in% c("beach", "dune", "foredune/face", "estuary/spit"), 
                         "Nest habitat is not beach, dune, foredune/face, or estuary/spit; ", NA)) %>%
  mutate(issue9 = ifelse(is.na(management_level), "Management type is not sufficient for making levels; ", NA)) %>%
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>% 
  mutate(issue10 = ifelse(found_and_alive_diff > 40 , "Double check dates because incubation time greater than 40 days; ", NA)) %>% 
  mutate(issue11 = ifelse(first_found2 > last_alive2, "Found date is after Last Alive date (should be greater or equal); ", NA)) %>% 
  mutate(issue12 = ifelse(first_found2 > last_checked2, "Found date is after Last Checked date (should be greater or equal); ", NA)) %>%
  mutate(issue13 = ifelse(last_checked2 < last_alive2, "Last Checked date is before Last Alive date (should be greater or equal); ", NA)) %>% 
  mutate(issues = ifelse(is.na(issue1) & is.na(issue2) & is.na(issue3) & 
                           is.na(issue4) & is.na(issue5) & is.na(issue6) & 
                           is.na(issue7) & is.na(issue8) & is.na(issue9) & 
                           is.na(issue10) & is.na(issue11) & is.na(issue12) & is.na(issue13), NA, 
                         paste0(issue1, issue2, issue3, 
                                issue4, issue5, issue6, 
                                issue7, issue8, issue9,
                                issue10, issue11, issue12, issue13))) %>% 
  mutate(issues = str_remove_all(issues, "NA")) %>% 
  mutate(issues = ifelse(is.na(issues), "usable", issues)) %>% 
  dplyr::select(-issue1, -issue2, -issue3, 
                -issue4, -issue5, -issue6, 
                -issue7, -issue8, -issue9, 
                -issue10, -issue11, -issue12, -issue13) %>% 
  filter(issues != "usable") %>%
  arrange(issues)
# 
# MP_nest_data_issues %>%
#   filter(str_detect(issues, "date")) %>%
#   select(nest_ID, Fate, clutch_comp, chick_1st_ob, first_found2, last_alive2, last_checked2, first_found, last_alive, last_checked, found_and_alive_diff, issues) %>% View()# Create a new workbook to store issues as two sheets
MP_nest_issues <- createWorkbook()
# Add all_issues sheet
addWorksheet(MP_nest_issues, "all_issues")
# view issues interactively in RStudio Viewer
MP_nest_data_issues %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')# write MP_nest_data_check
writeData(MP_nest_issues, sheet = "all_issues", MP_nest_data_issues)# Add date_issues
addWorksheet(MP_nest_issues, "date_issues")
# view issues interactively in RStudio Viewer
MP_nest_data_issues %>% 
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>%
  filter(str_detect(issues, "date")) %>%
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>%
  mutate(issues = str_remove_all(issues, "Nest habitat is not Beach, Dune, Foredune/face, Estuary/spit, or Rocks; ")) %>%
  dplyr::select(season, nest_ID, nest_hab, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, 
                Fate, found_and_alive_diff, issues)  %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')# write MP_nest_data_check
MP_nest_data_issues %>% 
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>%
  filter(str_detect(issues, "date")) %>%
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>%
  mutate(issues = str_remove_all(issues, "Nest habitat is not Beach, Dune, Foredune/face, Estuary/spit, or Rocks; ")) %>%
  dplyr::select(season, nest_ID, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, 
                Fate, found_and_alive_diff, issues) %>% 
  writeData(MP_nest_issues, sheet = "date_issues", .)
# Save the workbook
saveWorkbook(MP_nest_issues,
             here("data/nest_issues_commented/MP_nest_data_issues_011025.xlsx"), overwrite = TRUE)nest_data_MP <-
  bind_rows(
    nest_import(year_1 = "2023", year_2 = "2024", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 13, 
                        last_alive_date_col = 33, 
                        last_checked_col = 39, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2022", year_2 = "2023", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 13, 
                        last_alive_date_col = 33, 
                        last_checked_col = 39, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2021", year_2 = "2022", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 13, 
                        last_alive_date_col = 33, 
                        last_checked_col = 39, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2020", year_2 = "2021", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2019", year_2 = "2020", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2018", year_2 = "2019", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2017", year_2 = "2018", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2016", year_2 = "2017", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2015", year_2 = "2016", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2014", year_2 = "2015", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2013", year_2 = "2014", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2012", year_2 = "2013", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2011", year_2 = "2012", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2010", year_2 = "2011", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2009", year_2 = "2010", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2008", year_2 = "2009", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2007", year_2 = "2008", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36, Nest_ID_col_name = "Nest ID"),
    nest_import(year_1 = "2006", year_2 = "2007", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36, Nest_ID_col_name = "Nest ID")) %>% 
  group_by(season) %>% 
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  filter(!is.na(FirstFound) & !is.na(LastPresent) & !is.na(LastChecked)) %>% 
  filter(management_status %in% c("Y", "N")) %>% 
  filter(nest_hab %in% c("beach", "dune", "foredune/face", "estuary/spit")) %>%
  filter(!is.na(management_level)) %>% # drops 5 nests that have permanentfence in beach or foredune habitat OR have only a nondogssign
  mutate(region = "MP") %>% 
  mutate(site = as.factor(site)) %>%
  group_by(season, site) %>%
  arrange(first_found2, .by_group = TRUE) %>%
  mutate(rank = row_number()) %>%
  ungroup() %>%
  mutate(nest_ID_new = paste(season, site, rank, sep = "_")) %>% 
  ungroup()nest_data_MP_check <-
  nest_data_MP %>% 
  ungroup() %>% 
  mutate(first_found2_md = paste(format(first_found2 + 180, format = "%m"),
                                 format(first_found2 + 180, format = "%d"),
                                 sep = "-"),
         last_alive2_md = paste(format(last_alive2 + 180, format = "%m"),
                                format(last_alive2 + 180, format = "%d"),
                                sep = "-"),
         last_checked2_md = paste(format(last_checked2 + 180, format = "%m"),
                                  format(last_checked2 + 180, format = "%d"),
                                  sep = "-")) %>% 
  mutate(first_found2_trans = as.Date(paste("2020", first_found2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_alive2_trans = as.Date(paste("2020", last_alive2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_checked2_trans = as.Date(paste("2020", last_checked2_md, sep = "-"), format = "%Y-%m-%d") - 179) %>% 
  mutate(season_label = paste0(str_sub(season, 1, 4), " to ", str_sub(season, 5, 6)),
         Fate = as.factor(Fate))Note that this map only shows data that are in a decimal degrees format (e.g., -38.31), NOT degree minute seconds (e.g., 38 27.59). The map is interactive, so click on an outlier to see its metadata. Note that all nests in the 200607 and 200708 seasons are missing coordinates
nest_data_MP_sf <-
  nest_data_MP %>% 
  as.data.frame() %>% 
  mutate(nest_lon = as.numeric(nest_lon) %>% suppressWarnings(),
         nest_lat = as.numeric(nest_lat) %>% suppressWarnings()) %>% 
  filter(!is.na(nest_lon) & !is.na(nest_lat)) %>%
  st_as_sf(coords = c("nest_lon", "nest_lat"), 
           crs = 4326)
mapview(nest_data_MP_sf,
        zcol = "season", 
        popup = popupTable(nest_data_MP_sf,
                           zcol = c("season",
                                    "site",
                                    "nest_ID")))ggplot(nest_data_MP_check, aes(first_found2_trans, fill = Fate)) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               # expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_MP_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_MP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Found date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))ggplot(nest_data_MP_check, aes(last_alive2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_MP_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_MP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last alive date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))ggplot(nest_data_MP_check, aes(last_checked2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B",
               expand = c(0.01, 0.01),
               date_breaks = "1 months", limits = c(min(nest_data_MP_check$first_found2_trans, na.rm = TRUE),
                                                    max(nest_data_MP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last checked date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))nest_data_MP_check %>% 
  group_by(season) %>%
  summarise(n())# A tibble: 18 × 2
   season `n()`
   <fct>  <int>
 1 200607    18
 2 200708    31
 3 200809    18
 4 200910    23
 5 201011    45
 6 201112    43
 7 201213    48
 8 201314    46
 9 201415    61
10 201516    76
11 201617    93
12 201718    65
13 201819    64
14 201920    61
15 202021    78
16 202122    88
17 202223    81
18 202324    92# Total number of nests acorss all years
nest_data_MP_check %>% 
  summarise(n())# A tibble: 1 × 1
  `n()`
  <int>
1  1031# assess if there are nests with unusually long incubation periods
nest_data_MP_check %>% 
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>%
  arrange(desc(found_and_alive_diff)) %>% 
  filter(first_found2 < last_alive2 & first_found2 < last_checked2 & found_and_alive_diff < 100) %>% 
  ggplot() +
  geom_histogram(aes(found_and_alive_diff)) +
  luke_theme +
  xlab("Time between found date and last alive date (days)") +
  ylab("Frquency of nests")# A tibble: 0 × 35
# ℹ 35 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, chick_management_status <chr>,
#   chick_management_type <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>, …# A tibble: 0 × 35
# ℹ 35 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, chick_management_status <chr>,
#   chick_management_type <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>, …# A tibble: 0 × 35
# ℹ 35 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, chick_management_status <chr>,
#   chick_management_type <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>, ….
Double check dates because incubation time greater than 41 days;  
                                                                2 # A tibble: 2 × 10
  found_and_alive_diff season nest_ID     first_found2 last_alive2 last_checked2
  <drtn>               <fct>  <chr>       <date>       <date>      <date>       
1 59 days              201213 201213_Moa… 2012-12-18   2013-02-15  2013-02-21   
2 52 days              201112 201112_Moa… 2011-12-27   2012-02-17  2012-02-22   
# ℹ 4 more variables: Fate <chr>, clutch_comp <date>, chick_1st_ob <date>,
#   state_1st_ob <chr>As above, first we import the data and run a few checks to assess if there are any rows with the issues listed above
FP_nest_data_issues <- 
suppressMessages(
  bind_rows(
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2023", "_", str_sub("2024", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2022", "_", str_sub("2023", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2021", "_", str_sub("2022", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2020", "_", str_sub("2021", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2019", "_", str_sub("2020", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2018", "_", str_sub("2019", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2017", "_", str_sub("2018", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2016", "_", str_sub("2017", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2015", "_", str_sub("2016", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2014", "_", str_sub("2015", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2013", "_", str_sub("2014", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2012", "_", str_sub("2013", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2011", "_", str_sub("2012", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2010", "_", str_sub("2011", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2009", "_", str_sub("2010", 3, 4)), 
             col_types = "text", na = "n/a"))) %>% 
    filter(!is.na(Season)) %>% 
  rename(first_found = 13,
         last_alive = 33,
         last_checked = 39,
         Fate = `Hatch?`,
         season = Season,
         # site = Site,
         site = `Suggested update to site name`,
         nest_ID = `Nest ID_2`,
         nest_hab = `Nest habitat`,
         management_status = `Nest managed?`,
         management_type = `Nest management type`,
         nest_lat = `Nest latitude`,
         nest_lon = `Nest longitude`,
         state_1st_ob = `Age stage first observed`) %>% 
  rename(
    chick_1st_ob = !!names(.)[which(names(.) %in% c("Date chicks sighted", "Chicks first obsv date"))][1],
    clutch_comp  = !!names(.)[which(names(.) %in% c("Known clutch complete date", "Known laying date"))][1]
  ) %>% 
  # chick_1st_ob = which(names(.) %in% c("Date chicks sighted", "Chicks first obsv date"))[1],
  # clutch_comp = which(names(.) %in% c("Known clutch complete date", "Known laying date"))) %>% 
  dplyr::select(season, site, nest_ID, first_found, last_alive, last_checked, Fate, nest_hab, 
                management_status, management_type, nest_lat, nest_lon, site,
                chick_1st_ob, clutch_comp, state_1st_ob) %>%
  mutate(Fate = ifelse(Fate == "?", "Unk", Fate)) %>% 
  mutate(Fate = toupper(Fate)) %>% 
  filter(
    is.na(first_found) | 
      grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", first_found)
  ) %>%
  mutate(last_checked = ifelse(!is.na(last_checked) & !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_checked), 
                               NA, last_checked)) %>% 
  mutate(last_alive = ifelse(!is.na(last_alive) & !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_alive), 
                             NA, last_alive)) %>% 
  mutate(last_alive = ifelse(str_detect(last_alive, "Unk."), NA, last_alive),
         Fate = ifelse(Fate == "Y", "0", 
                       ifelse(Fate == "N", "1",
                              ifelse(Fate == "UNK", NA, "XXX")))) %>%
  # remove nests without Fate information
  filter(Fate %in% c("0", "1")) %>% 
  mutate(chick_1st_ob = case_when(
    # Excel serial dates stored as numbers
    str_detect(chick_1st_ob, "^[0-9]+$") ~ as.Date(as.numeric(chick_1st_ob), origin = "1899-12-30"),
    
    # Dates with extra text in parentheses — extract only the date part
    str_detect(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
      dmy(str_extract(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
    ),
    
    # Everything else (including "Unk", "Failed during laying") → NA
    TRUE ~ as.Date(NA)
  ), 
  clutch_comp =  case_when(
    # Excel serial dates stored as numbers
    str_detect(clutch_comp, "^[0-9]+$") ~ as.Date(as.numeric(clutch_comp), origin = "1899-12-30"),
    
    # Dates with extra text in parentheses — extract only the date part
    str_detect(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
      dmy(str_extract(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
    ),
    
    # Everything else (including "Unk", "Failed during laying") → NA
    TRUE ~ as.Date(NA)
  )) %>%
  # if the clutch completion date is NA, then estimate it as 28 days before estimated hatch date
  # using the date of first chick observation and the size of the chicks when seen
  mutate(clutch_comp = ifelse(!is.na(clutch_comp), clutch_comp, 
                              ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3 - 28,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10 - 28,
                                                   ifelse(state_1st_ob == "2/3 adult size, mottled grey", chick_1st_ob - 19 - 28,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30 - 28,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35 - 28,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob - 28, NA)))))), 
                                     ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob), NA, NA))) %>% as.Date()) %>% 
  mutate(last_alive2 = ifelse(Fate == "0" & !is.na(clutch_comp) & is.na(last_alive), clutch_comp + 28,
                              ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob) & is.na(last_alive),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10,
                                                   ifelse(state_1st_ob == "2/3 adult size, mottled grey", chick_1st_ob - 19,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob, NA)))))), 
                                     ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob) & is.na(last_alive), NA, NA))) %>% as.Date()) %>% 
  # mutate(last_alive2 = ifelse(Fate == "0" & !is.na(chick_1st_ob) & last_alive2 > chick_1st_ob, chick_1st_ob, last_alive2) %>% as.Date()) %>% 
  mutate(last_alive = ifelse(!is.na(last_alive2), 
                             paste0(str_sub(as.character(last_alive2), 9, 10),
                                    str_sub(as.character(last_alive2), 6, 7),
                                    str_sub(as.character(last_alive2), 1, 4)), last_alive)) %>% 
  mutate(
    last_checked = ifelse(!is.na(last_alive) & is.na(last_checked),
                          last_alive,
                          ifelse(is.na(last_alive) & is.na(last_checked),
                                 first_found, last_checked))) %>%
  mutate(
    last_alive = ifelse(is.na(last_alive) & Fate == "0" & !is.na(last_checked),
                        last_checked,
                        ifelse(is.na(last_alive) & Fate == "1" & !is.na(last_checked),
                               first_found,
                               last_alive))) %>%
  filter(
    (is.na(last_alive) | nchar(last_alive) == 8) &
      (is.na(first_found) | nchar(first_found) == 8) &
      (is.na(last_checked) | nchar(last_checked) == 8)
  ) %>% 
  mutate(first_found2 = as.Date(paste(str_sub(first_found, 5, 8),
                                      str_sub(first_found, 3, 4),
                                      str_sub(first_found, 1, 2), sep = "-")),
         last_alive2 = as.Date(paste(str_sub(last_alive, 5, 8),
                                     str_sub(last_alive, 3, 4),
                                     str_sub(last_alive, 1, 2), sep = "-")),
         last_checked2 = as.Date(paste(str_sub(last_checked, 5, 8),
                                       str_sub(last_checked, 3, 4),
                                       str_sub(last_checked, 1, 2), sep = "-"))) %>% 
  mutate(last_checked2 = ifelse(!is.na(last_alive2) & !is.na(last_checked2) & last_checked2 < last_alive2, 
                                last_alive2, last_checked2) %>% as.Date()) %>% 
  mutate(first_found2 = ifelse(!is.na(clutch_comp) & ((last_alive2 - first_found2) > 40 | (last_alive2 - first_found2) < 0)
                               & ((last_alive2 - clutch_comp) < 40 | (last_alive2 - clutch_comp) > 0), 
                               clutch_comp, first_found2) %>% as.Date()) %>% 
  mutate(FirstFound = as.numeric(format(first_found2 + 180, "%j")),
         LastPresent = as.numeric(format(last_alive2 + 180, "%j")),
         LastChecked = as.numeric(format(last_checked2 + 180, "%j"))) %>% 
  # mutate(FirstFound = ((as.integer(format(first_found2, "%j")) -
  #                         as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365),#as.numeric(format(first_found2 + 180, "%j")),
  #        LastPresent = ((as.integer(format(last_alive2, "%j")) -
  #                          as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365),#as.numeric(format(last_alive2 + 180, "%j")),
  #        LastChecked = ((as.integer(format(last_checked2, "%j")) -
  #                          as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365)) %>% #as.numeric(format(last_checked2 + 180, "%j"))) %>% 
  mutate(management_type = tolower(management_type)) %>%
  mutate(nest_hab = tolower(nest_hab)) %>%
  mutate(management_type = str_replace(management_type, "acess", "access")) %>%
  mutate(management_type = str_replace(management_type, "and", ",")) %>%
  mutate(management_type = str_replace(management_type, "temporary", "")) %>%
  mutate(management_type = str_replace_all(management_type, " ", "")) %>%
  mutate(management_type = str_replace_all(management_type, "shelters", "")) %>%
  mutate(management_type = str_replace_all(management_type, "banners", "")) %>%
  mutate(management_type = str_replace_all(management_type, ",,", ",")) %>%
  mutate(sign_access = ifelse(str_detect(management_type, "signaccess"), 1, 0)) %>%
  mutate(sign_nest = ifelse(str_detect(management_type, "signnest"), 1, 0)) %>%
  mutate(rope_fence = ifelse(str_detect(management_type, "ropefence"), 1, 0)) %>%
  mutate(perm_fence = ifelse(str_detect(management_type, "permanentfence"), 1, 0)) %>% # & nest_hab == "dune", 1, 0)) %>%
  mutate(wardens = ifelse(str_detect(management_type, "wardens"), 1, 0)) %>% 
  mutate(none = ifelse(str_detect(management_type, "none"), 1, 
                       ifelse(is.na(management_type) & management_status == "N", 1, 0))) %>%
  mutate(other = ifelse(str_detect(management_type, "other"), 1, 0)) %>%
  mutate(management_level = ifelse((sign_access == 1 | perm_fence == 1) & sign_nest == 1 & rope_fence == 1 & wardens == 1, 4,
                                   ifelse(rope_fence == 1, 3,
                                          ifelse(sign_nest == 1, 2,
                                                 ifelse(sign_access == 1 | perm_fence == 1, 1,
                                                        ifelse(none == 1, 0, NA)))))) %>%
  mutate(sign_nest_no_sign_access = ifelse(sign_access == 0 & sign_nest == 1, 1, 0)) %>%
  mutate(fence_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & rope_fence == 1, 1, 0)) %>%
  mutate(wardens_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & wardens == 1, 1, 0)) %>%
  mutate(wardens_no_fence = ifelse(rope_fence == 1 & wardens == 1, 1, 0)) %>%
  mutate(just_wardens = ifelse(rope_fence == 0 & sign_access == 0 & sign_nest == 0 & wardens == 1, 1, 0)) %>%
  dplyr::select(-other, -sign_nest_no_sign_access, -fence_no_sign, 
                -wardens_no_sign, -wardens_no_fence, -just_wardens) %>%
  group_by(season) %>%
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  mutate(region = "FP") %>%
  mutate(site = as.factor(site)) %>%
  mutate(issue1 = ifelse(nchar(first_found) != 8, "found date is not 8 characters; ", NA)) %>% 
  mutate(issue2 = ifelse(nchar(last_alive) != 8, "last seen alive date is not 8 characters; ", NA)) %>% 
  mutate(issue3 = ifelse(nchar(last_checked) != 8, "last checked date is not 8 characters; ", NA)) %>% 
  mutate(issue4 = ifelse(is.na(first_found), "found date missing; ", NA)) %>% 
  mutate(issue5 = ifelse(is.na(last_alive), "last seen alive date missing; ", NA)) %>% 
  mutate(issue6 = ifelse(is.na(last_checked), "last checked date missing; ", NA)) %>% 
  mutate(issue7 = ifelse(management_status %!in% c("Y", "N"), "Nest managed? is not Y or N; ", NA)) %>% 
  mutate(issue8 = ifelse(nest_hab %!in% c("beach", "dune", "foredune/face", "estuary/spit"), 
                         "Nest habitat is not beach, dune, foredune/face, or estuary/spit; ", NA)) %>%
  mutate(issue9 = ifelse(is.na(management_level), "Management type is not sufficient for making levels; ", NA)) %>%
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>% 
  mutate(issue10 = ifelse(found_and_alive_diff > 40 , "Double check dates because incubation time greater than 40 days; ", NA)) %>% 
  mutate(issue11 = ifelse(first_found2 > last_alive2, "Found date is after Last Alive date (should be greater or equal); ", NA)) %>% 
  mutate(issue12 = ifelse(first_found2 > last_checked2, "Found date is after Last Checked date (should be greater or equal); ", NA)) %>%
  mutate(issue13 = ifelse(last_checked2 < last_alive2, "Last Checked date is before Last Alive date (should be greater or equal); ", NA)) %>% 
  mutate(issues = ifelse(is.na(issue1) & is.na(issue2) & is.na(issue3) & 
                           is.na(issue4) & is.na(issue5) & is.na(issue6) & 
                           is.na(issue7) & is.na(issue8) & is.na(issue9) & 
                           is.na(issue10) & is.na(issue11) & is.na(issue12) & is.na(issue13), NA, 
                         paste0(issue1, issue2, issue3, 
                                issue4, issue5, issue6, 
                                issue7, issue8, issue9,
                                issue10, issue11, issue12, issue13))) %>% 
  mutate(issues = str_remove_all(issues, "NA")) %>% 
  mutate(issues = ifelse(is.na(issues), "usable", issues)) %>% 
  dplyr::select(-issue1, -issue2, -issue3, 
                -issue4, -issue5, -issue6, 
                -issue7, -issue8, -issue9, 
                -issue10, -issue11, -issue12, -issue13) %>% 
  filter(issues != "usable") %>%
  arrange(issues)# Create a new workbook to store issues as two sheets
FP_nest_issues <- createWorkbook()
# Add all_issues sheet
addWorksheet(FP_nest_issues, "all_issues")
# view issues interactively in RStudio Viewer
FP_nest_data_issues %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')# write FP_nest_data_check
writeData(FP_nest_issues, sheet = "all_issues", FP_nest_data_issues)# Add date_issues
addWorksheet(FP_nest_issues, "date_issues")
# there are some blank (but non-NA) observations of management_type
FP_nest_data_issues %>% filter(is.na(management_type))# A tibble: 0 × 32
# Groups:   season [0]
# ℹ 32 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, sign_nest <dbl>, rope_fence <dbl>, …# view issues interactively in RStudio Viewer
FP_nest_data_issues %>% 
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>%
  filter(str_detect(issues, "date")) %>%
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>%
  mutate(issues = str_remove_all(issues, "Nest habitat is not beach, dune, foredune/face, or estuary/spit; ")) %>%
  dplyr::select(season, nest_ID, nest_hab, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, 
                Fate, found_and_alive_diff, issues)  %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')# write FP_nest_data_check
FP_nest_data_issues %>% 
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>%
  filter(str_detect(issues, "date")) %>%
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>%
  mutate(issues = str_remove_all(issues, "Nest habitat is not Beach, Dune, Foredune/face, or Estuary/spit; ")) %>%
  dplyr::select(season, nest_ID, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, 
                Fate, found_and_alive_diff, issues) %>% 
  writeData(FP_nest_issues, sheet = "date_issues", .)
# Save the workbook
saveWorkbook(FP_nest_issues, here("data/nest_issues_commented/FP_nest_data_issues_011025.xlsx"), overwrite = TRUE)nest_data_FP <-
  bind_rows(
    nest_import(year_1 = "2023", year_2 = "2024", 
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP",
                        first_found_date_col = 13, 
                        last_alive_date_col = 33, 
                        last_checked_col = 39),
    nest_import(year_1 = "2022", year_2 = "2023", 
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP",
                        first_found_date_col = 13, 
                        last_alive_date_col = 33, 
                        last_checked_col = 39),
    nest_import(year_1 = "2021", year_2 = "2022", 
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP",
                        first_found_date_col = 13, 
                        last_alive_date_col = 33, 
                        last_checked_col = 39),
    nest_import(year_1 = "2020", year_2 = "2021", 
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2019", year_2 = "2020", 
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2018", year_2 = "2019", 
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2017", year_2 = "2018",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2016", year_2 = "2017",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2015", year_2 = "2016",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2014", year_2 = "2015",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2013", year_2 = "2014",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2012", year_2 = "2013",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2011", year_2 = "2012",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2010", year_2 = "2011",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2009", year_2 = "2010",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40)) %>% 
  group_by(season) %>% 
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  filter(!is.na(FirstFound) & !is.na(LastPresent) & !is.na(LastChecked)) %>% 
  filter(management_status %in% c("Y", "N")) %>% 
  filter(nest_hab %in% c("beach", "dune", "foredune/face", "estuary/spit")) %>%
  filter(!is.na(management_level)) %>% # drops 20 nests
  mutate(region = "FP") %>% 
  mutate(site = as.factor(site)) %>%
  group_by(season, site) %>%
  arrange(first_found2, .by_group = TRUE) %>%
  mutate(rank = row_number()) %>%
  ungroup() %>%
  mutate(nest_ID_new = paste(season, site, rank, sep = "_")) %>% 
  ungroup()nest_data_FP_check <-
  nest_data_FP %>% 
  ungroup() %>% 
  mutate(first_found2_md = paste(format(first_found2 + 180, format = "%m"),
                                 format(first_found2 + 180, format = "%d"),
                                 sep = "-"),
         last_alive2_md = paste(format(last_alive2 + 180, format = "%m"),
                                format(last_alive2 + 180, format = "%d"),
                                sep = "-"),
         last_checked2_md = paste(format(last_checked2 + 180, format = "%m"),
                                  format(last_checked2 + 180, format = "%d"),
                                  sep = "-")) %>% 
  mutate(first_found2_trans = as.Date(paste("2020", first_found2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_alive2_trans = as.Date(paste("2020", last_alive2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_checked2_trans = as.Date(paste("2020", last_checked2_md, sep = "-"), format = "%Y-%m-%d") - 179) %>% 
  mutate(season_label = paste0("season ", str_sub(season, 1, 4), " to ", str_sub(season, 5, 6)))Note that this map only shows data that are in a decimal degrees format (e.g., -38.31), NOT degree minute seconds (e.g., 38 27.59). The map is interactive, so click on an outlier to see its metadata
nest_data_FP_sf <-
  nest_data_FP %>% 
  as.data.frame() %>% 
  mutate(nest_lon = as.numeric(nest_lon),
         nest_lat = as.numeric(nest_lat)) %>% 
  filter(!is.na(nest_lon) & !is.na(nest_lat)) %>%
  st_as_sf(coords = c("nest_lon", "nest_lat"), 
           crs = 4326) %>% suppressWarnings()
mapview(nest_data_FP_sf,
        zcol = "season", 
        popup = popupTable(nest_data_FP_sf,
                           zcol = c("season",
                                    "site",
                                    "nest_ID")))ggplot(nest_data_FP_check, aes(first_found2_trans, fill = Fate)) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               # expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_FP_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_FP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10)) +
  luke_theme +
  xlab("Found date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))ggplot(nest_data_FP_check, aes(last_alive2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_FP_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_FP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last alive date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))ggplot(nest_data_FP_check, aes(last_checked2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B",
               expand = c(0.01, 0.01),
               date_breaks = "1 months", limits = c(min(nest_data_FP_check$first_found2_trans, na.rm = TRUE),
                                                    max(nest_data_FP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last checked date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))nest_data_FP_check %>% 
  group_by(season) %>% 
  summarise(n())# A tibble: 15 × 2
   season `n()`
   <fct>  <int>
 1 200910     8
 2 201011    22
 3 201112    14
 4 201213    21
 5 201314    25
 6 201415    29
 7 201516    35
 8 201617    50
 9 201718    49
10 201819    70
11 201920    73
12 202021    94
13 202122    90
14 202223   100
15 202324   113nest_data_FP_check %>% 
  summarise(n())# A tibble: 1 × 1
  `n()`
  <int>
1   793# assess if there are nests with unusually long incubation periods
nest_data_FP_check %>% 
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>%
  arrange(desc(found_and_alive_diff)) %>% 
  filter(first_found2 < last_alive2 & first_found2 < last_checked2 & found_and_alive_diff < 100) %>% 
  ggplot() +
  geom_histogram(aes(found_and_alive_diff)) +
  luke_theme +
  xlab("Time between found date and last alive date (days)") +
  ylab("Frquency of nests")# A tibble: 0 × 35
# ℹ 35 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, chick_management_status <chr>,
#   chick_management_type <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>, …# A tibble: 0 × 35
# ℹ 35 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, chick_management_status <chr>,
#   chick_management_type <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>, …# A tibble: 0 × 35
# ℹ 35 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, chick_management_status <chr>,
#   chick_management_type <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>, ….
Double check dates because incubation time greater than 42 days;  
                                                                1 # A tibble: 1 × 4
  issues                                     season nest_ID found_and_alive_diff
  <chr>                                      <fct>  <chr>   <drtn>              
1 "Double check dates because incubation ti… 201516 201516… 51 days             As above, first we import the data and run a few checks to assess if there are any rows with the issues listed above
BSC_nest_data_issues <- 
suppressMessages(
  bind_rows(
   read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2024", "_", str_sub("2025", 3, 4)), 
             col_types = "text", na = "n/a"),
    read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2023", "_", str_sub("2024", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2022", "_", str_sub("2023", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2021", "_", str_sub("2022", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2020", "_", str_sub("2021", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2019", "_", str_sub("2020", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2018", "_", str_sub("2019", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2017", "_", str_sub("2018", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2016", "_", str_sub("2017", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2015", "_", str_sub("2016", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2014", "_", str_sub("2015", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2013", "_", str_sub("2014", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2012", "_", str_sub("2013", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2011", "_", str_sub("2012", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2010", "_", str_sub("2011", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2009", "_", str_sub("2010", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2008", "_", str_sub("2009", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2007", "_", str_sub("2008", 3, 4)), 
             col_types = "text", na = "n/a"), 
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2006", "_", str_sub("2007", 3, 4)), 
             col_types = "text", na = "n/a"))) %>% 
    filter(!is.na(Season)) %>% 
  rename(first_found = 13,
         last_alive = 33,
         last_checked = 39,
         Fate = `Hatch?`,
         season = Season,
         # site = Site,
         site = `Suggested update to site name`,
         nest_ID = `Nest ID_2`,
         nest_hab = `Nest habitat`,
         management_status = `Nest managed?`,
         management_type = `Nest management type`,
         nest_lat = `Nest latitude`,
         nest_lon = `Nest longitude`,
         state_1st_ob = `Age stage first observed`) %>% 
  rename(
    chick_1st_ob = !!names(.)[which(names(.) %in% c("Date chicks sighted", "Chicks first obsv date"))][1],
    clutch_comp  = !!names(.)[which(names(.) %in% c("Known clutch complete date", "Known laying date"))][1]
  ) %>% 
  # chick_1st_ob = which(names(.) %in% c("Date chicks sighted", "Chicks first obsv date"))[1],
  # clutch_comp = which(names(.) %in% c("Known clutch complete date", "Known laying date"))) %>% 
  dplyr::select(season, site, nest_ID, first_found, last_alive, last_checked, Fate, nest_hab, 
                management_status, management_type, nest_lat, nest_lon, site,
                chick_1st_ob, clutch_comp, state_1st_ob) %>%
  mutate(Fate = ifelse(Fate == "?", "Unk", Fate)) %>% 
  mutate(Fate = toupper(Fate)) %>% 
  filter(
    is.na(first_found) | 
      grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", first_found)
  ) %>%
  mutate(last_checked = ifelse(!is.na(last_checked) & !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_checked), 
                               NA, last_checked)) %>% 
  mutate(last_alive = ifelse(!is.na(last_alive) & !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_alive), 
                             NA, last_alive)) %>% 
  mutate(last_alive = ifelse(str_detect(last_alive, "Unk."), NA, last_alive),
         Fate = ifelse(Fate == "Y", "0", 
                       ifelse(Fate == "N", "1",
                              ifelse(Fate == "UNK", NA, "XXX")))) %>%
  # remove nests without Fate information
  filter(Fate %in% c("0", "1")) %>% 
  mutate(chick_1st_ob = case_when(
    # Excel serial dates stored as numbers
    str_detect(chick_1st_ob, "^[0-9]+$") ~ as.Date(as.numeric(chick_1st_ob), origin = "1899-12-30"),
    
    # Dates with extra text in parentheses — extract only the date part
    str_detect(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
      dmy(str_extract(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
    ),
    
    # Everything else (including "Unk", "Failed during laying") → NA
    TRUE ~ as.Date(NA)
  ), 
  clutch_comp =  case_when(
    # Excel serial dates stored as numbers
    str_detect(clutch_comp, "^[0-9]+$") ~ as.Date(as.numeric(clutch_comp), origin = "1899-12-30"),
    
    # Dates with extra text in parentheses — extract only the date part
    str_detect(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
      dmy(str_extract(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
    ),
    
    # Everything else (including "Unk", "Failed during laying") → NA
    TRUE ~ as.Date(NA)
  )) %>%
  # if the clutch completion date is NA, then estimate it as 28 days before estimated hatch date
  # using the date of first chick observation and the size of the chicks when seen
  mutate(clutch_comp = ifelse(!is.na(clutch_comp), clutch_comp, 
                              ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3 - 28,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10 - 28,
                                                   ifelse(state_1st_ob == "2/3 adult size, mottled grey", chick_1st_ob - 19 - 28,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30 - 28,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35 - 28,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob - 28, NA)))))), 
                                     ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob), NA, NA))) %>% as.Date()) %>% 
  mutate(last_alive2 = ifelse(Fate == "0" & !is.na(clutch_comp) & is.na(last_alive), clutch_comp + 28,
                              ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob) & is.na(last_alive),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10,
                                                   ifelse(state_1st_ob == "2/3 adult size, mottled grey", chick_1st_ob - 19,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob, NA)))))), 
                                     ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob) & is.na(last_alive), NA, NA))) %>% as.Date()) %>% 
  # mutate(last_alive2 = ifelse(Fate == "0" & !is.na(chick_1st_ob) & last_alive2 > chick_1st_ob, chick_1st_ob, last_alive2) %>% as.Date()) %>% 
  mutate(last_alive = ifelse(!is.na(last_alive2), 
                             paste0(str_sub(as.character(last_alive2), 9, 10),
                                    str_sub(as.character(last_alive2), 6, 7),
                                    str_sub(as.character(last_alive2), 1, 4)), last_alive)) %>% 
  mutate(
    last_checked = ifelse(!is.na(last_alive) & is.na(last_checked),
                          last_alive,
                          ifelse(is.na(last_alive) & is.na(last_checked),
                                 first_found, last_checked))) %>%
  mutate(
    last_alive = ifelse(is.na(last_alive) & Fate == "0" & !is.na(last_checked),
                        last_checked,
                        ifelse(is.na(last_alive) & Fate == "1" & !is.na(last_checked),
                               first_found,
                               last_alive))) %>%
  filter(
    (is.na(last_alive) | nchar(last_alive) == 8) &
      (is.na(first_found) | nchar(first_found) == 8) &
      (is.na(last_checked) | nchar(last_checked) == 8)
  ) %>% 
  mutate(first_found2 = as.Date(paste(str_sub(first_found, 5, 8),
                                      str_sub(first_found, 3, 4),
                                      str_sub(first_found, 1, 2), sep = "-")),
         last_alive2 = as.Date(paste(str_sub(last_alive, 5, 8),
                                     str_sub(last_alive, 3, 4),
                                     str_sub(last_alive, 1, 2), sep = "-")),
         last_checked2 = as.Date(paste(str_sub(last_checked, 5, 8),
                                       str_sub(last_checked, 3, 4),
                                       str_sub(last_checked, 1, 2), sep = "-"))) %>% 
  mutate(last_checked2 = ifelse(!is.na(last_alive2) & !is.na(last_checked2) & last_checked2 < last_alive2, 
                                last_alive2, last_checked2) %>% as.Date()) %>% 
  mutate(first_found2 = ifelse(!is.na(clutch_comp) & ((last_alive2 - first_found2) > 40 | (last_alive2 - first_found2) < 0)
                               & ((last_alive2 - clutch_comp) < 40 | (last_alive2 - clutch_comp) > 0), 
                               clutch_comp, first_found2) %>% as.Date()) %>% 
  mutate(FirstFound = as.numeric(format(first_found2 + 180, "%j")),
         LastPresent = as.numeric(format(last_alive2 + 180, "%j")),
         LastChecked = as.numeric(format(last_checked2 + 180, "%j"))) %>% 
  # mutate(FirstFound = ((as.integer(format(first_found2, "%j")) -
  #                         as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365),#as.numeric(format(first_found2 + 180, "%j")),
  #        LastPresent = ((as.integer(format(last_alive2, "%j")) -
  #                          as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365),#as.numeric(format(last_alive2 + 180, "%j")),
  #        LastChecked = ((as.integer(format(last_checked2, "%j")) -
  #                          as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365)) %>% #as.numeric(format(last_checked2 + 180, "%j"))) %>% 
  mutate(management_type = tolower(management_type)) %>%
  mutate(nest_hab = tolower(nest_hab)) %>%
  mutate(management_type = str_replace(management_type, "acess", "access")) %>%
  mutate(management_type = str_replace(management_type, "and", ",")) %>%
  mutate(management_type = str_replace(management_type, "temporary", "")) %>%
  mutate(management_type = str_replace_all(management_type, " ", "")) %>%
  mutate(management_type = str_replace_all(management_type, "shelters", "")) %>%
  mutate(management_type = str_replace_all(management_type, "banners", "")) %>%
  mutate(management_type = str_replace_all(management_type, ",,", ",")) %>%
  mutate(sign_access = ifelse(str_detect(management_type, "signaccess"), 1, 0)) %>%
  mutate(sign_nest = ifelse(str_detect(management_type, "signnest"), 1, 0)) %>%
  mutate(rope_fence = ifelse(str_detect(management_type, "ropefence"), 1, 0)) %>%
  mutate(perm_fence = ifelse(str_detect(management_type, "permanentfence"), 1, 0)) %>% # & nest_hab == "dune", 1, 0)) %>%
  mutate(wardens = ifelse(str_detect(management_type, "wardens"), 1, 0)) %>% 
  mutate(none = ifelse(str_detect(management_type, "none"), 1, 
                       ifelse(is.na(management_type) & management_status == "N", 1, 0))) %>%
  mutate(other = ifelse(str_detect(management_type, "other"), 1, 0)) %>%
  mutate(management_level = ifelse((sign_access == 1 | perm_fence == 1) & sign_nest == 1 & rope_fence == 1 & wardens == 1, 4,
                                   ifelse(rope_fence == 1, 3,
                                          ifelse(sign_nest == 1, 2,
                                                 ifelse(sign_access == 1 | perm_fence == 1, 1,
                                                        ifelse(none == 1, 0, NA)))))) %>%
  mutate(sign_nest_no_sign_access = ifelse(sign_access == 0 & sign_nest == 1, 1, 0)) %>%
  mutate(fence_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & rope_fence == 1, 1, 0)) %>%
  mutate(wardens_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & wardens == 1, 1, 0)) %>%
  mutate(wardens_no_fence = ifelse(rope_fence == 1 & wardens == 1, 1, 0)) %>%
  mutate(just_wardens = ifelse(rope_fence == 0 & sign_access == 0 & sign_nest == 0 & wardens == 1, 1, 0)) %>%
  dplyr::select(-other, -sign_nest_no_sign_access, -fence_no_sign, 
                -wardens_no_sign, -wardens_no_fence, -just_wardens) %>%
  group_by(season) %>%
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  mutate(region = "MP") %>%
  mutate(site = as.factor(site)) %>%
  mutate(issue1 = ifelse(nchar(first_found) != 8, "found date is not 8 characters; ", NA)) %>% 
  mutate(issue2 = ifelse(nchar(last_alive) != 8, "last seen alive date is not 8 characters; ", NA)) %>% 
  mutate(issue3 = ifelse(nchar(last_checked) != 8, "last checked date is not 8 characters; ", NA)) %>% 
  mutate(issue4 = ifelse(is.na(first_found), "found date missing; ", NA)) %>% 
  mutate(issue5 = ifelse(is.na(last_alive), "last seen alive date missing; ", NA)) %>% 
  mutate(issue6 = ifelse(is.na(last_checked), "last checked date missing; ", NA)) %>% 
  mutate(issue7 = ifelse(management_status %!in% c("Y", "N"), "Nest managed? is not Y or N; ", NA)) %>% 
  mutate(issue8 = ifelse(nest_hab %!in% c("beach", "dune", "foredune/face", "estuary/spit"), 
                         "Nest habitat is not beach, dune, foredune/face, or estuary/spit; ", NA)) %>%
  mutate(issue9 = ifelse(is.na(management_level), "Management type is not sufficient for making levels; ", NA)) %>%
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>% 
  mutate(issue10 = ifelse(found_and_alive_diff > 40 , "Double check dates because incubation time greater than 40 days; ", NA)) %>% 
  mutate(issue11 = ifelse(first_found2 > last_alive2, "Found date is after Last Alive date (should be greater or equal); ", NA)) %>% 
  mutate(issue12 = ifelse(first_found2 > last_checked2, "Found date is after Last Checked date (should be greater or equal); ", NA)) %>%
  mutate(issue13 = ifelse(last_checked2 < last_alive2, "Last Checked date is before Last Alive date (should be greater or equal); ", NA)) %>% 
  mutate(issues = ifelse(is.na(issue1) & is.na(issue2) & is.na(issue3) & 
                           is.na(issue4) & is.na(issue5) & is.na(issue6) & 
                           is.na(issue7) & is.na(issue8) & is.na(issue9) & 
                           is.na(issue10) & is.na(issue11) & is.na(issue12) & is.na(issue13), NA, 
                         paste0(issue1, issue2, issue3, 
                                issue4, issue5, issue6, 
                                issue7, issue8, issue9,
                                issue10, issue11, issue12, issue13))) %>% 
  mutate(issues = str_remove_all(issues, "NA")) %>% 
  mutate(issues = ifelse(is.na(issues), "usable", issues)) %>% 
  dplyr::select(-issue1, -issue2, -issue3, 
                -issue4, -issue5, -issue6, 
                -issue7, -issue8, -issue9, 
                -issue10, -issue11, -issue12, -issue13) %>% 
  filter(issues != "usable") %>%
  arrange(issues)# Create a new workbook to store issues as two sheets
BSC_nest_issues <- createWorkbook()
# Add all_issues sheet
addWorksheet(BSC_nest_issues, "all_issues")
# view issues interactively in RStudio Viewer
BSC_nest_data_issues %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')# write BSC_nest_data_check
writeData(BSC_nest_issues, sheet = "all_issues", BSC_nest_data_issues)# Add date_issues
addWorksheet(BSC_nest_issues, "date_issues")
# there are some blank (but non-NA) observations of management_type
BSC_nest_data_issues %>% filter(is.na(management_type))# A tibble: 0 × 32
# Groups:   season [0]
# ℹ 32 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, sign_nest <dbl>, rope_fence <dbl>, …# view issues interactively in RStudio Viewer
BSC_nest_data_issues %>% 
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>%
  filter(str_detect(issues, "date")) %>%
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>%
  mutate(issues = str_remove_all(issues, "Nest habitat is not beach, dune, foredune/face, estuary/spit, or rocks; ")) %>%
  dplyr::select(season, nest_ID, nest_hab, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, 
                Fate, found_and_alive_diff, issues)  %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')# write BSC_nest_data_check
BSC_nest_data_issues %>% 
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>%
  filter(str_detect(issues, "date")) %>%
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>%
  mutate(issues = str_remove_all(issues, "Nest habitat is not Beach, Dune, Foredune/face, Estuary/spit, or Rocks; ")) %>%
  dplyr::select(season, nest_ID, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, 
                Fate, found_and_alive_diff, issues) %>% 
  writeData(BSC_nest_issues, sheet = "date_issues", .)
# Save the workbook
saveWorkbook(BSC_nest_issues, here("data/nest_issues_commented/BSC_nest_data_issues_011025.xlsx"), overwrite = TRUE)nest_data_BSC <-
  bind_rows(
    nest_import(year_1 = "2024", year_2 = "2025", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2023", year_2 = "2024", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2022", year_2 = "2023", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 32, 
                        last_checked_col = 38),
    nest_import(year_1 = "2021", year_2 = "2022", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2020", year_2 = "2021", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2019", year_2 = "2020", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2018", year_2 = "2019", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2017", year_2 = "2018", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2016", year_2 = "2017", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2015", year_2 = "2016", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2014", year_2 = "2015", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2013", year_2 = "2014", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2012", year_2 = "2013", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2011", year_2 = "2012", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2010", year_2 = "2011", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2009", year_2 = "2010", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2008", year_2 = "2009", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2007", year_2 = "2008", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2006", year_2 = "2007", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40)) %>% 
  group_by(season) %>% 
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  filter(!is.na(FirstFound) & !is.na(LastPresent) & !is.na(LastChecked)) %>% 
  filter(management_status %in% c("Y", "N")) %>% 
  filter(nest_hab %in% c("beach", "dune", "foredune/face", "estuary/spit")) %>%
  filter(!is.na(management_level)) %>% # drops 5 nests that have permanentfence in beach or foredune habitat OR have only a nondogssign
  mutate(region = "BSC") %>% 
  mutate(site = as.factor(site)) %>%
  group_by(season, site) %>%
  arrange(first_found2, .by_group = TRUE) %>%
  mutate(rank = row_number()) %>%
  ungroup() %>%
  mutate(nest_ID_new = paste(season, site, rank, sep = "_")) %>% 
  ungroup()nest_data_BSC_check <-
  nest_data_BSC %>% 
  ungroup() %>% 
  mutate(first_found2_md = paste(format(first_found2 + 180, format = "%m"),
                                 format(first_found2 + 180, format = "%d"),
                                 sep = "-"),
         last_alive2_md = paste(format(last_alive2 + 180, format = "%m"),
                                format(last_alive2 + 180, format = "%d"),
                                sep = "-"),
         last_checked2_md = paste(format(last_checked2 + 180, format = "%m"),
                                  format(last_checked2 + 180, format = "%d"),
                                  sep = "-")) %>% 
  mutate(first_found2_trans = as.Date(paste("2020", first_found2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_alive2_trans = as.Date(paste("2020", last_alive2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_checked2_trans = as.Date(paste("2020", last_checked2_md, sep = "-"), format = "%Y-%m-%d") - 179) %>% 
  mutate(season_label = paste0("season ", str_sub(season, 1, 4), " to ", str_sub(season, 5, 6)))Note that this map only shows data that are in a decimal degrees format (e.g., -38.31), NOT degree minute seconds (e.g., 38 27.59). The map is interactive, so click on an outlier to see its metadata
nest_data_BSC_sf <-
  nest_data_BSC %>% 
  as.data.frame() %>% 
  mutate(nest_lon = as.numeric(nest_lon),
         nest_lat = as.numeric(nest_lat)) %>% 
  filter(!is.na(nest_lon) & !is.na(nest_lat)) %>%
  st_as_sf(coords = c("nest_lon", "nest_lat"), 
           crs = 4326) %>% suppressWarnings()
mapview(nest_data_BSC_sf,
        zcol = "season", 
        popup = popupTable(nest_data_BSC_sf,
                           zcol = c("season",
                                    "site",
                                    "nest_ID")))ggplot(nest_data_BSC_check, aes(first_found2_trans, fill = Fate)) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               # expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_BSC_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_BSC_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10)) +
  luke_theme +
  xlab("Found date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))ggplot(nest_data_BSC_check, aes(last_alive2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_BSC_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_BSC_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last alive date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))ggplot(nest_data_BSC_check, aes(last_checked2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B",
               expand = c(0.01, 0.01),
               date_breaks = "1 months", limits = c(min(nest_data_BSC_check$first_found2_trans, na.rm = TRUE),
                                                    max(nest_data_BSC_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last checked date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))nest_data_BSC_check %>% 
  group_by(season) %>% 
  summarise(n())# A tibble: 19 × 2
   season `n()`
   <fct>  <int>
 1 200607    13
 2 200708    15
 3 200809    13
 4 200910    17
 5 201011    21
 6 201112    30
 7 201213    26
 8 201314    22
 9 201415    32
10 201516    34
11 201617    45
12 201718    40
13 201819    35
14 201920    42
15 202021    53
16 202122    47
17 202223    44
18 202324    49
19 202425    46nest_data_BSC_check %>% 
  summarise(n())# A tibble: 1 × 1
  `n()`
  <int>
1   624# assess if there are nests with unusually long incubation periods
nest_data_BSC_check %>% 
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>%
  arrange(desc(found_and_alive_diff)) %>% 
  filter(first_found2 < last_alive2 & first_found2 < last_checked2 & found_and_alive_diff < 100) %>% 
  ggplot() +
  geom_histogram(aes(found_and_alive_diff)) +
  luke_theme +
  xlab("Time between found date and last alive date (days)") +
  ylab("Frquency of nests")# A tibble: 0 × 35
# ℹ 35 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, chick_management_status <chr>,
#   chick_management_type <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>, …# A tibble: 0 × 35
# ℹ 35 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, chick_management_status <chr>,
#   chick_management_type <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>, …# A tibble: 0 × 35
# ℹ 35 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, chick_management_status <chr>,
#   chick_management_type <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>, ….
Double check dates because incubation time greater than 41 days;  
                                                                4 # A tibble: 4 × 3
  issues                                                            season site 
  <chr>                                                             <fct>  <fct>
1 "Double check dates because incubation time greater than 41 days… 200708 Poin…
2 "Double check dates because incubation time greater than 41 days… 201213 8W O…
3 "Double check dates because incubation time greater than 41 days… 201617 16W-…
4 "Double check dates because incubation time greater than 41 days… 202425 Ersk…As above, first we import the data and run a few checks to assess if there are any rows with the issues listed above
BC_nest_data_issues <-
suppressMessages(
  bind_rows(
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2024", "_", str_sub("2025", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2023", "_", str_sub("2024", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2022", "_", str_sub("2023", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2021", "_", str_sub("2022", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2020", "_", str_sub("2021", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2019", "_", str_sub("2020", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2018", "_", str_sub("2019", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2017", "_", str_sub("2018", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2016", "_", str_sub("2017", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2015", "_", str_sub("2016", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2014", "_", str_sub("2015", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2013", "_", str_sub("2014", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2012", "_", str_sub("2013", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2011", "_", str_sub("2012", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2010", "_", str_sub("2011", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2009", "_", str_sub("2010", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2008", "_", str_sub("2009", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2007", "_", str_sub("2008", 3, 4)), 
             col_types = "text", na = "n/a"), 
  read_excel(paste0("data/", "Bass Coast_nesting summaries.xlsx"), 
             sheet = paste0("BC", " ", "2006", "_", str_sub("2007", 3, 4)), 
             col_types = "text", na = "n/a"))) %>% 
    filter(!is.na(Season)) %>% 
  rename(first_found = 13,
         last_alive = 33,
         last_checked = 39,
         Fate = `Hatch?`,
         season = Season,
         # site = Site,
         site = `Suggested update to site name`,
         nest_ID = `Nest ID_2`,
         nest_hab = `Nest habitat`,
         management_status = `Nest managed?`,
         management_type = `Nest management type`,
         nest_lat = `Nest latitude`,
         nest_lon = `Nest longitude`,
         state_1st_ob = `Age stage first observed`) %>% 
  rename(
    chick_1st_ob = !!names(.)[which(names(.) %in% c("Date chicks sighted", "Chicks first obsv date"))][1],
    clutch_comp  = !!names(.)[which(names(.) %in% c("Known clutch complete date", "Known laying date"))][1]
  ) %>% 
  # chick_1st_ob = which(names(.) %in% c("Date chicks sighted", "Chicks first obsv date"))[1],
  # clutch_comp = which(names(.) %in% c("Known clutch complete date", "Known laying date"))) %>% 
  dplyr::select(season, site, nest_ID, first_found, last_alive, last_checked, Fate, nest_hab, 
                management_status, management_type, nest_lat, nest_lon, site,
                chick_1st_ob, clutch_comp, state_1st_ob) %>%
  mutate(Fate = ifelse(Fate == "?", "Unk", Fate)) %>% 
  mutate(Fate = toupper(Fate)) %>% 
  filter(
    is.na(first_found) | 
      grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", first_found)
  ) %>%
  mutate(last_checked = ifelse(!is.na(last_checked) & !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_checked), 
                               NA, last_checked)) %>% 
  mutate(last_alive = ifelse(!is.na(last_alive) & !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_alive), 
                             NA, last_alive)) %>% 
  mutate(last_alive = ifelse(str_detect(last_alive, "Unk."), NA, last_alive),
         Fate = ifelse(Fate == "Y", "0", 
                       ifelse(Fate == "N", "1",
                              ifelse(Fate == "UNK", NA, "XXX")))) %>%
  # remove nests without Fate information
  filter(Fate %in% c("0", "1")) %>% 
  mutate(chick_1st_ob = case_when(
    # Excel serial dates stored as numbers
    str_detect(chick_1st_ob, "^[0-9]+$") ~ as.Date(as.numeric(chick_1st_ob), origin = "1899-12-30"),
    
    # Dates with extra text in parentheses — extract only the date part
    str_detect(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
      dmy(str_extract(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
    ),
    
    # Everything else (including "Unk", "Failed during laying") → NA
    TRUE ~ as.Date(NA)
  ), 
  clutch_comp =  case_when(
    # Excel serial dates stored as numbers
    str_detect(clutch_comp, "^[0-9]+$") ~ as.Date(as.numeric(clutch_comp), origin = "1899-12-30"),
    
    # Dates with extra text in parentheses — extract only the date part
    str_detect(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
      dmy(str_extract(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
    ),
    
    # Everything else (including "Unk", "Failed during laying") → NA
    TRUE ~ as.Date(NA)
  )) %>%
  # if the clutch completion date is NA, then estimate it as 28 days before estimated hatch date
  # using the date of first chick observation and the size of the chicks when seen
  mutate(clutch_comp = ifelse(!is.na(clutch_comp), clutch_comp, 
                              ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3 - 28,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10 - 28,
                                                   ifelse(state_1st_ob == "2/3 adult size, mottled grey", chick_1st_ob - 19 - 28,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30 - 28,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35 - 28,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob - 28, NA)))))), 
                                     ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob), NA, NA))) %>% as.Date()) %>% 
  mutate(last_alive2 = ifelse(Fate == "0" & !is.na(clutch_comp) & is.na(last_alive), clutch_comp + 28,
                              ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob) & is.na(last_alive),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10,
                                                   ifelse(state_1st_ob == "2/3 adult size, mottled grey", chick_1st_ob - 19,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob, NA)))))), 
                                     ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob) & is.na(last_alive), NA, NA))) %>% as.Date()) %>% 
  # mutate(last_alive2 = ifelse(Fate == "0" & !is.na(chick_1st_ob) & last_alive2 > chick_1st_ob, chick_1st_ob, last_alive2) %>% as.Date()) %>% 
  mutate(last_alive = ifelse(!is.na(last_alive2), 
                             paste0(str_sub(as.character(last_alive2), 9, 10),
                                    str_sub(as.character(last_alive2), 6, 7),
                                    str_sub(as.character(last_alive2), 1, 4)), last_alive)) %>% 
  mutate(
    last_checked = ifelse(!is.na(last_alive) & is.na(last_checked),
                          last_alive,
                          ifelse(is.na(last_alive) & is.na(last_checked),
                                 first_found, last_checked))) %>%
  mutate(
    last_alive = ifelse(is.na(last_alive) & Fate == "0" & !is.na(last_checked),
                        last_checked,
                        ifelse(is.na(last_alive) & Fate == "1" & !is.na(last_checked),
                               first_found,
                               last_alive))) %>%
  filter(
    (is.na(last_alive) | nchar(last_alive) == 8) &
      (is.na(first_found) | nchar(first_found) == 8) &
      (is.na(last_checked) | nchar(last_checked) == 8)
  ) %>% 
  mutate(first_found2 = as.Date(paste(str_sub(first_found, 5, 8),
                                      str_sub(first_found, 3, 4),
                                      str_sub(first_found, 1, 2), sep = "-")),
         last_alive2 = as.Date(paste(str_sub(last_alive, 5, 8),
                                     str_sub(last_alive, 3, 4),
                                     str_sub(last_alive, 1, 2), sep = "-")),
         last_checked2 = as.Date(paste(str_sub(last_checked, 5, 8),
                                       str_sub(last_checked, 3, 4),
                                       str_sub(last_checked, 1, 2), sep = "-"))) %>% 
  mutate(last_checked2 = ifelse(!is.na(last_alive2) & !is.na(last_checked2) & last_checked2 < last_alive2, 
                                last_alive2, last_checked2) %>% as.Date()) %>% 
  mutate(first_found2 = ifelse(!is.na(clutch_comp) & ((last_alive2 - first_found2) > 40 | (last_alive2 - first_found2) < 0)
                               & ((last_alive2 - clutch_comp) < 40 | (last_alive2 - clutch_comp) > 0), 
                               clutch_comp, first_found2) %>% as.Date()) %>% 
  mutate(FirstFound = as.numeric(format(first_found2 + 180, "%j")),
         LastPresent = as.numeric(format(last_alive2 + 180, "%j")),
         LastChecked = as.numeric(format(last_checked2 + 180, "%j"))) %>% 
  # mutate(FirstFound = ((as.integer(format(first_found2, "%j")) -
  #                         as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365),#as.numeric(format(first_found2 + 180, "%j")),
  #        LastPresent = ((as.integer(format(last_alive2, "%j")) -
  #                          as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365),#as.numeric(format(last_alive2 + 180, "%j")),
  #        LastChecked = ((as.integer(format(last_checked2, "%j")) -
  #                          as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365)) %>% #as.numeric(format(last_checked2 + 180, "%j"))) %>% 
  mutate(management_type = tolower(management_type)) %>%
  mutate(nest_hab = tolower(nest_hab)) %>%
  mutate(management_type = str_replace(management_type, "acess", "access")) %>%
  mutate(management_type = str_replace(management_type, "and", ",")) %>%
  mutate(management_type = str_replace(management_type, "temporary", "")) %>%
  mutate(management_type = str_replace_all(management_type, " ", "")) %>%
  mutate(management_type = str_replace_all(management_type, "shelters", "")) %>%
  mutate(management_type = str_replace_all(management_type, "banners", "")) %>%
  mutate(management_type = str_replace_all(management_type, ",,", ",")) %>%
  mutate(sign_access = ifelse(str_detect(management_type, "signaccess"), 1, 0)) %>%
  mutate(sign_nest = ifelse(str_detect(management_type, "signnest"), 1, 0)) %>%
  mutate(rope_fence = ifelse(str_detect(management_type, "ropefence"), 1, 0)) %>%
  mutate(perm_fence = ifelse(str_detect(management_type, "permanentfence"), 1, 0)) %>% # & nest_hab == "dune", 1, 0)) %>%
  mutate(wardens = ifelse(str_detect(management_type, "wardens"), 1, 0)) %>% 
  mutate(none = ifelse(str_detect(management_type, "none"), 1, 
                       ifelse(is.na(management_type) & management_status == "N", 1, 0))) %>%
  mutate(other = ifelse(str_detect(management_type, "other"), 1, 0)) %>%
  mutate(management_level = ifelse((sign_access == 1 | perm_fence == 1) & sign_nest == 1 & rope_fence == 1 & wardens == 1, 4,
                                   ifelse(rope_fence == 1, 3,
                                          ifelse(sign_nest == 1, 2,
                                                 ifelse(sign_access == 1 | perm_fence == 1, 1,
                                                        ifelse(none == 1, 0, NA)))))) %>%
  mutate(sign_nest_no_sign_access = ifelse(sign_access == 0 & sign_nest == 1, 1, 0)) %>%
  mutate(fence_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & rope_fence == 1, 1, 0)) %>%
  mutate(wardens_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & wardens == 1, 1, 0)) %>%
  mutate(wardens_no_fence = ifelse(rope_fence == 1 & wardens == 1, 1, 0)) %>%
  mutate(just_wardens = ifelse(rope_fence == 0 & sign_access == 0 & sign_nest == 0 & wardens == 1, 1, 0)) %>%
  dplyr::select(-other, -sign_nest_no_sign_access, -fence_no_sign, 
                -wardens_no_sign, -wardens_no_fence, -just_wardens) %>%
  group_by(season) %>%
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  mutate(region = "MP") %>%
  mutate(site = as.factor(site)) %>%
  mutate(issue1 = ifelse(nchar(first_found) != 8, "found date is not 8 characters; ", NA)) %>% 
  mutate(issue2 = ifelse(nchar(last_alive) != 8, "last seen alive date is not 8 characters; ", NA)) %>% 
  mutate(issue3 = ifelse(nchar(last_checked) != 8, "last checked date is not 8 characters; ", NA)) %>% 
  mutate(issue4 = ifelse(is.na(first_found), "found date missing; ", NA)) %>% 
  mutate(issue5 = ifelse(is.na(last_alive), "last seen alive date missing; ", NA)) %>% 
  mutate(issue6 = ifelse(is.na(last_checked), "last checked date missing; ", NA)) %>% 
  mutate(issue7 = ifelse(management_status %!in% c("Y", "N"), "Nest managed? is not Y or N; ", NA)) %>% 
  mutate(issue8 = ifelse(nest_hab %!in% c("beach", "dune", "foredune/face", "estuary/spit"), 
                         "Nest habitat is not beach, dune, foredune/face, or estuary/spit; ", NA)) %>% 
  mutate(issue9 = ifelse(is.na(management_level), "Management type is not sufficient for making levels; ", NA)) %>%
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>% 
  mutate(issue10 = ifelse(found_and_alive_diff > 40 , "Double check dates because incubation time greater than 40 days; ", NA)) %>% 
  mutate(issue11 = ifelse(first_found2 > last_alive2, "Found date is after Last Alive date (should be greater or equal); ", NA)) %>% 
  mutate(issue12 = ifelse(first_found2 > last_checked2, "Found date is after Last Checked date (should be greater or equal); ", NA)) %>%
  mutate(issue13 = ifelse(last_checked2 < last_alive2, "Last Checked date is before Last Alive date (should be greater or equal); ", NA)) %>% 
  mutate(issues = ifelse(is.na(issue1) & is.na(issue2) & is.na(issue3) & 
                           is.na(issue4) & is.na(issue5) & is.na(issue6) & 
                           is.na(issue7) & is.na(issue8) & is.na(issue9) & 
                           is.na(issue10) & is.na(issue11) & is.na(issue12) & is.na(issue13), NA, 
                         paste0(issue1, issue2, issue3, 
                                issue4, issue5, issue6, 
                                issue7, issue8, issue9,
                                issue10, issue11, issue12, issue13))) %>% 
  mutate(issues = str_remove_all(issues, "NA")) %>% 
  mutate(issues = ifelse(is.na(issues), "usable", issues)) %>% 
  dplyr::select(-issue1, -issue2, -issue3, 
                -issue4, -issue5, -issue6, 
                -issue7, -issue8, -issue9, 
                -issue10, -issue11, -issue12, -issue13) %>% 
  filter(issues != "usable") %>%
  arrange(issues)# Create a new workbook to store issues as two sheets
BC_nest_issues <- createWorkbook()
# Add all_issues sheet
addWorksheet(BC_nest_issues, "all_issues")
# view issues interactively in RStudio Viewer
BC_nest_data_issues %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')# write BC_nest_data_check
writeData(BC_nest_issues, sheet = "all_issues", BC_nest_data_issues)# Add date_issues
addWorksheet(BC_nest_issues, "date_issues")
# there are some blank (but non-NA) observations of management_type
BC_nest_data_issues %>% filter(is.na(management_type))# A tibble: 0 × 32
# Groups:   season [0]
# ℹ 32 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, sign_nest <dbl>, rope_fence <dbl>, …# view issues interactively in RStudio Viewer
BC_nest_data_issues %>% 
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>%
  filter(str_detect(issues, "date")) %>%
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>%
  mutate(issues = str_remove_all(issues, "Nest habitat is not beach, dune, foredune/face, estuary/spit, or rocks; ")) %>%
  dplyr::select(season, nest_ID, nest_hab, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, 
                Fate, found_and_alive_diff, issues)  %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')# write BC_nest_data_check
BC_nest_data_issues %>% 
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>%
  filter(str_detect(issues, "date")) %>%
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>%
  mutate(issues = str_remove_all(issues, "Nest habitat is not Beach, Dune, Foredune/face, or Estuary/spit; ")) %>%
  dplyr::select(season, nest_ID, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, 
                Fate, found_and_alive_diff, issues) %>% 
  writeData(BC_nest_issues, sheet = "date_issues", .)
# Save the workbook
saveWorkbook(BC_nest_issues, here("data/nest_issues_commented/BC_nest_data_issues_011025.xlsx"), overwrite = TRUE)## I can't get the 2009/10 season to import properly so have removed it for now. There is only 1 nest in this season. Are you able to fix this for me
## LEH (1/10/25): fixed it. The issue was that the nest_import() function was specifying the "Fate" column as a numeric for the 2009/10 season, while Fate for the other years was specified as character. All variables need to have consistent classifications across sheets in order for it to merge.
nest_data_BC <-
  bind_rows(
    nest_import(year_1 = "2024", year_2 = "2025", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2023", year_2 = "2024", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
   nest_import(year_1 = "2022", year_2 = "2023", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
   nest_import(year_1 = "2021", year_2 = "2022", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2020", year_2 = "2021", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2019", year_2 = "2020", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2018", year_2 = "2019", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2017", year_2 = "2018", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2016", year_2 = "2017", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 13, 
                       last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2015", year_2 = "2016", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2014", year_2 = "2015", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2013", year_2 = "2014", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2012", year_2 = "2013", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2011", year_2 = "2012", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2010", year_2 = "2011", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2009", year_2 = "2010", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 30, 
                        last_checked_col = 36),
    nest_import(year_1 = "2008", year_2 = "2009", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 30, 
                        last_checked_col = 36),
    nest_import(year_1 = "2007", year_2 = "2008", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 11, 
                        last_alive_date_col = 29, 
                        last_checked_col = 35),
    nest_import(year_1 = "2006", year_2 = "2007", 
                        file_name = "Bass Coast_nesting summaries.xlsx", site = "BC",
                        first_found_date_col = 11, 
                        last_alive_date_col = 29, 
                        last_checked_col = 35)) %>%
  group_by(season) %>% 
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  filter(!is.na(FirstFound) & !is.na(LastPresent) & !is.na(LastChecked)) %>% 
  filter(management_status %in% c("Y", "N")) %>% 
  filter(nest_hab %in% c("beach", "dune", "foredune/face", "estuary/spit")) %>%
  filter(!is.na(management_level)) %>% # 
  mutate(region = "BC") %>% 
  mutate(site = as.factor(site)) %>%
  group_by(season, site) %>%
  arrange(first_found2, .by_group = TRUE) %>%
  mutate(rank = row_number()) %>%
  ungroup() %>%
  mutate(nest_ID_new = paste(season, site, rank, sep = "_")) %>% 
  ungroup()nest_data_BC_check <-
  nest_data_BC %>% 
  ungroup() %>% 
  mutate(first_found2_md = paste(format(first_found2 + 180, format = "%m"),
                                 format(first_found2 + 180, format = "%d"),
                                 sep = "-"),
         last_alive2_md = paste(format(last_alive2 + 180, format = "%m"),
                                format(last_alive2 + 180, format = "%d"),
                                sep = "-"),
         last_checked2_md = paste(format(last_checked2 + 180, format = "%m"),
                                  format(last_checked2 + 180, format = "%d"),
                                  sep = "-")) %>% 
  mutate(first_found2_trans = as.Date(paste("2020", first_found2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_alive2_trans = as.Date(paste("2020", last_alive2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_checked2_trans = as.Date(paste("2020", last_checked2_md, sep = "-"), format = "%Y-%m-%d") - 179) %>% 
  mutate(season_label = paste0("season ", str_sub(season, 1, 4), " to ", str_sub(season, 5, 6)))Note that this map only shows data that are in a decimal degrees format (e.g., -38.31), NOT degree minute seconds (e.g., 38 27.59). The map is interactive, so click on an outlier to see its metadata
nest_data_BC_sf <-
  nest_data_BC %>% 
  as.data.frame() %>% 
  mutate(nest_lon = as.numeric(nest_lon),
         nest_lat = as.numeric(nest_lat)) %>% 
  filter(!is.na(nest_lon) & !is.na(nest_lat)) %>%
  st_as_sf(coords = c("nest_lon", "nest_lat"), 
           crs = 4326) %>% suppressWarnings()
mapview(nest_data_BC_sf,
        zcol = "season", 
        popup = popupTable(nest_data_BC_sf,
                           zcol = c("season",
                                    "site",
                                    "nest_ID")))ggplot(nest_data_BC_check, aes(first_found2_trans, fill = Fate)) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               # expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_BC_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_BC_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10)) +
  luke_theme +
  xlab("Found date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))ggplot(nest_data_BC_check, aes(last_alive2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_BC_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_BC_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last alive date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))ggplot(nest_data_BC_check, aes(last_checked2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B",
               expand = c(0.01, 0.01),
               date_breaks = "1 months", limits = c(min(nest_data_BC_check$first_found2_trans, na.rm = TRUE),
                                                    max(nest_data_BC_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last checked date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))nest_data_BC_check %>% 
  group_by(season) %>% 
  summarise(n()) %>% 
  print(n = Inf)# A tibble: 19 × 2
   season `n()`
   <fct>  <int>
 1 200607    13
 2 200708    11
 3 200809    11
 4 200910     1
 5 201011     9
 6 201112    30
 7 201213    22
 8 201314    37
 9 201415    45
10 201516    62
11 201617    94
12 201718    74
13 201819    59
14 201920    50
15 202021    69
16 202122    52
17 202223    66
18 202324    65
19 202425    67nest_data_BC_check %>% 
  summarise(n())# A tibble: 1 × 1
  `n()`
  <int>
1   837# assess if there are nests with unusually long incubation periods
nest_data_BC_check %>% 
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>%
  arrange(desc(found_and_alive_diff)) %>% 
  filter(first_found2 < last_alive2 & first_found2 < last_checked2 & found_and_alive_diff < 100) %>% 
  ggplot() +
  geom_histogram(aes(found_and_alive_diff)) +
  luke_theme +
  xlab("Time between found date and last alive date (days)") +
  ylab("Frquency of nests")# A tibble: 0 × 35
# ℹ 35 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, chick_management_status <chr>,
#   chick_management_type <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>, …# A tibble: 0 × 35
# ℹ 35 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, chick_management_status <chr>,
#   chick_management_type <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>, …# A tibble: 0 × 35
# ℹ 35 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, chick_management_status <chr>,
#   chick_management_type <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>, ….
Double check dates because incubation time greater than 41 days;  
                                                                4 # A tibble: 4 × 3
  issues                                                            season site 
  <chr>                                                             <fct>  <fct>
1 "Double check dates because incubation time greater than 41 days… 201213 Powl…
2 "Double check dates because incubation time greater than 41 days… 201718 Coal…
3 "Double check dates because incubation time greater than 41 days… 201718 Inve…
4 "Double check dates because incubation time greater than 41 days… 202324 Inve…As above, first we import the data and run a few checks to assess if there are any rows with the issues listed above
PI_nest_data_issues <- 
suppressMessages(
  bind_rows(
  read_excel(paste0("data/", "PI Nesting summaries.xlsx"), 
             sheet = paste0("PI", " ", "2024", "_", str_sub("2025", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "PI Nesting summaries.xlsx"), 
             sheet = paste0("PI", " ", "2023", "_", str_sub("2024", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "PI Nesting summaries.xlsx"), 
             sheet = paste0("PI", " ", "2022", "_", str_sub("2023", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "PI Nesting summaries.xlsx"), 
             sheet = paste0("PI", " ", "2021", "_", str_sub("2022", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "PI Nesting summaries.xlsx"), 
             sheet = paste0("PI", " ", "2020", "_", str_sub("2021", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "PI Nesting summaries.xlsx"), 
             sheet = paste0("PI", " ", "2019", "_", str_sub("2020", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "PI Nesting summaries.xlsx"), 
             sheet = paste0("PI", " ", "2018", "_", str_sub("2019", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "PI Nesting summaries.xlsx"), 
             sheet = paste0("PI", " ", "2017", "_", str_sub("2018", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "PI Nesting summaries.xlsx"), 
             sheet = paste0("PI", " ", "2016", "_", str_sub("2017", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "PI Nesting summaries.xlsx"), 
             sheet = paste0("PI", " ", "2015", "_", str_sub("2016", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "PI Nesting summaries.xlsx"), 
             sheet = paste0("PI", " ", "2014", "_", str_sub("2015", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "PI Nesting summaries.xlsx"), 
             sheet = paste0("PI", " ", "2013", "_", str_sub("2014", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "PI Nesting summaries.xlsx"), 
             sheet = paste0("PI", " ", "2012", "_", str_sub("2013", 3, 4)), 
             col_types = "text", na = "n/a")))%>% 
    filter(!is.na(Season)) %>% 
  rename(first_found = 11,
         last_alive = 29,
         last_checked = 35,
         Fate = `Hatch?`,
         season = Season,
         #site = Site,
         site = `Suggested update to site name`,
         nest_ID = `Nest ID_2`,
         nest_hab = `Nest habitat`,
         management_status = `Nest managed?`,
         management_type = `Nest management type`,
         nest_lat = `Nest latitude`,
         nest_lon = `Nest longitude`,
         state_1st_ob = `Age stage first observed`) %>% 
  rename(
    chick_1st_ob = !!names(.)[which(names(.) %in% c("Date chicks sighted", "Chicks first obsv date"))][1],
    clutch_comp  = !!names(.)[which(names(.) %in% c("Known clutch complete date", "Known laying date"))][1]
  ) %>% 
  # chick_1st_ob = which(names(.) %in% c("Date chicks sighted", "Chicks first obsv date"))[1],
  # clutch_comp = which(names(.) %in% c("Known clutch complete date", "Known laying date"))) %>% 
  dplyr::select(season, site, nest_ID, first_found, last_alive, last_checked, Fate, nest_hab, 
                management_status, management_type, nest_lat, nest_lon, site,
                chick_1st_ob, clutch_comp, state_1st_ob) %>%
  mutate(Fate = ifelse(Fate == "?", "Unk", Fate)) %>% 
  mutate(Fate = toupper(Fate)) %>% 
  filter(
    is.na(first_found) | 
      grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", first_found)
  ) %>%
  mutate(last_checked = ifelse(!is.na(last_checked) & !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_checked), 
                               NA, last_checked)) %>% 
  mutate(last_alive = ifelse(!is.na(last_alive) & !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_alive), 
                             NA, last_alive)) %>% 
  mutate(last_alive = ifelse(str_detect(last_alive, "Unk."), NA, last_alive),
         Fate = ifelse(Fate == "Y", "0", 
                       ifelse(Fate == "N", "1",
                              ifelse(Fate == "UNK", NA, "XXX")))) %>%
  # remove nests without Fate information
  filter(Fate %in% c("0", "1")) %>% 
  mutate(chick_1st_ob = case_when(
    # Excel serial dates stored as numbers
    str_detect(chick_1st_ob, "^[0-9]+$") ~ as.Date(as.numeric(chick_1st_ob), origin = "1899-12-30"),
    
    # Dates with extra text in parentheses — extract only the date part
    str_detect(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
      dmy(str_extract(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
    ),
    
    # Everything else (including "Unk", "Failed during laying") → NA
    TRUE ~ as.Date(NA)
  ), 
  clutch_comp =  case_when(
    # Excel serial dates stored as numbers
    str_detect(clutch_comp, "^[0-9]+$") ~ as.Date(as.numeric(clutch_comp), origin = "1899-12-30"),
    
    # Dates with extra text in parentheses — extract only the date part
    str_detect(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
      dmy(str_extract(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
    ),
    
    # Everything else (including "Unk", "Failed during laying") → NA
    TRUE ~ as.Date(NA)
  )) %>%
  # if the clutch completion date is NA, then estimate it as 28 days before estimated hatch date
  # using the date of first chick observation and the size of the chicks when seen
  mutate(clutch_comp = ifelse(!is.na(clutch_comp), clutch_comp, 
                              ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3 - 28,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10 - 28,
                                                   ifelse(state_1st_ob == "2/3 adult size, mottled grey", chick_1st_ob - 19 - 28,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30 - 28,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35 - 28,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob - 28, NA)))))), 
                                     ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob), NA, NA))) %>% as.Date()) %>% 
  mutate(last_alive2 = ifelse(Fate == "0" & !is.na(clutch_comp) & is.na(last_alive), clutch_comp + 28,
                              ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob) & is.na(last_alive),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10,
                                                   ifelse(state_1st_ob == "2/3 adult size, mottled grey", chick_1st_ob - 19,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob, NA)))))), 
                                     ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob) & is.na(last_alive), NA, NA))) %>% as.Date()) %>% 
  # mutate(last_alive2 = ifelse(Fate == "0" & !is.na(chick_1st_ob) & last_alive2 > chick_1st_ob, chick_1st_ob, last_alive2) %>% as.Date()) %>% 
  mutate(last_alive = ifelse(!is.na(last_alive2), 
                             paste0(str_sub(as.character(last_alive2), 9, 10),
                                    str_sub(as.character(last_alive2), 6, 7),
                                    str_sub(as.character(last_alive2), 1, 4)), last_alive)) %>% 
  mutate(
    last_checked = ifelse(!is.na(last_alive) & is.na(last_checked),
                          last_alive,
                          ifelse(is.na(last_alive) & is.na(last_checked),
                                 first_found, last_checked))) %>%
  mutate(
    last_alive = ifelse(is.na(last_alive) & Fate == "0" & !is.na(last_checked),
                        last_checked,
                        ifelse(is.na(last_alive) & Fate == "1" & !is.na(last_checked),
                               first_found,
                               last_alive))) %>%
  filter(
    (is.na(last_alive) | nchar(last_alive) == 8) &
      (is.na(first_found) | nchar(first_found) == 8) &
      (is.na(last_checked) | nchar(last_checked) == 8)
  ) %>% 
  mutate(first_found2 = as.Date(paste(str_sub(first_found, 5, 8),
                                      str_sub(first_found, 3, 4),
                                      str_sub(first_found, 1, 2), sep = "-")),
         last_alive2 = as.Date(paste(str_sub(last_alive, 5, 8),
                                     str_sub(last_alive, 3, 4),
                                     str_sub(last_alive, 1, 2), sep = "-")),
         last_checked2 = as.Date(paste(str_sub(last_checked, 5, 8),
                                       str_sub(last_checked, 3, 4),
                                       str_sub(last_checked, 1, 2), sep = "-"))) %>% 
  mutate(last_checked2 = ifelse(!is.na(last_alive2) & !is.na(last_checked2) & last_checked2 < last_alive2, 
                                last_alive2, last_checked2) %>% as.Date()) %>% 
  mutate(first_found2 = ifelse(!is.na(clutch_comp) & ((last_alive2 - first_found2) > 40 | (last_alive2 - first_found2) < 0)
                               & ((last_alive2 - clutch_comp) < 40 | (last_alive2 - clutch_comp) > 0), 
                               clutch_comp, first_found2) %>% as.Date()) %>% 
  mutate(FirstFound = as.numeric(format(first_found2 + 180, "%j")),
         LastPresent = as.numeric(format(last_alive2 + 180, "%j")),
         LastChecked = as.numeric(format(last_checked2 + 180, "%j"))) %>% 
  # mutate(FirstFound = ((as.integer(format(first_found2, "%j")) -
  #                         as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365),#as.numeric(format(first_found2 + 180, "%j")),
  #        LastPresent = ((as.integer(format(last_alive2, "%j")) -
  #                          as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365),#as.numeric(format(last_alive2 + 180, "%j")),
  #        LastChecked = ((as.integer(format(last_checked2, "%j")) -
  #                          as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365)) %>% #as.numeric(format(last_checked2 + 180, "%j"))) %>% 
  mutate(management_type = tolower(management_type)) %>%
  mutate(nest_hab = tolower(nest_hab)) %>%
  mutate(management_type = str_replace(management_type, "acess", "access")) %>%
  mutate(management_type = str_replace(management_type, "and", ",")) %>%
  mutate(management_type = str_replace(management_type, "temporary", "")) %>%
  mutate(management_type = str_replace_all(management_type, " ", "")) %>%
  mutate(management_type = str_replace_all(management_type, "shelters", "")) %>%
  mutate(management_type = str_replace_all(management_type, "banners", "")) %>%
  mutate(management_type = str_replace_all(management_type, ",,", ",")) %>%
  mutate(sign_access = ifelse(str_detect(management_type, "signaccess"), 1, 0)) %>%
  mutate(sign_nest = ifelse(str_detect(management_type, "signnest"), 1, 0)) %>%
  mutate(rope_fence = ifelse(str_detect(management_type, "ropefence"), 1, 0)) %>%
  mutate(perm_fence = ifelse(str_detect(management_type, "permanentfence"), 1, 0)) %>% # & nest_hab == "dune", 1, 0)) %>%
  mutate(wardens = ifelse(str_detect(management_type, "wardens"), 1, 0)) %>% 
  mutate(none = ifelse(str_detect(management_type, "none"), 1, 
                       ifelse(is.na(management_type) & management_status == "N", 1, 0))) %>%
  mutate(other = ifelse(str_detect(management_type, "other"), 1, 0)) %>%
  mutate(management_level = ifelse((sign_access == 1 | perm_fence == 1) & sign_nest == 1 & rope_fence == 1 & wardens == 1, 4,
                                   ifelse(rope_fence == 1, 3,
                                          ifelse(sign_nest == 1, 2,
                                                 ifelse(sign_access == 1 | perm_fence == 1, 1,
                                                        ifelse(none == 1, 0, NA)))))) %>%
  mutate(sign_nest_no_sign_access = ifelse(sign_access == 0 & sign_nest == 1, 1, 0)) %>%
  mutate(fence_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & rope_fence == 1, 1, 0)) %>%
  mutate(wardens_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & wardens == 1, 1, 0)) %>%
  mutate(wardens_no_fence = ifelse(rope_fence == 1 & wardens == 1, 1, 0)) %>%
  mutate(just_wardens = ifelse(rope_fence == 0 & sign_access == 0 & sign_nest == 0 & wardens == 1, 1, 0)) %>%
  dplyr::select(-other, -sign_nest_no_sign_access, -fence_no_sign, 
                -wardens_no_sign, -wardens_no_fence, -just_wardens) %>%
  group_by(season) %>%
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  mutate(region = "MP") %>%
  mutate(site = as.factor(site)) %>%
  mutate(issue1 = ifelse(nchar(first_found) != 8, "found date is not 8 characters; ", NA)) %>% 
  mutate(issue2 = ifelse(nchar(last_alive) != 8, "last seen alive date is not 8 characters; ", NA)) %>% 
  mutate(issue3 = ifelse(nchar(last_checked) != 8, "last checked date is not 8 characters; ", NA)) %>% 
  mutate(issue4 = ifelse(is.na(first_found), "found date missing; ", NA)) %>% 
  mutate(issue5 = ifelse(is.na(last_alive), "last seen alive date missing; ", NA)) %>% 
  mutate(issue6 = ifelse(is.na(last_checked), "last checked date missing; ", NA)) %>% 
  mutate(issue7 = ifelse(management_status %!in% c("Y", "N"), "Nest managed? is not Y or N; ", NA)) %>% 
  mutate(issue8 = ifelse(nest_hab %!in% c("beach", "dune", "foredune/face", "estuary/spit"), 
                         "Nest habitat is not beach, dune, foredune/face, or estuary/spit; ", NA)) %>% 
  mutate(issue9 = ifelse(is.na(management_level), "Management type is not sufficient for making levels; ", NA)) %>%
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>% 
  mutate(issue10 = ifelse(found_and_alive_diff > 40 , "Double check dates because incubation time greater than 40 days; ", NA)) %>% 
  mutate(issue11 = ifelse(first_found2 > last_alive2, "Found date is after Last Alive date (should be greater or equal); ", NA)) %>% 
  mutate(issue12 = ifelse(first_found2 > last_checked2, "Found date is after Last Checked date (should be greater or equal); ", NA)) %>%
  mutate(issue13 = ifelse(last_checked2 < last_alive2, "Last Checked date is before Last Alive date (should be greater or equal); ", NA)) %>% 
  mutate(issues = ifelse(is.na(issue1) & is.na(issue2) & is.na(issue3) & 
                           is.na(issue4) & is.na(issue5) & is.na(issue6) & 
                           is.na(issue7) & is.na(issue8) & is.na(issue9) & 
                           is.na(issue10) & is.na(issue11) & is.na(issue12) & is.na(issue13), NA, 
                         paste0(issue1, issue2, issue3, 
                                issue4, issue5, issue6, 
                                issue7, issue8, issue9,
                                issue10, issue11, issue12, issue13))) %>% 
  mutate(issues = str_remove_all(issues, "NA")) %>% 
  mutate(issues = ifelse(is.na(issues), "usable", issues)) %>% 
  dplyr::select(-issue1, -issue2, -issue3, 
                -issue4, -issue5, -issue6, 
                -issue7, -issue8, -issue9, 
                -issue10, -issue11, -issue12, -issue13) %>% 
  filter(issues != "usable") %>%
  arrange(issues)# Create a new workbook to store issues as two sheets
PI_nest_issues <- createWorkbook()
# Add all_issues sheet
addWorksheet(PI_nest_issues, "all_issues")
# view issues interactively in RStudio Viewer
PI_nest_data_issues %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')# write PI_nest_data_check
writeData(PI_nest_issues, sheet = "all_issues", PI_nest_data_issues)# Add date_issues
addWorksheet(PI_nest_issues, "date_issues")
# there are some blank (but non-NA) observations of management_type
PI_nest_data_issues %>% filter(is.na(management_type))# A tibble: 0 × 32
# Groups:   season [0]
# ℹ 32 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, sign_nest <dbl>, rope_fence <dbl>, …# view issues interactively in RStudio Viewer
PI_nest_data_issues %>% 
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>%
  filter(str_detect(issues, "date")) %>%
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>%
  mutate(issues = str_remove_all(issues, "Nest habitat is not beach, dune, foredune/face, estuary/spit, or rocks; ")) %>%
  dplyr::select(season, nest_ID, nest_hab, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, 
                Fate, found_and_alive_diff, issues)  %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')# write PI_nest_data_check
PI_nest_data_issues %>% 
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>%
  filter(str_detect(issues, "date")) %>%
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>%
  mutate(issues = str_remove_all(issues, "Nest habitat is not Beach, Dune, Foredune/face, or Estuary/spit; ")) %>%
  dplyr::select(season, nest_ID, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, 
                Fate, found_and_alive_diff, issues) %>% 
  writeData(PI_nest_issues, sheet = "date_issues", .)
# Save the workbook
saveWorkbook(PI_nest_issues, here("data/nest_issues_commented/PI_nest_data_issues_011025.xlsx"), overwrite = TRUE)nest_data_PI <-
  bind_rows(
    nest_import(year_1 = "2024", year_2 = "2025", 
                        file_name = "PI Nesting summaries.xlsx", site = "PI",
                        first_found_date_col = 11, 
                        last_alive_date_col = 29, 
                        last_checked_col = 35),
    nest_import(year_1 = "2023", year_2 = "2024", 
                        file_name = "PI Nesting summaries.xlsx", site = "PI",
                        first_found_date_col = 11, 
                        last_alive_date_col = 29, 
                        last_checked_col = 35),
   nest_import(year_1 = "2022", year_2 = "2023", 
                        file_name = "PI Nesting summaries.xlsx", site = "PI",
                        first_found_date_col = 11, 
                        last_alive_date_col = 29, 
                        last_checked_col = 35),
   nest_import(year_1 = "2021", year_2 = "2022", 
                        file_name = "PI Nesting summaries.xlsx", site = "PI",
                        first_found_date_col = 11, 
                        last_alive_date_col = 29, 
                        last_checked_col = 35),
    nest_import(year_1 = "2020", year_2 = "2021", 
                        file_name = "PI Nesting summaries.xlsx", site = "PI",
                         first_found_date_col = 11, 
                        last_alive_date_col = 29, 
                        last_checked_col = 35),
    nest_import(year_1 = "2019", year_2 = "2020", 
                        file_name = "PI Nesting summaries.xlsx", site = "PI",
                        first_found_date_col = 11, 
                        last_alive_date_col = 29, 
                        last_checked_col = 35),
    nest_import(year_1 = "2018", year_2 = "2019", 
                        file_name = "PI Nesting summaries.xlsx", site = "PI",
                        first_found_date_col = 11, 
                        last_alive_date_col = 29, 
                        last_checked_col = 35),
    nest_import(year_1 = "2017", year_2 = "2018", 
                        file_name = "PI Nesting summaries.xlsx", site = "PI",
                         first_found_date_col = 11, 
                        last_alive_date_col = 29, 
                        last_checked_col = 35),
    nest_import(year_1 = "2016", year_2 = "2017", 
                        file_name = "PI Nesting summaries.xlsx", site = "PI",
                        first_found_date_col = 11, 
                        last_alive_date_col = 29, 
                        last_checked_col = 35),
    nest_import(year_1 = "2015", year_2 = "2016", 
                        file_name = "PI Nesting summaries.xlsx", site = "PI",
                       first_found_date_col = 11, 
                        last_alive_date_col = 29, 
                        last_checked_col = 35),
    nest_import(year_1 = "2014", year_2 = "2015", 
                        file_name = "PI Nesting summaries.xlsx", site = "PI",
                       first_found_date_col = 11, 
                        last_alive_date_col = 29, 
                        last_checked_col = 35),
    nest_import(year_1 = "2013", year_2 = "2014", 
                        file_name = "PI Nesting summaries.xlsx", site = "PI",
                         first_found_date_col = 11, 
                        last_alive_date_col = 29, 
                        last_checked_col = 35),
    nest_import(year_1 = "2012", year_2 = "2013", 
                        file_name = "PI Nesting summaries.xlsx", site = "PI",
                        first_found_date_col = 11, 
                        last_alive_date_col = 29, 
                        last_checked_col = 35)) %>% 
  
  group_by(season) %>% 
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  filter(!is.na(FirstFound) & !is.na(LastPresent) & !is.na(LastChecked)) %>% 
  filter(management_status %in% c("Y", "N")) %>% 
  filter(nest_hab %in% c("beach", "dune", "foredune/face", "estuary/spit")) %>%
  filter(!is.na(management_level)) %>% # 
  mutate(region = "PI") %>% 
  mutate(site = as.factor(site)) %>%
  group_by(season, site) %>%
  arrange(first_found2, .by_group = TRUE) %>%
  mutate(rank = row_number()) %>%
  ungroup() %>%
  mutate(nest_ID_new = paste(season, site, rank, sep = "_")) %>% 
  ungroup()nest_data_PI_check <-
  nest_data_PI %>% 
  ungroup() %>% 
  mutate(first_found2_md = paste(format(first_found2 + 180, format = "%m"),
                                 format(first_found2 + 180, format = "%d"),
                                 sep = "-"),
         last_alive2_md = paste(format(last_alive2 + 180, format = "%m"),
                                format(last_alive2 + 180, format = "%d"),
                                sep = "-"),
         last_checked2_md = paste(format(last_checked2 + 180, format = "%m"),
                                  format(last_checked2 + 180, format = "%d"),
                                  sep = "-")) %>% 
  mutate(first_found2_trans = as.Date(paste("2020", first_found2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_alive2_trans = as.Date(paste("2020", last_alive2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_checked2_trans = as.Date(paste("2020", last_checked2_md, sep = "-"), format = "%Y-%m-%d") - 179) %>% 
  mutate(season_label = paste0("season ", str_sub(season, 1, 4), " to ", str_sub(season, 5, 6)))Note that this map only shows data that are in a decimal degrees format (e.g., -38.31), NOT degree minute seconds (e.g., 38 27.59). The map is interactive, so click on an outlier to see its metadata
nest_data_PI_sf <-
  nest_data_PI %>% 
  as.data.frame() %>% 
  mutate(nest_lon = as.numeric(nest_lon),
         nest_lat = as.numeric(nest_lat)) %>% 
  filter(!is.na(nest_lon) & !is.na(nest_lat)) %>%
  st_as_sf(coords = c("nest_lon", "nest_lat"), 
           crs = 4326) %>% suppressWarnings()
mapview(nest_data_PI_sf,
        zcol = "season", 
        popup = popupTable(nest_data_PI_sf,
                           zcol = c("season",
                                    "site",
                                    "nest_ID")))ggplot(nest_data_PI_check, aes(first_found2_trans, fill = Fate)) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               # expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_PI_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_PI_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10)) +
  luke_theme +
  xlab("Found date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))ggplot(nest_data_PI_check, aes(last_alive2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_PI_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_PI_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last alive date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))ggplot(nest_data_PI_check, aes(last_checked2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B",
               expand = c(0.01, 0.01),
               date_breaks = "1 months", limits = c(min(nest_data_PI_check$first_found2_trans, na.rm = TRUE),
                                                    max(nest_data_PI_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last checked date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))nest_data_PI_check %>% 
  group_by(season) %>% 
  summarise(n()) %>% 
  print(n = Inf)# A tibble: 13 × 2
   season `n()`
   <fct>  <int>
 1 201213    34
 2 201314    15
 3 201415    27
 4 201516    35
 5 201617    32
 6 201718    40
 7 201819    43
 8 201920    38
 9 202021    45
10 202122    27
11 202223    29
12 202324    19
13 202425    31nest_data_PI_check %>% 
  summarise(n())# A tibble: 1 × 1
  `n()`
  <int>
1   415# assess if there are nests with unusually long incubation periods
nest_data_PI_check %>% 
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>%
  arrange(desc(found_and_alive_diff)) %>% 
  filter(first_found2 < last_alive2 & first_found2 < last_checked2 & found_and_alive_diff < 100) %>% 
  ggplot() +
  geom_histogram(aes(found_and_alive_diff)) +
  luke_theme +
  xlab("Time between found date and last alive date (days)") +
  ylab("Frquency of nests")# A tibble: 0 × 35
# ℹ 35 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, chick_management_status <chr>,
#   chick_management_type <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>, …# A tibble: 0 × 35
# ℹ 35 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, chick_management_status <chr>,
#   chick_management_type <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>, …# A tibble: 0 × 35
# ℹ 35 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, chick_management_status <chr>,
#   chick_management_type <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>, …< table of extent 0 ># A tibble: 0 × 3
# ℹ 3 variables: issues <chr>, season <fct>, site <fct>MP_threat_data <- 
  read_excel("data/Threat data all years 25062025.xlsx",
             sheet = "MP threats (all years)", 
             col_types = "text") %>% 
  mutate(season = str_remove(Season, "/")) %>%
  rename(obs_lon = `Observation Longitude`,
         obs_lat = `Observation Latitude`,
         obs_date = `Observation Date`) %>% 
  mutate(obs_date = as.Date(as.numeric(obs_date), 
                            origin = "1899-12-30")) %>% 
  mutate(obs_date2 = as.numeric(format(obs_date + 180, "%j"))) %>% 
  mutate(region = "MP")
FP_threat_data <- 
  read_excel("data/Threat data all years 25062025.xlsx",
             sheet = "FP threat (all years)", 
             col_types = "text") %>% 
  mutate(season = str_remove(Season, "/")) %>%
  rename(obs_lon = `Observation Longitude`,
         obs_lat = `Observation Latitude`,
         obs_date = `Observation Date`) %>% 
  mutate(obs_date = as.Date(as.numeric(obs_date), 
                            origin = "1899-12-30")) %>% 
  mutate(obs_date2 = as.numeric(format(obs_date + 180, "%j"))) %>% 
  mutate(region = "FP")
BSC_threat_data <- 
  read_excel("data/Threat data all years 25062025.xlsx",
             sheet = "BSC threats (all years)", 
             col_types = "text") %>% 
  mutate(season = str_remove(Season, "/")) %>%
  rename(obs_lon = `Observation Longitude`,
         obs_lat = `Observation Latitude`,
         obs_date = `Observation date`) %>% 
  mutate(obs_date = as.Date(as.numeric(obs_date), 
                            origin = "1899-12-30")) %>% 
  mutate(obs_date2 = as.numeric(format(obs_date + 180, "%j"))) %>% 
  mutate(region = "BSC")
BC_threat_data <- 
  read_excel("data/Threat data all years 25062025.xlsx",
             sheet = "BC threat (all years)", 
             col_types = "text") %>% 
  mutate(season = str_remove(Season, "/")) %>%
  rename(obs_lon = `Observation Longitude`,
         obs_lat = `Observation Latitude`,
         obs_date = `Observation date`) %>% 
  mutate(obs_date = as.Date(as.numeric(obs_date), 
                            origin = "1899-12-30")) %>% 
  mutate(obs_date2 = as.numeric(format(obs_date + 180, "%j"))) %>% 
  mutate(region = "BC")
PI_threat_data <- 
  read_excel("data/Threat data all years 25062025.xlsx",
             sheet = "PI threat (all years)", 
             col_types = "text") %>% 
  mutate(season = str_remove(Season, "/")) %>%
  rename(obs_lon = `Observation Longitude`,
         obs_lat = `Observation Latitude`,
         obs_date = `Observation date`) %>% 
  mutate(obs_date = as.Date(as.numeric(obs_date), 
                            origin = "1899-12-30")) %>% 
  mutate(obs_date2 = as.numeric(format(obs_date + 180, "%j"))) %>% 
  mutate(region = "PI")
threat_data <- 
  bind_rows(FP_threat_data, 
            MP_threat_data, 
            BC_threat_data, 
            BSC_threat_data, 
            PI_threat_data)###Import threat data
threat_data_ <-
  threat_data %>% 
  rename(site = `Site name`) %>% 
  # first convert all the count columns to numeric
  mutate_at(vars(
    `Walkers/Joggers (wet sand)`,`Walkers/Joggers (dry sand)`,
    `Walkers/Joggers (signs/fence)`,`Walkers/Joggers (Dune)`,`People sunbaking/sitting (wet sand)`,
    `People sunbaking/sitting (dry sand)`,`People sunbaking/sitting (signs/fence)`,
    `People sunbaking/sitting (Dune)`,`Surfers/Swimmers (wet sand)`,
    `Surfers/Swimmers (dry sand)`,`Surfers/Swimmers (signs/fence)`,
    `Surfers/Swimmers (Dune)`,`People Fishing (wet sand)`,
    `People Fishing (dry sand)`,`People Fishing (signs/fence)`,
    `People Fishing (Dune)`,`People Playing Games (wet sand)`,
    `People Playing Games (dry sand)`,`People Playing Games (signs/fence)`,
    `People Playing Games (Dune)`,`Dog Walkers (wet sand)`,
    `Dog Walkers (dry sand)`,`Dog Walkers (signs/fence)`,
    `Dog Walkers (Dune)`,`Dog On Leash (# dogs) (wet sand)`,
    `Dog On Leash (# dogs) (dry sand)`,`Dog On Leash (# dogs) (signs/fence)`,
    `Dog On Leash (# dogs) (Dune)`,`Dog Off Leash (# dogs) (wet sand)`,
    `Dog Off Leash (# dogs) (dry sand)`,`Dog Off Leash (# dogs) (signs/fence)`,
    `Dog Off Leash (# dogs) (Dune)`,`Horses (wet sand)`,
    `Horses (dry sand)`,`Horses (signs/fence)`,
    `Horses (Dune)`,`Permitted vehicle (wet sand)`,
    `Permitted vehicle (dry sand)`,`Permitted vehicle (signs/fence)`,
    `Permitted vehicle (Dune)`,`Illegal vehicle (wet sand)`,
    `Illegal vehicle (dry sand)`,`Illegal vehicle (signs/fence)`,
    `Illegal vehicle (Dune)`,`Ravens (wet sand)`,                     
    `Ravens (dry sand)`,`Ravens (signs/fence)`, 
    `Ravens (Dune)`,`Magpies (wet sand)`, 
    `Magpies (dry sand)`,`Magpies (signs/fence)`, 
    `Magpies (Dune)`,`Silver Gulls (wet sand)`,  
    `Silver Gulls (dry sand)`,`Silver Gulls (signs/fence)`,
    `Silver Gulls (Dune)`,`Pacific/Kelp Gulls (wet sand)`,
    `Pacific/Kelp Gulls (dry sand)`,`Pacific/Kelp Gulls (signs/fence)`,
    `Pacific/Kelp Gulls (Dune)`,`Nankeen Kestrels (wet sand)`,
    `Nankeen Kestrels (dry sand)`,`Nankeen Kestrels (signs/fence)`,
    `Nankeen Kestrels (Dune)`,`Other bird of prey (wet sand)`,
    `Other bird of prey (dry sand)`,`Other bird of prey (signs/fence)`,
    `Other bird of prey (Dune)`,
    `Stock (cattle/sheep) (wet sand)`,
    `Stock (cattle/sheep) (dry sand)`,`Stock (cattle/sheep) (signs/fence)`,
    `Stock (cattle/sheep) (Dune)`), as.numeric) %>% 
  ungroup() %>% 
  
  # take the total sum of counts for each threat type (e.g., humans includes
  # Dog Walkers, People Playing Games, People Fishing, Surfers/Swimmers, 
  # People sunbaking/sitting, and Walkers/Joggers)
  mutate(humans = rowSums(dplyr::select(.,`Walkers/Joggers (wet sand)`, 
                                        `Walkers/Joggers (dry sand)`, 
                                        `Walkers/Joggers (signs/fence)`, 
                                        `Walkers/Joggers (Dune)`, 
                                        `People sunbaking/sitting (wet sand)`, 
                                        `People sunbaking/sitting (dry sand)`, 
                                        `People sunbaking/sitting (signs/fence)`, 
                                        `People sunbaking/sitting (Dune)`, 
                                        `Surfers/Swimmers (wet sand)`, 
                                        `Surfers/Swimmers (dry sand)`, 
                                        `Surfers/Swimmers (signs/fence)`, 
                                        `Surfers/Swimmers (Dune)`, 
                                        `People Fishing (wet sand)`, 
                                        `People Fishing (dry sand)`, 
                                        `People Fishing (signs/fence)`, 
                                        `People Fishing (Dune)`, 
                                        `People Playing Games (wet sand)`, 
                                        `People Playing Games (dry sand)`, 
                                        `People Playing Games (signs/fence)`, 
                                        `People Playing Games (Dune)`, 
                                        `Dog Walkers (wet sand)`, 
                                        `Dog Walkers (dry sand)`, 
                                        `Dog Walkers (signs/fence)`, 
                                        `Dog Walkers (Dune)`), na.rm = TRUE),
         # do a micro-habitat specific sum for humans
         humans_wet = rowSums(dplyr::select(.,`Walkers/Joggers (wet sand)`, 
                                            `People sunbaking/sitting (wet sand)`, 
                                            `Surfers/Swimmers (wet sand)`, 
                                            `People Fishing (wet sand)`, 
                                            `People Playing Games (wet sand)`, 
                                            `Dog Walkers (wet sand)`), na.rm = TRUE),
         humans_dry = rowSums(dplyr::select(.,`Walkers/Joggers (dry sand)`, 
                                            `People sunbaking/sitting (dry sand)`, 
                                            `Surfers/Swimmers (dry sand)`, 
                                            `People Fishing (dry sand)`, 
                                            `People Playing Games (dry sand)`, 
                                            `Dog Walkers (dry sand)`), na.rm = TRUE),
         humans_dune = rowSums(dplyr::select(.,`Walkers/Joggers (Dune)`, 
                                             `People sunbaking/sitting (Dune)`, 
                                            `Surfers/Swimmers (Dune)`, 
                                            `People Fishing (Dune)`, 
                                            `People Playing Games (Dune)`, 
                                            `Dog Walkers (Dune)`), na.rm = TRUE),
         humans_SF = rowSums(dplyr::select(.,`Walkers/Joggers (signs/fence)`, 
                                            `People sunbaking/sitting (signs/fence)`, 
                                            `Surfers/Swimmers (signs/fence)`, 
                                            `People Fishing (signs/fence)`, 
                                            `People Playing Games (signs/fence)`, 
                                            `Dog Walkers (signs/fence)`), na.rm = TRUE),
       dogs = rowSums(dplyr::select(., `Dog On Leash (# dogs) (wet sand)`, 
                                    `Dog On Leash (# dogs) (dry sand)`,
                                    `Dog On Leash (# dogs) (signs/fence)`, 
                                    `Dog On Leash (# dogs) (Dune)`, 
                                    `Dog Off Leash (# dogs) (wet sand)`, 
                                    `Dog Off Leash (# dogs) (dry sand)`, 
                                    `Dog Off Leash (# dogs) (signs/fence)`, 
                                    `Dog Off Leash (# dogs) (Dune)`), na.rm = TRUE),
       # specify a dog on leash and a dog of leash summary
       dogs_on = rowSums(dplyr::select(., `Dog On Leash (# dogs) (wet sand)`, 
                                       `Dog On Leash (# dogs) (dry sand)`,
                                       `Dog On Leash (# dogs) (signs/fence)`, 
                                       `Dog On Leash (# dogs) (Dune)`), na.rm = TRUE),
       dogs_off = rowSums(dplyr::select(., `Dog Off Leash (# dogs) (wet sand)`, 
                                        `Dog Off Leash (# dogs) (dry sand)`, 
                                        `Dog Off Leash (# dogs) (signs/fence)`, 
                                        `Dog Off Leash (# dogs) (Dune)`), na.rm = TRUE),
       pred_birds = rowSums(dplyr::select(., `Ravens (wet sand)`, 
                                          `Ravens (dry sand)`, 
                                          `Ravens (signs/fence)`, 
                                          `Ravens (Dune)`, 
                                          `Magpies (wet sand)`, 
                                          `Magpies (dry sand)`, 
                                          `Magpies (signs/fence)`, 
                                          `Magpies (Dune)`#, 
                                          # `Silver Gulls (wet sand)`,
                                          # `Silver Gulls (dry sand)`,
                                          # `Silver Gulls (signs/fence)`,
                                          # `Silver Gulls (Dune)`,
                                          # `Pacific/Kelp Gulls (wet sand)`,
                                          # `Pacific/Kelp Gulls (dry sand)`,
                                          # `Pacific/Kelp Gulls (signs/fence)`,
                                          # `Pacific/Kelp Gulls (Dune)`,
                                          # `Nankeen Kestrels (wet sand)`, 
                                          # `Nankeen Kestrels (dry sand)`, 
                                          # `Nankeen Kestrels (signs/fence)`, 
                                          # `Nankeen Kestrels (Dune)`, 
                                          # `Other bird of prey (wet sand)`, 
                                          # `Other bird of prey (dry sand)`, 
                                          # `Other bird of prey (signs/fence)`, 
                                          # `Other bird of prey (Dune)`
                                          ), na.rm = TRUE),
       gulls = rowSums(dplyr::select(., #`Ravens (wet sand)`, 
                                          # `Ravens (dry sand)`, 
                                          # `Ravens (signs/fence)`, 
                                          # `Ravens (Dune)`, 
                                          # `Magpies (wet sand)`, 
                                          # `Magpies (dry sand)`, 
                                          # `Magpies (signs/fence)`, 
                                          # `Magpies (Dune)` 
                                          `Silver Gulls (wet sand)`,
                                          `Silver Gulls (dry sand)`,
                                          `Silver Gulls (signs/fence)`,
                                          `Silver Gulls (Dune)`,
                                          `Pacific/Kelp Gulls (wet sand)`,
                                          `Pacific/Kelp Gulls (dry sand)`,
                                          `Pacific/Kelp Gulls (signs/fence)`,
                                          `Pacific/Kelp Gulls (Dune)`
                                          # `Nankeen Kestrels (wet sand)`, 
                                          # `Nankeen Kestrels (dry sand)`, 
                                          # `Nankeen Kestrels (signs/fence)`, 
                                          # `Nankeen Kestrels (Dune)`, 
                                          # `Other bird of prey (wet sand)`, 
                                          # `Other bird of prey (dry sand)`, 
                                          # `Other bird of prey (signs/fence)`, 
                                          # `Other bird of prey (Dune)`
                                          ), na.rm = TRUE),
       vehicles = rowSums(dplyr::select(., `Permitted vehicle (wet sand)`, 
                                        `Permitted vehicle (dry sand)`, 
                                        `Permitted vehicle (signs/fence)`, 
                                        `Permitted vehicle (Dune)`, 
                                        `Illegal vehicle (wet sand)`, 
                                        `Illegal vehicle (dry sand)`, 
                                        `Illegal vehicle (signs/fence)`, 
                                        `Illegal vehicle (Dune)`), na.rm = TRUE),
       hoofed_animals = rowSums(dplyr::select(.,`Horses (wet sand)`, 
                                              `Horses (dry sand)`, 
                                              `Horses (signs/fence)`,
                                              `Horses (Dune)`, 
                                              `Stock (cattle/sheep) (wet sand)`, 
                                              `Stock (cattle/sheep) (dry sand)`, 
                                              `Stock (cattle/sheep) (signs/fence)`, 
                                              `Stock (cattle/sheep) (Dune)`), na.rm = TRUE)) %>% 
  # consolidate columns names
  rename(hum_pri_wet = `Human Prints (wet sand)`,
         hum_pri_dry = `Human Prints (dry sand)`,
         hum_pri_dune = `Human Prints (Dune)`,
         hum_pri_SF = `Human Prints (signs/fence)`,
         fox_pri_wet = `Fox Prints (wet sand)`,
         fox_pri_dry = `Fox Prints (dry sand)`,
         fox_pri_dune = `Fox Prints (Dune)`,
         fox_pri_SF = `Fox Prints (signs/fence)`,
         dog_pri_wet = `Dog Prints (wet sand)`,
         dog_pri_dry = `Dog Prints (dry sand)`,
         dog_pri_dune = `Dog Prints (Dune)`,
         dog_pri_SF = `Dog Prints (signs/fence)`,
         vehicle_pri_wet = `Vehicle Tracks (wet sand)`,
         vehicle_pri_dry = `Vehicle Tracks (dry sand)`,
         vehicle_pri_dune = `Vehicle Tracks (Dune)`,
         vehicle_pri_SF = `Vehicle Tracks (signs/fence)`,
         trailbike_pri_wet = `Trail bike tracks (wet sand)`,
         trailbike_pri_dry = `Trail bike tracks (dry sand)`,
         trailbike_pri_dune = `Trail bike tracks (Dune)`,
         trailbike_pri_SF = `Trail bike tracks (signs/fence)`,
         stock_pri_wet = `Stock (wet sand)`,
         stock_pri_dry = `Stock (dry sand)`,
         stock_pri_dune = `Stock (Dune)`,
         stock_pri_SF = `Stock (signs/fence)`,
         horse_pri_wet = `Horses Prints (wet sand)`,
         horse_pri_dry = `Horses Prints (dry sand)`,
         horse_pri_dune = `Horses Prints (Dune)`,
         horse_pri_SF = `Horses Prints (signs/fence)`) %>%
  # specify coordinates as numeric
  mutate(obs_lon = as.numeric(obs_lon),
         obs_lat = as.numeric(obs_lat)) %>% 
  # clean up factor levels (e.g., sometime "Light", sometimes just "L")
  mutate(hum_pri_wet = ifelse(hum_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(hum_pri_wet, 1, 1), 
                              ifelse(hum_pri_wet == "0", "N",
                                     ifelse(hum_pri_wet == "1", "L",
                                           ifelse(hum_pri_wet == "2", "M",
                                                  ifelse(hum_pri_wet == "3", "H",
                                                         ifelse(hum_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         hum_pri_dry = ifelse(hum_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(hum_pri_dry, 1, 1), 
                              ifelse(hum_pri_dry == "0", "N",
                                     ifelse(hum_pri_dry == "1", "L",
                                           ifelse(hum_pri_dry == "2", "M",
                                                  ifelse(hum_pri_dry == "3", "H",
                                                         ifelse(hum_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         hum_pri_SF =  ifelse(hum_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(hum_pri_SF, 1, 1), 
                              ifelse(hum_pri_SF == "0", "N",
                                     ifelse(hum_pri_SF == "1", "L",
                                           ifelse(hum_pri_SF == "2", "M",
                                                  ifelse(hum_pri_SF == "3", "H",
                                                         ifelse(hum_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         hum_pri_dune = ifelse(hum_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                               substr(hum_pri_dune, 1, 1), 
                              ifelse(hum_pri_dune == "0", "N",
                                     ifelse(hum_pri_dune == "1", "L",
                                           ifelse(hum_pri_dune == "2", "M",
                                                  ifelse(hum_pri_dune == "3", "H",
                                                         ifelse(hum_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         fox_pri_wet = ifelse(fox_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(fox_pri_wet, 1, 1), 
                              ifelse(fox_pri_wet == "0", "N",
                                     ifelse(fox_pri_wet == "1", "L",
                                           ifelse(fox_pri_wet == "2", "M",
                                                  ifelse(fox_pri_wet == "3", "H",
                                                         ifelse(fox_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         fox_pri_dry = ifelse(fox_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(fox_pri_dry, 1, 1), 
                              ifelse(fox_pri_dry == "0", "N",
                                     ifelse(fox_pri_dry == "1", "L",
                                           ifelse(fox_pri_dry == "2", "M",
                                                  ifelse(fox_pri_dry == "3", "H",
                                                         ifelse(fox_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         fox_pri_SF = ifelse(fox_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                             substr(fox_pri_SF, 1, 1), 
                              ifelse(fox_pri_SF == "0", "N",
                                     ifelse(fox_pri_SF == "1", "L",
                                           ifelse(fox_pri_SF == "2", "M",
                                                  ifelse(fox_pri_SF == "3", "H",
                                                         ifelse(fox_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         fox_pri_dune = ifelse(fox_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                               substr(fox_pri_dune, 1, 1), 
                              ifelse(fox_pri_dune == "0", "N",
                                     ifelse(fox_pri_dune == "1", "L",
                                           ifelse(fox_pri_dune == "2", "M",
                                                  ifelse(fox_pri_dune == "3", "H",
                                                         ifelse(fox_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         dog_pri_wet = ifelse(dog_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(dog_pri_wet, 1, 1), 
                              ifelse(dog_pri_wet == "0", "N",
                                     ifelse(dog_pri_wet == "1", "L",
                                           ifelse(dog_pri_wet == "2", "M",
                                                  ifelse(dog_pri_wet == "3", "H",
                                                         ifelse(dog_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         dog_pri_dry = ifelse(dog_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(dog_pri_dry, 1, 1), 
                              ifelse(dog_pri_dry == "0", "N",
                                     ifelse(dog_pri_dry == "1", "L",
                                           ifelse(dog_pri_dry == "2", "M",
                                                  ifelse(dog_pri_dry == "3", "H",
                                                         ifelse(dog_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         dog_pri_SF = ifelse(dog_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                             substr(dog_pri_SF, 1, 1), 
                              ifelse(dog_pri_SF == "0", "N",
                                     ifelse(dog_pri_SF == "1", "L",
                                           ifelse(dog_pri_SF == "2", "M",
                                                  ifelse(dog_pri_SF == "3", "H",
                                                         ifelse(dog_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         dog_pri_dune = ifelse(dog_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                               substr(dog_pri_dune, 1, 1), 
                              ifelse(dog_pri_dune == "0", "N",
                                     ifelse(dog_pri_dune == "1", "L",
                                           ifelse(dog_pri_dune == "2", "M",
                                                  ifelse(dog_pri_dune == "3", "H",
                                                         ifelse(dog_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         vehicle_pri_wet = ifelse(vehicle_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                  substr(vehicle_pri_wet, 1, 1), 
                              ifelse(vehicle_pri_wet == "0", "N",
                                     ifelse(vehicle_pri_wet == "1", "L",
                                           ifelse(vehicle_pri_wet == "2", "M",
                                                  ifelse(vehicle_pri_wet == "3", "H",
                                                         ifelse(vehicle_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         vehicle_pri_dry = ifelse(vehicle_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                  substr(vehicle_pri_dry, 1, 1), 
                              ifelse(vehicle_pri_dry == "0", "N",
                                     ifelse(vehicle_pri_dry == "1", "L",
                                           ifelse(vehicle_pri_dry == "2", "M",
                                                  ifelse(vehicle_pri_dry == "3", "H",
                                                         ifelse(vehicle_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         vehicle_pri_SF = ifelse(vehicle_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                 substr(vehicle_pri_SF, 1, 1), 
                              ifelse(vehicle_pri_SF == "0", "N",
                                     ifelse(vehicle_pri_SF == "1", "L",
                                           ifelse(vehicle_pri_SF == "2", "M",
                                                  ifelse(vehicle_pri_SF == "3", "H",
                                                         ifelse(vehicle_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         vehicle_pri_dune = ifelse(vehicle_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                   substr(vehicle_pri_dune, 1, 1), 
                              ifelse(vehicle_pri_dune == "0", "N",
                                     ifelse(vehicle_pri_dune == "1", "L",
                                           ifelse(vehicle_pri_dune == "2", "M",
                                                  ifelse(vehicle_pri_dune == "3", "H",
                                                         ifelse(vehicle_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         trailbike_pri_wet = ifelse(trailbike_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                    substr(trailbike_pri_wet, 1, 1), 
                              ifelse(trailbike_pri_wet == "0", "N",
                                     ifelse(trailbike_pri_wet == "1", "L",
                                           ifelse(trailbike_pri_wet == "2", "M",
                                                  ifelse(trailbike_pri_wet == "3", "H",
                                                         ifelse(trailbike_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         trailbike_pri_dry = ifelse(trailbike_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                    substr(trailbike_pri_dry, 1, 1), 
                              ifelse(trailbike_pri_dry == "0", "N",
                                     ifelse(trailbike_pri_dry == "1", "L",
                                           ifelse(trailbike_pri_dry == "2", "M",
                                                  ifelse(trailbike_pri_dry == "3", "H",
                                                         ifelse(trailbike_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         trailbike_pri_SF = ifelse(trailbike_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                   substr(trailbike_pri_SF, 1, 1), 
                              ifelse(trailbike_pri_SF == "0", "N",
                                     ifelse(trailbike_pri_SF == "1", "L",
                                           ifelse(trailbike_pri_SF == "2", "M",
                                                  ifelse(trailbike_pri_SF == "3", "H",
                                                         ifelse(trailbike_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         trailbike_pri_dune = ifelse(trailbike_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                     substr(trailbike_pri_dune, 1, 1), 
                              ifelse(trailbike_pri_dune == "0", "N",
                                     ifelse(trailbike_pri_dune == "1", "L",
                                           ifelse(trailbike_pri_dune == "2", "M",
                                                  ifelse(trailbike_pri_dune == "3", "H",
                                                         ifelse(trailbike_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         horse_pri_wet = ifelse(horse_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                substr(horse_pri_wet, 1, 1), 
                              ifelse(horse_pri_wet == "0", "N",
                                     ifelse(horse_pri_wet == "1", "L",
                                           ifelse(horse_pri_wet == "2", "M",
                                                  ifelse(horse_pri_wet == "3", "H",
                                                         ifelse(horse_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         horse_pri_dry = ifelse(horse_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                substr(horse_pri_dry, 1, 1), 
                              ifelse(horse_pri_dry == "0", "N",
                                     ifelse(horse_pri_dry == "1", "L",
                                           ifelse(horse_pri_dry == "2", "M",
                                                  ifelse(horse_pri_dry == "3", "H",
                                                         ifelse(horse_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         horse_pri_SF = ifelse(horse_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                               substr(horse_pri_SF, 1, 1), 
                              ifelse(horse_pri_SF == "0", "N",
                                     ifelse(horse_pri_SF == "1", "L",
                                           ifelse(horse_pri_SF == "2", "M",
                                                  ifelse(horse_pri_SF == "3", "H",
                                                         ifelse(horse_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         horse_pri_dune = ifelse(horse_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                 substr(horse_pri_dune, 1, 1), 
                              ifelse(horse_pri_dune == "0", "N",
                                     ifelse(horse_pri_dune == "1", "L",
                                           ifelse(horse_pri_dune == "2", "M",
                                                  ifelse(horse_pri_dune == "3", "H",
                                                         ifelse(horse_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         stock_pri_wet = ifelse(stock_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                substr(stock_pri_wet, 1, 1), 
                              ifelse(stock_pri_wet == "0", "N",
                                     ifelse(stock_pri_wet == "1", "L",
                                           ifelse(stock_pri_wet == "2", "M",
                                                  ifelse(stock_pri_wet == "3", "H",
                                                         ifelse(stock_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         stock_pri_dry = ifelse(stock_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                substr(stock_pri_dry, 1, 1), 
                              ifelse(stock_pri_dry == "0", "N",
                                     ifelse(stock_pri_dry == "1", "L",
                                           ifelse(stock_pri_dry == "2", "M",
                                                  ifelse(stock_pri_dry == "3", "H",
                                                         ifelse(stock_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         stock_pri_SF = ifelse(stock_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                               substr(stock_pri_SF, 1, 1), 
                              ifelse(stock_pri_SF == "0", "N",
                                     ifelse(stock_pri_SF == "1", "L",
                                           ifelse(stock_pri_SF == "2", "M",
                                                  ifelse(stock_pri_SF == "3", "H",
                                                         ifelse(stock_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         stock_pri_dune = ifelse(stock_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                 substr(stock_pri_dune, 1, 1), 
                              ifelse(stock_pri_dune == "0", "N",
                                     ifelse(stock_pri_dune == "1", "L",
                                           ifelse(stock_pri_dune == "2", "M",
                                                  ifelse(stock_pri_dune == "3", "H",
                                                         ifelse(stock_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H"))) %>% 
  # to control for multiple threat surveys per date, summarise by date
  group_by(region, site, season, obs_date, obs_date2) %>% 
  summarise(obs_lon = mean(obs_lon, na.rm = TRUE),
            obs_lat = mean(obs_lat, na.rm = TRUE),
            # in the case of multiple surveys on a single date at a specific 
            # site, take the max humans counted, etc., and the highest level of
            # prints, etc.
            humans = max(humans, na.rm = TRUE),
            humans_wet = max(humans_wet, na.rm = TRUE),
            humans_dry = max(humans_dry, na.rm = TRUE),
            humans_dune = max(humans_dune, na.rm = TRUE),
            humans_SF = max(humans_SF, na.rm = TRUE),
            hoofed_animals = max(hoofed_animals, na.rm = TRUE),
            vehicles = max(vehicles, na.rm = TRUE),
            pred_birds = max(pred_birds, na.rm = TRUE),
            gulls = max(gulls, na.rm = TRUE),
            dogs_off = max(dogs_off, na.rm = TRUE),
            dogs_on = max(dogs_on, na.rm = TRUE),
            dogs = max(dogs, na.rm = TRUE),
            hum_pri_wet = ifelse(all(is.na(hum_pri_wet)), NA, 
                                 levels(hum_pri_wet)[max(as.integer(hum_pri_wet), na.rm = TRUE)]),
            hum_pri_dry = ifelse(all(is.na(hum_pri_dry)), NA, 
                                 levels(hum_pri_dry)[max(as.integer(hum_pri_dry), na.rm = TRUE)]),
            hum_pri_dune = ifelse(all(is.na(hum_pri_dune)), NA, 
                                  levels(hum_pri_dune)[max(as.integer(hum_pri_dune), na.rm = TRUE)]),
            hum_pri_SF = ifelse(all(is.na(hum_pri_SF)), NA, 
                                levels(hum_pri_SF)[max(as.integer(hum_pri_SF), na.rm = TRUE)]),
            fox_pri_wet = ifelse(all(is.na(fox_pri_wet)), NA, 
                                 levels(fox_pri_wet)[max(as.integer(fox_pri_wet), na.rm = TRUE)]),
            fox_pri_dry = ifelse(all(is.na(fox_pri_dry)), NA, 
                                 levels(fox_pri_dry)[max(as.integer(fox_pri_dry), na.rm = TRUE)]),
            fox_pri_dune = ifelse(all(is.na(fox_pri_dune)), NA, 
                                  levels(fox_pri_dune)[max(as.integer(fox_pri_dune), na.rm = TRUE)]),
            fox_pri_SF = ifelse(all(is.na(fox_pri_SF)), NA, 
                                levels(fox_pri_SF)[max(as.integer(fox_pri_SF), na.rm = TRUE)]),
            dog_pri_wet = ifelse(all(is.na(dog_pri_wet)), NA, 
                                 levels(dog_pri_wet)[max(as.integer(dog_pri_wet), na.rm = TRUE)]),
            dog_pri_dry = ifelse(all(is.na(dog_pri_dry)), NA, 
                                 levels(dog_pri_dry)[max(as.integer(dog_pri_dry), na.rm = TRUE)]),
            dog_pri_dune = ifelse(all(is.na(dog_pri_dune)), NA, 
                                  levels(dog_pri_dune)[max(as.integer(dog_pri_dune), na.rm = TRUE)]),
            dog_pri_SF = ifelse(all(is.na(dog_pri_SF)), NA, 
                                levels(dog_pri_SF)[max(as.integer(dog_pri_SF), na.rm = TRUE)]),
            vehicle_pri_wet = ifelse(all(is.na(vehicle_pri_wet)), NA, 
                                     levels(vehicle_pri_wet)[max(as.integer(vehicle_pri_wet), na.rm = TRUE)]),
            vehicle_pri_dry = ifelse(all(is.na(vehicle_pri_dry)), NA, 
                                     levels(vehicle_pri_dry)[max(as.integer(vehicle_pri_dry), na.rm = TRUE)]),
            vehicle_pri_dune = ifelse(all(is.na(vehicle_pri_dune)), NA, 
                                      levels(vehicle_pri_dune)[max(as.integer(vehicle_pri_dune), na.rm = TRUE)]),
            vehicle_pri_SF = ifelse(all(is.na(vehicle_pri_SF)), NA, 
                                    levels(vehicle_pri_SF)[max(as.integer(vehicle_pri_SF), na.rm = TRUE)]),
            trailbike_pri_wet = ifelse(all(is.na(trailbike_pri_wet)), NA, 
                                       levels(trailbike_pri_wet)[max(as.integer(trailbike_pri_wet), na.rm = TRUE)]),
            trailbike_pri_dry = ifelse(all(is.na(trailbike_pri_dry)), NA, 
                                       levels(trailbike_pri_dry)[max(as.integer(trailbike_pri_dry), na.rm = TRUE)]),
            trailbike_pri_dune = ifelse(all(is.na(trailbike_pri_dune)), NA, 
                                        levels(trailbike_pri_dune)[max(as.integer(trailbike_pri_dune), na.rm = TRUE)]),
            trailbike_pri_SF = ifelse(all(is.na(trailbike_pri_SF)), NA, 
                                      levels(trailbike_pri_SF)[max(as.integer(trailbike_pri_SF), na.rm = TRUE)]),
            horse_pri_wet = ifelse(all(is.na(horse_pri_wet)), NA, 
                                   levels(horse_pri_wet)[max(as.integer(horse_pri_wet), na.rm = TRUE)]),
            horse_pri_dry = ifelse(all(is.na(horse_pri_dry)), NA, 
                                   levels(horse_pri_dry)[max(as.integer(horse_pri_dry), na.rm = TRUE)]),
            horse_pri_dune = ifelse(all(is.na(horse_pri_dune)), NA, 
                                    levels(horse_pri_dune)[max(as.integer(horse_pri_dune), na.rm = TRUE)]),
            horse_pri_SF = ifelse(all(is.na(horse_pri_SF)), NA, 
                                  levels(horse_pri_SF)[max(as.integer(horse_pri_SF), na.rm = TRUE)]),
            stock_pri_wet = ifelse(all(is.na(stock_pri_wet)), NA, 
                                   levels(stock_pri_wet)[max(as.integer(stock_pri_wet), na.rm = TRUE)]),
            stock_pri_dry = ifelse(all(is.na(stock_pri_dry)), NA, 
                                   levels(stock_pri_dry)[max(as.integer(stock_pri_dry), na.rm = TRUE)]),
            stock_pri_dune = ifelse(all(is.na(stock_pri_dune)), NA, 
                                    levels(stock_pri_dune)[max(as.integer(stock_pri_dune), na.rm = TRUE)]),
            stock_pri_SF = ifelse(all(is.na(stock_pri_SF)), NA, 
                                  levels(stock_pri_SF)[max(as.integer(stock_pri_SF), na.rm = TRUE)])) %>%
  # make the print variables a factor
  mutate_at(vars(hum_pri_wet, hum_pri_dry, hum_pri_dune, hum_pri_SF,
                 dog_pri_wet, dog_pri_dry, dog_pri_dune, dog_pri_SF,
                 fox_pri_wet, fox_pri_dry, fox_pri_dune, fox_pri_SF,
                 vehicle_pri_wet, vehicle_pri_dry, vehicle_pri_dune, vehicle_pri_SF,
                 trailbike_pri_wet, trailbike_pri_dry, trailbike_pri_dune, trailbike_pri_SF,
                 horse_pri_wet, horse_pri_dry, horse_pri_dune, horse_pri_SF,
                 stock_pri_wet, stock_pri_dry, stock_pri_dune, stock_pri_SF),
            ~ as.factor(.)) %>% 
  # specify the level order of the print variables
  mutate_at(vars(hum_pri_wet, hum_pri_dry, hum_pri_dune, hum_pri_SF,
                 dog_pri_wet, dog_pri_dry, dog_pri_dune, dog_pri_SF,
                 fox_pri_wet, fox_pri_dry, fox_pri_dune, fox_pri_SF,
                 vehicle_pri_wet, vehicle_pri_dry, vehicle_pri_dune, vehicle_pri_SF,
                 trailbike_pri_wet, trailbike_pri_dry, trailbike_pri_dune, trailbike_pri_SF,
                 horse_pri_wet, horse_pri_dry, horse_pri_dune, horse_pri_SF,
                 stock_pri_wet, stock_pri_dry, stock_pri_dune, stock_pri_SF),
            ~ factor(., levels = c("L", "M", "H"))) %>% 
  # summarize the print variables across the wet, dry, dune, and sign/fence micro habitats
  mutate(hum_pri = ifelse(all(is.na(hum_pri_wet)) && all(is.na(hum_pri_dry)) && 
                            all(is.na(hum_pri_dune)) && all(is.na(hum_pri_SF)), NA,
                          pmax(as.integer(hum_pri_wet), as.integer(hum_pri_dry), 
                               as.integer(hum_pri_dune), as.integer(hum_pri_SF), na.rm = TRUE)),
         fox_pri = ifelse(all(is.na(fox_pri_wet)) && all(is.na(fox_pri_dry)) && 
                            all(is.na(fox_pri_dune)) && all(is.na(fox_pri_SF)), NA,
                          pmax(as.integer(fox_pri_wet), as.integer(fox_pri_dry), 
                               as.integer(fox_pri_dune), as.integer(fox_pri_SF), na.rm = TRUE)),
         dog_pri = ifelse(all(is.na(dog_pri_wet)) && all(is.na(dog_pri_dry)) && 
                            all(is.na(dog_pri_dune)) && all(is.na(dog_pri_SF)), NA,
                          pmax(as.integer(dog_pri_wet), as.integer(dog_pri_dry), 
                               as.integer(dog_pri_dune), as.integer(dog_pri_SF), na.rm = TRUE)),
         vehicle_pri = ifelse(all(is.na(vehicle_pri_wet)) && all(is.na(vehicle_pri_dry)) && 
                                all(is.na(vehicle_pri_dune)) && all(is.na(vehicle_pri_SF)) &&
                              all(is.na(trailbike_pri_wet)) && all(is.na(trailbike_pri_dry)) && 
                                all(is.na(trailbike_pri_dune)) && all(is.na(trailbike_pri_SF)), NA,
                              pmax(as.integer(vehicle_pri_wet), as.integer(vehicle_pri_dry), 
                                   as.integer(vehicle_pri_dune), as.integer(vehicle_pri_SF), 
                                   as.integer(trailbike_pri_wet), as.integer(trailbike_pri_dry), 
                                   as.integer(trailbike_pri_dune), as.integer(trailbike_pri_SF), na.rm = TRUE)),
         hoofed_pri = ifelse(all(is.na(horse_pri_wet)) && all(is.na(horse_pri_dry)) && 
                               all(is.na(horse_pri_dune)) && all(is.na(horse_pri_SF)) &&
                             all(is.na(stock_pri_wet)) && all(is.na(stock_pri_dry)) && 
                               all(is.na(stock_pri_dune)) && all(is.na(stock_pri_SF)), NA,
                             pmax(as.integer(horse_pri_wet), as.integer(horse_pri_dry), 
                                  as.integer(horse_pri_dune), as.integer(horse_pri_SF), 
                                  as.integer(stock_pri_wet), as.integer(stock_pri_dry), 
                                  as.integer(stock_pri_dune), as.integer(stock_pri_SF), na.rm = TRUE))) %>% 
  # consolidate the threat data into a clean dataframe
  dplyr::select(region, site, season, obs_date, obs_date2, obs_lon, obs_lat, 
         humans, vehicles, dogs, dogs_on, dogs_off, hoofed_animals, pred_birds,
         gulls, hum_pri, fox_pri, dog_pri, vehicle_pri, hoofed_pri) %>% 
  ungroup()
saveRDS(threat_data_, file = "output/threat_data_(all_years).rds")determine the 99% quantile limit for each threat (i.e., to remove outlier data) - shown as the red vertical line here
# determine the 99% quantile limit for each threat (i.e., to remove outlier data)
threat_data_99_ql <- 
  threat_data_ %>% 
  summarise_at(c("humans", "vehicles", "dogs", "dogs_on", "dogs_off", "hoofed_animals", "pred_birds", "gulls"), 
               ~ quantile(.x, probs = c(0.99)))
threat_data_99_ql# A tibble: 1 × 8
  humans vehicles  dogs dogs_on dogs_off hoofed_animals pred_birds gulls
   <dbl>    <dbl> <dbl>   <dbl>    <dbl>          <dbl>      <dbl> <dbl>
1     62        4    15       8       10              0         10   151# check histograms of threat data while inspecting the 99% cut-off
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(humans + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$humans[1])), color = "red") +
  luke_themethreat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(dogs + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$dogs[1])), color = "red") +
  luke_themethreat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(pred_birds + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$pred_birds[1])), color = "red") +
  luke_themethreat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(gulls + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$pred_birds[1])), color = "red") +
  luke_themethreat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(vehicles))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$vehicles[1])), color = "red") +
  luke_themethreat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(dogs_off + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$dogs_off[1])), color = "red") +
  luke_themethreat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(dogs_on + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$dogs_on[1])), color = "red") +
  luke_themethreat_data_ %>% 
  ggplot() +
  geom_histogram(aes(hoofed_animals)) +
  geom_vline(xintercept = as.numeric(threat_data_99_ql$hoofed_animals[1]), color = "red") +
  luke_theme# extract public holidays and merge them to the threat data
#### FP ----
FP_holidays <-
  bind_rows(
    holiday_aus(2009, state = "SA"),
    holiday_aus(2010, state = "SA"),
    holiday_aus(2011, state = "SA"),
    holiday_aus(2012, state = "SA"),
    holiday_aus(2013, state = "SA"),
    holiday_aus(2014, state = "SA"),
    holiday_aus(2015, state = "SA"),
    holiday_aus(2016, state = "SA"),
    holiday_aus(2017, state = "SA"),
    holiday_aus(2018, state = "SA"),
    holiday_aus(2019, state = "SA"),
    holiday_aus(2020, state = "SA"),
    holiday_aus(2021, state = "SA"),
    holiday_aus(2022, state = "SA"),
    holiday_aus(2023, state = "SA"),
    holiday_aus(2024, state = "SA")) %>% 
  mutate(event = holiday) %>% 
  mutate(region = "FP",
         end_date = date) %>% 
  rename(start_date = date) %>% 
  mutate(year = year(start_date)) %>% 
  mutate(season = ifelse(month(start_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(start_date) >= 6, 
                         paste0(year, substr(year + 1, 3, 4)), 
                         paste0(season, substr(year, 3, 4))))
SA_start_end_holidays <- 
  read_excel("data/School holiday dates.xlsx",
             sheet = "SA Sch. Hol Dates", 
             col_types = "text") %>% 
  separate(`Autumn school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(autumn_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         autumn_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Winter school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(winter_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         winter_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Spring school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(spring_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         spring_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Summer school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(summer_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         summer_end = as.Date(paste(as.character(as.numeric(Year)+1), new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(Year:Source))
FP_start_school_holidays <- 
  SA_start_end_holidays %>% 
  select(autumn_start, winter_start, spring_start, summer_start) %>% 
  pivot_longer(cols = everything(), names_to = "event") %>% 
  mutate(event = str_remove(event, "_start")) %>% 
  mutate(region = "FP") %>% 
  rename(start_date = value) %>% 
  mutate(year = year(start_date)) %>% 
  mutate(season = ifelse(month(start_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(start_date) >= 6, 
                         paste0(year, substr(year+1, 3, 4)), 
                         paste0(season, substr(year, 3, 4))))
FP_school_holidays <- 
  SA_start_end_holidays %>% 
  select(autumn_end, winter_end, spring_end, summer_end) %>% 
  pivot_longer(cols = everything(), names_to = "event") %>% 
  mutate(event = str_remove(event, "_end")) %>% 
  rename(end_date = value) %>% 
  mutate(year = year(end_date)) %>% 
  mutate(season = ifelse(month(end_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(end_date) >= 6, 
                         paste0(year, substr(year+1, 3, 4)), 
                         paste0(season, substr(year, 3, 4)))) %>% 
  left_join(FP_start_school_holidays, ., by = c("season", "event")) %>% 
  mutate(event = paste(event, "school", sep = "_")) %>% 
  select(-c(year.x, year.y))
FP_holidays <- 
  bind_rows(FP_school_holidays, FP_holidays) %>% 
  select(season, region, event, start_date, end_date) %>% 
  arrange(start_date)
#### MP ----
MP_holidays <-
  bind_rows(
    holiday_aus(2006, state = "VIC"),
    holiday_aus(2007, state = "VIC"),
    holiday_aus(2008, state = "VIC"),
    holiday_aus(2009, state = "VIC"),
    holiday_aus(2010, state = "VIC"),
    holiday_aus(2011, state = "VIC"),
    holiday_aus(2012, state = "VIC"),
    holiday_aus(2013, state = "VIC"),
    holiday_aus(2014, state = "VIC"),
    holiday_aus(2015, state = "VIC"),
    holiday_aus(2016, state = "VIC"),
    holiday_aus(2017, state = "VIC"),
    holiday_aus(2018, state = "VIC"),
    holiday_aus(2019, state = "VIC"),
    holiday_aus(2020, state = "VIC"),
    holiday_aus(2021, state = "VIC"),
    holiday_aus(2022, state = "VIC"),
    holiday_aus(2023, state = "VIC"),
    holiday_aus(2024, state = "VIC")) %>% 
  mutate(event = holiday) %>% 
  mutate(region = "MP",
         end_date = date) %>% 
  rename(start_date = date) %>% 
  mutate(year = year(start_date)) %>% 
  mutate(season = ifelse(month(start_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(start_date) >= 6, 
                         paste0(year, substr(year + 1, 3, 4)), 
                         paste0(season, substr(year, 3, 4))))
VIC_start_end_holidays <- 
  read_excel("data/School holiday dates.xlsx",
             sheet = "VIC Sch. Hol. Dates", 
             col_types = "text") %>% 
  separate(`Autumn school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(autumn_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         autumn_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Winter school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(winter_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         winter_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Spring school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(spring_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         spring_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Summer school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(summer_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         summer_end = as.Date(paste(as.character(as.numeric(Year)+1), new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(Year:Source))
MP_start_school_holidays <- 
  VIC_start_end_holidays %>% 
  select(autumn_start, winter_start, spring_start, summer_start) %>% 
  pivot_longer(cols = everything(), names_to = "event") %>% 
  mutate(event = str_remove(event, "_start")) %>% 
  mutate(region = "MP") %>% 
  rename(start_date = value) %>% 
  mutate(year = year(start_date)) %>% 
  mutate(season = ifelse(month(start_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(start_date) >= 6, 
                         paste0(year, substr(year+1, 3, 4)), 
                         paste0(season, substr(year, 3, 4))))
MP_school_holidays <- 
  VIC_start_end_holidays %>% 
  select(autumn_end, winter_end, spring_end, summer_end) %>% 
  pivot_longer(cols = everything(), names_to = "event") %>% 
  mutate(event = str_remove(event, "_end")) %>% 
  rename(end_date = value) %>% 
  mutate(year = year(end_date)) %>% 
  mutate(season = ifelse(month(end_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(end_date) >= 6, 
                         paste0(year, substr(year+1, 3, 4)), 
                         paste0(season, substr(year, 3, 4)))) %>% 
  left_join(MP_start_school_holidays, ., by = c("season", "event")) %>% 
  mutate(event = paste(event, "school", sep = "_")) %>% 
  select(-c(year.x, year.y)) %>% arrange(start_date)
MP_holidays <- 
  bind_rows(MP_school_holidays, MP_holidays) %>% 
  select(season, region, event, start_date, end_date) %>% 
  arrange(start_date)
BSC_holidays <- 
  bind_rows(MP_school_holidays, MP_holidays) %>% 
  select(season, region, event, start_date, end_date) %>% 
  arrange(start_date) %>% 
  mutate(region = "BSC")
PI_holidays <- 
  bind_rows(MP_school_holidays, MP_holidays) %>% 
  select(season, region, event, start_date, end_date) %>% 
  arrange(start_date) %>% 
  mutate(region = "PI")
BC_holidays <- 
  bind_rows(MP_school_holidays, MP_holidays) %>% 
  select(season, region, event, start_date, end_date) %>% 
  arrange(start_date) %>% 
  mutate(region = "BC")
holidays <- 
  bind_rows(FP_holidays, BC_holidays, MP_holidays, BSC_holidays, PI_holidays)# %>% 
  # pivot_longer(-c(season:holiday), names_to = "start_end", values_to = "date")threat_data__ <-
  threat_data_ %>% 
  mutate(season_site = paste(season, site, sep = "_"),
         weekday = factor(as.factor(weekdays(obs_date)), 
                          levels = c("Monday", "Tuesday", "Wednesday", 
                                     "Thursday", "Friday", "Saturday", 
                                     "Sunday"))) %>% 
  rename(date = obs_date) %>% 
  left_join(., holidays, by = c("region", "season"), relationship = "many-to-many") %>%
  mutate(holiday = ifelse(date >= start_date & date <= end_date, 1, 0)) %>% 
  # dplyr::select(region, season, site, date, start_date, end_date, event, holiday) %>% distinct() %>% 
  group_by(region, season, site, date) %>% 
  mutate(holiday = max(holiday, na.rm = TRUE)) %>% 
  dplyr::select(-c(event, start_date, end_date)) %>% 
  distinct() %>% 
  ungroup() %>% 
  mutate(day_type = ifelse(holiday == 1 | weekday %in% 
                             c("Saturday", "Sunday"), "funday", "workday")) %>% 
  mutate(funday = ifelse(day_type == "funday", 1, 0)) %>% 
  mutate(humans_ = ifelse(humans > as.numeric(threat_data_99_ql$humans[1]), NA, humans),
         vehicles_ = ifelse(vehicles > as.numeric(threat_data_99_ql$vehicles[1]), NA, vehicles),
         dogs_ = ifelse(dogs > as.numeric(threat_data_99_ql$dogs[1]), NA, dogs),
         dogs_off_ = ifelse(dogs_off > as.numeric(threat_data_99_ql$dogs_off[1]), NA, dogs_off),
         dogs_on_ = ifelse(dogs_on > as.numeric(threat_data_99_ql$dogs_on[1]), NA, dogs_on),
         hoofed_animals_ = ifelse(hoofed_animals > as.numeric(threat_data_99_ql$hoofed_animals[1]), NA, hoofed_animals),
         pred_birds_ = ifelse(pred_birds > as.numeric(threat_data_99_ql$pred_birds[1]), NA, pred_birds),
         gulls_ = ifelse(gulls > as.numeric(threat_data_99_ql$gulls[1]), NA, pred_birds)) %>% 
  mutate(weekdayN = as.numeric(weekday) - 1) %>% 
  mutate(weekdayC = circular::circular(weekdayN, type = "angles", units = "radians")) %>% 
  filter(!is.na(weekday))
threat_data__ %>% 
  ggplot() +
  geom_histogram(aes(funday)) +
  # geom_vline(xintercept = log(10), color = "red") +
  luke_themetest if weekends and holidays have more threat counts than other days using zero-inflated models. For all threats, there are more counted on weekends and holidays than during the week, except for vehicles (which occur randomly across the week)
#### test if weekends and holidays have more threat counts than other days
# use a zero-inflated model (https://stats.oarc.ucla.edu/r/dae/zip/)
# for all threats, there are more counted on weekends and holidays than during the week,
# except for vehicles (which occur randomly across the week)
mod_hum_zi <- pscl::zeroinfl(humans_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_hum_zi)
Call:
pscl::zeroinfl(formula = humans_ ~ day_type, data = threat_data__, dist = "poisson")
Pearson residuals:
    Min      1Q  Median      3Q     Max 
-1.2061 -0.8818 -0.6253  0.3427 18.3750 
Count model coefficients (poisson with log link):
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)      2.252603   0.002228    1011   <2e-16 ***
day_typeworkday -0.549608   0.003764    -146   <2e-16 ***
Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)     -0.64079    0.01169  -54.79   <2e-16 ***
day_typeworkday  0.57244    0.01549   36.96   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
Number of iterations in BFGS optimization: 9 
Log-likelihood: -2.649e+05 on 4 Dfmod_dogs_zi <- pscl::zeroinfl(dogs_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_dogs_zi)
Call:
pscl::zeroinfl(formula = dogs_ ~ day_type, data = threat_data__, dist = "poisson")
Pearson residuals:
     Min       1Q   Median       3Q      Max 
-0.64229 -0.64229 -0.54623  0.07525  8.77584 
Count model coefficients (poisson with log link):
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)      1.276497   0.005065  252.01   <2e-16 ***
day_typeworkday -0.238079   0.007812  -30.47   <2e-16 ***
Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      0.51706    0.01177   43.94   <2e-16 ***
day_typeworkday  0.27768    0.01646   16.87   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
Number of iterations in BFGS optimization: 12 
Log-likelihood: -9.928e+04 on 4 Dfmod_dogs_on_zi <- pscl::zeroinfl(dogs_on_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_dogs_on_zi)
Call:
pscl::zeroinfl(formula = dogs_on_ ~ day_type, data = threat_data__, dist = "poisson")
Pearson residuals:
    Min      1Q  Median      3Q     Max 
-0.4587 -0.4587 -0.3609 -0.3609  9.5352 
Count model coefficients (poisson with log link):
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)      0.729730   0.009064   80.51   <2e-16 ***
day_typeworkday -0.303207   0.015292  -19.83   <2e-16 ***
Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      1.05820    0.01434   73.80   <2e-16 ***
day_typeworkday  0.38903    0.02166   17.96   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
Number of iterations in BFGS optimization: 9 
Log-likelihood: -5.444e+04 on 4 Dfmod_dogs_off_zi <- pscl::zeroinfl(dogs_off_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_dogs_off_zi)
Call:
pscl::zeroinfl(formula = dogs_off_ ~ day_type, data = threat_data__, 
    dist = "poisson")
Pearson residuals:
    Min      1Q  Median      3Q     Max 
-0.5126 -0.5126 -0.4528 -0.4528  7.5219 
Count model coefficients (poisson with log link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      0.98225    0.00709  138.55   <2e-16 ***
day_typeworkday -0.13328    0.01050  -12.69   <2e-16 ***
Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      0.91466    0.01305   70.10   <2e-16 ***
day_typeworkday  0.22205    0.01831   12.13   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
Number of iterations in BFGS optimization: 15 
Log-likelihood: -7.246e+04 on 4 Dfmod_pred_birds_zi <- pscl::zeroinfl(pred_birds_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_pred_birds_zi)
Call:
pscl::zeroinfl(formula = pred_birds_ ~ day_type, data = threat_data__, 
    dist = "poisson")
Pearson residuals:
    Min      1Q  Median      3Q     Max 
-0.3752 -0.3752 -0.3457 -0.3457  8.4648 
Count model coefficients (poisson with log link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)     0.984160   0.009857  99.849  < 2e-16 ***
day_typeworkday 0.045493   0.012806   3.552 0.000382 ***
Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      1.76109    0.01645 107.036  < 2e-16 ***
day_typeworkday -0.15735    0.02173  -7.241 4.46e-13 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
Number of iterations in BFGS optimization: 10 
Log-likelihood: -5.053e+04 on 4 Dfmod_gulls_zi <- pscl::zeroinfl(gulls_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_gulls_zi)
Call:
pscl::zeroinfl(formula = gulls_ ~ day_type, data = threat_data__, dist = "poisson")
Pearson residuals:
     Min       1Q   Median       3Q      Max 
 -0.3928  -0.3928  -0.3628  -0.3628 181.8698 
Count model coefficients (poisson with log link):
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)      1.392991   0.007522 185.195  < 2e-16 ***
day_typeworkday -0.040040   0.009980  -4.012 6.02e-05 ***
Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      1.77261    0.01590 111.507   <2e-16 ***
day_typeworkday -0.17449    0.02101  -8.305   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
Number of iterations in BFGS optimization: 16 
Log-likelihood: -7.234e+04 on 4 Dfmod_vehicles_zi <- pscl::zeroinfl(vehicles_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_vehicles_zi)
Call:
pscl::zeroinfl(formula = vehicles_ ~ day_type, data = threat_data__, 
    dist = "poisson")
Pearson residuals:
    Min      1Q  Median      3Q     Max 
-0.1179 -0.1179 -0.1048 -0.1048 15.0266 
Count model coefficients (poisson with log link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      0.35633    0.04101   8.689   <2e-16 ***
day_typeworkday  0.08162    0.05717   1.427    0.153    
Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      3.73507    0.04632  80.640  < 2e-16 ***
day_typeworkday  0.27076    0.06551   4.133 3.57e-05 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
Number of iterations in BFGS optimization: 19 
Log-likelihood: -7256 on 4 DfFit circular GAM to weekly count data to assess trends over the week.
how do human counts vary over the week?
#### Fit circular GAM to weekly count data ----
mod_hum <- 
  mgcv::gam(humans_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_hum)
Family: gaussian 
Link function: identity 
Formula:
humans_ ~ s(weekdayN, bs = "cc", k = 7)
Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  4.37295    0.02932   149.2   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Approximate significance of smooth terms:
              edf Ref.df     F p-value    
s(weekdayN) 4.968      5 194.4  <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
R-sq.(adj) =  0.0134   Deviance explained = 1.34%
GCV =  61.49  Scale est. = 61.485    n = 71535# estimate model predictions 
newdata_weekdays <- 
  data.frame(weekdayN = seq(0, 6))
# plot the weekly variation in the human counts
mod_hum_fits <- 
  predict(mod_hum, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)
mod_hum_predicts <-  
  data.frame(newdata_weekdays, mod_hum_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")
threat_data__ %>%
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(humans_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1, color = "grey70"
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(humans_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA, color = "grey70"
    ) +
  # geom_smooth(aes(x = as.numeric(weekday), y = humans_), 
  #             method = lm, 
  #             formula = y ~ splines::bs(x, 5)) +
  geom_ribbon(data = mod_hum_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_hum_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  luke_theme +
  xlab("Day of the week") +
  ylab("Number of humans counted (log)")how do dog counts vary over the week?
mod_dogs <- 
  mgcv::gam(dogs_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_dogs)
Family: gaussian 
Link function: identity 
Formula:
dogs_ ~ s(weekdayN, bs = "cc", k = 7)
Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 1.087289   0.008379   129.8   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Approximate significance of smooth terms:
              edf Ref.df     F p-value    
s(weekdayN) 4.766      5 57.85  <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
R-sq.(adj) =  0.00402   Deviance explained = 0.408%
GCV = 5.0247  Scale est. = 5.0243    n = 71567# plot the weekly variation in the dog counts
mod_dogs_fits <- 
  predict(mod_dogs, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)
mod_dogs_predicts <-  
  data.frame(newdata_weekdays, mod_dogs_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(dogs_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(dogs_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_dogs_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_dogs_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = dogs_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("Day of the week") +
  ylab("Number of dogs counted (log)")how do dogs on leash counts vary over the week?
mod_dogs_on <- 
  mgcv::gam(dogs_on_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_dogs_on)
Family: gaussian 
Link function: identity 
Formula:
dogs_on_ ~ s(weekdayN, bs = "cc", k = 7)
Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.401783   0.004032   99.66   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Approximate significance of smooth terms:
              edf Ref.df     F p-value    
s(weekdayN) 4.768      5 46.31  <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
R-sq.(adj) =  0.0032   Deviance explained = 0.327%
GCV = 1.1633  Scale est. = 1.1632    n = 71566# plot the weekly variation in the dog on leash counts
mod_dogs_on_fits <- 
  predict(mod_dogs_on, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)
mod_dogs_on_predicts <-  
  data.frame(newdata_weekdays, mod_dogs_on_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(dogs_on_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(dogs_on_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_dogs_on_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_dogs_on_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = dogs_on_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("Day of the week") +
  ylab("Number of dogs on leashes counted (log)")how do dogs off leash counts vary over the week?
mod_dogs_off <- 
  mgcv::gam(dogs_off_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_dogs_off)
Family: gaussian 
Link function: identity 
Formula:
dogs_off_ ~ s(weekdayN, bs = "cc", k = 7)
Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.656742   0.005721   114.8   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Approximate significance of smooth terms:
              edf Ref.df     F p-value    
s(weekdayN) 4.615      5 40.29  <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
R-sq.(adj) =  0.0028   Deviance explained = 0.286%
GCV =  2.345  Scale est. = 2.3448    n = 71637# plot the weekly variation in the dog off leash counts
mod_dogs_off_fits <- 
  predict(mod_dogs_off, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)
mod_dogs_off_predicts <-  
  data.frame(newdata_weekdays, mod_dogs_off_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(dogs_off_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(dogs_off_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_dogs_off_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_dogs_off_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = dogs_off_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("Day of the week") +
  ylab("Number of dogs off leashes counted (log)")how do corvid counts vary over the week?
mod_pred_birds <- 
  mgcv::gam(pred_birds_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_pred_birds)
Family: gaussian 
Link function: identity 
Formula:
pred_birds_ ~ s(weekdayN, bs = "cc", k = 7)
Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.43397    0.00485   89.48   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Approximate significance of smooth terms:
              edf Ref.df     F p-value    
s(weekdayN) 4.193      5 6.911  <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
R-sq.(adj) =  0.000466   Deviance explained = 0.0524%
GCV = 1.6861  Scale est. = 1.6859    n = 71676# plot the weekly variation in the predatory bird counts
mod_pred_birds_fits <- 
  predict(mod_pred_birds, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)
mod_pred_birds_predicts <-  
  data.frame(newdata_weekdays, mod_pred_birds_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(pred_birds_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(pred_birds_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_pred_birds_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_pred_birds_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = pred_birds_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("Day of the week") +
  ylab("Number of corvids counted (log)")how do gulls counts vary over the week?
mod_pred_birds <- 
  mgcv::gam(gulls_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_pred_birds)
Family: gaussian 
Link function: identity 
Formula:
gulls_ ~ s(weekdayN, bs = "cc", k = 7)
Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.62076    0.01318   47.11   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Approximate significance of smooth terms:
              edf Ref.df     F p-value   
s(weekdayN) 2.396      5 1.948 0.00548 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
R-sq.(adj) =  0.000132   Deviance explained = 0.0165%
GCV = 12.422  Scale est. = 12.421    n = 71533# plot the weekly variation in the predatory bird counts
mod_gulls_fits <- 
  predict(mod_pred_birds, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)
mod_gulls_predicts <-  
  data.frame(newdata_weekdays, mod_gulls_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(gulls_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(gulls_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_gulls_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_gulls_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = gulls_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("Day of the week") +
  ylab("Number of gulls counted (log)")how do vehicle counts vary over the week?
mod_vehicles <- 
  mgcv::gam(vehicles_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_vehicles)
Family: gaussian 
Link function: identity 
Formula:
vehicles_ ~ s(weekdayN, bs = "cc", k = 7)
Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.030248   0.001024   29.53   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Approximate significance of smooth terms:
             edf Ref.df     F p-value  
s(weekdayN) 3.52      5 2.006  0.0184 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
R-sq.(adj) =  0.000121   Deviance explained = 0.017%
GCV = 0.075064  Scale est. = 0.075059  n = 71543# plot the weekly variation in the vehicle counts
mod_vehicles_fits <- 
  predict(mod_vehicles, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)
mod_vehicles_predicts <-  
  data.frame(newdata_weekdays, mod_vehicles_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = vehicles_),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = vehicles_),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_vehicles_predicts,
              aes(x = as.numeric(weekday), ymin = lower, ymax = upper)) +
  geom_line(data = mod_vehicles_predicts, aes(x = as.numeric(weekday), y = fit), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = vehicles_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("Day of the week") +
  ylab("Number of vehicles counted")Inspect the weekly variation in human prints
# plot the weekly variation in the human print detections
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = hum_pri),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = hum_pri),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_smooth(aes(x = as.numeric(weekday), y = hum_pri), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("Day of the week") +
  ylab("Level of human prints recorded")Inspect the weekly variation in dog prints
# plot the weekly variation in the dog print detections
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = dog_pri),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = dog_pri),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_smooth(aes(x = as.numeric(weekday), y = dog_pri), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("Day of the week") +
  ylab("Level of dogs prints recorded")Inspect the weekly variation in vehicle prints
# plot the weekly variation in the vehicle print detections
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = vehicle_pri),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = vehicle_pri),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_smooth(aes(x = as.numeric(weekday), y = vehicle_pri), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("Day of the week") +
  ylab("Level of vehicle prints recorded")Inspect the weekly variation in fox prints
# plot the weekly variation in the fox print detections
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = fox_pri),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = fox_pri),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_smooth(aes(x = as.numeric(weekday), y = fox_pri), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("Day of the week") +
  ylab("Level of fox prints recorded")check correlation between counts of the various threats
# check correlation between humans counts
threat_data__ %>% 
  dplyr::select(humans_, vehicles_, dogs_, pred_birds_) %>% 
  na.omit() %>% 
  cor() %>% 
  corrplot(type = "upper", method = "number", tl.srt = 45)# relationship between human counts and dog counts
threat_data__ %>% 
  ggplot() +
  geom_jitter(aes(x = humans_, y = dogs_), alpha = 0.1) +
  geom_smooth(aes(x = humans_, y = dogs_)) +#, method = lm, formula = y ~ splines::bs(x, 2)) +
  luke_theme +
  xlab("Number of humans counted") +
  ylab("Number of dogs counted")# relationship between human counts and corvid counts
threat_data__ %>% 
  ggplot() +
  geom_jitter(aes(x = humans_, y = pred_birds_), alpha = 0.1) +
  geom_smooth(aes(x = humans_, y = pred_birds_)) +#, method = lm) +
  luke_theme +
  xlab("Number of humans counted") +
  ylab("Number of corvids counted")# relationship between human counts and gull counts
threat_data__ %>% 
  ggplot() +
  geom_jitter(aes(x = humans_, y = gulls_), alpha = 0.1) +
  geom_smooth(aes(x = humans_, y = gulls_)) +#, method = lm) +
  luke_theme +
  xlab("Number of humans counted") +
  ylab("Number of gulls counted")# relationship between human counts and vehicle counts
threat_data__ %>% 
  ggplot() +
  geom_jitter(aes(x = humans_, y = vehicles_), alpha = 0.1) +
  geom_smooth(aes(x = humans_, y = vehicles_)) + #, method = lm, formula = y ~ splines::bs(x, 2)) +
  luke_theme +
  xlab("Number of humans counted") +
  ylab("Number of vehicles counted")# determine which territories are in the threat data and the nest data
sites_intersect_FP <- 
  inner_join(nest_data_FP, threat_data__ %>% filter(region == "FP"), by = c("season", "site"), relationship = "many-to-many") %>% 
  dplyr::select(season, site) %>% distinct() %>% 
  mutate(season_site = paste(season, site, sep = "_"))
sites_intersect_MP <- 
  inner_join(nest_data_MP, threat_data__ %>% filter(region == "MP"), by = c("season", "site"), relationship = "many-to-many") %>% 
  dplyr::select(season, site) %>% distinct() %>% 
  mutate(season_site = paste(season, site, sep = "_"))
sites_intersect_BSC <- 
  inner_join(nest_data_BSC, threat_data__ %>% filter(region == "BSC"), by = c("season", "site"), relationship = "many-to-many") %>% 
  dplyr::select(season, site) %>% distinct() %>% 
  mutate(season_site = paste(season, site, sep = "_"))
sites_intersect_PI <- 
  inner_join(nest_data_PI, threat_data__ %>% filter(region == "PI"), by = c("season", "site"), relationship = "many-to-many") %>% 
  dplyr::select(season, site) %>% distinct() %>% 
  mutate(season_site = paste(season, site, sep = "_"))
sites_intersect_BC <- 
  inner_join(nest_data_BC, threat_data__ %>% filter(region == "BC"), by = c("season", "site"), relationship = "many-to-many") %>% 
  dplyr::select(season, site) %>% distinct() %>% 
  mutate(season_site = paste(season, site, sep = "_"))# FP
# Combine and classify unique season_site values
sites_diff_FP <- full_join(nest_data_FP %>% ungroup() %>% 
                             mutate(season_site = paste(season, site, sep = "_")) %>% 
                             select(season_site) %>% distinct() %>% mutate(source = "nest_data_FP"),
                           threat_data__ %>% ungroup() %>% filter(region == "FP")  %>%
                             mutate(season_site = paste(season, site, sep = "_")) %>% 
                             select(season_site) %>% distinct() %>% mutate(source = "threat_data_FP"),
                           by = "season_site")
# Find unique values in each dataframe
only_in_nest_data_FP <- 
  sites_diff_FP %>% 
  filter(is.na(source.y)) %>% 
  select(season_site) %>%
  # separate(season_site, into = c("season", "site"), sep = "_", extra = "merge") %>% 
  mutate(issue = "only in nest survival data")
only_in_threat_data_FP <-
  sites_diff_FP %>% 
  filter(is.na(source.x)) %>% 
  select(season_site) %>%
  # separate(season_site, into = c("season", "site"), sep = "_", extra = "merge") %>% 
  mutate(issue = "only in threat data")
  
# fuzzy matching and data cleaning
clean_text <- function(x) {
  x %>%
    str_replace_all("[^a-zA-Z0-9 _]", "") %>%  # Remove special characters but keep letters, numbers, and spaces
    str_replace_all("\\s+", "_") %>%         # Replace spaces with underscores
    tolower()                                 # Convert to lowercase
}
# Perform fuzzy join
fuzzy_result_FP <-
  stringdist_full_join(
    nest_data_FP %>% 
    ungroup() %>% 
    mutate(season_site = paste(season, site, sep = "_")) %>% 
    select(season_site) %>% distinct() %>% mutate(source = "nest_data_FP") %>% 
    mutate(season_site_clean = clean_text(season_site)), 
    threat_data__ %>% 
    ungroup() %>% 
    filter(region == "FP")  %>%
    mutate(season_site = paste(season, site, sep = "_")) %>% 
    select(season_site) %>% distinct() %>% mutate(source = "threat_data_FP") %>% 
    mutate(season_site_clean = clean_text(season_site)), 
    by = "season_site_clean", 
    method = "jw", # Jaro-Winkler distance
    max_dist = 0.2, # Adjust for optimal matching
    distance_col = "dist") %>% 
  left_join(., only_in_nest_data_FP, by = c("season_site.x" = "season_site")) %>% 
  left_join(., only_in_threat_data_FP, by = c("season_site.y" = "season_site")) %>% 
  mutate(nest_season = str_extract(season_site.x, "^\\d{6}"),
         threat_season = str_extract(season_site.y, "^\\d{6}")) %>% 
  filter(nest_season == threat_season) %>% 
  group_by(season_site.x) %>%
  slice_min(order_by = dist) %>%  # Keep only the best fuzzy match per season
  ungroup() %>% 
  mutate(site_nest_data = str_remove(season_site.x, "^\\d{6}_?"),
         site_threat_data = str_remove(season_site.y, "^\\d{6}_?")) %>% 
  filter(issue.x == "only in nest survival data") %>% 
  select(nest_season, site_nest_data, site_threat_data, dist) %>% 
  arrange(desc(dist)) %>% 
  rename(season = nest_season)
# Create a new workbook
sites_diff_FP_xl <- createWorkbook()
# Add each dataframe as a sheet
addWorksheet(sites_diff_FP_xl, "only_in_nest_data_FP")
writeData(sites_diff_FP_xl, "only_in_nest_data_FP", only_in_nest_data_FP)
addWorksheet(sites_diff_FP_xl, "only_in_threat_data_FP")
writeData(sites_diff_FP_xl, "only_in_threat_data_FP", only_in_threat_data_FP)
addWorksheet(sites_diff_FP_xl, "fuzzy_matches_to_consider")
writeData(sites_diff_FP_xl, "fuzzy_matches_to_consider", fuzzy_result_FP)
# Save the workbook
saveWorkbook(sites_diff_FP_xl, here("data/nest_issues_commented/site_names_issues_FP.xlsx"), overwrite = TRUE)
# MP
# Combine and classify unique season_site values
sites_diff_MP <- full_join(nest_data_MP %>% ungroup() %>% 
                             mutate(season_site = paste(season, site, sep = "_")) %>% 
                             select(season_site) %>% distinct() %>% mutate(source = "nest_data_MP"),
                           threat_data__ %>% ungroup() %>% filter(region == "MP")  %>%
                             mutate(season_site = paste(season, site, sep = "_")) %>% 
                             select(season_site) %>% distinct() %>% mutate(source = "threat_data_MP"),
                           by = "season_site")
# Find unique values in each dataframe
only_in_nest_data_MP <- 
  sites_diff_MP %>% 
  filter(is.na(source.y)) %>% 
  select(season_site) %>%
  # separate(season_site, into = c("season", "site"), sep = "_", extra = "merge") %>% 
  mutate(issue = "only in nest survival data")
only_in_threat_data_MP <-
  sites_diff_MP %>% 
  filter(is.na(source.x)) %>% 
  select(season_site) %>%
  # separate(season_site, into = c("season", "site"), sep = "_", extra = "merge") %>% 
  mutate(issue = "only in threat data")
# Perform fuzzy join
fuzzy_result_MP <-
  stringdist_full_join(
    nest_data_MP %>% 
    ungroup() %>% 
    mutate(season_site = paste(season, site, sep = "_")) %>% 
    select(season_site) %>% distinct() %>% mutate(source = "nest_data_MP") %>% 
    mutate(season_site_clean = clean_text(season_site)), 
    threat_data__ %>% 
    ungroup() %>% 
    filter(region == "MP")  %>%
    mutate(season_site = paste(season, site, sep = "_")) %>% 
    select(season_site) %>% distinct() %>% mutate(source = "threat_data_MP") %>% 
    mutate(season_site_clean = clean_text(season_site)), 
    by = "season_site_clean", 
    method = "jw", # Jaro-Winkler distance
    max_dist = 0.2, # Adjust for optimal matching
    distance_col = "dist") %>% 
  left_join(., only_in_nest_data_MP, by = c("season_site.x" = "season_site")) %>% 
  left_join(., only_in_threat_data_MP, by = c("season_site.y" = "season_site")) %>% 
  mutate(nest_season = str_extract(season_site.x, "^\\d{6}"),
         threat_season = str_extract(season_site.y, "^\\d{6}")) %>% 
  filter(nest_season == threat_season) %>% 
  group_by(season_site.x) %>%
  slice_min(order_by = dist) %>%  # Keep only the best fuzzy match per season
  ungroup() %>% 
  mutate(site_nest_data = str_remove(season_site.x, "^\\d{6}_?"),
         site_threat_data = str_remove(season_site.y, "^\\d{6}_?")) %>% 
  filter(issue.x == "only in nest survival data") %>% 
  select(nest_season, site_nest_data, site_threat_data, dist) %>% 
  arrange(desc(dist)) %>% 
  rename(season = nest_season)
# Create a new workbook
sites_diff_MP_xl <- createWorkbook()
# Add each dataframe as a sheet
addWorksheet(sites_diff_MP_xl, "only_in_nest_data_MP")
writeData(sites_diff_MP_xl, "only_in_nest_data_MP", only_in_nest_data_MP)
addWorksheet(sites_diff_MP_xl, "only_in_threat_data_MP")
writeData(sites_diff_MP_xl, "only_in_threat_data_MP", only_in_threat_data_MP)
addWorksheet(sites_diff_MP_xl, "fuzzy_matches_to_consider")
writeData(sites_diff_MP_xl, "fuzzy_matches_to_consider", fuzzy_result_MP)
# Save the workbook
saveWorkbook(sites_diff_MP_xl, here("data/nest_issues_commented/site_names_issues_MP.xlsx"), overwrite = TRUE)
# BSC
# Combine and classify unique season_site values
sites_diff_BSC <- full_join(nest_data_BSC %>% ungroup() %>% 
                             mutate(season_site = paste(season, site, sep = "_")) %>% 
                             select(season_site) %>% distinct() %>% mutate(source = "nest_data_BSC"),
                           threat_data__ %>% ungroup() %>% filter(region == "BSC")  %>%
                             mutate(season_site = paste(season, site, sep = "_")) %>% 
                             select(season_site) %>% distinct() %>% mutate(source = "threat_data_BSC"),
                           by = "season_site")
# Find unique values in each dataframe
only_in_nest_data_BSC <- 
  sites_diff_BSC %>% 
  filter(is.na(source.y)) %>% 
  select(season_site) %>%
  # separate(season_site, into = c("season", "site"), sep = "_", extra = "merge") %>% 
  mutate(issue = "only in nest survival data")
only_in_threat_data_BSC <-
  sites_diff_BSC %>% 
  filter(is.na(source.x)) %>% 
  select(season_site) %>%
  # separate(season_site, into = c("season", "site"), sep = "_", extra = "merge") %>% 
  mutate(issue = "only in threat data")
# Perform fuzzy join
fuzzy_result_BSC <-
  stringdist_full_join(
    nest_data_BSC %>% 
    ungroup() %>% 
    mutate(season_site = paste(season, site, sep = "_")) %>% 
    select(season_site) %>% distinct() %>% mutate(source = "nest_data_BSC") %>% 
    mutate(season_site_clean = clean_text(season_site)), 
    threat_data__ %>% 
    ungroup() %>% 
    filter(region == "BSC")  %>%
    mutate(season_site = paste(season, site, sep = "_")) %>% 
    select(season_site) %>% distinct() %>% mutate(source = "threat_data_BSC") %>% 
    mutate(season_site_clean = clean_text(season_site)), 
    by = "season_site_clean", 
    method = "jw", # Jaro-Winkler distance
    max_dist = 0.2, # Adjust for optimal matching
    distance_col = "dist") %>% 
  left_join(., only_in_nest_data_BSC, by = c("season_site.x" = "season_site")) %>% 
  left_join(., only_in_threat_data_BSC, by = c("season_site.y" = "season_site")) %>% 
  mutate(nest_season = str_extract(season_site.x, "^\\d{6}"),
         threat_season = str_extract(season_site.y, "^\\d{6}")) %>% 
  filter(nest_season == threat_season) %>% 
  group_by(season_site.x) %>%
  slice_min(order_by = dist) %>%  # Keep only the best fuzzy match per season
  ungroup() %>% 
  mutate(site_nest_data = str_remove(season_site.x, "^\\d{6}_?"),
         site_threat_data = str_remove(season_site.y, "^\\d{6}_?")) %>% 
  filter(issue.x == "only in nest survival data") %>% 
  select(nest_season, site_nest_data, site_threat_data, dist) %>% 
  arrange(desc(dist)) %>% 
  rename(season = nest_season)
# Create a new workbook
sites_diff_BSC_xl <- createWorkbook()
# Add each dataframe as a sheet
addWorksheet(sites_diff_BSC_xl, "only_in_nest_data_BSC")
writeData(sites_diff_BSC_xl, "only_in_nest_data_BSC", only_in_nest_data_BSC)
addWorksheet(sites_diff_BSC_xl, "only_in_threat_data_BSC")
writeData(sites_diff_BSC_xl, "only_in_threat_data_BSC", only_in_threat_data_BSC)
addWorksheet(sites_diff_BSC_xl, "fuzzy_matches_to_consider")
writeData(sites_diff_BSC_xl, "fuzzy_matches_to_consider", fuzzy_result_BSC)
# Save the workbook
saveWorkbook(sites_diff_BSC_xl, here("data/nest_issues_commented/site_names_issues_BSC.xlsx"), overwrite = TRUE)
# BC
# Combine and classify unique season_site values
sites_diff_BC <- full_join(nest_data_BC %>% ungroup() %>% 
                             mutate(season_site = paste(season, site, sep = "_")) %>% 
                             select(season_site) %>% distinct() %>% mutate(source = "nest_data_BC"),
                           threat_data__ %>% ungroup() %>% filter(region == "BC")  %>%
                             mutate(season_site = paste(season, site, sep = "_")) %>% 
                             select(season_site) %>% distinct() %>% mutate(source = "threat_data_BC"),
                           by = "season_site")
# Find unique values in each dataframe
only_in_nest_data_BC <- 
  sites_diff_BC %>% 
  filter(is.na(source.y)) %>% 
  select(season_site) %>%
  # separate(season_site, into = c("season", "site"), sep = "_", extra = "merge") %>% 
  mutate(issue = "only in nest survival data")
only_in_threat_data_BC <-
  sites_diff_BC %>% 
  filter(is.na(source.x)) %>% 
  select(season_site) %>%
  # separate(season_site, into = c("season", "site"), sep = "_", extra = "merge") %>% 
  mutate(issue = "only in threat data")
# Perform fuzzy join
fuzzy_result_BC <-
  stringdist_full_join(
    nest_data_BC %>% 
    ungroup() %>% 
    mutate(season_site = paste(season, site, sep = "_")) %>% 
    select(season_site) %>% distinct() %>% mutate(source = "nest_data_BC") %>% 
    mutate(season_site_clean = clean_text(season_site)), 
    threat_data__ %>% 
    ungroup() %>% 
    filter(region == "BC")  %>%
    mutate(season_site = paste(season, site, sep = "_")) %>% 
    select(season_site) %>% distinct() %>% mutate(source = "threat_data_BC") %>% 
    mutate(season_site_clean = clean_text(season_site)), 
    by = "season_site_clean", 
    method = "jw", # Jaro-Winkler distance
    max_dist = 0.2, # Adjust for optimal matching
    distance_col = "dist") %>% 
  left_join(., only_in_nest_data_BC, by = c("season_site.x" = "season_site")) %>% 
  left_join(., only_in_threat_data_BC, by = c("season_site.y" = "season_site")) %>% 
  mutate(nest_season = str_extract(season_site.x, "^\\d{6}"),
         threat_season = str_extract(season_site.y, "^\\d{6}")) %>% 
  filter(nest_season == threat_season) %>% 
  group_by(season_site.x) %>%
  slice_min(order_by = dist) %>%  # Keep only the best fuzzy match per season
  ungroup() %>% 
  mutate(site_nest_data = str_remove(season_site.x, "^\\d{6}_?"),
         site_threat_data = str_remove(season_site.y, "^\\d{6}_?")) %>% 
  filter(issue.x == "only in nest survival data") %>% 
  select(nest_season, site_nest_data, site_threat_data, dist) %>% 
  arrange(desc(dist)) %>% 
  rename(season = nest_season)
# Create a new workbook
sites_diff_BC_xl <- createWorkbook()
# Add each dataframe as a sheet
addWorksheet(sites_diff_BC_xl, "only_in_nest_data_BC")
writeData(sites_diff_BC_xl, "only_in_nest_data_BC", only_in_nest_data_BC)
addWorksheet(sites_diff_BC_xl, "only_in_threat_data_BC")
writeData(sites_diff_BC_xl, "only_in_threat_data_BC", only_in_threat_data_BC)
addWorksheet(sites_diff_BC_xl, "fuzzy_matches_to_consider")
writeData(sites_diff_BC_xl, "fuzzy_matches_to_consider", fuzzy_result_BC)
# Save the workbook
saveWorkbook(sites_diff_BC_xl, here("data/nest_issues_commented/site_names_issues_BC.xlsx"), overwrite = TRUE)
  
# PI
# Combine and classify unique season_site values
sites_diff_PI <- full_join(nest_data_PI %>% ungroup() %>% 
                             mutate(season_site = paste(season, site, sep = "_")) %>% 
                             select(season_site) %>% distinct() %>% mutate(source = "nest_data_PI"),
                           threat_data__ %>% ungroup() %>% filter(region == "PI")  %>%
                             mutate(season_site = paste(season, site, sep = "_")) %>% 
                             select(season_site) %>% distinct() %>% mutate(source = "threat_data_PI"),
                           by = "season_site")
# Find unique values in each dataframe
only_in_nest_data_PI <- 
  sites_diff_PI %>% 
  filter(is.na(source.y)) %>% 
  select(season_site) %>%
  # separate(season_site, into = c("season", "site"), sep = "_", extra = "merge") %>% 
  mutate(issue = "only in nest survival data")
only_in_threat_data_PI <-
  sites_diff_PI %>% 
  filter(is.na(source.x)) %>% 
  select(season_site) %>%
  # separate(season_site, into = c("season", "site"), sep = "_", extra = "merge") %>% 
  mutate(issue = "only in threat data")
# Perform fuzzy join
fuzzy_result_PI <-
  stringdist_full_join(
    nest_data_PI %>% 
    ungroup() %>% 
    mutate(season_site = paste(season, site, sep = "_")) %>% 
    select(season_site) %>% distinct() %>% mutate(source = "nest_data_PI") %>% 
    mutate(season_site_clean = clean_text(season_site)), 
    threat_data__ %>% 
    ungroup() %>% 
    filter(region == "PI")  %>%
    mutate(season_site = paste(season, site, sep = "_")) %>% 
    select(season_site) %>% distinct() %>% mutate(source = "threat_data_PI") %>% 
    mutate(season_site_clean = clean_text(season_site)), 
    by = "season_site_clean", 
    method = "jw", # Jaro-Winkler distance
    max_dist = 0.2, # Adjust for optimal matching
    distance_col = "dist") %>% 
  left_join(., only_in_nest_data_PI, by = c("season_site.x" = "season_site")) %>% 
  left_join(., only_in_threat_data_PI, by = c("season_site.y" = "season_site")) %>% 
  mutate(nest_season = str_extract(season_site.x, "^\\d{6}"),
         threat_season = str_extract(season_site.y, "^\\d{6}")) %>% 
  filter(nest_season == threat_season) %>% 
  group_by(season_site.x) %>%
  slice_min(order_by = dist) %>%  # Keep only the best fuzzy match per season
  ungroup() %>% 
  mutate(site_nest_data = str_remove(season_site.x, "^\\d{6}_?"),
         site_threat_data = str_remove(season_site.y, "^\\d{6}_?")) %>% 
  filter(issue.x == "only in nest survival data") %>% 
  select(nest_season, site_nest_data, site_threat_data, dist) %>% 
  arrange(desc(dist)) %>% 
  rename(season = nest_season)
# Create a new workbook
sites_diff_PI_xl <- createWorkbook()
# Add each dataframe as a sheet
addWorksheet(sites_diff_PI_xl, "only_in_nest_data_PI")
writeData(sites_diff_PI_xl, "only_in_nest_data_PI", only_in_nest_data_PI)
addWorksheet(sites_diff_PI_xl, "only_in_threat_data_PI")
writeData(sites_diff_PI_xl, "only_in_threat_data_PI", only_in_threat_data_PI)
addWorksheet(sites_diff_PI_xl, "fuzzy_matches_to_consider")
writeData(sites_diff_PI_xl, "fuzzy_matches_to_consider", fuzzy_result_PI)
# Save the workbook
saveWorkbook(sites_diff_PI_xl, here("data/nest_issues_commented/site_names_issues_PI.xlsx"), overwrite = TRUE)
nrow(fuzzy_result_BC) + nrow(fuzzy_result_FP) + nrow(fuzzy_result_MP)+ nrow(fuzzy_result_BSC)+ nrow(fuzzy_result_PI)[1] 24nest_data_FP_with_threat_data <- 
  nest_data_FP %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_FP$season_site) %>%
  dplyr::select(season, site, region, nest_ID, 
                FirstFound, LastPresent, LastChecked,
                first_found2, last_alive2, last_checked2,
                management_status, management_level,
                nest_hab, Fate) %>% 
  rename(status = management_status,
         level = management_level) %>% 
  mutate(level = paste0("L", level)) %>% 
  mutate(level = factor(level, 
                        levels = c("L0", "L1", 
                                   "L2", "L3", 
                                   "L4"))) %>% 
  ungroup() %>% 
  mutate(
    hum_a = NA,
    veh_a = NA,
    dog_a = NA,
    don_a = NA,
    dof_a = NA,
    hof_a = NA,
    pbd_a = NA,
    gul_a = NA,
    hum_m = NA,
    veh_m = NA,
    dog_m = NA,
    don_m = NA,
    dof_m = NA,
    hof_m = NA,
    pbd_m = NA,
    gul_m = NA,
    hum_b = NA,
    veh_b = NA,
    dog_b = NA,
    don_b = NA,
    dof_b = NA,
    pbd_b = NA,
    gul_b = NA,
    hof_b = NA,
    hum_p = NA,
    veh_p = NA,
    dog_p = NA,
    hof_p = NA,
    fox_p = NA,
    n_surveys = NA,
    days_active = NA,
    fundays = NA, 
    uncertain_days = NA,
    halfway = NA) %>% 
  filter(FirstFound <= LastPresent & FirstFound <= LastChecked & LastPresent <= LastChecked) %>% 
  filter(first_found2 <= last_alive2 & first_found2 <= last_checked2 & last_alive2 <= last_checked2)
FP_threat_data_subset <- 
  threat_data__ %>% 
  filter(region == "FP") %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_FP$season_site) %>%
  ungroup()
for(i in 1:nrow(nest_data_FP_with_threat_data)){
  FirstFound <- nest_data_FP_with_threat_data$FirstFound[i]
  LastPresent <- nest_data_FP_with_threat_data$LastPresent[i]
  LastChecked <- nest_data_FP_with_threat_data$LastChecked[i]
  FirstFound2 <- nest_data_FP_with_threat_data$first_found2[i]
  LastPresent2 <- nest_data_FP_with_threat_data$last_alive2[i]
  LastChecked2 <- nest_data_FP_with_threat_data$last_checked2[i]
  halfway <- (LastChecked - LastPresent)/2
  days_active <- (LastPresent + halfway) - FirstFound
  uncertain_days <- LastChecked - LastPresent
  site_ <- as.character(nest_data_FP_with_threat_data$site[i])
  season_ <- as.character(nest_data_FP_with_threat_data$season[i])
  
  fundays_df <- 
    data.frame(date = seq(from = LastPresent2, to = LastChecked2, 1)) %>% 
    # mutate(weekday = weekdays(dates)) %>% 
    mutate(weekday = factor(as.factor(weekdays(date)), 
                            levels = c("Monday", "Tuesday", "Wednesday", 
                                       "Thursday", "Friday", "Saturday", 
                                       "Sunday")),
           region = "FP") %>% 
    mutate(year = year(date)) %>% 
    mutate(season = ifelse(month(date) < 6, year - 1, year)) %>% 
    mutate(season = ifelse(month(date) >= 6, 
                           paste0(year, substr(year + 1, 3, 4)), 
                           paste0(season, substr(year, 3, 4)))) %>% 
    left_join(., holidays, by = c("region", "season"), relationship = "many-to-many") %>%
    mutate(holiday = ifelse(date >= start_date & date <= end_date, 1, 0)) %>% 
    group_by(region, season, date) %>% 
    mutate(holiday = max(holiday, na.rm = TRUE)) %>% 
    dplyr::select(-c(event, start_date, end_date)) %>% 
    distinct() %>% 
    ungroup() %>% 
    mutate(day_type = ifelse(holiday == 1 | weekday %in% 
                               c("Saturday", "Sunday"), "funday", "workday")) %>% 
    mutate(funday = ifelse(day_type == "funday", 1, 0))
    
  FP_threat_data_subset_ <- 
    FP_threat_data_subset %>% 
    ungroup() %>% 
    # data.frame() %>% 
    # dplyr::filter(as.numeric(obs_date2) >= FirstFound & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    # dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + (LastChecked - LastPresent)) & season == season_) %>%
    dplyr::filter(site == site_)
  
  if(nrow(FP_threat_data_subset_) > 0){
    avgeraged_threats <-
      FP_threat_data_subset_ %>% 
      mutate(hum_bi = ifelse(humans > 0 | (!is.na(hum_pri)), 1, 0),
             vehicle_bi = ifelse(vehicles > 0 | (!is.na(vehicle_pri)), 1, 0),
             dogs_bi = ifelse(dogs > 0 | (!is.na(dog_pri)), 1, 0),
             dogs_off_bi = ifelse(dogs_off > 0, 1, 0),
             dogs_on_bi = ifelse(dogs_on > 0, 1, 0),
             p_birds_bi = ifelse(pred_birds > 0, 1, 0),
             gulls_bi = ifelse(gulls > 0, 1, 0),
             hoof_bi = ifelse(hoofed_animals > 0 | (!is.na(hoofed_pri)), 1, 0)) %>%
      dplyr::summarise(
        # fundays = sum(funday),
        hum_avg = mean(humans, na.rm = TRUE),
        vehicles_avg = mean(vehicles, na.rm = TRUE),
        dogs_avg = mean(dogs, na.rm = TRUE),
        dogs_on_avg = mean(dogs_on, na.rm = TRUE),
        dogs_off_avg = mean(dogs_off, na.rm = TRUE),
        hoof_avg = mean(hoofed_animals, na.rm = TRUE),
        p_birds_avg = mean(pred_birds, na.rm = TRUE),
        gulls_avg = mean(gulls, na.rm = TRUE),
        hum_max = max(humans, na.rm = TRUE),
        vehicles_max = max(vehicles, na.rm = TRUE),
        dogs_max = max(dogs, na.rm = TRUE),
        dogs_on_max = max(dogs_on, na.rm = TRUE),
        dogs_off_max = max(dogs_off, na.rm = TRUE),
        hoof_max = max(hoofed_animals, na.rm = TRUE),
        p_birds_max = max(pred_birds, na.rm = TRUE),
        gulls_max = max(gulls, na.rm = TRUE),
        hum_bi = max(hum_bi, na.rm = TRUE),
        vehicle_bi = max(vehicle_bi, na.rm = TRUE),
        dogs_bi = max(dogs_bi, na.rm = TRUE),
        dogs_on_bi = max(dogs_on_bi, na.rm = TRUE),
        dogs_off_bi = max(dogs_off_bi, na.rm = TRUE),
        p_birds_bi = max(p_birds_bi, na.rm = TRUE),
        gulls_bi = max(gulls_bi, na.rm = TRUE),
        hoof_bi = max(hoof_bi, na.rm = TRUE),
        hum_pr = max(hum_pri, na.rm = TRUE),
        vehicle_pr = max(vehicle_pri, na.rm = TRUE),
        dog_pr = max(dog_pri, na.rm = TRUE),
        hoof_pr = max(hoofed_pri, na.rm = TRUE),
        fox_pr = max(fox_pri, na.rm = TRUE),
        n_surveys = n(),
        days_active = days_active,
        halfway = halfway, 
        uncertain_days = uncertain_days)
    
    nest_data_FP_with_threat_data$fundays[i] <- sum(fundays_df$funday)
    nest_data_FP_with_threat_data$hum_a[i] <- avgeraged_threats$hum_avg
    nest_data_FP_with_threat_data$veh_a[i] <- avgeraged_threats$vehicles_avg
    nest_data_FP_with_threat_data$dog_a[i] <- avgeraged_threats$dogs_avg
    nest_data_FP_with_threat_data$don_a[i] <- avgeraged_threats$dogs_on_avg
    nest_data_FP_with_threat_data$dof_a[i] <- avgeraged_threats$dogs_off_avg
    nest_data_FP_with_threat_data$hof_a[i] <- avgeraged_threats$hoof_avg
    nest_data_FP_with_threat_data$pbd_a[i] <- avgeraged_threats$p_birds_avg
    nest_data_FP_with_threat_data$gul_a[i] <- avgeraged_threats$gulls_avg
    
    nest_data_FP_with_threat_data$hum_m[i] <- avgeraged_threats$hum_max
    nest_data_FP_with_threat_data$veh_m[i] <- avgeraged_threats$vehicles_max
    nest_data_FP_with_threat_data$dog_m[i] <- avgeraged_threats$dogs_max
    nest_data_FP_with_threat_data$don_m[i] <- avgeraged_threats$dogs_on_max
    nest_data_FP_with_threat_data$dof_m[i] <- avgeraged_threats$dogs_off_max
    nest_data_FP_with_threat_data$hof_m[i] <- avgeraged_threats$hoof_max
    nest_data_FP_with_threat_data$pbd_m[i] <- avgeraged_threats$p_birds_max
    nest_data_FP_with_threat_data$gul_m[i] <- avgeraged_threats$gulls_max
    
    nest_data_FP_with_threat_data$hum_b[i] <- avgeraged_threats$hum_bi
    nest_data_FP_with_threat_data$veh_b[i] <- avgeraged_threats$vehicle_bi
    nest_data_FP_with_threat_data$dog_b[i] <- avgeraged_threats$dogs_bi
    nest_data_FP_with_threat_data$don_b[i] <- avgeraged_threats$dogs_on_bi
    nest_data_FP_with_threat_data$dof_b[i] <- avgeraged_threats$dogs_off_bi
    nest_data_FP_with_threat_data$pbd_b[i] <- avgeraged_threats$p_birds_bi
    nest_data_FP_with_threat_data$hof_b[i] <- avgeraged_threats$hoof_bi
    nest_data_FP_with_threat_data$gul_b[i] <- avgeraged_threats$gulls_bi
    
    nest_data_FP_with_threat_data$hum_p[i] <- avgeraged_threats$hum_pr
    nest_data_FP_with_threat_data$veh_p[i] <- avgeraged_threats$vehicle_pr
    nest_data_FP_with_threat_data$dog_p[i] <- avgeraged_threats$dog_pr
    nest_data_FP_with_threat_data$hof_p[i] <- avgeraged_threats$hoof_pr
    nest_data_FP_with_threat_data$fox_p[i] <- avgeraged_threats$fox_pr
    
    nest_data_FP_with_threat_data$n_surveys[i] <- avgeraged_threats$n_surveys
    nest_data_FP_with_threat_data$days_active[i] <- avgeraged_threats$days_active
    nest_data_FP_with_threat_data$halfway[i] <- avgeraged_threats$halfway
    nest_data_FP_with_threat_data$uncertain_days[i] <- avgeraged_threats$uncertain_days
    
  }else{
    nest_data_FP_with_threat_data$hum_a[i] <- NA
    nest_data_FP_with_threat_data$veh_a[i] <- NA
    nest_data_FP_with_threat_data$dog_a[i] <- NA
    nest_data_FP_with_threat_data$don_a[i] <- NA
    nest_data_FP_with_threat_data$dof_a[i] <- NA
    nest_data_FP_with_threat_data$hof_a[i] <- NA
    nest_data_FP_with_threat_data$pbd_a[i] <- NA
    nest_data_FP_with_threat_data$gul_a[i] <- NA
    nest_data_FP_with_threat_data$hum_m[i] <- NA
    nest_data_FP_with_threat_data$veh_m[i] <- NA
    nest_data_FP_with_threat_data$dog_m[i] <- NA
    nest_data_FP_with_threat_data$don_m[i] <- NA
    nest_data_FP_with_threat_data$dof_m[i] <- NA
    nest_data_FP_with_threat_data$hof_m[i] <- NA
    nest_data_FP_with_threat_data$pbd_m[i] <- NA
    nest_data_FP_with_threat_data$gul_m[i] <- NA
    nest_data_FP_with_threat_data$hum_b[i] <- NA
    nest_data_FP_with_threat_data$veh_b[i] <- NA
    nest_data_FP_with_threat_data$dog_b[i] <- NA
    nest_data_FP_with_threat_data$don_b[i] <- NA
    nest_data_FP_with_threat_data$dof_b[i] <- NA
    nest_data_FP_with_threat_data$pbd_b[i] <- NA
    nest_data_FP_with_threat_data$gul_b[i] <- NA
    nest_data_FP_with_threat_data$hof_b[i] <- NA
    nest_data_FP_with_threat_data$hum_p[i] <- NA
    nest_data_FP_with_threat_data$veh_p[i] <- NA
    nest_data_FP_with_threat_data$dog_p[i] <- NA
    nest_data_FP_with_threat_data$hof_p[i] <- NA
    nest_data_FP_with_threat_data$fox_p[i] <- NA
    nest_data_FP_with_threat_data$n_surveys[i] <- 0
    nest_data_FP_with_threat_data$days_active[i] <- days_active
    nest_data_FP_with_threat_data$halfway[i] <- halfway
    nest_data_FP_with_threat_data$uncertain_days[i] <- uncertain_days
    nest_data_FP_with_threat_data$fundays[i] <- NA
  }
}
saveRDS(nest_data_FP_with_threat_data, file = "output/nest_data_FP_with_threat_data.rds")nest_data_MP_with_threat_data <- 
  nest_data_MP %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_MP$season_site) %>%
  dplyr::select(season, site, region, nest_ID, 
                FirstFound, LastPresent, LastChecked,
                first_found2, last_alive2, last_checked2,
                management_status, management_level,
                nest_hab, Fate) %>% 
  rename(status = management_status,
         level = management_level) %>% 
  mutate(level = paste0("L", level)) %>% 
  mutate(level = factor(level, 
                        levels = c("L0", "L1", 
                                   "L2", "L3", 
                                   "L4"))) %>% 
  ungroup() %>% 
  mutate(
    hum_a = NA,
    veh_a = NA,
    dog_a = NA,
    don_a = NA,
    dof_a = NA,
    hof_a = NA,
    pbd_a = NA,
    gul_a = NA,
    hum_m = NA,
    veh_m = NA,
    dog_m = NA,
    don_m = NA,
    dof_m = NA,
    hof_m = NA,
    pbd_m = NA,
    gul_m = NA,
    hum_b = NA,
    veh_b = NA,
    dog_b = NA,
    don_b = NA,
    dof_b = NA,
    pbd_b = NA,
    gul_b = NA,
    hof_b = NA,
    hum_p = NA,
    veh_p = NA,
    dog_p = NA,
    hof_p = NA,
    fox_p = NA,
    n_surveys = NA,
    days_active = NA,
    fundays = NA, 
    uncertain_days = NA,
    halfway = NA) %>% 
  filter(FirstFound <= LastPresent & FirstFound <= LastChecked & LastPresent <= LastChecked) %>% 
  filter(first_found2 <= last_alive2 & first_found2 <= last_checked2 & last_alive2 <= last_checked2)
MP_threat_data_subset <- 
  threat_data__ %>% 
  filter(region == "MP") %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_MP$season_site) %>%
  ungroup()
for(i in 1:nrow(nest_data_MP_with_threat_data)){
  FirstFound <- nest_data_MP_with_threat_data$FirstFound[i]
  LastPresent <- nest_data_MP_with_threat_data$LastPresent[i]
  LastChecked <- nest_data_MP_with_threat_data$LastChecked[i]
  FirstFound2 <- nest_data_MP_with_threat_data$first_found2[i]
  LastPresent2 <- nest_data_MP_with_threat_data$last_alive2[i]
  LastChecked2 <- nest_data_MP_with_threat_data$last_checked2[i]
  halfway <- (LastChecked - LastPresent)/2
  days_active <- (LastPresent + halfway) - FirstFound
  uncertain_days <- LastChecked - LastPresent
  site_ <- as.character(nest_data_MP_with_threat_data$site[i])
  season_ <- as.character(nest_data_MP_with_threat_data$season[i])
  
  fundays_df <- 
    data.frame(date = seq(from = LastPresent2, to = LastChecked2, 1)) %>% 
    # mutate(weekday = weekdays(dates)) %>% 
    mutate(weekday = factor(as.factor(weekdays(date)), 
                            levels = c("Monday", "Tuesday", "Wednesday", 
                                       "Thursday", "Friday", "Saturday", 
                                       "Sunday")),
           region = "MP") %>% 
    mutate(year = year(date)) %>% 
    mutate(season = ifelse(month(date) < 6, year - 1, year)) %>% 
    mutate(season = ifelse(month(date) >= 6, 
                           paste0(year, substr(year + 1, 3, 4)), 
                           paste0(season, substr(year, 3, 4)))) %>% 
    left_join(., holidays, by = c("region", "season"), relationship = "many-to-many") %>%
    mutate(holiday = ifelse(date >= start_date & date <= end_date, 1, 0)) %>% 
    group_by(region, season, date) %>% 
    mutate(holiday = max(holiday, na.rm = TRUE)) %>% 
    dplyr::select(-c(event, start_date, end_date)) %>% 
    distinct() %>% 
    ungroup() %>% 
    mutate(day_type = ifelse(holiday == 1 | weekday %in% 
                               c("Saturday", "Sunday"), "funday", "workday")) %>% 
    mutate(funday = ifelse(day_type == "funday", 1, 0))
    
  MP_threat_data_subset_ <- 
    MP_threat_data_subset %>% 
    ungroup() %>% 
    # data.frame() %>% 
    # dplyr::filter(as.numeric(obs_date2) >= FirstFound & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    # dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + (LastChecked - LastPresent)) & season == season_) %>%
    dplyr::filter(site == site_)
  
  if(nrow(MP_threat_data_subset_) > 0){
    avgeraged_threats <-
      MP_threat_data_subset_ %>% 
      mutate(hum_bi = ifelse(humans > 0 | (!is.na(hum_pri)), 1, 0),
             vehicle_bi = ifelse(vehicles > 0 | (!is.na(vehicle_pri)), 1, 0),
             dogs_bi = ifelse(dogs > 0 | (!is.na(dog_pri)), 1, 0),
             dogs_off_bi = ifelse(dogs_off > 0, 1, 0),
             dogs_on_bi = ifelse(dogs_on > 0, 1, 0),
             p_birds_bi = ifelse(pred_birds > 0, 1, 0),
             gulls_bi = ifelse(gulls > 0, 1, 0),
             hoof_bi = ifelse(hoofed_animals > 0 | (!is.na(hoofed_pri)), 1, 0)) %>%
      dplyr::summarise(
        # fundays = sum(funday),
        hum_avg = mean(humans, na.rm = TRUE),
        vehicles_avg = mean(vehicles, na.rm = TRUE),
        dogs_avg = mean(dogs, na.rm = TRUE),
        dogs_on_avg = mean(dogs_on, na.rm = TRUE),
        dogs_off_avg = mean(dogs_off, na.rm = TRUE),
        hoof_avg = mean(hoofed_animals, na.rm = TRUE),
        p_birds_avg = mean(pred_birds, na.rm = TRUE),
        gulls_avg = mean(gulls, na.rm = TRUE),
        hum_max = max(humans, na.rm = TRUE),
        vehicles_max = max(vehicles, na.rm = TRUE),
        dogs_max = max(dogs, na.rm = TRUE),
        dogs_on_max = max(dogs_on, na.rm = TRUE),
        dogs_off_max = max(dogs_off, na.rm = TRUE),
        hoof_max = max(hoofed_animals, na.rm = TRUE),
        p_birds_max = max(pred_birds, na.rm = TRUE),
        gulls_max = max(gulls, na.rm = TRUE),
        hum_bi = max(hum_bi, na.rm = TRUE),
        vehicle_bi = max(vehicle_bi, na.rm = TRUE),
        dogs_bi = max(dogs_bi, na.rm = TRUE),
        dogs_on_bi = max(dogs_on_bi, na.rm = TRUE),
        dogs_off_bi = max(dogs_off_bi, na.rm = TRUE),
        p_birds_bi = max(p_birds_bi, na.rm = TRUE),
        gulls_bi = max(gulls_bi, na.rm = TRUE),
        hoof_bi = max(hoof_bi, na.rm = TRUE),
        hum_pr = max(hum_pri, na.rm = TRUE),
        vehicle_pr = max(vehicle_pri, na.rm = TRUE),
        dog_pr = max(dog_pri, na.rm = TRUE),
        hoof_pr = max(hoofed_pri, na.rm = TRUE),
        fox_pr = max(fox_pri, na.rm = TRUE),
        n_surveys = n(),
        days_active = days_active,
        halfway = halfway, 
        uncertain_days = uncertain_days)
    
    nest_data_MP_with_threat_data$fundays[i] <- sum(fundays_df$funday)
    nest_data_MP_with_threat_data$hum_a[i] <- avgeraged_threats$hum_avg
    nest_data_MP_with_threat_data$veh_a[i] <- avgeraged_threats$vehicles_avg
    nest_data_MP_with_threat_data$dog_a[i] <- avgeraged_threats$dogs_avg
    nest_data_MP_with_threat_data$don_a[i] <- avgeraged_threats$dogs_on_avg
    nest_data_MP_with_threat_data$dof_a[i] <- avgeraged_threats$dogs_off_avg
    nest_data_MP_with_threat_data$hof_a[i] <- avgeraged_threats$hoof_avg
    nest_data_MP_with_threat_data$pbd_a[i] <- avgeraged_threats$p_birds_avg
    nest_data_MP_with_threat_data$gul_a[i] <- avgeraged_threats$gulls_avg
    
    nest_data_MP_with_threat_data$hum_m[i] <- avgeraged_threats$hum_max
    nest_data_MP_with_threat_data$veh_m[i] <- avgeraged_threats$vehicles_max
    nest_data_MP_with_threat_data$dog_m[i] <- avgeraged_threats$dogs_max
    nest_data_MP_with_threat_data$don_m[i] <- avgeraged_threats$dogs_on_max
    nest_data_MP_with_threat_data$dof_m[i] <- avgeraged_threats$dogs_off_max
    nest_data_MP_with_threat_data$hof_m[i] <- avgeraged_threats$hoof_max
    nest_data_MP_with_threat_data$pbd_m[i] <- avgeraged_threats$p_birds_max
    nest_data_MP_with_threat_data$gul_m[i] <- avgeraged_threats$gulls_max
    
    nest_data_MP_with_threat_data$hum_b[i] <- avgeraged_threats$hum_bi
    nest_data_MP_with_threat_data$veh_b[i] <- avgeraged_threats$vehicle_bi
    nest_data_MP_with_threat_data$dog_b[i] <- avgeraged_threats$dogs_bi
    nest_data_MP_with_threat_data$don_b[i] <- avgeraged_threats$dogs_on_bi
    nest_data_MP_with_threat_data$dof_b[i] <- avgeraged_threats$dogs_off_bi
    nest_data_MP_with_threat_data$pbd_b[i] <- avgeraged_threats$p_birds_bi
    nest_data_MP_with_threat_data$hof_b[i] <- avgeraged_threats$hoof_bi
    nest_data_MP_with_threat_data$gul_b[i] <- avgeraged_threats$gulls_bi
    
    nest_data_MP_with_threat_data$hum_p[i] <- avgeraged_threats$hum_pr
    nest_data_MP_with_threat_data$veh_p[i] <- avgeraged_threats$vehicle_pr
    nest_data_MP_with_threat_data$dog_p[i] <- avgeraged_threats$dog_pr
    nest_data_MP_with_threat_data$hof_p[i] <- avgeraged_threats$hoof_pr
    nest_data_MP_with_threat_data$fox_p[i] <- avgeraged_threats$fox_pr
    
    nest_data_MP_with_threat_data$n_surveys[i] <- avgeraged_threats$n_surveys
    nest_data_MP_with_threat_data$days_active[i] <- avgeraged_threats$days_active
    nest_data_MP_with_threat_data$halfway[i] <- avgeraged_threats$halfway
    nest_data_MP_with_threat_data$uncertain_days[i] <- avgeraged_threats$uncertain_days
    
  }else{
    nest_data_MP_with_threat_data$hum_a[i] <- NA
    nest_data_MP_with_threat_data$veh_a[i] <- NA
    nest_data_MP_with_threat_data$dog_a[i] <- NA
    nest_data_MP_with_threat_data$don_a[i] <- NA
    nest_data_MP_with_threat_data$dof_a[i] <- NA
    nest_data_MP_with_threat_data$hof_a[i] <- NA
    nest_data_MP_with_threat_data$pbd_a[i] <- NA
    nest_data_MP_with_threat_data$gul_a[i] <- NA
    nest_data_MP_with_threat_data$hum_m[i] <- NA
    nest_data_MP_with_threat_data$veh_m[i] <- NA
    nest_data_MP_with_threat_data$dog_m[i] <- NA
    nest_data_MP_with_threat_data$don_m[i] <- NA
    nest_data_MP_with_threat_data$dof_m[i] <- NA
    nest_data_MP_with_threat_data$hof_m[i] <- NA
    nest_data_MP_with_threat_data$pbd_m[i] <- NA
    nest_data_MP_with_threat_data$gul_m[i] <- NA
    nest_data_MP_with_threat_data$hum_b[i] <- NA
    nest_data_MP_with_threat_data$veh_b[i] <- NA
    nest_data_MP_with_threat_data$dog_b[i] <- NA
    nest_data_MP_with_threat_data$don_b[i] <- NA
    nest_data_MP_with_threat_data$dof_b[i] <- NA
    nest_data_MP_with_threat_data$pbd_b[i] <- NA
    nest_data_MP_with_threat_data$gul_b[i] <- NA
    nest_data_MP_with_threat_data$hof_b[i] <- NA
    nest_data_MP_with_threat_data$hum_p[i] <- NA
    nest_data_MP_with_threat_data$veh_p[i] <- NA
    nest_data_MP_with_threat_data$dog_p[i] <- NA
    nest_data_MP_with_threat_data$hof_p[i] <- NA
    nest_data_MP_with_threat_data$fox_p[i] <- NA
    nest_data_MP_with_threat_data$n_surveys[i] <- 0
    nest_data_MP_with_threat_data$days_active[i] <- days_active
    nest_data_MP_with_threat_data$halfway[i] <- halfway
    nest_data_MP_with_threat_data$uncertain_days[i] <- uncertain_days
    nest_data_MP_with_threat_data$fundays[i] <- NA
  }
}
saveRDS(nest_data_MP_with_threat_data, file = "output/nest_data_MP_with_threat_data.rds")nest_data_BSC_with_threat_data <- 
  nest_data_BSC %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_BSC$season_site) %>%
  dplyr::select(season, site, region, nest_ID, 
                FirstFound, LastPresent, LastChecked,
                first_found2, last_alive2, last_checked2,
                management_status, management_level,
                nest_hab, Fate) %>% 
  rename(status = management_status,
         level = management_level) %>% 
  mutate(level = paste0("L", level)) %>% 
  mutate(level = factor(level, 
                        levels = c("L0", "L1", 
                                   "L2", "L3", 
                                   "L4"))) %>% 
  ungroup() %>% 
  mutate(
    hum_a = NA,
    veh_a = NA,
    dog_a = NA,
    don_a = NA,
    dof_a = NA,
    hof_a = NA,
    pbd_a = NA,
    gul_a = NA,
    hum_m = NA,
    veh_m = NA,
    dog_m = NA,
    don_m = NA,
    dof_m = NA,
    hof_m = NA,
    pbd_m = NA,
    gul_m = NA,
    hum_b = NA,
    veh_b = NA,
    dog_b = NA,
    don_b = NA,
    dof_b = NA,
    pbd_b = NA,
    gul_b = NA,
    hof_b = NA,
    hum_p = NA,
    veh_p = NA,
    dog_p = NA,
    hof_p = NA,
    fox_p = NA,
    n_surveys = NA,
    days_active = NA,
    fundays = NA, 
    uncertain_days = NA,
    halfway = NA) %>% 
  filter(FirstFound <= LastPresent & FirstFound <= LastChecked & LastPresent <= LastChecked) %>% 
  filter(first_found2 <= last_alive2 & first_found2 <= last_checked2 & last_alive2 <= last_checked2)
BSC_threat_data_subset <- 
  threat_data__ %>% 
  filter(region == "BSC") %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_BSC$season_site) %>%
  ungroup()
for(i in 1:nrow(nest_data_BSC_with_threat_data)){
  FirstFound <- nest_data_BSC_with_threat_data$FirstFound[i]
  LastPresent <- nest_data_BSC_with_threat_data$LastPresent[i]
  LastChecked <- nest_data_BSC_with_threat_data$LastChecked[i]
  FirstFound2 <- nest_data_BSC_with_threat_data$first_found2[i]
  LastPresent2 <- nest_data_BSC_with_threat_data$last_alive2[i]
  LastChecked2 <- nest_data_BSC_with_threat_data$last_checked2[i]
  halfway <- (LastChecked - LastPresent)/2
  days_active <- (LastPresent + halfway) - FirstFound
  uncertain_days <- LastChecked - LastPresent
  site_ <- as.character(nest_data_BSC_with_threat_data$site[i])
  season_ <- as.character(nest_data_BSC_with_threat_data$season[i])
  
  fundays_df <- 
    data.frame(date = seq(from = LastPresent2, to = LastChecked2, 1)) %>% 
    # mutate(weekday = weekdays(dates)) %>% 
    mutate(weekday = factor(as.factor(weekdays(date)), 
                            levels = c("Monday", "Tuesday", "Wednesday", 
                                       "Thursday", "Friday", "Saturday", 
                                       "Sunday")),
           region = "BSC") %>% 
    mutate(year = year(date)) %>% 
    mutate(season = ifelse(month(date) < 6, year - 1, year)) %>% 
    mutate(season = ifelse(month(date) >= 6, 
                           paste0(year, substr(year + 1, 3, 4)), 
                           paste0(season, substr(year, 3, 4)))) %>% 
    left_join(., holidays, by = c("region", "season"), relationship = "many-to-many") %>%
    mutate(holiday = ifelse(date >= start_date & date <= end_date, 1, 0)) %>% 
    group_by(region, season, date) %>% 
    mutate(holiday = max(holiday, na.rm = TRUE)) %>% 
    dplyr::select(-c(event, start_date, end_date)) %>% 
    distinct() %>% 
    ungroup() %>% 
    mutate(day_type = ifelse(holiday == 1 | weekday %in% 
                               c("Saturday", "Sunday"), "funday", "workday")) %>% 
    mutate(funday = ifelse(day_type == "funday", 1, 0))
    
  BSC_threat_data_subset_ <- 
    BSC_threat_data_subset %>% 
    ungroup() %>% 
    # data.frame() %>% 
    # dplyr::filter(as.numeric(obs_date2) >= FirstFound & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    # dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + (LastChecked - LastPresent)) & season == season_) %>%
    dplyr::filter(site == site_)
  
  if(nrow(BSC_threat_data_subset_) > 0){
    avgeraged_threats <-
      BSC_threat_data_subset_ %>% 
      mutate(hum_bi = ifelse(humans > 0 | (!is.na(hum_pri)), 1, 0),
             vehicle_bi = ifelse(vehicles > 0 | (!is.na(vehicle_pri)), 1, 0),
             dogs_bi = ifelse(dogs > 0 | (!is.na(dog_pri)), 1, 0),
             dogs_off_bi = ifelse(dogs_off > 0, 1, 0),
             dogs_on_bi = ifelse(dogs_on > 0, 1, 0),
             p_birds_bi = ifelse(pred_birds > 0, 1, 0),
             gulls_bi = ifelse(gulls > 0, 1, 0),
             hoof_bi = ifelse(hoofed_animals > 0 | (!is.na(hoofed_pri)), 1, 0)) %>%
      dplyr::summarise(
        # fundays = sum(funday),
        hum_avg = mean(humans, na.rm = TRUE),
        vehicles_avg = mean(vehicles, na.rm = TRUE),
        dogs_avg = mean(dogs, na.rm = TRUE),
        dogs_on_avg = mean(dogs_on, na.rm = TRUE),
        dogs_off_avg = mean(dogs_off, na.rm = TRUE),
        hoof_avg = mean(hoofed_animals, na.rm = TRUE),
        p_birds_avg = mean(pred_birds, na.rm = TRUE),
        gulls_avg = mean(gulls, na.rm = TRUE),
        hum_max = max(humans, na.rm = TRUE),
        vehicles_max = max(vehicles, na.rm = TRUE),
        dogs_max = max(dogs, na.rm = TRUE),
        dogs_on_max = max(dogs_on, na.rm = TRUE),
        dogs_off_max = max(dogs_off, na.rm = TRUE),
        hoof_max = max(hoofed_animals, na.rm = TRUE),
        p_birds_max = max(pred_birds, na.rm = TRUE),
        gulls_max = max(gulls, na.rm = TRUE),
        hum_bi = max(hum_bi, na.rm = TRUE),
        vehicle_bi = max(vehicle_bi, na.rm = TRUE),
        dogs_bi = max(dogs_bi, na.rm = TRUE),
        dogs_on_bi = max(dogs_on_bi, na.rm = TRUE),
        dogs_off_bi = max(dogs_off_bi, na.rm = TRUE),
        p_birds_bi = max(p_birds_bi, na.rm = TRUE),
        gulls_bi = max(gulls_bi, na.rm = TRUE),
        hoof_bi = max(hoof_bi, na.rm = TRUE),
        hum_pr = max(hum_pri, na.rm = TRUE),
        vehicle_pr = max(vehicle_pri, na.rm = TRUE),
        dog_pr = max(dog_pri, na.rm = TRUE),
        hoof_pr = max(hoofed_pri, na.rm = TRUE),
        fox_pr = max(fox_pri, na.rm = TRUE),
        n_surveys = n(),
        days_active = days_active,
        halfway = halfway, 
        uncertain_days = uncertain_days)
    
    nest_data_BSC_with_threat_data$fundays[i] <- sum(fundays_df$funday)
    nest_data_BSC_with_threat_data$hum_a[i] <- avgeraged_threats$hum_avg
    nest_data_BSC_with_threat_data$veh_a[i] <- avgeraged_threats$vehicles_avg
    nest_data_BSC_with_threat_data$dog_a[i] <- avgeraged_threats$dogs_avg
    nest_data_BSC_with_threat_data$don_a[i] <- avgeraged_threats$dogs_on_avg
    nest_data_BSC_with_threat_data$dof_a[i] <- avgeraged_threats$dogs_off_avg
    nest_data_BSC_with_threat_data$hof_a[i] <- avgeraged_threats$hoof_avg
    nest_data_BSC_with_threat_data$pbd_a[i] <- avgeraged_threats$p_birds_avg
    nest_data_BSC_with_threat_data$gul_a[i] <- avgeraged_threats$gulls_avg
    
    nest_data_BSC_with_threat_data$hum_m[i] <- avgeraged_threats$hum_max
    nest_data_BSC_with_threat_data$veh_m[i] <- avgeraged_threats$vehicles_max
    nest_data_BSC_with_threat_data$dog_m[i] <- avgeraged_threats$dogs_max
    nest_data_BSC_with_threat_data$don_m[i] <- avgeraged_threats$dogs_on_max
    nest_data_BSC_with_threat_data$dof_m[i] <- avgeraged_threats$dogs_off_max
    nest_data_BSC_with_threat_data$hof_m[i] <- avgeraged_threats$hoof_max
    nest_data_BSC_with_threat_data$pbd_m[i] <- avgeraged_threats$p_birds_max
    nest_data_BSC_with_threat_data$gul_m[i] <- avgeraged_threats$gulls_max
    
    nest_data_BSC_with_threat_data$hum_b[i] <- avgeraged_threats$hum_bi
    nest_data_BSC_with_threat_data$veh_b[i] <- avgeraged_threats$vehicle_bi
    nest_data_BSC_with_threat_data$dog_b[i] <- avgeraged_threats$dogs_bi
    nest_data_BSC_with_threat_data$don_b[i] <- avgeraged_threats$dogs_on_bi
    nest_data_BSC_with_threat_data$dof_b[i] <- avgeraged_threats$dogs_off_bi
    nest_data_BSC_with_threat_data$pbd_b[i] <- avgeraged_threats$p_birds_bi
    nest_data_BSC_with_threat_data$hof_b[i] <- avgeraged_threats$hoof_bi
    nest_data_BSC_with_threat_data$gul_b[i] <- avgeraged_threats$gulls_bi
    
    nest_data_BSC_with_threat_data$hum_p[i] <- avgeraged_threats$hum_pr
    nest_data_BSC_with_threat_data$veh_p[i] <- avgeraged_threats$vehicle_pr
    nest_data_BSC_with_threat_data$dog_p[i] <- avgeraged_threats$dog_pr
    nest_data_BSC_with_threat_data$hof_p[i] <- avgeraged_threats$hoof_pr
    nest_data_BSC_with_threat_data$fox_p[i] <- avgeraged_threats$fox_pr
    
    nest_data_BSC_with_threat_data$n_surveys[i] <- avgeraged_threats$n_surveys
    nest_data_BSC_with_threat_data$days_active[i] <- avgeraged_threats$days_active
    nest_data_BSC_with_threat_data$halfway[i] <- avgeraged_threats$halfway
    nest_data_BSC_with_threat_data$uncertain_days[i] <- avgeraged_threats$uncertain_days
    
  }else{
    nest_data_BSC_with_threat_data$hum_a[i] <- NA
    nest_data_BSC_with_threat_data$veh_a[i] <- NA
    nest_data_BSC_with_threat_data$dog_a[i] <- NA
    nest_data_BSC_with_threat_data$don_a[i] <- NA
    nest_data_BSC_with_threat_data$dof_a[i] <- NA
    nest_data_BSC_with_threat_data$hof_a[i] <- NA
    nest_data_BSC_with_threat_data$pbd_a[i] <- NA
    nest_data_BSC_with_threat_data$gul_a[i] <- NA
    nest_data_BSC_with_threat_data$hum_m[i] <- NA
    nest_data_BSC_with_threat_data$veh_m[i] <- NA
    nest_data_BSC_with_threat_data$dog_m[i] <- NA
    nest_data_BSC_with_threat_data$don_m[i] <- NA
    nest_data_BSC_with_threat_data$dof_m[i] <- NA
    nest_data_BSC_with_threat_data$hof_m[i] <- NA
    nest_data_BSC_with_threat_data$pbd_m[i] <- NA
    nest_data_BSC_with_threat_data$gul_m[i] <- NA
    nest_data_BSC_with_threat_data$hum_b[i] <- NA
    nest_data_BSC_with_threat_data$veh_b[i] <- NA
    nest_data_BSC_with_threat_data$dog_b[i] <- NA
    nest_data_BSC_with_threat_data$don_b[i] <- NA
    nest_data_BSC_with_threat_data$dof_b[i] <- NA
    nest_data_BSC_with_threat_data$pbd_b[i] <- NA
    nest_data_BSC_with_threat_data$gul_b[i] <- NA
    nest_data_BSC_with_threat_data$hof_b[i] <- NA
    nest_data_BSC_with_threat_data$hum_p[i] <- NA
    nest_data_BSC_with_threat_data$veh_p[i] <- NA
    nest_data_BSC_with_threat_data$dog_p[i] <- NA
    nest_data_BSC_with_threat_data$hof_p[i] <- NA
    nest_data_BSC_with_threat_data$fox_p[i] <- NA
    nest_data_BSC_with_threat_data$n_surveys[i] <- 0
    nest_data_BSC_with_threat_data$days_active[i] <- days_active
    nest_data_BSC_with_threat_data$halfway[i] <- halfway
    nest_data_BSC_with_threat_data$uncertain_days[i] <- uncertain_days
    nest_data_BSC_with_threat_data$fundays[i] <- NA
  }
}
saveRDS(nest_data_BSC_with_threat_data, file = "output/nest_data_BSC_with_threat_data.rds")nest_data_BC_with_threat_data <- 
  nest_data_BC %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  ####
  
  ####
  filter(season_site %in% sites_intersect_BC$season_site) %>%
  dplyr::select(season, site, region, nest_ID, 
                FirstFound, LastPresent, LastChecked,
                first_found2, last_alive2, last_checked2,
                management_status, management_level,
                nest_hab, Fate) %>% 
  rename(status = management_status,
         level = management_level) %>% 
  mutate(level = paste0("L", level)) %>% 
  mutate(level = factor(level, 
                        levels = c("L0", "L1", 
                                   "L2", "L3", 
                                   "L4"))) %>% 
  ungroup() %>% 
  mutate(
    hum_a = NA,
    veh_a = NA,
    dog_a = NA,
    don_a = NA,
    dof_a = NA,
    hof_a = NA,
    pbd_a = NA,
    gul_a = NA,
    hum_m = NA,
    veh_m = NA,
    dog_m = NA,
    don_m = NA,
    dof_m = NA,
    hof_m = NA,
    pbd_m = NA,
    gul_m = NA,
    hum_b = NA,
    veh_b = NA,
    dog_b = NA,
    don_b = NA,
    dof_b = NA,
    pbd_b = NA,
    gul_b = NA,
    hof_b = NA,
    hum_p = NA,
    veh_p = NA,
    dog_p = NA,
    hof_p = NA,
    fox_p = NA,
    n_surveys = NA,
    days_active = NA,
    fundays = NA, 
    uncertain_days = NA,
    halfway = NA) %>% 
  filter(FirstFound <= LastPresent & FirstFound <= LastChecked & LastPresent <= LastChecked) %>% 
  filter(first_found2 <= last_alive2 & first_found2 <= last_checked2 & last_alive2 <= last_checked2)
BC_threat_data_subset <- 
  threat_data__ %>% 
  filter(region == "BC") %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_BC$season_site) %>%
  ungroup()
for(i in 1:nrow(nest_data_BC_with_threat_data)){
  FirstFound <- nest_data_BC_with_threat_data$FirstFound[i]
  LastPresent <- nest_data_BC_with_threat_data$LastPresent[i]
  LastChecked <- nest_data_BC_with_threat_data$LastChecked[i]
  FirstFound2 <- nest_data_BC_with_threat_data$first_found2[i]
  LastPresent2 <- nest_data_BC_with_threat_data$last_alive2[i]
  LastChecked2 <- nest_data_BC_with_threat_data$last_checked2[i]
  halfway <- (LastChecked - LastPresent)/2
  days_active <- (LastPresent + halfway) - FirstFound
  uncertain_days <- LastChecked - LastPresent
  site_ <- as.character(nest_data_BC_with_threat_data$site[i])
  season_ <- as.character(nest_data_BC_with_threat_data$season[i])
  
  fundays_df <- 
    data.frame(date = seq(from = LastPresent2, to = LastChecked2, 1)) %>% 
    # mutate(weekday = weekdays(dates)) %>% 
    mutate(weekday = factor(as.factor(weekdays(date)), 
                            levels = c("Monday", "Tuesday", "Wednesday", 
                                       "Thursday", "Friday", "Saturday", 
                                       "Sunday")),
           region = "BC") %>% 
    mutate(year = year(date)) %>% 
    mutate(season = ifelse(month(date) < 6, year - 1, year)) %>% 
    mutate(season = ifelse(month(date) >= 6, 
                           paste0(year, substr(year + 1, 3, 4)), 
                           paste0(season, substr(year, 3, 4)))) %>% 
    left_join(., holidays, by = c("region", "season"), relationship = "many-to-many") %>%
    mutate(holiday = ifelse(date >= start_date & date <= end_date, 1, 0)) %>% 
    group_by(region, season, date) %>% 
    mutate(holiday = max(holiday, na.rm = TRUE)) %>% 
    dplyr::select(-c(event, start_date, end_date)) %>% 
    distinct() %>% 
    ungroup() %>% 
    mutate(day_type = ifelse(holiday == 1 | weekday %in% 
                               c("Saturday", "Sunday"), "funday", "workday")) %>% 
    mutate(funday = ifelse(day_type == "funday", 1, 0))
    
  BC_threat_data_subset_ <- 
    BC_threat_data_subset %>% 
    ungroup() %>% 
    # data.frame() %>% 
    # dplyr::filter(as.numeric(obs_date2) >= FirstFound & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    # dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + (LastChecked - LastPresent)) & season == season_) %>%
    dplyr::filter(site == site_)
  
  if(nrow(BC_threat_data_subset_) > 0){
    avgeraged_threats <-
      BC_threat_data_subset_ %>% 
      mutate(hum_bi = ifelse(humans > 0 | (!is.na(hum_pri)), 1, 0),
             vehicle_bi = ifelse(vehicles > 0 | (!is.na(vehicle_pri)), 1, 0),
             dogs_bi = ifelse(dogs > 0 | (!is.na(dog_pri)), 1, 0),
             dogs_off_bi = ifelse(dogs_off > 0, 1, 0),
             dogs_on_bi = ifelse(dogs_on > 0, 1, 0),
             p_birds_bi = ifelse(pred_birds > 0, 1, 0),
             gulls_bi = ifelse(gulls > 0, 1, 0),
             hoof_bi = ifelse(hoofed_animals > 0 | (!is.na(hoofed_pri)), 1, 0)) %>%
      dplyr::summarise(
        # fundays = sum(funday),
        hum_avg = mean(humans, na.rm = TRUE),
        vehicles_avg = mean(vehicles, na.rm = TRUE),
        dogs_avg = mean(dogs, na.rm = TRUE),
        dogs_on_avg = mean(dogs_on, na.rm = TRUE),
        dogs_off_avg = mean(dogs_off, na.rm = TRUE),
        hoof_avg = mean(hoofed_animals, na.rm = TRUE),
        p_birds_avg = mean(pred_birds, na.rm = TRUE),
        gulls_avg = mean(gulls, na.rm = TRUE),
        hum_max = max(humans, na.rm = TRUE),
        vehicles_max = max(vehicles, na.rm = TRUE),
        dogs_max = max(dogs, na.rm = TRUE),
        dogs_on_max = max(dogs_on, na.rm = TRUE),
        dogs_off_max = max(dogs_off, na.rm = TRUE),
        hoof_max = max(hoofed_animals, na.rm = TRUE),
        p_birds_max = max(pred_birds, na.rm = TRUE),
        gulls_max = max(gulls, na.rm = TRUE),
        hum_bi = max(hum_bi, na.rm = TRUE),
        vehicle_bi = max(vehicle_bi, na.rm = TRUE),
        dogs_bi = max(dogs_bi, na.rm = TRUE),
        dogs_on_bi = max(dogs_on_bi, na.rm = TRUE),
        dogs_off_bi = max(dogs_off_bi, na.rm = TRUE),
        p_birds_bi = max(p_birds_bi, na.rm = TRUE),
        gulls_bi = max(gulls_bi, na.rm = TRUE),
        hoof_bi = max(hoof_bi, na.rm = TRUE),
        hum_pr = max(hum_pri, na.rm = TRUE),
        vehicle_pr = max(vehicle_pri, na.rm = TRUE),
        dog_pr = max(dog_pri, na.rm = TRUE),
        hoof_pr = max(hoofed_pri, na.rm = TRUE),
        fox_pr = max(fox_pri, na.rm = TRUE),
        n_surveys = n(),
        days_active = days_active,
        halfway = halfway, 
        uncertain_days = uncertain_days)
    
    nest_data_BC_with_threat_data$fundays[i] <- sum(fundays_df$funday)
    nest_data_BC_with_threat_data$hum_a[i] <- avgeraged_threats$hum_avg
    nest_data_BC_with_threat_data$veh_a[i] <- avgeraged_threats$vehicles_avg
    nest_data_BC_with_threat_data$dog_a[i] <- avgeraged_threats$dogs_avg
    nest_data_BC_with_threat_data$don_a[i] <- avgeraged_threats$dogs_on_avg
    nest_data_BC_with_threat_data$dof_a[i] <- avgeraged_threats$dogs_off_avg
    nest_data_BC_with_threat_data$hof_a[i] <- avgeraged_threats$hoof_avg
    nest_data_BC_with_threat_data$pbd_a[i] <- avgeraged_threats$p_birds_avg
    nest_data_BC_with_threat_data$gul_a[i] <- avgeraged_threats$gulls_avg
    
    nest_data_BC_with_threat_data$hum_m[i] <- avgeraged_threats$hum_max
    nest_data_BC_with_threat_data$veh_m[i] <- avgeraged_threats$vehicles_max
    nest_data_BC_with_threat_data$dog_m[i] <- avgeraged_threats$dogs_max
    nest_data_BC_with_threat_data$don_m[i] <- avgeraged_threats$dogs_on_max
    nest_data_BC_with_threat_data$dof_m[i] <- avgeraged_threats$dogs_off_max
    nest_data_BC_with_threat_data$hof_m[i] <- avgeraged_threats$hoof_max
    nest_data_BC_with_threat_data$pbd_m[i] <- avgeraged_threats$p_birds_max
    nest_data_BC_with_threat_data$gul_m[i] <- avgeraged_threats$gulls_max
    
    nest_data_BC_with_threat_data$hum_b[i] <- avgeraged_threats$hum_bi
    nest_data_BC_with_threat_data$veh_b[i] <- avgeraged_threats$vehicle_bi
    nest_data_BC_with_threat_data$dog_b[i] <- avgeraged_threats$dogs_bi
    nest_data_BC_with_threat_data$don_b[i] <- avgeraged_threats$dogs_on_bi
    nest_data_BC_with_threat_data$dof_b[i] <- avgeraged_threats$dogs_off_bi
    nest_data_BC_with_threat_data$pbd_b[i] <- avgeraged_threats$p_birds_bi
    nest_data_BC_with_threat_data$hof_b[i] <- avgeraged_threats$hoof_bi
    nest_data_BC_with_threat_data$gul_b[i] <- avgeraged_threats$gulls_bi
    
    nest_data_BC_with_threat_data$hum_p[i] <- avgeraged_threats$hum_pr
    nest_data_BC_with_threat_data$veh_p[i] <- avgeraged_threats$vehicle_pr
    nest_data_BC_with_threat_data$dog_p[i] <- avgeraged_threats$dog_pr
    nest_data_BC_with_threat_data$hof_p[i] <- avgeraged_threats$hoof_pr
    nest_data_BC_with_threat_data$fox_p[i] <- avgeraged_threats$fox_pr
    
    nest_data_BC_with_threat_data$n_surveys[i] <- avgeraged_threats$n_surveys
    nest_data_BC_with_threat_data$days_active[i] <- avgeraged_threats$days_active
    nest_data_BC_with_threat_data$halfway[i] <- avgeraged_threats$halfway
    nest_data_BC_with_threat_data$uncertain_days[i] <- avgeraged_threats$uncertain_days
    
  }else{
    nest_data_BC_with_threat_data$hum_a[i] <- NA
    nest_data_BC_with_threat_data$veh_a[i] <- NA
    nest_data_BC_with_threat_data$dog_a[i] <- NA
    nest_data_BC_with_threat_data$don_a[i] <- NA
    nest_data_BC_with_threat_data$dof_a[i] <- NA
    nest_data_BC_with_threat_data$hof_a[i] <- NA
    nest_data_BC_with_threat_data$pbd_a[i] <- NA
    nest_data_BC_with_threat_data$gul_a[i] <- NA
    nest_data_BC_with_threat_data$hum_m[i] <- NA
    nest_data_BC_with_threat_data$veh_m[i] <- NA
    nest_data_BC_with_threat_data$dog_m[i] <- NA
    nest_data_BC_with_threat_data$don_m[i] <- NA
    nest_data_BC_with_threat_data$dof_m[i] <- NA
    nest_data_BC_with_threat_data$hof_m[i] <- NA
    nest_data_BC_with_threat_data$pbd_m[i] <- NA
    nest_data_BC_with_threat_data$gul_m[i] <- NA
    nest_data_BC_with_threat_data$hum_b[i] <- NA
    nest_data_BC_with_threat_data$veh_b[i] <- NA
    nest_data_BC_with_threat_data$dog_b[i] <- NA
    nest_data_BC_with_threat_data$don_b[i] <- NA
    nest_data_BC_with_threat_data$dof_b[i] <- NA
    nest_data_BC_with_threat_data$pbd_b[i] <- NA
    nest_data_BC_with_threat_data$gul_b[i] <- NA
    nest_data_BC_with_threat_data$hof_b[i] <- NA
    nest_data_BC_with_threat_data$hum_p[i] <- NA
    nest_data_BC_with_threat_data$veh_p[i] <- NA
    nest_data_BC_with_threat_data$dog_p[i] <- NA
    nest_data_BC_with_threat_data$hof_p[i] <- NA
    nest_data_BC_with_threat_data$fox_p[i] <- NA
    nest_data_BC_with_threat_data$n_surveys[i] <- 0
    nest_data_BC_with_threat_data$days_active[i] <- days_active
    nest_data_BC_with_threat_data$halfway[i] <- halfway
    nest_data_BC_with_threat_data$uncertain_days[i] <- uncertain_days
    nest_data_BC_with_threat_data$fundays[i] <- NA
  }
}
saveRDS(nest_data_BC_with_threat_data, file = "output/nest_data_BC_with_threat_data.rds")nest_data_PI_with_threat_data <- 
  nest_data_PI %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  ####
  
  ####
  filter(season_site %in% sites_intersect_PI$season_site) %>%
  dplyr::select(season, site, region, nest_ID, 
                FirstFound, LastPresent, LastChecked,
                first_found2, last_alive2, last_checked2,
                management_status, management_level,
                nest_hab, Fate) %>% 
  rename(status = management_status,
         level = management_level) %>% 
  mutate(level = paste0("L", level)) %>% 
  mutate(level = factor(level, 
                        levels = c("L0", "L1", 
                                   "L2", "L3", 
                                   "L4"))) %>% 
  ungroup() %>% 
  mutate(
    hum_a = NA,
    veh_a = NA,
    dog_a = NA,
    don_a = NA,
    dof_a = NA,
    hof_a = NA,
    pbd_a = NA,
    gul_a = NA,
    hum_m = NA,
    veh_m = NA,
    dog_m = NA,
    don_m = NA,
    dof_m = NA,
    hof_m = NA,
    pbd_m = NA,
    gul_m = NA,
    hum_b = NA,
    veh_b = NA,
    dog_b = NA,
    don_b = NA,
    dof_b = NA,
    pbd_b = NA,
    gul_b = NA,
    hof_b = NA,
    hum_p = NA,
    veh_p = NA,
    dog_p = NA,
    hof_p = NA,
    fox_p = NA,
    n_surveys = NA,
    days_active = NA,
    fundays = NA, 
    uncertain_days = NA,
    halfway = NA) %>% 
  filter(FirstFound <= LastPresent & FirstFound <= LastChecked & LastPresent <= LastChecked) %>% 
  filter(first_found2 <= last_alive2 & first_found2 <= last_checked2 & last_alive2 <= last_checked2)
PI_threat_data_subset <- 
  threat_data__ %>% 
  filter(region == "PI") %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_PI$season_site) %>%
  ungroup()
for(i in 1:nrow(nest_data_PI_with_threat_data)){
  FirstFound <- nest_data_PI_with_threat_data$FirstFound[i]
  LastPresent <- nest_data_PI_with_threat_data$LastPresent[i]
  LastChecked <- nest_data_PI_with_threat_data$LastChecked[i]
  FirstFound2 <- nest_data_PI_with_threat_data$first_found2[i]
  LastPresent2 <- nest_data_PI_with_threat_data$last_alive2[i]
  LastChecked2 <- nest_data_PI_with_threat_data$last_checked2[i]
  halfway <- (LastChecked - LastPresent)/2
  days_active <- (LastPresent + halfway) - FirstFound
  uncertain_days <- LastChecked - LastPresent
  site_ <- as.character(nest_data_PI_with_threat_data$site[i])
  season_ <- as.character(nest_data_PI_with_threat_data$season[i])
  
  fundays_df <- 
    data.frame(date = seq(from = LastPresent2, to = LastChecked2, 1)) %>% 
    # mutate(weekday = weekdays(dates)) %>% 
    mutate(weekday = factor(as.factor(weekdays(date)), 
                            levels = c("Monday", "Tuesday", "Wednesday", 
                                       "Thursday", "Friday", "Saturday", 
                                       "Sunday")),
           region = "PI") %>% 
    mutate(year = year(date)) %>% 
    mutate(season = ifelse(month(date) < 6, year - 1, year)) %>% 
    mutate(season = ifelse(month(date) >= 6, 
                           paste0(year, substr(year + 1, 3, 4)), 
                           paste0(season, substr(year, 3, 4)))) %>% 
    left_join(., holidays, by = c("region", "season"), relationship = "many-to-many") %>%
    mutate(holiday = ifelse(date >= start_date & date <= end_date, 1, 0)) %>% 
    group_by(region, season, date) %>% 
    mutate(holiday = max(holiday, na.rm = TRUE)) %>% 
    dplyr::select(-c(event, start_date, end_date)) %>% 
    distinct() %>% 
    ungroup() %>% 
    mutate(day_type = ifelse(holiday == 1 | weekday %in% 
                               c("Saturday", "Sunday"), "funday", "workday")) %>% 
    mutate(funday = ifelse(day_type == "funday", 1, 0))
    
  PI_threat_data_subset_ <- 
    PI_threat_data_subset %>% 
    ungroup() %>% 
    # data.frame() %>% 
    # dplyr::filter(as.numeric(obs_date2) >= FirstFound & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    # dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + (LastChecked - LastPresent)) & season == season_) %>%
    dplyr::filter(site == site_)
  
  if(nrow(PI_threat_data_subset_) > 0){
    avgeraged_threats <-
      PI_threat_data_subset_ %>% 
      mutate(hum_bi = ifelse(humans > 0 | (!is.na(hum_pri)), 1, 0),
             vehicle_bi = ifelse(vehicles > 0 | (!is.na(vehicle_pri)), 1, 0),
             dogs_bi = ifelse(dogs > 0 | (!is.na(dog_pri)), 1, 0),
             dogs_off_bi = ifelse(dogs_off > 0, 1, 0),
             dogs_on_bi = ifelse(dogs_on > 0, 1, 0),
             p_birds_bi = ifelse(pred_birds > 0, 1, 0),
             gulls_bi = ifelse(gulls > 0, 1, 0),
             hoof_bi = ifelse(hoofed_animals > 0 | (!is.na(hoofed_pri)), 1, 0)) %>%
      dplyr::summarise(
        # fundays = sum(funday),
        hum_avg = mean(humans, na.rm = TRUE),
        vehicles_avg = mean(vehicles, na.rm = TRUE),
        dogs_avg = mean(dogs, na.rm = TRUE),
        dogs_on_avg = mean(dogs_on, na.rm = TRUE),
        dogs_off_avg = mean(dogs_off, na.rm = TRUE),
        hoof_avg = mean(hoofed_animals, na.rm = TRUE),
        p_birds_avg = mean(pred_birds, na.rm = TRUE),
        gulls_avg = mean(gulls, na.rm = TRUE),
        hum_max = max(humans, na.rm = TRUE),
        vehicles_max = max(vehicles, na.rm = TRUE),
        dogs_max = max(dogs, na.rm = TRUE),
        dogs_on_max = max(dogs_on, na.rm = TRUE),
        dogs_off_max = max(dogs_off, na.rm = TRUE),
        hoof_max = max(hoofed_animals, na.rm = TRUE),
        p_birds_max = max(pred_birds, na.rm = TRUE),
        gulls_max = max(gulls, na.rm = TRUE),
        hum_bi = max(hum_bi, na.rm = TRUE),
        vehicle_bi = max(vehicle_bi, na.rm = TRUE),
        dogs_bi = max(dogs_bi, na.rm = TRUE),
        dogs_on_bi = max(dogs_on_bi, na.rm = TRUE),
        dogs_off_bi = max(dogs_off_bi, na.rm = TRUE),
        p_birds_bi = max(p_birds_bi, na.rm = TRUE),
        gulls_bi = max(gulls_bi, na.rm = TRUE),
        hoof_bi = max(hoof_bi, na.rm = TRUE),
        hum_pr = max(hum_pri, na.rm = TRUE),
        vehicle_pr = max(vehicle_pri, na.rm = TRUE),
        dog_pr = max(dog_pri, na.rm = TRUE),
        hoof_pr = max(hoofed_pri, na.rm = TRUE),
        fox_pr = max(fox_pri, na.rm = TRUE),
        n_surveys = n(),
        days_active = days_active,
        halfway = halfway, 
        uncertain_days = uncertain_days)
    
    nest_data_PI_with_threat_data$fundays[i] <- sum(fundays_df$funday)
    nest_data_PI_with_threat_data$hum_a[i] <- avgeraged_threats$hum_avg
    nest_data_PI_with_threat_data$veh_a[i] <- avgeraged_threats$vehicles_avg
    nest_data_PI_with_threat_data$dog_a[i] <- avgeraged_threats$dogs_avg
    nest_data_PI_with_threat_data$don_a[i] <- avgeraged_threats$dogs_on_avg
    nest_data_PI_with_threat_data$dof_a[i] <- avgeraged_threats$dogs_off_avg
    nest_data_PI_with_threat_data$hof_a[i] <- avgeraged_threats$hoof_avg
    nest_data_PI_with_threat_data$pbd_a[i] <- avgeraged_threats$p_birds_avg
    nest_data_PI_with_threat_data$gul_a[i] <- avgeraged_threats$gulls_avg
    
    nest_data_PI_with_threat_data$hum_m[i] <- avgeraged_threats$hum_max
    nest_data_PI_with_threat_data$veh_m[i] <- avgeraged_threats$vehicles_max
    nest_data_PI_with_threat_data$dog_m[i] <- avgeraged_threats$dogs_max
    nest_data_PI_with_threat_data$don_m[i] <- avgeraged_threats$dogs_on_max
    nest_data_PI_with_threat_data$dof_m[i] <- avgeraged_threats$dogs_off_max
    nest_data_PI_with_threat_data$hof_m[i] <- avgeraged_threats$hoof_max
    nest_data_PI_with_threat_data$pbd_m[i] <- avgeraged_threats$p_birds_max
    nest_data_PI_with_threat_data$gul_m[i] <- avgeraged_threats$gulls_max
    
    nest_data_PI_with_threat_data$hum_b[i] <- avgeraged_threats$hum_bi
    nest_data_PI_with_threat_data$veh_b[i] <- avgeraged_threats$vehicle_bi
    nest_data_PI_with_threat_data$dog_b[i] <- avgeraged_threats$dogs_bi
    nest_data_PI_with_threat_data$don_b[i] <- avgeraged_threats$dogs_on_bi
    nest_data_PI_with_threat_data$dof_b[i] <- avgeraged_threats$dogs_off_bi
    nest_data_PI_with_threat_data$pbd_b[i] <- avgeraged_threats$p_birds_bi
    nest_data_PI_with_threat_data$hof_b[i] <- avgeraged_threats$hoof_bi
    nest_data_PI_with_threat_data$gul_b[i] <- avgeraged_threats$gulls_bi
    
    nest_data_PI_with_threat_data$hum_p[i] <- avgeraged_threats$hum_pr
    nest_data_PI_with_threat_data$veh_p[i] <- avgeraged_threats$vehicle_pr
    nest_data_PI_with_threat_data$dog_p[i] <- avgeraged_threats$dog_pr
    nest_data_PI_with_threat_data$hof_p[i] <- avgeraged_threats$hoof_pr
    nest_data_PI_with_threat_data$fox_p[i] <- avgeraged_threats$fox_pr
    
    nest_data_PI_with_threat_data$n_surveys[i] <- avgeraged_threats$n_surveys
    nest_data_PI_with_threat_data$days_active[i] <- avgeraged_threats$days_active
    nest_data_PI_with_threat_data$halfway[i] <- avgeraged_threats$halfway
    nest_data_PI_with_threat_data$uncertain_days[i] <- avgeraged_threats$uncertain_days
    
  }else{
    nest_data_PI_with_threat_data$hum_a[i] <- NA
    nest_data_PI_with_threat_data$veh_a[i] <- NA
    nest_data_PI_with_threat_data$dog_a[i] <- NA
    nest_data_PI_with_threat_data$don_a[i] <- NA
    nest_data_PI_with_threat_data$dof_a[i] <- NA
    nest_data_PI_with_threat_data$hof_a[i] <- NA
    nest_data_PI_with_threat_data$pbd_a[i] <- NA
    nest_data_PI_with_threat_data$gul_a[i] <- NA
    nest_data_PI_with_threat_data$hum_m[i] <- NA
    nest_data_PI_with_threat_data$veh_m[i] <- NA
    nest_data_PI_with_threat_data$dog_m[i] <- NA
    nest_data_PI_with_threat_data$don_m[i] <- NA
    nest_data_PI_with_threat_data$dof_m[i] <- NA
    nest_data_PI_with_threat_data$hof_m[i] <- NA
    nest_data_PI_with_threat_data$pbd_m[i] <- NA
    nest_data_PI_with_threat_data$gul_m[i] <- NA
    nest_data_PI_with_threat_data$hum_b[i] <- NA
    nest_data_PI_with_threat_data$veh_b[i] <- NA
    nest_data_PI_with_threat_data$dog_b[i] <- NA
    nest_data_PI_with_threat_data$don_b[i] <- NA
    nest_data_PI_with_threat_data$dof_b[i] <- NA
    nest_data_PI_with_threat_data$pbd_b[i] <- NA
    nest_data_PI_with_threat_data$gul_b[i] <- NA
    nest_data_PI_with_threat_data$hof_b[i] <- NA
    nest_data_PI_with_threat_data$hum_p[i] <- NA
    nest_data_PI_with_threat_data$veh_p[i] <- NA
    nest_data_PI_with_threat_data$dog_p[i] <- NA
    nest_data_PI_with_threat_data$hof_p[i] <- NA
    nest_data_PI_with_threat_data$fox_p[i] <- NA
    nest_data_PI_with_threat_data$n_surveys[i] <- 0
    nest_data_PI_with_threat_data$days_active[i] <- days_active
    nest_data_PI_with_threat_data$halfway[i] <- halfway
    nest_data_PI_with_threat_data$uncertain_days[i] <- uncertain_days
    nest_data_PI_with_threat_data$fundays[i] <- NA
  }
}
saveRDS(nest_data_PI_with_threat_data, file = "output/nest_data_PI_with_threat_data.rds")remove outlier data and those with very infrequent threat surveys (cut off: visited at least once per week)
##### remove outlier data and those with very infrequent threat surveys
nest_data_with_threat_data <-
  bind_rows(nest_data_FP_with_threat_data,
            nest_data_MP_with_threat_data,
            nest_data_BSC_with_threat_data,
            nest_data_PI_with_threat_data,
            nest_data_BC_with_threat_data) %>%
  filter(n_surveys > 0) %>% 
  # mutate(dof_b = ifelse(dof_b == 1, "Y", "N")) %>%
  # dplyr::select(-fox_p) %>%
  mutate_at(vars(hum_b, veh_b, dog_b, don_b, dof_b, pbd_b, gul_b, hof_b),
            ~ as.factor(.)) %>% 
  mutate_at(vars(hum_p, veh_p, dog_p, hof_p, fox_p),
            ~ ifelse(is.na(.), 0, .)) 
# nest_data_with_threat_data %>% filter(fundays > 10) %>% dplyr::select(fundays) %>% arrange(desc(fundays))
# nest_data_with_threat_data %>% 
#   filter()
# nest_data_with_threat_data %>% 
#   # filter(fundays <= 25) %>% 
#   ggplot() +
#   geom_histogram(aes(fundays)) +
#   # geom_vline(xintercept = log(10), color = "red") +
#   luke_theme
nest_data_with_threat_data %>% 
  ggplot() +
  geom_histogram(aes(halfway/n_surveys), binwidth = 1) +
  geom_vline(xintercept = 7, color = "red") +
  luke_themenest_data_with_threat_data %>% 
  ggplot() +
  geom_histogram(aes(fundays)) +
  geom_vline(xintercept = 7, color = "red") +
  luke_themenest_data_with_threat_data_7d <- 
  nest_data_with_threat_data %>% 
  filter(halfway/n_surveys <= 7)
# nest_data_with_threat_data
#### check variable distributions and collinearity ----
# determine the 99% quantile limit for each threat (i.e., to remove outlier data)
threat_data_99_ql_ <- 
  nest_data_with_threat_data_7d %>% 
  summarise_at(c("hum_a", "pbd_a", "gul_a", "veh_a", "dog_a", "don_a", "dof_a", 
                 "hum_m", "pbd_m", "gul_m", "veh_m", "dog_m", "don_m", "dof_m",
                 "hum_p", "veh_p", "dog_p", "hof_p", "fox_p"), 
               ~ quantile(.x, probs = c(0.99)))
nest_data_with_threat_data_7d %>% 
  filter(hum_a <= ceiling(as.numeric(threat_data_99_ql_$hum_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(hum_a), binwidth = 5) +
  luke_theme +
  xlab("average number of humans counted in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(veh_a <= ceiling(as.numeric(threat_data_99_ql_$veh_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(veh_a), binwidth = 1) +
  luke_theme +
  xlab("average number of vehicles counted in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(dog_a <= ceiling(as.numeric(threat_data_99_ql_$dog_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(dog_a), binwidth = 1) +
  luke_theme +
  xlab("average number of dogs counted in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(don_a <= ceiling(as.numeric(threat_data_99_ql_$don_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(don_a), binwidth = 1) +
  luke_theme +
  xlab("average number of dogs on leashes counted in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$dof_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(dof_a), binwidth = 1) +
  luke_theme +
  xlab("average number of dogs off leashes counted in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$pbd_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(pbd_a), binwidth = 1) +
  luke_theme +
  xlab("average number of corvids counted in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$gul_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(gul_a), binwidth = 1) +
  luke_theme +
  xlab("average number of gulls counted in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(hum_m <= ceiling(as.numeric(threat_data_99_ql_$hum_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(hum_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of humans counted in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(veh_m <= ceiling(as.numeric(threat_data_99_ql_$veh_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(veh_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of vehicles counted in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(dog_m <= ceiling(as.numeric(threat_data_99_ql_$dog_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(dog_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of dogs counted in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(don_m <= ceiling(as.numeric(threat_data_99_ql_$don_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(don_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of dogs on leashes counted in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(dof_m <= ceiling(as.numeric(threat_data_99_ql_$dof_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(dof_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of dogs off leashes counted in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$pbd_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(pbd_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of corvids counted in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$gul_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(gul_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of gulls counted in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(hum_p <= ceiling(as.numeric(threat_data_99_ql_$hum_p[1]))) %>% 
  ggplot() +
  geom_histogram(aes(hum_p), binwidth = 1) +
  luke_theme +
  xlab("maximum human print level detected in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(veh_p < ceiling(as.numeric(threat_data_99_ql_$veh_p[1]))) %>% 
  ggplot() +
  geom_histogram(aes(veh_p), binwidth = 1) +
  luke_theme +
  xlab("maximum vehicle print level detected in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(dog_p <= ceiling(as.numeric(threat_data_99_ql_$dog_p[1]))) %>% 
  ggplot() +
  geom_histogram(aes(dog_p), binwidth = 1) +
  luke_theme +
  xlab("maximum dog print level detected in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(hof_p <= ceiling(as.numeric(threat_data_99_ql_$hof_p[1]))) %>% 
  ggplot() +
  geom_histogram(aes(hof_p), binwidth = 1) +
  luke_theme +
  xlab("maximum hooved print level detected in territory during active nest")nest_data_with_threat_data_7d %>% 
  filter(fox_p <= ceiling(as.numeric(threat_data_99_ql_$fox_p[1]))) %>% 
  ggplot() +
  geom_histogram(aes(fox_p), binwidth = 1) +
  luke_theme +
  xlab("maximum fox print level detected in territory during active nest")nest_data_with_threat_data_7d_ <- 
  nest_data_with_threat_data_7d %>% 
  filter(fox_p <= ceiling(as.numeric(threat_data_99_ql_$fox_p[1]))) %>% 
  filter(hum_a <= ceiling(as.numeric(threat_data_99_ql_$hum_a[1]))) %>% 
  filter(veh_a <= ceiling(as.numeric(threat_data_99_ql_$veh_a[1]))) %>% 
  filter(dog_a <= ceiling(as.numeric(threat_data_99_ql_$dog_a[1]))) %>% 
  filter(don_a <= ceiling(as.numeric(threat_data_99_ql_$don_a[1]))) %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$dof_a[1]))) %>% 
  filter(pbd_a <= ceiling(as.numeric(threat_data_99_ql_$pbd_a[1]))) %>% 
  filter(gul_a <= ceiling(as.numeric(threat_data_99_ql_$gul_a[1]))) %>% 
  filter(hum_m <= ceiling(as.numeric(threat_data_99_ql_$hum_m[1]))) %>% 
  filter(veh_m <= ceiling(as.numeric(threat_data_99_ql_$veh_m[1]))) %>% 
  filter(dog_m <= ceiling(as.numeric(threat_data_99_ql_$dog_m[1]))) %>% 
  filter(don_m <= ceiling(as.numeric(threat_data_99_ql_$don_m[1]))) %>% 
  filter(dof_m <= ceiling(as.numeric(threat_data_99_ql_$dof_m[1]))) %>%
  filter(pbd_m <= ceiling(as.numeric(threat_data_99_ql_$pbd_m[1]))) %>% 
  filter(gul_m <= ceiling(as.numeric(threat_data_99_ql_$gul_m[1]))) %>% 
  filter(hum_p <= ceiling(as.numeric(threat_data_99_ql_$hum_p[1]))) %>% 
  filter(veh_p <= ceiling(as.numeric(threat_data_99_ql_$veh_p[1]))) %>% 
  filter(dog_p <= ceiling(as.numeric(threat_data_99_ql_$dog_p[1]))) %>% 
  filter(hof_p <= ceiling(as.numeric(threat_data_99_ql_$hof_p[1]))) %>%
  mutate(fox_p = ifelse(is.infinite(fox_p), 0, fox_p) %>% as.factor())write.csv(nest_data_with_threat_data_7d_, "data/nest_data_with_threat_data_7d_01102025.csv")Number of nests
nest_data_with_threat_data_7d_ %>%
  summarise(n_obs = n())# A tibble: 1 × 1
  n_obs
  <int>
1  2956Number of nests at each region
nest_data_with_threat_data_7d_ %>% 
  group_by(region) %>% 
  summarise(n_obs = n())# A tibble: 5 × 2
  region n_obs
  <chr>  <int>
1 BC       604
2 BSC      453
3 FP       666
4 MP       917
5 PI       316Number of nests at each region for each year
nest_data_with_threat_data_7d_ %>% 
  group_by(region, season) %>% 
  summarise(n_obs = n()) %>% 
  pivot_wider(names_from = region, values_from = n_obs) %>% 
  mutate(season = as.numeric(as.character(season))) %>% 
  arrange(season)# A tibble: 19 × 6
   season    BC   BSC    FP    MP    PI
    <dbl> <int> <int> <int> <int> <int>
 1 200607    11     9    NA    14    NA
 2 200708     9     9    NA    19    NA
 3 200809     5     7    NA     9    NA
 4 200910     1     7     6    15    NA
 5 201011     3    13    21    22    NA
 6 201112     8    27    10    40    NA
 7 201213     5    17    12    45    14
 8 201314    14    10    19    45     6
 9 201415    29    15    23    59    17
10 201516    51    22    27    72    21
11 201617    49    43    42    87    29
12 201718    60    38    45    64    32
13 201819    43    33    60    59    33
14 201920    38    42    68    55    34
15 202021    57    48    75    75    38
16 202122    42    29    72    85    24
17 202223    60    27    82    76    28
18 202324    57    31   104    76    15
19 202425    62    26    NA    NA    25Number of nests at each region in each management level
nest_data_with_threat_data_7d_ %>% 
  group_by(region, level) %>% 
  summarise(n_obs = n()) %>% 
  pivot_wider(names_from = region, values_from = n_obs) # A tibble: 5 × 6
  level    BC   BSC    FP    MP    PI
  <fct> <int> <int> <int> <int> <int>
1 L0      162    24   136   169    46
2 L1       37    38    50    70    14
3 L2       19    73    22    84     8
4 L3      386   314   444   591   246
5 L4       NA     4    14     3     2Number of nests at each region in each management status
nest_data_with_threat_data_7d_ %>% 
  group_by(region, status) %>% 
  summarise(n_obs = n()) %>% 
  pivot_wider(names_from = region, values_from = n_obs) # A tibble: 2 × 6
  status    BC   BSC    FP    MP    PI
  <fct>  <int> <int> <int> <int> <int>
1 N        162    60   155   230    46
2 Y        442   393   511   687   270nest_data_with_threat_data_7d_ <- 
  read.csv("data/nest_data_with_threat_data_7d_01102025.csv") %>% 
  mutate(season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         status = as.factor(status),
         level = as.factor(level))occ_FP <- 
  nest_data_with_threat_data_7d_ %>% 
  filter(region == "FP") %>% 
  pull(LastChecked) %>% 
  max(., na.rm = TRUE)
occ_MP <- 
  nest_data_with_threat_data_7d_ %>% 
  filter(region == "MP") %>% 
  pull(LastChecked) %>% 
  max(., na.rm = TRUE)
occ_BSC <- 
  nest_data_with_threat_data_7d_ %>% 
  filter(region == "BSC") %>% 
  pull(LastChecked) %>% 
  max(., na.rm = TRUE)
occ_BC <- 
  nest_data_with_threat_data_7d_ %>% 
  filter(region == "BC") %>% 
  pull(LastChecked) %>% 
  max(., na.rm = TRUE)
occ_PI <- 
  nest_data_with_threat_data_7d_ %>% 
  filter(region == "PI") %>% 
  pull(LastChecked) %>% 
  max(., na.rm = TRUE)
# create processed RMARK data format as NestSurvival with Year as group
nest_data.processed_FP_5d <- 
  RMark::process.data(nest_data_with_threat_data_7d_ %>% 
                        filter(region == "FP"), 
                      model = "Nest",
                      nocc = occ_FP, groups = c("season", 
                                                "nest_hab", 
                                                "status",
                                                # "site"
                                                # "fox_p", 
                                                "level"))
nest_data.processed_MP_5d <- 
  RMark::process.data(nest_data_with_threat_data_7d_ %>% 
                        filter(region == "MP"), 
                      model = "Nest",
                      nocc = occ_MP, groups = c("season", 
                                                "nest_hab", 
                                                "status",
                                                # "site",
                                                # "fox_p", 
                                                "level"))
nest_data.processed_BC_5d <- 
  RMark::process.data(nest_data_with_threat_data_7d_ %>% 
                        filter(region == "BC"), 
                      model = "Nest",
                      nocc = occ_BC, groups = c("season", 
                                                "nest_hab", 
                                                "status",
                                                # "site",
                                                # "fox_p", 
                                                "level"))
nest_data.processed_BSC_5d <- 
  RMark::process.data(nest_data_with_threat_data_7d_ %>% 
                        filter(region == "BSC"), 
                      model = "Nest",
                      nocc = occ_BSC, groups = c("season", 
                                                "nest_hab", 
                                                "status",
                                                # "site",
                                                # "fox_p", 
                                                "level"))
nest_data.processed_PI_5d <- 
  RMark::process.data(nest_data_with_threat_data_7d_ %>% 
                        filter(region == "PI"), 
                      model = "Nest",
                      nocc = occ_PI, groups = c("season", 
                                                "nest_hab", 
                                                "status",
                                                # "site",
                                                # "fox_p", 
                                                "level"))
# create the design data
nest_fate.ddl_FP_5d <- RMark::make.design.data(nest_data.processed_FP_5d)
nest_fate.ddl_MP_5d <- RMark::make.design.data(nest_data.processed_MP_5d)
nest_fate.ddl_BSC_5d <- RMark::make.design.data(nest_data.processed_BSC_5d)
nest_fate.ddl_BC_5d <- RMark::make.design.data(nest_data.processed_BC_5d)
nest_fate.ddl_PI_5d <- RMark::make.design.data(nest_data.processed_PI_5d)
# add a new variable to the design data that is the quadratic transformation of
# time
time <- c(0:(occ_FP-1))
Cubic <- time^3
Quadratic <- time^2
quad_time <- data.frame(time, Quadratic, Cubic)
quad_time$time <- c(1:occ_FP)
nest_fate.ddl_FP_5d$S <- 
  RMark::merge_design.covariates(nest_fate.ddl_FP_5d$S, quad_time, 
                                 bygroup = FALSE, bytime = TRUE)
time <- c(0:(occ_MP-1))
Cubic <- time^3
Quadratic <- time^2
quad_time <- data.frame(time, Quadratic, Cubic)
quad_time$time <- c(1:occ_MP)
nest_fate.ddl_MP_5d$S <- 
  RMark::merge_design.covariates(nest_fate.ddl_MP_5d$S, quad_time, 
                                 bygroup = FALSE, bytime = TRUE)
time <- c(0:(occ_BC-1))
Cubic <- time^3
Quadratic <- time^2
quad_time <- data.frame(time, Quadratic, Cubic)
quad_time$time <- c(1:occ_BC)
nest_fate.ddl_BC_5d$S <- 
  RMark::merge_design.covariates(nest_fate.ddl_BC_5d$S, quad_time, 
                                 bygroup = FALSE, bytime = TRUE)
time <- c(0:(occ_BSC-1))
Cubic <- time^3
Quadratic <- time^2
quad_time <- data.frame(time, Quadratic, Cubic)
quad_time$time <- c(1:occ_BSC)
nest_fate.ddl_BSC_5d$S <- 
  RMark::merge_design.covariates(nest_fate.ddl_BSC_5d$S, quad_time, 
                                 bygroup = FALSE, bytime = TRUE)
time <- c(0:(occ_PI-1))
Cubic <- time^3
Quadratic <- time^2
quad_time <- data.frame(time, Quadratic, Cubic)
quad_time$time <- c(1:occ_PI)
nest_fate.ddl_PI_5d$S <- 
  RMark::merge_design.covariates(nest_fate.ddl_PI_5d$S, quad_time, 
                                 bygroup = FALSE, bytime = TRUE)
# nest_fate.ddl$S <- 
#   RMark::merge_design.covariates(nest_fate.ddl$S, data.frame(management_level = c(0, 1, 2, 3, 4)), 
#                                  bygroup = FALSE, bytime = FALSE)
# nest_fate.ddl$S <-
#   inner_join(nest_fate.ddl$S, int_threat_data, by = c("site", "time"))
RMark_data_FP <- 
  list(nest_data.processed = nest_data.processed_FP_5d, 
       nest_fate.ddl = nest_fate.ddl_FP_5d)
RMark_data_MP <- 
  list(nest_data.processed = nest_data.processed_MP_5d, 
       nest_fate.ddl = nest_fate.ddl_MP_5d)
RMark_data_BC <- 
  list(nest_data.processed = nest_data.processed_BC_5d, 
       nest_fate.ddl = nest_fate.ddl_BC_5d)
RMark_data_BSC <- 
  list(nest_data.processed = nest_data.processed_BSC_5d, 
       nest_fate.ddl = nest_fate.ddl_BSC_5d)
RMark_data_PI <- 
  list(nest_data.processed = nest_data.processed_PI_5d, 
       nest_fate.ddl = nest_fate.ddl_PI_5d)
# RMark_data_FP$nest_data.processed$data %>% summary()
# RMark_data_MP$nest_data.processed$data %>% summary()
# RMark_data_BC$nest_data.processed$data %>% summary()
# RMark_data_BSC$nest_data.processed$data %>% summary()
# RMark_data_PI$nest_data.processed$data %>% summary()nest_survival_FP <- function()
{
  # Specify models to test
  
  # constant daily survival rate (DSR)
  S.dot <- 
    list(formula = ~1)
  
  # fox print status
  # S.fox_p <-
  #   list(formula = ~fox_p)
  
  #### maximum counts of threats
  # max humans detected
  S.hum_m <-
    list(formula = ~hum_m)
  
  # max vehicles detected
  S.veh_m <-
    list(formula = ~veh_m)
  
  # max dogs detected
  S.dog_m <-
    list(formula = ~dog_m)
  
  # max dogs off leash detected
  S.dof_m <-
    list(formula = ~dof_m)
  
  # max corvids detected
  S.pbd_m <-
    list(formula = ~pbd_m)
  
  # max gulls detected
  S.gul_m <-
    list(formula = ~gul_m)
  
  #### interaction of max threat counts and management status 
  # max humans detected
  S.hum_m_x_status <-
    list(formula = ~hum_m * status)
  
  # max vehicles detected and management status
  S.veh_m_x_status <-
    list(formula = ~veh_m * status)
  
  # max dogs detected and management status
  S.dog_m_x_status <-
    list(formula = ~dog_m * status)
  
  # max dogs off leash detected and management status
  S.dof_m_x_status <-
    list(formula = ~dof_m * status)
  
  # max corvids detected and management status
  S.pbd_m_x_status <-
    list(formula = ~pbd_m * status)
  
  # max gulls detected and management status
  S.gul_m_x_status <-
    list(formula = ~gul_m * status)
  
  # specify to run as a nest survival model in program MARK
  cml <- RMark::create.model.list("Nest")
  
  # run model list in MARK. Supress generation of MARK files.
  model.list <- RMark::mark.wrapper(cml,
                                    data = RMark_data_FP$nest_data.processed, 
                                    ddl = RMark_data_FP$nest_fate.ddl,
                                    threads = 4, 
                                    brief = TRUE, 
                                    delete = TRUE) 
  
  # store completed model list
  return(model.list)
}
nest_survival_run_FP <- nest_survival_FP()
nest_survival_run_FP
nest_survival_FP <- 
  list(RMark_data = RMark_data_FP, 
       model_selection = nest_survival_run_FP)
saveRDS(nest_survival_FP, file = "output/nest_survival_FP_threats&status_011025.rds")nest_survival_MP <- function()
{
  # Specify models to test
  
  # constant daily survival rate (DSR)
  S.dot <- 
    list(formula = ~1)
  
  # fox print status
  # S.fox_p <-
  #   list(formula = ~fox_p)
  
  #### maximum counts of threats
  # max humans detected
  S.hum_m <-
    list(formula = ~hum_m)
  
  # max vehicles detected
  # S.veh_m <-
  #   list(formula = ~veh_m)
  
  # max dogs detected
  S.dog_m <-
    list(formula = ~dog_m)
  
  # max dogs off leash detected
  S.dof_m <-
    list(formula = ~dof_m)
  
  # max corvids detected
  S.pbd_m <-
    list(formula = ~pbd_m)
  
  # max gulls detected
  S.gul_m <-
    list(formula = ~gul_m)
  
  #### interaction of max threat counts and management status 
  # max humans detected
  S.hum_m_x_status <-
    list(formula = ~hum_m * status)
  
  # max vehicles detected and management status
  # S.veh_m_x_status <-
  #   list(formula = ~veh_m * status)
  
  # max dogs detected and management status
  S.dog_m_x_status <-
    list(formula = ~dog_m * status)
  
  # max dogs off leash detected and management status
  S.dof_m_x_status <-
    list(formula = ~dof_m * status)
  
  # max corvids detected and management status
  S.pbd_m_x_status <-
    list(formula = ~pbd_m * status)
  
  # max gulls detected and management status
  S.gul_m_x_status <-
    list(formula = ~gul_m * status)
  
  # specify to run as a nest survival model in program MARK
  cml <- RMark::create.model.list("Nest")
  
  # run model list in MARK. Supress generation of MARK files.
  model.list <- RMark::mark.wrapper(cml,
                                    data = RMark_data_MP$nest_data.processed, 
                                    ddl = RMark_data_MP$nest_fate.ddl,
                                    threads = 4, 
                                    brief = TRUE, 
                                    delete = TRUE) 
  
  # store completed model list
  return(model.list)
}
nest_survival_run_MP <- nest_survival_MP()
nest_survival_run_MP
nest_survival_MP <- 
  list(RMark_data = RMark_data_MP, 
       model_selection = nest_survival_run_MP)
saveRDS(nest_survival_MP, file = "output/nest_survival_MP_threats&status_011025.rds")nest_survival_BSC <- function()
{
  # Specify models to test
  
  # constant daily survival rate (DSR)
  S.dot <- 
    list(formula = ~1)
  
  # fox print status
  # S.fox_p <-
  #   list(formula = ~fox_p)
  
  #### maximum counts of threats
  # max humans detected
  S.hum_m <-
    list(formula = ~hum_m)
  
  # max vehicles detected
  # S.veh_m <-
  #   list(formula = ~veh_m)
  
  # max dogs detected
  S.dog_m <-
    list(formula = ~dog_m)
  
  # max dogs off leash detected
  S.dof_m <-
    list(formula = ~dof_m)
  
  # max corvids detected
  S.pbd_m <-
    list(formula = ~pbd_m)
  
  # max gulls detected
  S.gul_m <-
    list(formula = ~gul_m)
  
  #### interaction of max threat counts and management status 
  # max humans detected
  S.hum_m_x_status <-
    list(formula = ~hum_m * status)
  
  # max vehicles detected and management status
  # S.veh_m_x_status <-
  #   list(formula = ~veh_m * status)
  
  # max dogs detected and management status
  S.dog_m_x_status <-
    list(formula = ~dog_m * status)
  
  # max dogs off leash detected and management status
  S.dof_m_x_status <-
    list(formula = ~dof_m * status)
  
  # max corvids detected and management status
  S.pbd_m_x_status <-
    list(formula = ~pbd_m * status)
  
  # max gulls detected and management status
  S.gul_m_x_status <-
    list(formula = ~gul_m * status)
  
  # specify to run as a nest survival model in program MARK
  cml <- RMark::create.model.list("Nest")
  
  # run model list in MARK. Supress generation of MARK files.
  model.list <- RMark::mark.wrapper(cml,
                                    data = RMark_data_BSC$nest_data.processed, 
                                    ddl = RMark_data_BSC$nest_fate.ddl,
                                    threads = 4, 
                                    brief = TRUE, 
                                    delete = TRUE) 
  
  # store completed model list
  return(model.list)
}
nest_survival_run_BSC <- nest_survival_BSC()
nest_survival_run_BSC
nest_survival_BSC <- 
  list(RMark_data = RMark_data_BSC, 
       model_selection = nest_survival_run_BSC)
saveRDS(nest_survival_BSC, file = "output/nest_survival_BSC_threats&status_011025.rds")nest_survival_BC <- function()
{
  # Specify models to test
  
  # constant daily survival rate (DSR)
  S.dot <- 
    list(formula = ~1)
  
  # fox print status
  # S.fox_p <-
  #   list(formula = ~fox_p)
  
  #### maximum counts of threats
  # max humans detected
  S.hum_m <-
    list(formula = ~hum_m)
  
  # max vehicles detected
  # S.veh_m <-
  #   list(formula = ~veh_m)
  
  # max dogs detected
  S.dog_m <-
    list(formula = ~dog_m)
  
  # max dogs off leash detected
  S.dof_m <-
    list(formula = ~dof_m)
  
  # max corvids detected
  S.pbd_m <-
    list(formula = ~pbd_m)
  
  # max gulls detected
  S.gul_m <-
    list(formula = ~gul_m)
  
  #### interaction of max threat counts and management status 
  # max humans detected
  S.hum_m_x_status <-
    list(formula = ~hum_m * status)
  
  # max vehicles detected and management status
  # S.veh_m_x_status <-
  #   list(formula = ~veh_m * status)
  
  # max dogs detected and management status
  S.dog_m_x_status <-
    list(formula = ~dog_m * status)
  
  # max dogs off leash detected and management status
  S.dof_m_x_status <-
    list(formula = ~dof_m * status)
  
  # max corvids detected and management status
  S.pbd_m_x_status <-
    list(formula = ~pbd_m * status)
  
  # max gulls detected and management status
  S.gul_m_x_status <-
    list(formula = ~gul_m * status)
  
  # specify to run as a nest survival model in program MARK
  cml <- RMark::create.model.list("Nest")
  
  # run model list in MARK. Supress generation of MARK files.
  model.list <- RMark::mark.wrapper(cml,
                                    data = RMark_data_BC$nest_data.processed, 
                                    ddl = RMark_data_BC$nest_fate.ddl,
                                    threads = 4, 
                                    brief = TRUE, 
                                    delete = TRUE) 
  
  # store completed model list
  return(model.list)
}
nest_survival_run_BC <- nest_survival_BC()
nest_survival_run_BC
nest_survival_BC <- 
  list(RMark_data = RMark_data_BC, 
       model_selection = nest_survival_run_BC)
saveRDS(nest_survival_BC, file = "output/nest_survival_BC_threats&status_011025.rds")nest_survival_PI <- function()
{
  # Specify models to test
  
  # constant daily survival rate (DSR)
  S.dot <- 
    list(formula = ~1)
  
  # fox print status
  # S.fox_p <-
  #   list(formula = ~fox_p)
  
  #### maximum counts of threats
  # max humans detected
  S.hum_m <-
    list(formula = ~hum_m)
  
  # max vehicles detected
  # S.veh_m <-
  #   list(formula = ~veh_m)
  
  # max dogs detected
  S.dog_m <-
    list(formula = ~dog_m)
  
  # max dogs off leash detected
  S.dof_m <-
    list(formula = ~dof_m)
  
  # max corvids detected
  S.pbd_m <-
    list(formula = ~pbd_m)
  
  # max gulls detected
  S.gul_m <-
    list(formula = ~gul_m)
  
  #### interaction of max threat counts and management status 
  # max humans detected
  S.hum_m_x_status <-
    list(formula = ~hum_m * status)
  
  # max vehicles detected and management status
  # S.veh_m_x_status <-
  #   list(formula = ~veh_m * status)
  
  # max dogs detected and management status
  S.dog_m_x_status <-
    list(formula = ~dog_m * status)
  
  # max dogs off leash detected and management status
  S.dof_m_x_status <-
    list(formula = ~dof_m * status)
  
  # max corvids detected and management status
  S.pbd_m_x_status <-
    list(formula = ~pbd_m * status)
  
  # max gulls detected and management status
  S.gul_m_x_status <-
    list(formula = ~gul_m * status)
  
  # specify to run as a nest survival model in program MARK
  cml <- RMark::create.model.list("Nest")
  
  # run model list in MARK. Supress generation of MARK files.
  model.list <- RMark::mark.wrapper(cml,
                                    data = RMark_data_PI$nest_data.processed, 
                                    ddl = RMark_data_PI$nest_fate.ddl,
                                    threads = 4, 
                                    brief = TRUE, 
                                    delete = TRUE) 
  
  # store completed model list
  return(model.list)
}
nest_survival_run_PI <- nest_survival_PI()
nest_survival_run_PI
nest_survival_PI <- 
  list(RMark_data = RMark_data_PI, 
       model_selection = nest_survival_run_PI)
saveRDS(nest_survival_PI, file = "output/nest_survival_PI_threats&status_011025.rds")model selection results
nest_survival_FP <- readRDS(file = "output/nest_survival_FP_threats&status_011025.rds")
nest_survival_run_FP <- nest_survival_FP$model_selection
nest_survival_run_FP$model.table %>% 
  dplyr::select(model, npar, DeltaAICc, weight) %>% 
  gt() %>% 
  cols_label(model = html("<i>Fleurieu Peninsula</i>"),
             npar = "K",
             DeltaAICc = "DeltaAICc",
             weight = "weight") %>% 
  fmt_number(columns = DeltaAICc,
             rows = 1:10,
             decimals = 2,
             use_seps = FALSE) %>% 
  fmt_number(columns = weight,
             rows = 1:10,
             decimals = 3,
             use_seps = FALSE) %>% 
  cols_align(align = "left",
             columns = vars(model)) %>% 
  tab_options(row_group.font.weight = "bold",
              row_group.background.color = brewer.pal(9,"Greys")[3],
              table.font.size = 12,
              data_row.padding = 3,
              row_group.padding = 4,
              summary_row.padding = 2,
              column_labels.font.size = 14,
              row_group.font.size = 12,
              table.width = pct(80))| Fleurieu Peninsula | K | DeltaAICc | weight | 
|---|---|---|---|
| S(~pbd_m * status) | 4 | 0.00 | 0.823 | 
| S(~gul_m * status) | 4 | 3.11 | 0.174 | 
| S(~dof_m * status) | 4 | 12.00 | 0.002 | 
| S(~dog_m * status) | 4 | 13.16 | 0.001 | 
| S(~veh_m * status) | 4 | 17.65 | 0.000 | 
| S(~hum_m * status) | 4 | 17.81 | 0.000 | 
| S(~pbd_m) | 2 | 86.78 | 0.000 | 
| S(~gul_m) | 2 | 116.36 | 0.000 | 
| S(~1) | 1 | 116.96 | 0.000 | 
| S(~dog_m) | 2 | 117.50 | 0.000 | 
| S(~dof_m) | 2 | 118.3299 | 0 | 
| S(~veh_m) | 2 | 118.7142 | 0 | 
| S(~hum_m) | 2 | 118.8322 | 0 | 
nest_survival_MP <- readRDS(file = "output/nest_survival_MP_threats&status_011025.rds")
nest_survival_run_MP <- nest_survival_MP$model_selection
nest_survival_run_MP$model.table %>% 
  dplyr::select(model, npar, DeltaAICc, weight) %>% 
  gt() %>% 
  cols_label(model = html("<i>Mornington Peninsula</i>"),
             npar = "K",
             DeltaAICc = "DeltaAICc",
             weight = "weight") %>% 
  fmt_number(columns = DeltaAICc,
             rows = 1:10,
             decimals = 2,
             use_seps = FALSE) %>% 
  fmt_number(columns = weight,
             rows = 1:10,
             decimals = 3,
             use_seps = FALSE) %>% 
  cols_align(align = "left",
             columns = vars(model)) %>% 
  tab_options(row_group.font.weight = "bold",
              row_group.background.color = brewer.pal(9,"Greys")[3],
              table.font.size = 12,
              data_row.padding = 3,
              row_group.padding = 4,
              summary_row.padding = 2,
              column_labels.font.size = 14,
              row_group.font.size = 12,
              table.width = pct(80))| Mornington Peninsula | K | DeltaAICc | weight | 
|---|---|---|---|
| S(~gul_m * status) | 4 | 0.00 | 0.967 | 
| S(~pbd_m * status) | 4 | 9.01 | 0.011 | 
| S(~hum_m * status) | 4 | 9.06 | 0.010 | 
| S(~dof_m * status) | 4 | 9.80 | 0.007 | 
| S(~dog_m * status) | 4 | 10.76 | 0.004 | 
| S(~gul_m) | 2 | 21.55 | 0.000 | 
| S(~pbd_m) | 2 | 29.14 | 0.000 | 
| S(~hum_m) | 2 | 30.75 | 0.000 | 
| S(~1) | 1 | 31.15 | 0.000 | 
| S(~dof_m) | 2 | 31.52 | 0.000 | 
| S(~dog_m) | 2 | 31.6885 | 1.271944e-07 | 
nest_survival_BSC <- readRDS(file = "output/nest_survival_BSC_threats&status_011025.rds")
nest_survival_run_BSC <- nest_survival_BSC$model_selection
nest_survival_run_BSC$model.table %>% 
  dplyr::select(model, npar, DeltaAICc, weight) %>% 
  gt() %>% 
  cols_label(model = html("<i>Bellarine / Surf Coast</i>"),
             npar = "K",
             DeltaAICc = "DeltaAICc",
             weight = "weight") %>% 
  fmt_number(columns = DeltaAICc,
             rows = 1:10,
             decimals = 2,
             use_seps = FALSE) %>% 
  fmt_number(columns = weight,
             rows = 1:10,
             decimals = 3,
             use_seps = FALSE) %>% 
  cols_align(align = "left",
             columns = vars(model)) %>% 
  tab_options(row_group.font.weight = "bold",
              row_group.background.color = brewer.pal(9,"Greys")[3],
              table.font.size = 12,
              data_row.padding = 3,
              row_group.padding = 4,
              summary_row.padding = 2,
              column_labels.font.size = 14,
              row_group.font.size = 12,
              table.width = pct(80))| Bellarine / Surf Coast | K | DeltaAICc | weight | 
|---|---|---|---|
| S(~dof_m * status) | 4 | 0.00 | 0.553 | 
| S(~pbd_m * status) | 4 | 2.64 | 0.147 | 
| S(~gul_m * status) | 4 | 3.15 | 0.115 | 
| S(~dog_m * status) | 4 | 3.36 | 0.103 | 
| S(~hum_m * status) | 4 | 3.83 | 0.081 | 
| S(~1) | 1 | 40.49 | 0.000 | 
| S(~dof_m) | 2 | 40.71 | 0.000 | 
| S(~pbd_m) | 2 | 40.96 | 0.000 | 
| S(~gul_m) | 2 | 41.21 | 0.000 | 
| S(~dog_m) | 2 | 42.05 | 0.000 | 
| S(~hum_m) | 2 | 42.47748 | 3.304073e-10 | 
nest_survival_BC <- readRDS(file = "output/nest_survival_BC_threats&status_011025.rds")
nest_survival_run_BC <- nest_survival_BC$model_selection
nest_survival_run_BC$model.table %>% 
  dplyr::select(model, npar, DeltaAICc, weight) %>% 
  gt() %>% 
  cols_label(model = html("<i>Bellarine / Surf Coast</i>"),
             npar = "K",
             DeltaAICc = "DeltaAICc",
             weight = "weight") %>% 
  fmt_number(columns = DeltaAICc,
             rows = 1:10,
             decimals = 2,
             use_seps = FALSE) %>% 
  fmt_number(columns = weight,
             rows = 1:10,
             decimals = 3,
             use_seps = FALSE) %>% 
  cols_align(align = "left",
             columns = vars(model)) %>% 
  tab_options(row_group.font.weight = "bold",
              row_group.background.color = brewer.pal(9,"Greys")[3],
              table.font.size = 12,
              data_row.padding = 3,
              row_group.padding = 4,
              summary_row.padding = 2,
              column_labels.font.size = 14,
              row_group.font.size = 12,
              table.width = pct(80))| Bellarine / Surf Coast | K | DeltaAICc | weight | 
|---|---|---|---|
| S(~pbd_m * status) | 4 | 0.00 | 0.574 | 
| S(~dog_m * status) | 4 | 1.59 | 0.259 | 
| S(~dof_m * status) | 4 | 4.36 | 0.065 | 
| S(~gul_m * status) | 4 | 4.87 | 0.050 | 
| S(~hum_m * status) | 4 | 5.07 | 0.045 | 
| S(~pbd_m) | 2 | 9.70 | 0.004 | 
| S(~1) | 1 | 13.98 | 0.001 | 
| S(~dog_m) | 2 | 14.56 | 0.000 | 
| S(~gul_m) | 2 | 15.61 | 0.000 | 
| S(~dof_m) | 2 | 15.80 | 0.000 | 
| S(~hum_m) | 2 | 15.90069 | 0.0002023696 | 
nest_survival_PI <- readRDS(file = "output/nest_survival_PI_threats&status_011025.rds")
nest_survival_run_PI <- nest_survival_PI$model_selection
nest_survival_run_PI$model.table %>% 
  dplyr::select(model, npar, DeltaAICc, weight) %>% 
  gt() %>% 
  cols_label(model = html("<i>Phillip Island</i>"),
             npar = "K",
             DeltaAICc = "DeltaAICc",
             weight = "weight") %>% 
  fmt_number(columns = DeltaAICc,
             rows = 1:10,
             decimals = 2,
             use_seps = FALSE) %>% 
  fmt_number(columns = weight,
             rows = 1:10,
             decimals = 3,
             use_seps = FALSE) %>% 
  cols_align(align = "left",
             columns = vars(model)) %>% 
  tab_options(row_group.font.weight = "bold",
              row_group.background.color = brewer.pal(9,"Greys")[3],
              table.font.size = 12,
              data_row.padding = 3,
              row_group.padding = 4,
              summary_row.padding = 2,
              column_labels.font.size = 14,
              row_group.font.size = 12,
              table.width = pct(80))| Phillip Island | K | DeltaAICc | weight | 
|---|---|---|---|
| S(~pbd_m * status) | 4 | 0.00 | 0.965 | 
| S(~dog_m * status) | 4 | 6.98 | 0.029 | 
| S(~dof_m * status) | 4 | 10.35 | 0.005 | 
| S(~gul_m * status) | 4 | 16.53 | 0.000 | 
| S(~hum_m * status) | 4 | 18.04 | 0.000 | 
| S(~pbd_m) | 2 | 21.58 | 0.000 | 
| S(~gul_m) | 2 | 43.55 | 0.000 | 
| S(~1) | 1 | 43.71 | 0.000 | 
| S(~dog_m) | 2 | 44.71 | 0.000 | 
| S(~dof_m) | 2 | 44.82 | 0.000 | 
| S(~hum_m) | 2 | 45.59224 | 1.213902e-10 | 
S.fundays <- 
  mark(data = RMark_data_FP$nest_data.processed, 
       ddl = RMark_data_FP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ fundays)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~fundays)  npar= 2  lnl =  2615.6245 AICc = 2619.6258min.fundays = min(RMark_data_FP$nest_data.processed$data$fundays)
max.fundays = max(RMark_data_FP$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays, to = max.fundays, length = 100)
pred.fundays <- 
  covariate.predictions(model = S.fundays, 
                        data = data.frame(fundays = fundays.values),
                        indices = 1)
pred.fundays_FP <- 
  pred.fundays$estimates %>% 
  mutate(region = "FP")
S.fundays <-   
  mark(data = RMark_data_MP$nest_data.processed, 
       ddl = RMark_data_MP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ fundays)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~fundays)  npar= 2  lnl =  3120.103 AICc = 3124.104min.fundays = min(RMark_data_MP$nest_data.processed$data$fundays)
max.fundays = max(RMark_data_MP$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays, to = max.fundays, length = 100)
pred.fundays <- 
  covariate.predictions(model = S.fundays, 
                        data = data.frame(fundays = fundays.values),
                        indices = 1)
pred.fundays_MP <- 
  pred.fundays$estimates %>% 
  mutate(region = "MP")
S.fundays <- 
  mark(data = RMark_data_BC$nest_data.processed, 
       ddl = RMark_data_BC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ fundays)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~fundays)  npar= 2  lnl =  1721.3286 AICc = 1725.3308min.fundays = min(RMark_data_BC$nest_data.processed$data$fundays)
max.fundays = max(RMark_data_BC$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays, to = max.fundays, length = 100)
pred.fundays <- 
  covariate.predictions(model = S.fundays, 
                        data = data.frame(fundays = fundays.values),
                        indices = 1)
pred.fundays_BC <- 
  pred.fundays$estimates %>% 
  mutate(region = "BC")
S.fundays <- 
  mark(data = RMark_data_BSC$nest_data.processed, 
       ddl = RMark_data_BSC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ fundays)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~fundays)  npar= 2  lnl =  1614.6491 AICc = 1618.6514min.fundays = min(RMark_data_BSC$nest_data.processed$data$fundays)
max.fundays = max(RMark_data_BSC$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays, to = max.fundays, length = 100)
pred.fundays <- 
  covariate.predictions(model = S.fundays, 
                        data = data.frame(fundays = fundays.values),
                        indices = 1)
pred.fundays_BSC <- 
  pred.fundays$estimates %>% 
  mutate(region = "BSC")
S.fundays <- 
  mark(data = RMark_data_PI$nest_data.processed, 
       ddl = RMark_data_PI$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ fundays)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~fundays)  npar= 2  lnl =  1006.1515 AICc = 1010.1553min.fundays = min(RMark_data_PI$nest_data.processed$data$fundays)
max.fundays = max(RMark_data_PI$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays, to = max.fundays, length = 100)
pred.fundays <- 
  covariate.predictions(model = S.fundays, 
                        data = data.frame(fundays = fundays.values),
                        indices = 1)
pred.fundays_PI <- 
  pred.fundays$estimates %>% 
  mutate(region = "PI")
pred.fundays <- 
  bind_rows(pred.fundays_FP, pred.fundays_MP, 
            pred.fundays_BC, pred.fundays_BSC, pred.fundays_PI)
ggplot(pred.fundays, 
       aes(x = covdata, y = estimate, color = region, fill = region)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2") +
  scale_fill_brewer(palette = "Dark2") +
  scale_x_continuous(breaks = c(0, 5, 10, 15, 20, 25)) +
  luke_theme +
  theme(legend.position = "none",
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("number of weekend days and holidays exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))S.fundays_status <- 
  mark(data = RMark_data_FP$nest_data.processed, 
       ddl = RMark_data_FP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ fundays + status)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~fundays + status)  npar= 3  lnl =  2546.4738 AICc = 2552.4764min.fundays_status = min(RMark_data_FP$nest_data.processed$data$fundays)
max.fundays_status = max(RMark_data_FP$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays_status, to = max.fundays_status, length = 100)
pred.fundays_status <- 
  covariate.predictions(model = S.fundays_status, 
                        data = data.frame(fundays = fundays.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.fundays_status_FP <- 
  pred.fundays_status$estimates %>% 
  mutate(region = "FP",
         status = ifelse(par.index == 1, "N", "Y"))
S.fundays_status <-   
  mark(data = RMark_data_MP$nest_data.processed, 
       ddl = RMark_data_MP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ fundays + status)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~fundays + status)  npar= 3  lnl =  3114.8422 AICc = 3120.8442min.fundays_status = min(RMark_data_MP$nest_data.processed$data$fundays)
max.fundays_status = max(RMark_data_MP$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays_status, to = max.fundays_status, length = 100)
pred.fundays_status <- 
  covariate.predictions(model = S.fundays_status, 
                        data = data.frame(fundays = fundays.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.fundays_status_MP <- 
  pred.fundays_status$estimates %>% 
  mutate(region = "MP",
         status = ifelse(par.index == 1, "N", "Y"))
S.fundays_status <- 
  mark(data = RMark_data_BC$nest_data.processed, 
       ddl = RMark_data_BC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ fundays + status)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~fundays + status)  npar= 3  lnl =  1714.4468 AICc = 1720.451min.fundays_status = min(RMark_data_BC$nest_data.processed$data$fundays)
max.fundays_status = max(RMark_data_BC$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays_status, to = max.fundays_status, length = 100)
pred.fundays_status <- 
  covariate.predictions(model = S.fundays_status, 
                        data = data.frame(fundays = fundays.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.fundays_status_BC <- 
  pred.fundays_status$estimates %>% 
  mutate(region = "BC",
         status = ifelse(par.index == 1, "N", "Y"))
S.fundays_status <- 
  mark(data = RMark_data_BSC$nest_data.processed, 
       ddl = RMark_data_BSC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ fundays + status)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~fundays + status)  npar= 3  lnl =  1573.2605 AICc = 1579.265min.fundays_status = min(RMark_data_BSC$nest_data.processed$data$fundays)
max.fundays_status = max(RMark_data_BSC$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays_status, to = max.fundays_status, length = 100)
pred.fundays_status <- 
  covariate.predictions(model = S.fundays_status, 
                        data = data.frame(fundays = fundays.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.fundays_status_BSC <- 
  pred.fundays_status$estimates %>% 
  mutate(region = "BSC",
         status = ifelse(par.index == 1, "N", "Y"))
S.fundays_status <- 
  mark(data = RMark_data_PI$nest_data.processed, 
       ddl = RMark_data_PI$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ fundays + status)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~fundays + status)  npar= 3  lnl =  985.4834 AICc = 991.49111min.fundays_status = min(RMark_data_PI$nest_data.processed$data$fundays)
max.fundays_status = max(RMark_data_PI$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays_status, to = max.fundays_status, length = 100)
pred.fundays_status <- 
  covariate.predictions(model = S.fundays_status, 
                        data = data.frame(fundays = fundays.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_PI$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_PI$nest_fate.ddl$S, status == "Y")[1,]))))
pred.fundays_status_PI <- 
  pred.fundays_status$estimates %>% 
  mutate(region = "PI",
         status = ifelse(par.index == 1, "N", "Y"))
pred.fundays_status <- 
  bind_rows(pred.fundays_status_FP, pred.fundays_status_MP, pred.fundays_status_BC, pred.fundays_status_BSC, pred.fundays_status_PI)
ggplot(pred.fundays_status, 
       aes(x = covdata, y = estimate, color = status, fill = status)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_fill_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_x_continuous(breaks = c(0, 5, 10, 15, 20, 25)) +
  luke_theme +
  theme(legend.position = c(0.25, 0.1),
        legend.title = element_blank(),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("number of weekend days and holidays exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))S.levels <- 
  mark(data = RMark_data_FP$nest_data.processed, 
       ddl = RMark_data_FP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ level)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~level)  npar= 5  lnl =  2583.9027 AICc = 2593.9092nest_survival_reals_FP_levels <- 
  S.levels$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_FP_levels), " ", n = 4))
nest_survival_reals_FP_levels <- cbind(Groups, nest_survival_reals_FP_levels)
nest_survival_reals_FP_levels$rows <-  rownames(nest_survival_reals_FP_levels)
nest_survival_reals_FP_levels$management_level <- 
  as.factor(str_sub(nest_survival_reals_FP_levels$rows, 
                    nchar(nest_survival_reals_FP_levels$rows) - 7, nchar(nest_survival_reals_FP_levels$rows) - 6))
nest_survival_reals_FP_levels <- 
  nest_survival_reals_FP_levels %>% 
  dplyr::select(management_level, estimate, se, lcl, ucl) %>% 
  mutate(region = "FP")
row.names(nest_survival_reals_FP_levels) <- NULL
S.levels <- 
  mark(data = RMark_data_MP$nest_data.processed, 
       ddl = RMark_data_MP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ level)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~level)  npar= 5  lnl =  3227.2874 AICc = 3237.2923nest_survival_reals_MP_levels <- 
  S.levels$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_MP_levels), " ", n = 4))
nest_survival_reals_MP_levels <- cbind(Groups, nest_survival_reals_MP_levels)
nest_survival_reals_MP_levels$rows <-  rownames(nest_survival_reals_MP_levels)
nest_survival_reals_MP_levels$management_level <- 
  as.factor(str_sub(nest_survival_reals_MP_levels$rows, 
                    nchar(nest_survival_reals_MP_levels$rows) - 7, nchar(nest_survival_reals_MP_levels$rows) - 6))
nest_survival_reals_MP_levels <- 
  nest_survival_reals_MP_levels %>% 
  dplyr::select(management_level, estimate, se, lcl, ucl) %>% 
  mutate(region = "MP")
row.names(nest_survival_reals_MP_levels) <- NULL
S.levels <- 
  mark(data = RMark_data_BC$nest_data.processed, 
       ddl = RMark_data_BC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ level)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~level)  npar= 4  lnl =  1733.8583 AICc = 1741.8655nest_survival_reals_BC_levels <- 
  S.levels$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BC_levels), " ", n = 4))
nest_survival_reals_BC_levels <- cbind(Groups, nest_survival_reals_BC_levels)
nest_survival_reals_BC_levels$rows <-  rownames(nest_survival_reals_BC_levels)
nest_survival_reals_BC_levels$management_level <- 
  as.factor(str_sub(nest_survival_reals_BC_levels$rows, 
                    nchar(nest_survival_reals_BC_levels$rows) - 7, nchar(nest_survival_reals_BC_levels$rows) - 6))
nest_survival_reals_BC_levels <- 
  nest_survival_reals_BC_levels %>% 
  dplyr::select(management_level, estimate, se, lcl, ucl) %>% 
  mutate(region = "BC")
row.names(nest_survival_reals_BC_levels) <- NULL
S.levels <- 
  mark(data = RMark_data_BSC$nest_data.processed, 
       ddl = RMark_data_BSC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ level)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~level)  npar= 5  lnl =  1588.2042 AICc = 1598.2156nest_survival_reals_BSC_levels <- 
  S.levels$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BSC_levels), " ", n = 4))
nest_survival_reals_BSC_levels <- cbind(Groups, nest_survival_reals_BSC_levels)
nest_survival_reals_BSC_levels$rows <-  rownames(nest_survival_reals_BSC_levels)
nest_survival_reals_BSC_levels$management_level <- 
  as.factor(str_sub(nest_survival_reals_BSC_levels$rows, 
                    nchar(nest_survival_reals_BSC_levels$rows) - 7, nchar(nest_survival_reals_BSC_levels$rows) - 6))
nest_survival_reals_BSC_levels <- 
  nest_survival_reals_BSC_levels %>% 
  dplyr::select(management_level, estimate, se, lcl, ucl) %>% 
  mutate(region = "BSC")
row.names(nest_survival_reals_BSC_levels) <- NULL
S.levels <- 
  mark(data = RMark_data_PI$nest_data.processed, 
       ddl = RMark_data_PI$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ level)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~level)  npar= 5  lnl =  1007.7148 AICc = 1017.7341nest_survival_reals_PI_levels <- 
  S.levels$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_PI_levels), " ", n = 4))
nest_survival_reals_PI_levels <- cbind(Groups, nest_survival_reals_PI_levels)
nest_survival_reals_PI_levels$rows <-  rownames(nest_survival_reals_PI_levels)
nest_survival_reals_PI_levels$management_level <- 
  as.factor(str_sub(nest_survival_reals_PI_levels$rows, 
                    nchar(nest_survival_reals_PI_levels$rows) - 7, nchar(nest_survival_reals_PI_levels$rows) - 6))
nest_survival_reals_PI_levels <- 
  nest_survival_reals_PI_levels %>% 
  dplyr::select(management_level, estimate, se, lcl, ucl) %>% 
  mutate(region = "PI")
row.names(nest_survival_reals_PI_levels) <- NULL
nest_survival_reals_levels <- 
  bind_rows(nest_survival_reals_FP_levels,
            nest_survival_reals_MP_levels, 
            nest_survival_reals_BC_levels,
            nest_survival_reals_BSC_levels,
            nest_survival_reals_PI_levels)
ggplot() +
  geom_line(data = nest_survival_reals_levels, 
            aes(x = management_level, y = estimate, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2, size = 2) +
  geom_errorbar(data = nest_survival_reals_levels, 
                aes(ymin = lcl, ymax = ucl, 
                    x = management_level, 
                    y = estimate, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = nest_survival_reals_levels, 
             aes(x = management_level, y = estimate, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  scale_colour_brewer(palette = "Set1") +
  luke_theme +
  theme(legend.position = c(0.8, 0.2),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("management level") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0.4, 1)) +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
labels = c("BSC" = "Bellarine/Surf Coast", 
                                 "FP" = "Fleurieu Peninsula",
                                 "MP" = "Mornington Peninsula",
                                 "BC" = "Bass Coast",
                                 "PI" = "Phillip Island")) +
  scale_fill_brewer(palette = "Dark2", 
                      name = "Region", 
labels = c("BSC" = "Bellarine/Surf Coast", 
                                 "FP" = "Fleurieu Peninsula",
                                 "MP" = "Mornington Peninsula",
                                 "BC" = "Bass Coast",
                                 "PI" = "Phillip Island"))S.status <- 
  mark(data = RMark_data_FP$nest_data.processed, 
       ddl = RMark_data_FP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula = ~ status)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~status)  npar= 2  lnl =  2600.6034 AICc = 2604.6047nest_survival_reals_FP_status <- 
  S.status$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_FP_status), " ", n = 4))
nest_survival_reals_FP_status <- cbind(Groups, nest_survival_reals_FP_status)
nest_survival_reals_FP_status$rows <-  rownames(nest_survival_reals_FP_status)
nest_survival_reals_FP_status$status <- 
  as.factor(str_sub(nest_survival_reals_FP_status$rows, 
                    nchar(nest_survival_reals_FP_status$rows) - 8, nchar(nest_survival_reals_FP_status$rows) - 8))
nest_survival_reals_FP_status <- 
  nest_survival_reals_FP_status %>% 
  dplyr::select(status, estimate, se, lcl, ucl) %>% 
  mutate(region = "FP")
row.names(nest_survival_reals_FP_status) <- NULL
S.status <- 
  mark(data = RMark_data_MP$nest_data.processed, 
       ddl = RMark_data_MP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ status)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~status)  npar= 2  lnl =  3231.7168 AICc = 3235.7177nest_survival_reals_MP_status <- 
  S.status$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_MP_status), " ", n = 4))
nest_survival_reals_MP_status <- cbind(Groups, nest_survival_reals_MP_status)
nest_survival_reals_MP_status$rows <-  rownames(nest_survival_reals_MP_status)
nest_survival_reals_MP_status$status <- 
  as.factor(str_sub(nest_survival_reals_MP_status$rows, 
                    nchar(nest_survival_reals_MP_status$rows) - 8, nchar(nest_survival_reals_MP_status$rows) - 8))
nest_survival_reals_MP_status <- 
  nest_survival_reals_MP_status %>% 
  dplyr::select(status, estimate, se, lcl, ucl) %>% 
  mutate(region = "MP")
row.names(nest_survival_reals_MP_status) <- NULL
S.status <- 
  mark(data = RMark_data_BC$nest_data.processed, 
       ddl = RMark_data_BC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ status)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~status)  npar= 2  lnl =  1752.8385 AICc = 1756.8407nest_survival_reals_BC_status <- 
  S.status$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BC_status), " ", n = 4))
nest_survival_reals_BC_status <- cbind(Groups, nest_survival_reals_BC_status)
nest_survival_reals_BC_status$rows <-  rownames(nest_survival_reals_BC_status)
nest_survival_reals_BC_status$status <- 
  as.factor(str_sub(nest_survival_reals_BC_status$rows, 
                    nchar(nest_survival_reals_BC_status$rows) - 8, nchar(nest_survival_reals_BC_status$rows) - 8))
nest_survival_reals_BC_status <- 
  nest_survival_reals_BC_status %>% 
  dplyr::select(status, estimate, se, lcl, ucl) %>% 
  mutate(region = "BC")
row.names(nest_survival_reals_BC_status) <- NULL
S.status <- 
  mark(data = RMark_data_PI$nest_data.processed, 
       ddl = RMark_data_PI$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ status)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~status)  npar= 2  lnl =  1013.4942 AICc = 1017.4981nest_survival_reals_PI_status <- 
  S.status$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_PI_status), " ", n = 4))
nest_survival_reals_PI_status <- cbind(Groups, nest_survival_reals_PI_status)
nest_survival_reals_PI_status$rows <-  rownames(nest_survival_reals_PI_status)
nest_survival_reals_PI_status$status <- 
  as.factor(str_sub(nest_survival_reals_PI_status$rows, 
                    nchar(nest_survival_reals_PI_status$rows) - 8, nchar(nest_survival_reals_PI_status$rows) - 8))
nest_survival_reals_PI_status <- 
  nest_survival_reals_PI_status %>% 
  dplyr::select(status, estimate, se, lcl, ucl) %>% 
  mutate(region = "PI")
row.names(nest_survival_reals_PI_status) <- NULL
S.status <- 
  mark(data = RMark_data_BSC$nest_data.processed, 
       ddl = RMark_data_BSC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ status)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~status)  npar= 2  lnl =  1604.0904 AICc = 1608.0927nest_survival_reals_BSC_status <- 
  S.status$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BSC_status), " ", n = 4))
nest_survival_reals_BSC_status <- cbind(Groups, nest_survival_reals_BSC_status)
nest_survival_reals_BSC_status$rows <-  rownames(nest_survival_reals_BSC_status)
nest_survival_reals_BSC_status$status <- 
  as.factor(str_sub(nest_survival_reals_BSC_status$rows, 
                    nchar(nest_survival_reals_BSC_status$rows) - 8, nchar(nest_survival_reals_BSC_status$rows) - 8))
nest_survival_reals_BSC_status <- 
  nest_survival_reals_BSC_status %>% 
  dplyr::select(status, estimate, se, lcl, ucl) %>% 
  mutate(region = "BSC")
row.names(nest_survival_reals_BSC_status) <- NULL
nest_survival_reals_status <- 
  bind_rows(nest_survival_reals_FP_status,
            nest_survival_reals_MP_status, 
            nest_survival_reals_BC_status,
            nest_survival_reals_BSC_status,
            nest_survival_reals_PI_status)
ggplot() +
  geom_line(data = nest_survival_reals_status, 
            aes(x = status, y = estimate, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2, size = 2) +
  geom_errorbar(data = nest_survival_reals_status, 
                aes(ymin = lcl, ymax = ucl, 
                    x = status, 
                    y = estimate, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = nest_survival_reals_status, 
             aes(x = status, y = estimate, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  # scale_colour_brewer(palette = "Set1") +
  luke_theme +
  theme(legend.position = c(0.8, 0.2),
        legend.justification = c(1, 0),
        strip.background = element_blank(),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 10)) +
  xlab("management level") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0.4, 1)) +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("BSC" = "Bellarine/Surf Coast", 
                                 "FP" = "Fleurieu Peninsula",
                                 "MP" = "Mornington Peninsula",
                                 "BC" = "Bass Coast",
                                 "PI" = "Phillip Island")) +
  scale_fill_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("BSC" = "Bellarine/Surf Coast", 
                                 "FP" = "Fleurieu Peninsula",
                                 "MP" = "Mornington Peninsula",
                                 "BC" = "Bass Coast",
                                 "PI" = "Phillip Island")) +
  scale_x_discrete(labels = c("No management", "management"))S.habitat <- 
  mark(data = RMark_data_FP$nest_data.processed, 
       ddl = RMark_data_FP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ nest_hab)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~nest_hab)  npar= 4  lnl =  2702.2083 AICc = 2710.2126nest_survival_reals_FP_habitat <- 
  S.habitat$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_FP_habitat), " ", n = 4))
nest_survival_reals_FP_habitat <- cbind(Groups, nest_survival_reals_FP_habitat)
nest_survival_reals_FP_habitat$habitat <- str_extract(nest_survival_reals_FP_habitat$X2, "beach|dune|foredune/face|estuary/spit")
nest_survival_reals_FP_habitat <- 
  nest_survival_reals_FP_habitat %>% 
  dplyr::select(habitat, estimate, se, lcl, ucl) %>% 
  mutate(region = "FP")
row.names(nest_survival_reals_FP_habitat) <- NULL
S.habitat <- 
  mark(data = RMark_data_MP$nest_data.processed, 
       ddl = RMark_data_MP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ nest_hab)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~nest_hab)  npar= 3  lnl =  3245.5948 AICc = 3251.5968nest_survival_reals_MP_habitat <- 
  S.habitat$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_MP_habitat), " ", n = 4))
nest_survival_reals_MP_habitat <- cbind(Groups, nest_survival_reals_MP_habitat)
nest_survival_reals_MP_habitat$habitat <- str_extract(nest_survival_reals_MP_habitat$X2, "beach|dune|foredune/face|estuary/spit")
nest_survival_reals_MP_habitat <- 
  nest_survival_reals_MP_habitat %>% 
  dplyr::select(habitat, estimate, se, lcl, ucl) %>% 
  mutate(region = "MP")
row.names(nest_survival_reals_MP_habitat) <- NULL
S.habitat <- 
  mark(data = RMark_data_BC$nest_data.processed, 
       ddl = RMark_data_BC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ nest_hab)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~nest_hab)  npar= 4  lnl =  1766.7888 AICc = 1774.796nest_survival_reals_BC_habitat <- 
  S.habitat$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BC_habitat), " ", n = 4))
nest_survival_reals_BC_habitat <- cbind(Groups, nest_survival_reals_BC_habitat)
nest_survival_reals_BC_habitat$habitat <- str_extract(nest_survival_reals_BC_habitat$X2, "beach|dune|foredune/face|estuary/spit")
nest_survival_reals_BC_habitat <- 
  nest_survival_reals_BC_habitat %>% 
  dplyr::select(habitat, estimate, se, lcl, ucl) %>% 
  mutate(region = "BC")
row.names(nest_survival_reals_BC_habitat) <- NULL
S.habitat <- 
  mark(data = RMark_data_BSC$nest_data.processed, 
       ddl = RMark_data_BSC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ nest_hab)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~nest_hab)  npar= 4  lnl =  1643.1384 AICc = 1651.146nest_survival_reals_BSC_habitat <- 
  S.habitat$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BSC_habitat), " ", n = 4))
nest_survival_reals_BSC_habitat <- cbind(Groups, nest_survival_reals_BSC_habitat)
nest_survival_reals_BSC_habitat$habitat <- str_extract(nest_survival_reals_BSC_habitat$X2, "beach|dune|foredune/face|estuary/spit")
nest_survival_reals_BSC_habitat <- 
  nest_survival_reals_BSC_habitat %>% 
  dplyr::select(habitat, estimate, se, lcl, ucl) %>% 
  mutate(region = "BSC")
row.names(nest_survival_reals_BSC_habitat) <- NULL
S.habitat <- 
  mark(data = RMark_data_PI$nest_data.processed, 
       ddl = RMark_data_PI$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ nest_hab)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~nest_hab)  npar= 4  lnl =  1123.8333 AICc = 1125.8346nest_survival_reals_PI_habitat <- 
  S.habitat$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_PI_habitat), " ", n = 4))
nest_survival_reals_PI_habitat <- cbind(Groups, nest_survival_reals_PI_habitat)
nest_survival_reals_PI_habitat$habitat <- str_extract(nest_survival_reals_PI_habitat$X2, "beach|dune|foredune/face|estuary/spit")
nest_survival_reals_PI_habitat <- 
  nest_survival_reals_PI_habitat %>% 
  dplyr::select(habitat, estimate, se, lcl, ucl) %>% 
  mutate(region = "PI")
row.names(nest_survival_reals_PI_habitat) <- NULL
nest_survival_reals_habitat <- 
  bind_rows(nest_survival_reals_FP_habitat,
            nest_survival_reals_MP_habitat, 
            nest_survival_reals_BSC_habitat,
            nest_survival_reals_BC_habitat,
            nest_survival_reals_PI_habitat)
ggplot() +
  geom_errorbar(data = nest_survival_reals_habitat, 
                aes(ymin = lcl, ymax = ucl, 
                    x = habitat, 
                    y = estimate, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = nest_survival_reals_habitat, 
             aes(x = habitat, y = estimate, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  # scale_colour_brewer(palette = "Set1") +
  luke_theme +
  theme(legend.position = c(0.5, 0.2),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("habitat") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0.75, 1)) +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
labels = c("BSC" = "Bellarine/Surf Coast", 
                                 "FP" = "Fleurieu Peninsula",
                                 "MP" = "Mornington Peninsula",
                                 "BC" = "Bass Coast",
                                 "PI" = "Phillip Island")) +
  scale_fill_brewer(palette = "Dark2", 
                      name = "Region", 
labels = c("BSC" = "Bellarine/Surf Coast", 
                                 "FP" = "Fleurieu Peninsula",
                                 "MP" = "Mornington Peninsula",
                                 "BC" = "Bass Coast",
                                 "PI" = "Phillip Island"))S.dog_m <- nest_survival_run_FP[[4]]
min.dog_m = min(RMark_data_FP$nest_data.processed$data$dog_m)
max.dog_m = max(RMark_data_FP$nest_data.processed$data$dog_m)
dog_m.values = seq(from = min.dog_m, to = max.dog_m, length = 100)
pred.dog_m_status <- 
  covariate.predictions(model = S.dog_m, 
                        data = data.frame(dog_m = dog_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.dog_m_status_FP <- 
  pred.dog_m_status$estimates %>% 
  mutate(region = "FP",
         status = ifelse(par.index == 1, "N", "Y"))
S.dog_m <- nest_survival_run_MP[[4]]
min.dog_m = min(RMark_data_MP$nest_data.processed$data$dog_m)
max.dog_m = max(RMark_data_MP$nest_data.processed$data$dog_m)
dog_m.values = seq(from = min.dog_m, to = max.dog_m, length = 100)
pred.dog_m_status <- 
  covariate.predictions(model = S.dog_m, 
                        data = data.frame(dog_m = dog_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.dog_m_status_MP <- 
  pred.dog_m_status$estimates %>% 
  mutate(region = "MP",
         status = ifelse(par.index == 1, "N", "Y"))
S.dog_m <- nest_survival_run_BC[[4]]
min.dog_m = min(RMark_data_BC$nest_data.processed$data$dog_m)
max.dog_m = max(RMark_data_BC$nest_data.processed$data$dog_m)
dog_m.values = seq(from = min.dog_m, to = max.dog_m, length = 100)
pred.dog_m_status <- 
  covariate.predictions(model = S.dog_m, 
                        data = data.frame(dog_m = dog_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.dog_m_status_BC <- 
  pred.dog_m_status$estimates %>% 
  mutate(region = "BC",
         status = ifelse(par.index == 1, "N", "Y"))
S.dog_m <- nest_survival_run_PI[[4]]
min.dog_m = min(RMark_data_PI$nest_data.processed$data$dog_m)
max.dog_m = max(RMark_data_PI$nest_data.processed$data$dog_m)
dog_m.values = seq(from = min.dog_m, to = max.dog_m, length = 100)
pred.dog_m_status <- 
  covariate.predictions(model = S.dog_m, 
                        data = data.frame(dog_m = dog_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_PI$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_PI$nest_fate.ddl$S, status == "Y")[1,]))))
pred.dog_m_status_PI <- 
  pred.dog_m_status$estimates %>% 
  mutate(region = "PI",
         status = ifelse(par.index == 1, "N", "Y"))
S.dog_m <- nest_survival_run_BSC[[4]]
min.dog_m = min(RMark_data_BSC$nest_data.processed$data$dog_m)
max.dog_m = max(RMark_data_BSC$nest_data.processed$data$dog_m)
dog_m.values = seq(from = min.dog_m, to = max.dog_m, length = 100)
pred.dog_m_status <- 
  covariate.predictions(model = S.dog_m, 
                        data = data.frame(dog_m = dog_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.dog_m_status_BSC <- 
  pred.dog_m_status$estimates %>% 
  mutate(region = "BSC",
         status = ifelse(par.index == 1, "N", "Y"))
pred.dog_m <- 
  bind_rows(pred.dog_m_status_FP,
            pred.dog_m_status_MP, 
            pred.dog_m_status_BC,
            pred.dog_m_status_BSC,
            pred.dog_m_status_PI)
ggplot(pred.dog_m, 
       aes(x = covdata, y = estimate, color = status, fill = status)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_fill_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_x_continuous(breaks = c(0, 5, 10, 15, 20, 25)) +
  luke_theme +
  theme(legend.position = c(0.25, 0.1),
        legend.title = element_blank(),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of dogs exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))S.dof_m <- nest_survival_run_FP[[2]]
min.dof_m = min(RMark_data_FP$nest_data.processed$data$dof_m)
max.dof_m = max(RMark_data_FP$nest_data.processed$data$dof_m)
dof_m.values = seq(from = min.dof_m, to = max.dof_m, length = 100)
pred.dof_m_status <- 
  covariate.predictions(model = S.dof_m, 
                        data = data.frame(dof_m = dof_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.dof_m_status_FP <- 
  pred.dof_m_status$estimates %>% 
  mutate(region = "FP",
         status = ifelse(par.index == 1, "N", "Y"))
S.dof_m <- nest_survival_run_MP[[2]]
min.dof_m = min(RMark_data_MP$nest_data.processed$data$dof_m)
max.dof_m = max(RMark_data_MP$nest_data.processed$data$dof_m)
dof_m.values = seq(from = min.dof_m, to = max.dof_m, length = 100)
pred.dof_m_status <- 
  covariate.predictions(model = S.dof_m, 
                        data = data.frame(dof_m = dof_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.dof_m_status_MP <- 
  pred.dof_m_status$estimates %>% 
  mutate(region = "MP",
         status = ifelse(par.index == 1, "N", "Y"))
S.dof_m <- nest_survival_run_BC[[2]]
min.dof_m = min(RMark_data_BC$nest_data.processed$data$dof_m)
max.dof_m = max(RMark_data_BC$nest_data.processed$data$dof_m)
dof_m.values = seq(from = min.dof_m, to = max.dof_m, length = 100)
pred.dof_m_status <- 
  covariate.predictions(model = S.dof_m, 
                        data = data.frame(dof_m = dof_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.dof_m_status_BC <- 
  pred.dof_m_status$estimates %>% 
  mutate(region = "BC",
         status = ifelse(par.index == 1, "N", "Y"))
S.dof_m <- nest_survival_run_BSC[[2]]
min.dof_m = min(RMark_data_BSC$nest_data.processed$data$dof_m)
max.dof_m = max(RMark_data_BSC$nest_data.processed$data$dof_m)
dof_m.values = seq(from = min.dof_m, to = max.dof_m, length = 100)
pred.dof_m_status <- 
  covariate.predictions(model = S.dof_m, 
                        data = data.frame(dof_m = dof_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.dof_m_status_BSC <- 
  pred.dof_m_status$estimates %>% 
  mutate(region = "BSC",
         status = ifelse(par.index == 1, "N", "Y"))
S.dof_m <- nest_survival_run_PI[[2]]
min.dof_m = min(RMark_data_PI$nest_data.processed$data$dof_m)
max.dof_m = max(RMark_data_PI$nest_data.processed$data$dof_m)
dof_m.values = seq(from = min.dof_m, to = max.dof_m, length = 100)
pred.dof_m_status <- 
  covariate.predictions(model = S.dof_m, 
                        data = data.frame(dof_m = dof_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_PI$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_PI$nest_fate.ddl$S, status == "Y")[1,]))))
pred.dof_m_status_PI <- 
  pred.dof_m_status$estimates %>% 
  mutate(region = "PI",
         status = ifelse(par.index == 1, "N", "Y"))
pred.dof_m <- 
  bind_rows(pred.dof_m_status_FP,
            pred.dof_m_status_MP, 
            pred.dof_m_status_BC,
            pred.dof_m_status_BSC,
            pred.dof_m_status_PI)
ggplot(pred.dof_m, 
       aes(x = covdata, y = estimate, color = status, fill = status)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_fill_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_x_continuous(breaks = c(0, 5, 10, 15, 20, 25)) +
  luke_theme +
  theme(legend.position = c(0.25, 0.1),
        legend.title = element_blank(),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of dogs off leash exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))S.hum_m <- nest_survival_run_FP[[9]]
min.hum_m = min(RMark_data_FP$nest_data.processed$data$hum_m)
max.hum_m = max(RMark_data_FP$nest_data.processed$data$hum_m)
hum_m.values = seq(from = min.hum_m, to = max.hum_m, length = 100)
pred.hum_m_status <- 
  covariate.predictions(model = S.hum_m, 
                        data = data.frame(hum_m = hum_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.hum_m_status_FP <- 
  pred.hum_m_status$estimates %>% 
  mutate(region = "FP",
         status = ifelse(par.index == 1, "N", "Y"))
S.hum_m <- nest_survival_run_MP[[9]]
min.hum_m = min(RMark_data_MP$nest_data.processed$data$hum_m)
max.hum_m = max(RMark_data_MP$nest_data.processed$data$hum_m)
hum_m.values = seq(from = min.hum_m, to = max.hum_m, length = 100)
pred.hum_m_status <- 
  covariate.predictions(model = S.hum_m, 
                        data = data.frame(hum_m = hum_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.hum_m_status_MP <- 
  pred.hum_m_status$estimates %>% 
  mutate(region = "MP",
         status = ifelse(par.index == 1, "N", "Y"))
S.hum_m <- nest_survival_run_BC[[9]]
min.hum_m = min(RMark_data_BC$nest_data.processed$data$hum_m)
max.hum_m = max(RMark_data_BC$nest_data.processed$data$hum_m)
hum_m.values = seq(from = min.hum_m, to = max.hum_m, length = 100)
pred.hum_m_status <- 
  covariate.predictions(model = S.hum_m, 
                        data = data.frame(hum_m = hum_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.hum_m_status_BC <- 
  pred.hum_m_status$estimates %>% 
  mutate(region = "BC",
         status = ifelse(par.index == 1, "N", "Y"))
S.hum_m <- nest_survival_run_PI[[9]]
min.hum_m = min(RMark_data_PI$nest_data.processed$data$hum_m)
max.hum_m = max(RMark_data_PI$nest_data.processed$data$hum_m)
hum_m.values = seq(from = min.hum_m, to = max.hum_m, length = 100)
pred.hum_m_status <- 
  covariate.predictions(model = S.hum_m, 
                        data = data.frame(hum_m = hum_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_PI$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_PI$nest_fate.ddl$S, status == "Y")[1,]))))
pred.hum_m_status_PI <- 
  pred.hum_m_status$estimates %>% 
  mutate(region = "PI",
         status = ifelse(par.index == 1, "N", "Y"))
S.hum_m <- nest_survival_run_BSC[[9]]
min.hum_m = min(RMark_data_BSC$nest_data.processed$data$hum_m)
max.hum_m = max(RMark_data_BSC$nest_data.processed$data$hum_m)
hum_m.values = seq(from = min.hum_m, to = max.hum_m, length = 100)
pred.hum_m_status <- 
  covariate.predictions(model = S.hum_m, 
                        data = data.frame(hum_m = hum_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.hum_m_status_BSC <- 
  pred.hum_m_status$estimates %>% 
  mutate(region = "BSC",
         status = ifelse(par.index == 1, "N", "Y"))
pred.hum_m <- 
  bind_rows(pred.hum_m_status_FP,
            pred.hum_m_status_MP, 
            pred.hum_m_status_BC,
            pred.hum_m_status_BSC,
            pred.hum_m_status_PI)
ggplot(pred.hum_m, 
       aes(x = covdata, y = estimate, color = status, fill = status)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_fill_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_x_continuous(breaks = c(0, 10, 20, 30, 40, 50)) +
  luke_theme +
  theme(legend.position = c(0.25, 0.1),
        legend.title = element_blank(),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of humans exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))S.pbd_m <- nest_survival_run_FP[[11]]
min.pbd_m = min(RMark_data_FP$nest_data.processed$data$pbd_m)
max.pbd_m = max(RMark_data_FP$nest_data.processed$data$pbd_m)
pbd_m.values = seq(from = min.pbd_m, to = max.pbd_m, length = 100)
pred.pbd_m_status <- 
  covariate.predictions(model = S.pbd_m, 
                        data = data.frame(pbd_m = pbd_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.pbd_m_status_FP <- 
  pred.pbd_m_status$estimates %>% 
  mutate(region = "FP",
         status = ifelse(par.index == 1, "N", "Y"))
S.pbd_m <- nest_survival_run_MP[[11]]
min.pbd_m = min(RMark_data_MP$nest_data.processed$data$pbd_m)
max.pbd_m = max(RMark_data_MP$nest_data.processed$data$pbd_m)
pbd_m.values = seq(from = min.pbd_m, to = max.pbd_m, length = 100)
pred.pbd_m_status <- 
  covariate.predictions(model = S.pbd_m, 
                        data = data.frame(pbd_m = pbd_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.pbd_m_status_MP <- 
  pred.pbd_m_status$estimates %>% 
  mutate(region = "MP",
         status = ifelse(par.index == 1, "N", "Y"))
S.pbd_m <- nest_survival_run_BC[[11]]
min.pbd_m = min(RMark_data_BC$nest_data.processed$data$pbd_m)
max.pbd_m = max(RMark_data_BC$nest_data.processed$data$pbd_m)
pbd_m.values = seq(from = min.pbd_m, to = max.pbd_m, length = 100)
pred.pbd_m_status <- 
  covariate.predictions(model = S.pbd_m, 
                        data = data.frame(pbd_m = pbd_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.pbd_m_status_BC <- 
  pred.pbd_m_status$estimates %>% 
  mutate(region = "BC",
         status = ifelse(par.index == 1, "N", "Y"))
S.pbd_m <- nest_survival_run_BSC[[11]]
min.pbd_m = min(RMark_data_BSC$nest_data.processed$data$pbd_m)
max.pbd_m = max(RMark_data_BSC$nest_data.processed$data$pbd_m)
pbd_m.values = seq(from = min.pbd_m, to = max.pbd_m, length = 100)
pred.pbd_m_status <- 
  covariate.predictions(model = S.pbd_m, 
                        data = data.frame(pbd_m = pbd_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.pbd_m_status_BSC <- 
  pred.pbd_m_status$estimates %>% 
  mutate(region = "BSC",
         status = ifelse(par.index == 1, "N", "Y"))
S.pbd_m <- nest_survival_run_PI[[11]]
min.pbd_m = min(RMark_data_PI$nest_data.processed$data$pbd_m)
max.pbd_m = max(RMark_data_PI$nest_data.processed$data$pbd_m)
pbd_m.values = seq(from = min.pbd_m, to = max.pbd_m, length = 100)
pred.pbd_m_status <- 
  covariate.predictions(model = S.pbd_m, 
                        data = data.frame(pbd_m = pbd_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_PI$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_PI$nest_fate.ddl$S, status == "Y")[1,]))))
pred.pbd_m_status_PI <- 
  pred.pbd_m_status$estimates %>% 
  mutate(region = "PI",
         status = ifelse(par.index == 1, "N", "Y"))
pred.pbd_m <- 
  bind_rows(pred.pbd_m_status_FP,
            pred.pbd_m_status_MP, 
            pred.pbd_m_status_BC,
            pred.pbd_m_status_BSC,
            pred.pbd_m_status_PI)
ggplot(pred.pbd_m, 
       aes(x = covdata, y = estimate, color = status, fill = status)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_fill_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_x_continuous(breaks = c(0, 5, 10, 15, 20, 25)) +
  luke_theme +
  theme(legend.position = c(0.25, 0.1),
        legend.title = element_blank(),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of ravens and magpies exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))S.gul_m <- nest_survival_run_FP[[7]]
min.gul_m = min(RMark_data_FP$nest_data.processed$data$gul_m)
max.gul_m = max(RMark_data_FP$nest_data.processed$data$gul_m)
gul_m.values = seq(from = min.gul_m, to = max.gul_m, length = 100)
pred.gul_m_status <- 
  covariate.predictions(model = S.gul_m, 
                        data = data.frame(gul_m = gul_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.gul_m_status_FP <- 
  pred.gul_m_status$estimates %>% 
  mutate(region = "FP",
         status = ifelse(par.index == 1, "N", "Y"))
S.gul_m <- nest_survival_run_MP[[7]]
min.gul_m = min(RMark_data_MP$nest_data.processed$data$gul_m)
max.gul_m = max(RMark_data_MP$nest_data.processed$data$gul_m)
gul_m.values = seq(from = min.gul_m, to = max.gul_m, length = 100)
pred.gul_m_status <- 
  covariate.predictions(model = S.gul_m, 
                        data = data.frame(gul_m = gul_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.gul_m_status_MP <- 
  pred.gul_m_status$estimates %>% 
  mutate(region = "MP",
         status = ifelse(par.index == 1, "N", "Y"))
S.gul_m <- nest_survival_run_BC[[7]]
min.gul_m = min(RMark_data_BC$nest_data.processed$data$gul_m)
max.gul_m = max(RMark_data_BC$nest_data.processed$data$gul_m)
gul_m.values = seq(from = min.gul_m, to = max.gul_m, length = 100)
pred.gul_m_status <- 
  covariate.predictions(model = S.gul_m, 
                        data = data.frame(gul_m = gul_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.gul_m_status_BC <- 
  pred.gul_m_status$estimates %>% 
  mutate(region = "BC",
         status = ifelse(par.index == 1, "N", "Y"))
S.gul_m <- nest_survival_run_PI[[7]]
min.gul_m = min(RMark_data_PI$nest_data.processed$data$gul_m)
max.gul_m = max(RMark_data_PI$nest_data.processed$data$gul_m)
gul_m.values = seq(from = min.gul_m, to = max.gul_m, length = 100)
pred.gul_m_status <- 
  covariate.predictions(model = S.gul_m, 
                        data = data.frame(gul_m = gul_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_PI$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_PI$nest_fate.ddl$S, status == "Y")[1,]))))
pred.gul_m_status_PI <- 
  pred.gul_m_status$estimates %>% 
  mutate(region = "PI",
         status = ifelse(par.index == 1, "N", "Y"))
S.gul_m <- nest_survival_run_BSC[[7]]
min.gul_m = min(RMark_data_BSC$nest_data.processed$data$gul_m)
max.gul_m = max(RMark_data_BSC$nest_data.processed$data$gul_m)
gul_m.values = seq(from = min.gul_m, to = max.gul_m, length = 100)
pred.gul_m_status <- 
  covariate.predictions(model = S.gul_m, 
                        data = data.frame(gul_m = gul_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.gul_m_status_BSC <- 
  pred.gul_m_status$estimates %>% 
  mutate(region = "BSC",
         status = ifelse(par.index == 1, "N", "Y"))
pred.gul_m <- 
  bind_rows(pred.gul_m_status_FP,
            pred.gul_m_status_MP, 
            pred.gul_m_status_BC, 
            pred.gul_m_status_BSC, 
            pred.gul_m_status_PI)
ggplot(pred.gul_m, 
       aes(x = covdata, y = estimate, color = status, fill = status)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_fill_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  # scale_x_continuous(breaks = c(0, 10, 20, 30, 40, 50, 60, 70)) +
  luke_theme +
  theme(legend.position = c(0.25, 0.1),
        legend.title = element_blank(),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of gulls exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))# S.fox_prints <- 
#   mark(data = RMark_data_FP$nest_data.processed, 
#        ddl = RMark_data_FP$nest_fate.ddl, 
#        model = "Nest",
#        model.parameters = list("S" = list(formula =  ~ fox_p)),
#        brief = TRUE, 
#        delete = TRUE)
# nest_survival_reals_FP_fox_p <- 
#   S.fox_prints$results$real
# Groups <- data.frame(
#   str_split_fixed(rownames(nest_survival_reals_FP_fox_p), " ", n = 4))
# nest_survival_reals_FP_fox_p <- cbind(Groups, nest_survival_reals_FP_fox_p)
# nest_survival_reals_FP_fox_p$rows <-  rownames(nest_survival_reals_FP_fox_p)
# nest_survival_reals_FP_fox_p$fox_p <- 
#   str_sub(nest_survival_reals_FP_fox_p$rows, 
#           nchar(nest_survival_reals_FP_fox_p$rows) - 6, 
#           nchar(nest_survival_reals_FP_fox_p$rows) - 6)
# nest_survival_reals_FP_fox_p$fox_p <- 
#   as.factor(nest_survival_reals_FP_fox_p$fox_p)
# nest_survival_reals_FP_fox_p <- 
#   nest_survival_reals_FP_fox_p %>% 
#   dplyr::select(fox_p, estimate, se, lcl, ucl) %>% 
#   mutate(region = "FP") %>% 
#   slice(-1)
# row.names(nest_survival_reals_FP_fox_p) <- NULL
# 
# S.fox_prints <- 
#   mark(data = RMark_data_MP$nest_data.processed, 
#        ddl = RMark_data_MP$nest_fate.ddl, 
#        model = "Nest",
#        model.parameters = list("S" = list(formula =  ~ fox_p)),
#        brief = TRUE, 
#        delete = TRUE)
# nest_survival_reals_MP_fox_p <- 
#   S.fox_prints$results$real
# Groups <- data.frame(
#   str_split_fixed(rownames(nest_survival_reals_MP_fox_p), " ", n = 4))
# nest_survival_reals_MP_fox_p <- cbind(Groups, nest_survival_reals_MP_fox_p)
# nest_survival_reals_MP_fox_p$rows <-  rownames(nest_survival_reals_MP_fox_p)
# nest_survival_reals_MP_fox_p$fox_p <- 
#   str_sub(nest_survival_reals_MP_fox_p$rows, 
#           nchar(nest_survival_reals_MP_fox_p$rows) - 6, 
#           nchar(nest_survival_reals_MP_fox_p$rows) - 6)
# nest_survival_reals_MP_fox_p$fox_p <- 
#   as.factor(nest_survival_reals_MP_fox_p$fox_p)
# nest_survival_reals_MP_fox_p <- 
#   nest_survival_reals_MP_fox_p %>% 
#   dplyr::select(fox_p, estimate, se, lcl, ucl) %>% 
#   mutate(region = "MP") %>% 
#   slice(-1)
# row.names(nest_survival_reals_MP_fox_p) <- NULL
# 
# S.fox_prints <- 
#   mark(data = RMark_data_BC$nest_data.processed, 
#        ddl = RMark_data_BC$nest_fate.ddl, 
#        model = "Nest",
#        model.parameters = list("S" = list(formula =  ~ fox_p)),
#        brief = TRUE, 
#        delete = TRUE)
# nest_survival_reals_BC_fox_p <- 
#   S.fox_prints$results$real
# Groups <- data.frame(
#   str_split_fixed(rownames(nest_survival_reals_BC_fox_p), " ", n = 4))
# nest_survival_reals_BC_fox_p <- cbind(Groups, nest_survival_reals_BC_fox_p)
# nest_survival_reals_BC_fox_p$rows <-  rownames(nest_survival_reals_BC_fox_p)
# nest_survival_reals_BC_fox_p$fox_p <- 
#   str_sub(nest_survival_reals_BC_fox_p$rows, 
#           nchar(nest_survival_reals_BC_fox_p$rows) - 6, 
#           nchar(nest_survival_reals_BC_fox_p$rows) - 6) %>% as.factor()
# nest_survival_reals_BC_fox_p <- 
#   nest_survival_reals_BC_fox_p %>% 
#   dplyr::select(fox_p, estimate, se, lcl, ucl) %>% 
#   mutate(region = "BC") %>% 
#   slice(-1)
# row.names(nest_survival_reals_BC_fox_p) <- NULL
# 
# nest_survival_reals_levels <- 
#   bind_rows(nest_survival_reals_FP_fox_p,
#             nest_survival_reals_MP_fox_p, 
#             nest_survival_reals_BC_fox_p)
# 
# ggplot() +
#   geom_line(data = nest_survival_reals_levels, 
#             aes(x = fox_p, y = estimate, color = region, group = region),
#             position = position_dodge(width = 0.5), alpha = 0.2, size = 2) +
#   geom_errorbar(data = nest_survival_reals_levels, 
#                 aes(ymin = lcl, ymax = ucl, 
#                     x = fox_p, 
#                     y = estimate, group = region), position = position_dodge(width = 0.5),
#                 alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
#   geom_point(data = nest_survival_reals_levels, 
#              aes(x = fox_p, y = estimate, fill = region),
#              shape = 21, size = 4, position = position_dodge(width = 0.5)) +
#   luke_theme +
#   theme(legend.position = c(0.9, 0.1),
#         legend.justification = c(1, 0),
#         strip.background = element_blank()) +
#   xlab("fox prints") + 
#   ylab("estimated daily survival rate (± 95% CI)") +
#   ylim(c(0.55, 1)) +
#   scale_colour_brewer(palette = "Dark2", 
#                       name = "Region", 
#                       labels = #c("Bellarine/Surf Coast", 
#                         # "Fleurieu Peninsula", 
#                       "Mornington Peninsula") +#) +
#   scale_fill_brewer(palette = "Dark2", 
#                       name = "Region", 
#                       labels = #c("Bellarine/Surf Coast", 
#                         # "Fleurieu Peninsula", 
#                       "Mornington Peninsula")S.veh_m <- nest_survival_run_FP[[12]]
min.veh_m = min(RMark_data_FP$nest_data.processed$data$veh_m)
max.veh_m = max(RMark_data_FP$nest_data.processed$data$veh_m)
veh_m.values = seq(from = min.veh_m, to = max.veh_m, length = 100)
pred.veh_m_status <- 
  covariate.predictions(model = S.veh_m, 
                        data = data.frame(veh_m = veh_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "N")[1,]))))
pred.veh_m_status_FP <- 
  pred.veh_m_status$estimates %>% 
  mutate(region = "FP")
# S.veh_m <- nest_survival_run_MP[[13]]
# min.veh_m = min(RMark_data_MP$nest_data.processed$data$veh_m)
# max.veh_m = max(RMark_data_MP$nest_data.processed$data$veh_m)
# veh_m.values = seq(from = min.veh_m, to = max.veh_m, length = 100)
# pred.veh_m_status <- 
#   covariate.predictions(model = S.veh_m, 
#                         data = data.frame(veh_m = veh_m.values),
#                         indices = c(as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "N")[1,]))))
# pred.veh_m_status_MP <- 
#   pred.veh_m_status$estimates %>% 
#   mutate(region = "MP")
# 
# S.veh_m <- nest_survival_run_BC[[13]]
# min.veh_m = min(RMark_data_BC$nest_data.processed$data$veh_m)
# max.veh_m = max(RMark_data_BC$nest_data.processed$data$veh_m)
# veh_m.values = seq(from = min.veh_m, to = max.veh_m, length = 100)
# pred.veh_m_status <- 
#   covariate.predictions(model = S.veh_m, 
#                         data = data.frame(veh_m = veh_m.values),
#                         indices = c(as.numeric(row.names(filter(RMark_data_BC$nest_fate.ddl$S, status == "N")[1,]))))
# pred.veh_m_status_BC <- 
#   pred.veh_m_status$estimates %>% 
#   mutate(region = "BC")
# 
# pred.veh_m <- 
#   bind_rows(pred.veh_m_status_FP, pred.veh_m_status_MP, pred.veh_m_status_BC)
ggplot(pred.veh_m_status_FP, 
       aes(x = covdata, y = estimate)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_fill_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_x_continuous(breaks = c(0, 1, 2, 3, 4, 5)) +
  luke_theme +
  theme(legend.position = c(0.25, 0.1),
        legend.title = element_blank(),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of vehicles exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))S.year <- 
  mark(data = RMark_data_FP$nest_data.processed, 
       ddl = RMark_data_FP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ season)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~season)  npar= 16  lnl =  2690.1106 AICc = 2722.16922700722nest_survival_reals_FP_year <- 
  S.year$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_FP_year), " ", n = 4))
nest_survival_reals_FP_year <- cbind(Groups, nest_survival_reals_FP_year)
nest_survival_reals_FP_year$season <- 
  as.numeric(str_sub(nest_survival_reals_FP_year$X2, 2, 5))
nest_survival_reals_FP_year$season <- paste(nest_survival_reals_FP_year$season, nest_survival_reals_FP_year$season + 1, sep = " - ")
nest_survival_reals_FP_year <- 
  nest_survival_reals_FP_year %>% 
  dplyr::select(season, estimate, se, lcl, ucl) %>% 
  mutate(region = "FP")
row.names(nest_survival_reals_FP_year) <- NULL
S.year <- 
  mark(data = RMark_data_MP$nest_data.processed, 
       ddl = RMark_data_MP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ season)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~season)  npar= 18  lnl =  3240.9 AICc = 3276.9563nest_survival_reals_MP_year <- 
  S.year$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_MP_year), " ", n = 4))
nest_survival_reals_MP_year <- cbind(Groups, nest_survival_reals_MP_year)
nest_survival_reals_MP_year$season <- 
  as.numeric(str_sub(nest_survival_reals_MP_year$X2, 2, 5))
nest_survival_reals_MP_year$season <- paste(nest_survival_reals_MP_year$season, nest_survival_reals_MP_year$season + 1, sep = " - ")
nest_survival_reals_MP_year <- 
  nest_survival_reals_MP_year %>% 
  dplyr::select(season, estimate, se, lcl, ucl) %>% 
  mutate(region = "MP")
row.names(nest_survival_reals_MP_year) <- NULL
S.year <- 
  mark(data = RMark_data_BC$nest_data.processed, 
       ddl = RMark_data_BC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ season)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~season)  npar= 19  lnl =  1742.8149 AICc = 1780.95112512995nest_survival_reals_BC_year <- 
  S.year$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BC_year), " ", n = 4))
nest_survival_reals_BC_year <- cbind(Groups, nest_survival_reals_BC_year)
nest_survival_reals_BC_year$season <- 
  as.numeric(str_sub(nest_survival_reals_BC_year$X2, 2, 5))
nest_survival_reals_BC_year$season <- paste(nest_survival_reals_BC_year$season, nest_survival_reals_BC_year$season + 1, sep = " - ")
nest_survival_reals_BC_year <- 
  nest_survival_reals_BC_year %>% 
  dplyr::select(season, estimate, se, lcl, ucl) %>% 
  mutate(region = "BC")
row.names(nest_survival_reals_BC_year) <- NULL
S.year <- 
  mark(data = RMark_data_BSC$nest_data.processed, 
       ddl = RMark_data_BSC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ season)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~season)  npar= 19  lnl =  1617.1688 AICc = 1655.31353433632nest_survival_reals_BSC_year <- 
  S.year$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BSC_year), " ", n = 4))
nest_survival_reals_BSC_year <- cbind(Groups, nest_survival_reals_BSC_year)
nest_survival_reals_BSC_year$season <- 
  as.numeric(str_sub(nest_survival_reals_BSC_year$X2, 2, 5))
nest_survival_reals_BSC_year$season <- paste(nest_survival_reals_BSC_year$season, nest_survival_reals_BSC_year$season + 1, sep = " - ")
nest_survival_reals_BSC_year <- 
  nest_survival_reals_BSC_year %>% 
  dplyr::select(season, estimate, se, lcl, ucl) %>% 
  mutate(region = "BSC")
row.names(nest_survival_reals_BSC_year) <- NULL
S.year <- 
  mark(data = RMark_data_PI$nest_data.processed, 
       ddl = RMark_data_PI$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ season)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~season)  npar= 14  lnl =  1031.0835 AICc = 1059.21898387097nest_survival_reals_PI_year <- 
  S.year$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_PI_year), " ", n = 4))
nest_survival_reals_PI_year <- cbind(Groups, nest_survival_reals_PI_year)
nest_survival_reals_PI_year$season <- 
  as.numeric(str_sub(nest_survival_reals_PI_year$X2, 2, 5))
nest_survival_reals_PI_year$season <- paste(nest_survival_reals_PI_year$season, nest_survival_reals_PI_year$season + 1, sep = " - ")
nest_survival_reals_PI_year <- 
  nest_survival_reals_PI_year %>% 
  dplyr::select(season, estimate, se, lcl, ucl) %>% 
  mutate(region = "PI")
row.names(nest_survival_reals_PI_year) <- NULL
nest_survival_reals_year <- 
  bind_rows(nest_survival_reals_FP_year,
            nest_survival_reals_MP_year, 
            nest_survival_reals_BC_year, 
            nest_survival_reals_BSC_year, 
            nest_survival_reals_PI_year)
ggplot() +
  geom_line(data = nest_survival_reals_year, 
            aes(x = season, y = estimate, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2) +
  geom_errorbar(data = nest_survival_reals_year, 
                aes(ymin = lcl, ymax = ucl, 
                    x = season, 
                    y = estimate, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = nest_survival_reals_year, 
             aes(x = season, y = estimate, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  scale_colour_brewer(palette = "Set1") +
  luke_theme +
  theme(legend.position = "none",
        legend.justification = c(1, 0),
        strip.background = element_blank(),
        axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1)) +
  xlab("season") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0.7, 1)) +
  scale_colour_brewer(palette = "Dark2") +
  scale_fill_brewer(palette = "Dark2") +
  facet_grid(region ~ ., labeller = as_labeller(region_names))# Extract estimates of survival from Cubic model with management 
# (non-linear season variation and management effect)
S.season <- 
  mark(data = RMark_data_MP$nest_data.processed, 
       ddl = RMark_data_MP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ Time + Quadratic + Cubic)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~Time + Quadratic + Cubic)  npar= 4  lnl =  3237.8876 AICc = 3245.8909nest_survival_reals_MP_season <- 
  S.season$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_MP_season), " ", n = 4))
nest_survival_reals_MP_season <- cbind(Groups, nest_survival_reals_MP_season)
nest_survival_reals_MP_season$day_of_season <- 
  unlist(str_extract_all(nest_survival_reals_MP_season$X4, "\\d+")) %>% unique() %>% as.numeric()
nest_survival_reals_MP_season$region = "MP"
S.season <- 
  mark(data = RMark_data_BC$nest_data.processed, 
       ddl = RMark_data_BC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ Time + Quadratic + Cubic)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~Time + Quadratic + Cubic)  npar= 4  lnl =  1744.7265 AICc = 1752.7336nest_survival_reals_BC_season <- 
  S.season$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BC_season), " ", n = 4))
nest_survival_reals_BC_season <- cbind(Groups, nest_survival_reals_BC_season)
nest_survival_reals_BC_season$day_of_season <- 
  unlist(str_extract_all(nest_survival_reals_BC_season$X4, "\\d+")) %>% unique() %>% as.numeric()
nest_survival_reals_BC_season$region = "BC"
S.season <- 
  mark(data = RMark_data_FP$nest_data.processed, 
       ddl = RMark_data_FP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ Time + Quadratic + Cubic)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~Time + Quadratic + Cubic)  npar= 4  lnl =  2700.9422 AICc = 2708.9466nest_survival_reals_FP_season <- 
  S.season$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_FP_season), " ", n = 4))
nest_survival_reals_FP_season <- cbind(Groups, nest_survival_reals_FP_season)
nest_survival_reals_FP_season$day_of_season <- 
  unlist(str_extract_all(nest_survival_reals_FP_season$X4, "\\d+")) %>% unique() %>% as.numeric()
nest_survival_reals_FP_season$region = "FP"
S.season <- 
  mark(data = RMark_data_PI$nest_data.processed, 
       ddl = RMark_data_PI$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ Time + Quadratic + Cubic)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~Time + Quadratic + Cubic)  npar= 4  lnl =  1032.968 AICc = 1040.9808nest_survival_reals_PI_season <- 
  S.season$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_PI_season), " ", n = 4))
nest_survival_reals_PI_season <- cbind(Groups, nest_survival_reals_PI_season)
nest_survival_reals_PI_season$day_of_season <- 
  unlist(str_extract_all(nest_survival_reals_PI_season$X4, "\\d+")) %>% unique() %>% as.numeric()
nest_survival_reals_PI_season$region = "PI"
S.season <- 
  mark(data = RMark_data_BSC$nest_data.processed, 
       ddl = RMark_data_BSC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ Time + Quadratic + Cubic)),
       brief = TRUE, 
       delete = TRUE)
 Model: S(~Time + Quadratic + Cubic)  npar= 4  lnl =  1618.3474 AICc = 1626.355nest_survival_reals_BSC_season <- 
  S.season$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BSC_season), " ", n = 4))
nest_survival_reals_BSC_season <- cbind(Groups, nest_survival_reals_BSC_season)
nest_survival_reals_BSC_season$day_of_season <- 
  unlist(str_extract_all(nest_survival_reals_BSC_season$X4, "\\d+")) %>% unique() %>% as.numeric()
nest_survival_reals_BSC_season$region = "BSC"
nest_survival_reals_season <- 
  bind_rows(
    nest_survival_reals_MP_season, 
            nest_survival_reals_BC_season,
            nest_survival_reals_FP_season,
            nest_survival_reals_BSC_season,
            nest_survival_reals_PI_season) %>%
  dplyr::select(region, day_of_season, estimate, lcl, ucl)
row.names(nest_survival_reals_season) <- NULL
# FP
dates_for_plot_FP <- 
  data.frame(date = as.Date(min(as.numeric(RMark_data_FP$nest_data.processed$data$FirstFound)):
                              max(max(as.numeric(RMark_data_FP$nest_data.processed$data$LastChecked)), 
                                  max(as.numeric(RMark_data_FP$nest_data.processed$data$LastPresent))), 
                            origin = "2023-01-01") - 180,
             day_of_season = c(0:(max(max(as.numeric(RMark_data_FP$nest_data.processed$data$LastChecked)), 
                                      max(as.numeric(RMark_data_FP$nest_data.processed$data$LastPresent))) - 
                                    min(as.numeric(RMark_data_FP$nest_data.processed$data$FirstFound)))))
nest_survival_reals_dates_FP <- 
  left_join(nest_survival_reals_FP_season, dates_for_plot_FP, by = "day_of_season")
nest_survival_season_plot_FP <- 
  ggplot(data = nest_survival_reals_dates_FP) +
  geom_ribbon(aes(x = date, ymin = lcl, ymax = ucl),
              fill = brewer.pal(8, "Dark2")[c(1)], 
              alpha = 0.3) +
  geom_line(aes(x = date, y = estimate), 
            color = brewer.pal(8, "Dark2")[c(1)],
            size = 1) +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months") +
  ylab("daily nest survival ± 95% CI") +
  scale_y_continuous(limits = c(0, 1)) +
  luke_theme +
  theme(legend.position = "bottom",
        legend.title = element_blank(),
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.title.x = element_blank(),
        axis.text.x = element_text(angle = 45, 
                                   hjust = 1, 
                                   vjust = 1))
nest_discovery_season_plot_FP <- 
      ggplot(RMark_data_FP$nest_data.processed$data, 
             aes(as.Date(FirstFound, origin = "2023-01-01") - 180,
                               fill = Fate)) +
      geom_histogram(bins = 30,
                     # fill = brewer.pal(8, "Set1")[c(2)], 
                     alpha = 0.5) +
      scale_fill_manual(values = brewer.pal(8, "Set1")[c(2, 1)],
                        labels = c("Failed", "Hatched")) +
      ylab("nests found\nweekly") +
      scale_x_date(date_labels = "%B", 
                   expand = c(0.01, 0.01), 
                   date_breaks = "1 months", limits = c(min(nest_survival_reals_dates_FP$date, na.rm = TRUE), 
                                                        max(nest_survival_reals_dates_FP$date, na.rm = TRUE))) +
      scale_y_continuous(breaks = c(10, 20, 30, 40)) +
      luke_theme +
      theme(legend.position = "none",
            panel.grid.major = element_line(colour = "grey70", 
                                            size = 0.15),
            axis.title.x = element_blank(),
            axis.text.x = element_blank(),
            axis.ticks.x = element_blank())
    
# merge plots together
hooded_plover_nest_plot_FP <- 
  nest_discovery_season_plot_FP / 
  nest_survival_season_plot_FP +
  plot_layout(widths = c(5), 
              heights = unit(c(1, 3), c('in', 'in'))) +
  plot_annotation(tag_levels = 'A', title = "Fleurieu Peninsula")
### MP ----
dates_for_plot_MP <- 
  data.frame(date = as.Date(min(as.numeric(RMark_data_MP$nest_data.processed$data$FirstFound)):
                              max(max(as.numeric(RMark_data_MP$nest_data.processed$data$LastChecked)), 
                                  max(as.numeric(RMark_data_MP$nest_data.processed$data$LastPresent))), 
                            origin = "2023-01-01") - 180,
             day_of_season = c(0:(max(max(as.numeric(RMark_data_MP$nest_data.processed$data$LastChecked)), 
                                      max(as.numeric(RMark_data_MP$nest_data.processed$data$LastPresent))) - 
                                    min(as.numeric(RMark_data_MP$nest_data.processed$data$FirstFound)))))
nest_survival_reals_dates_MP <- 
  left_join(nest_survival_reals_MP_season, dates_for_plot_MP, by = "day_of_season")
nest_survival_season_plot_MP <- 
  ggplot(data = nest_survival_reals_dates_MP) +
  geom_ribbon(aes(x = date, ymin = lcl, ymax = ucl),
              fill = brewer.pal(8, "Dark2")[c(1)], 
              alpha = 0.3) +
  geom_line(aes(x = date, y = estimate), 
            color = brewer.pal(8, "Dark2")[c(1)],
            size = 1) +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months") +
  ylab("daily nest survival ± 95% CI") +
  scale_y_continuous(limits = c(0, 1)) +
  luke_theme +
  theme(legend.position = "bottom",
        legend.title = element_blank(),
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.title.x = element_blank(),
        axis.text.x = element_text(angle = 45, 
                                   hjust = 1, 
                                   vjust = 1))
nest_discovery_season_plot_MP <- 
      ggplot(RMark_data_MP$nest_data.processed$data, 
             aes(as.Date(FirstFound, origin = "2023-01-01") - 180,
                               fill = Fate)) +
      geom_histogram(bins = 30,
                     # fill = brewer.pal(8, "Set1")[c(2)], 
                     alpha = 0.5) +
      scale_fill_manual(values = brewer.pal(8, "Set1")[c(2, 1)],
                        labels = c("Failed", "Hatched")) +
      ylab("nests found\nweekly") +
      scale_x_date(date_labels = "%B", 
                   expand = c(0.01, 0.01), 
                   date_breaks = "1 months", limits = c(min(nest_survival_reals_dates_MP$date, na.rm = TRUE), 
                                                        max(nest_survival_reals_dates_MP$date, na.rm = TRUE))) +
      scale_y_continuous(breaks = c(10, 20, 30, 40)) +
      luke_theme +
      theme(legend.position = "none",
            panel.grid.major = element_line(colour = "grey70", 
                                            size = 0.15),
            axis.title.x = element_blank(),
            axis.text.x = element_blank(),
            axis.ticks.x = element_blank())
    
# merge plots together
hooded_plover_nest_plot_MP <- 
  nest_discovery_season_plot_MP / 
  nest_survival_season_plot_MP +
  plot_layout(widths = c(5), 
              heights = unit(c(1, 3), c('in', 'in'))) +
  plot_annotation(tag_levels = 'A', title = "Mornington Peninsula")
### BC ----
dates_for_plot_BC <- 
  data.frame(date = as.Date(min(as.numeric(RMark_data_BC$nest_data.processed$data$FirstFound)):
                              max(max(as.numeric(RMark_data_BC$nest_data.processed$data$LastChecked)), 
                                  max(as.numeric(RMark_data_BC$nest_data.processed$data$LastPresent))), 
                            origin = "2023-01-01") - 180,
             day_of_season = c(0:(max(max(as.numeric(RMark_data_BC$nest_data.processed$data$LastChecked)), 
                                      max(as.numeric(RMark_data_BC$nest_data.processed$data$LastPresent))) - 
                                    min(as.numeric(RMark_data_BC$nest_data.processed$data$FirstFound)))))
nest_survival_reals_dates_BC <- 
  left_join(nest_survival_reals_BC_season, dates_for_plot_BC, by = "day_of_season")
nest_survival_season_plot_BC <- 
  ggplot(data = nest_survival_reals_dates_BC) +
  geom_ribbon(aes(x = date, ymin = lcl, ymax = ucl),
              fill = brewer.pal(8, "Dark2")[c(1)], 
              alpha = 0.3) +
  geom_line(aes(x = date, y = estimate), 
            color = brewer.pal(8, "Dark2")[c(1)],
            size = 1) +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_survival_reals_dates_BC$date, na.rm = TRUE), 
                                                        max(nest_survival_reals_dates_BC$date, na.rm = TRUE))) +
  ylab("daily nest survival ± 95% CI") +
  scale_y_continuous(limits = c(0, 1)) +
  luke_theme +
  theme(legend.position = "bottom",
        legend.title = element_blank(),
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.title.x = element_blank(),
        axis.text.x = element_text(angle = 45, 
                                   hjust = 1, 
                                   vjust = 1))
nest_discovery_season_plot_BC <- 
      ggplot(RMark_data_BC$nest_data.processed$data, 
             aes(as.Date(FirstFound, origin = "2023-01-01") - 180,
                               fill = Fate)) +
      geom_histogram(bins = 30,
                     # fill = brewer.pal(8, "Set1")[c(2)], 
                     alpha = 0.5) +
      scale_fill_manual(values = brewer.pal(8, "Set1")[c(2, 1)],
                        labels = c("Failed", "Hatched")) +
      ylab("nests found\nweekly") +
      scale_x_date(date_labels = "%B", 
                   expand = c(0.01, 0.01),
                   date_breaks = "1 months", limits = c(min(nest_survival_reals_dates_BC$date, na.rm = TRUE), 
                                                        max(nest_survival_reals_dates_BC$date, na.rm = TRUE))) +
      scale_y_continuous(breaks = c(10, 20, 30, 40)) +
      luke_theme +
      theme(legend.position = "none",
            panel.grid.major = element_line(colour = "grey70", 
                                            size = 0.15),
            axis.title.x = element_blank(),
            axis.text.x = element_blank(),
            axis.ticks.x = element_blank())
    
# merge plots together
hooded_plover_nest_plot_BC <- 
  nest_discovery_season_plot_BC / 
  nest_survival_season_plot_BC +
  plot_layout(widths = c(5), 
              heights = unit(c(1, 3), c('in', 'in'))) +
  plot_annotation(tag_levels = 'A', title = "Bellarine / Surf Coast")
### BSC ---
dates_for_plot_BSC <- 
  data.frame(date = as.Date(min(as.numeric(RMark_data_BSC$nest_data.processed$data$FirstFound)):
                              max(max(as.numeric(RMark_data_BSC$nest_data.processed$data$LastChecked)), 
                                  max(as.numeric(RMark_data_BSC$nest_data.processed$data$LastPresent))), 
                            origin = "2023-01-01") - 180,
             day_of_season = c(0:(max(max(as.numeric(RMark_data_BSC$nest_data.processed$data$LastChecked)), 
                                      max(as.numeric(RMark_data_BSC$nest_data.processed$data$LastPresent))) - 
                                    min(as.numeric(RMark_data_BSC$nest_data.processed$data$FirstFound)))))
nest_survival_reals_dates_BSC <- 
  left_join(nest_survival_reals_BSC_season, dates_for_plot_BSC, by = "day_of_season")
nest_survival_season_plot_BSC <- 
  ggplot(data = nest_survival_reals_dates_BSC) +
  geom_ribbon(aes(x = date, ymin = lcl, ymax = ucl),
              fill = brewer.pal(8, "Dark2")[c(1)], 
              alpha = 0.3) +
  geom_line(aes(x = date, y = estimate), 
            color = brewer.pal(8, "Dark2")[c(1)],
            size = 1) +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months") +
  ylab("daily nest survival ± 95% CI") +
  scale_y_continuous(limits = c(0, 1)) +
  luke_theme +
  theme(legend.position = "bottom",
        legend.title = element_blank(),
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.title.x = element_blank(),
        axis.text.x = element_text(angle = 45, 
                                   hjust = 1, 
                                   vjust = 1))
nest_discovery_season_plot_BSC <- 
      ggplot(RMark_data_BSC$nest_data.processed$data, 
             aes(as.Date(FirstFound, origin = "2023-01-01") - 180,
                               fill = Fate)) +
      geom_histogram(bins = 30,
                     # fill = brewer.pal(8, "Set1")[c(2)], 
                     alpha = 0.5) +
      scale_fill_manual(values = brewer.pal(8, "Set1")[c(2, 1)],
                        labels = c("Failed", "Hatched")) +
      ylab("nests found\nweekly") +
      scale_x_date(date_labels = "%B", 
                   expand = c(0.01, 0.01), 
                   date_breaks = "1 months", limits = c(min(nest_survival_reals_dates_BSC$date, na.rm = TRUE), 
                                                        max(nest_survival_reals_dates_BSC$date, na.rm = TRUE))) +
      scale_y_continuous(breaks = c(10, 20, 30, 40)) +
      luke_theme +
      theme(legend.position = "none",
            panel.grid.major = element_line(colour = "grey70", 
                                            size = 0.15),
            axis.title.x = element_blank(),
            axis.text.x = element_blank(),
            axis.ticks.x = element_blank())
    
# merge plots together
hooded_plover_nest_plot_BSC <- 
  nest_discovery_season_plot_BSC / 
  nest_survival_season_plot_BSC +
  plot_layout(widths = c(5), 
              heights = unit(c(1, 3), c('in', 'in'))) +
  plot_annotation(tag_levels = 'A', title = "Bellarine / Surf Coast")
### PI ---
dates_for_plot_PI <- 
  data.frame(date = as.Date(min(as.numeric(RMark_data_PI$nest_data.processed$data$FirstFound)):
                              max(max(as.numeric(RMark_data_PI$nest_data.processed$data$LastChecked)), 
                                  max(as.numeric(RMark_data_PI$nest_data.processed$data$LastPresent))), 
                            origin = "2023-01-01") - 180,
             day_of_season = c(0:(max(max(as.numeric(RMark_data_PI$nest_data.processed$data$LastChecked)), 
                                      max(as.numeric(RMark_data_PI$nest_data.processed$data$LastPresent))) - 
                                    min(as.numeric(RMark_data_PI$nest_data.processed$data$FirstFound)))))
nest_survival_reals_dates_PI <- 
  left_join(nest_survival_reals_PI_season, dates_for_plot_PI, by = "day_of_season")
nest_survival_season_plot_PI <- 
  ggplot(data = nest_survival_reals_dates_PI) +
  geom_ribbon(aes(x = date, ymin = lcl, ymax = ucl),
              fill = brewer.pal(8, "Dark2")[c(1)], 
              alpha = 0.3) +
  geom_line(aes(x = date, y = estimate), 
            color = brewer.pal(8, "Dark2")[c(1)],
            size = 1) +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months") +
  ylab("daily nest survival ± 95% CI") +
  scale_y_continuous(limits = c(0, 1)) +
  luke_theme +
  theme(legend.position = "bottom",
        legend.title = element_blank(),
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.title.x = element_blank(),
        axis.text.x = element_text(angle = 45, 
                                   hjust = 1, 
                                   vjust = 1))
nest_discovery_season_plot_PI <- 
      ggplot(RMark_data_PI$nest_data.processed$data, 
             aes(as.Date(FirstFound, origin = "2023-01-01") - 180,
                               fill = Fate)) +
      geom_histogram(bins = 30,
                     # fill = brewer.pal(8, "Set1")[c(2)], 
                     alpha = 0.5) +
      scale_fill_manual(values = brewer.pal(8, "Set1")[c(2, 1)],
                        labels = c("Failed", "Hatched")) +
      ylab("nests found\nweekly") +
      scale_x_date(date_labels = "%B", 
                   expand = c(0.01, 0.01), 
                   date_breaks = "1 months", limits = c(min(nest_survival_reals_dates_PI$date, na.rm = TRUE), 
                                                        max(nest_survival_reals_dates_PI$date, na.rm = TRUE))) +
      scale_y_continuous(breaks = c(10, 20, 30, 40)) +
      luke_theme +
      theme(legend.position = "none",
            panel.grid.major = element_line(colour = "grey70", 
                                            size = 0.15),
            axis.title.x = element_blank(),
            axis.text.x = element_blank(),
            axis.ticks.x = element_blank())
    
# merge plots together
hooded_plover_nest_plot_PI <- 
  nest_discovery_season_plot_PI / 
  nest_survival_season_plot_PI +
  plot_layout(widths = c(5), 
              heights = unit(c(1, 3), c('in', 'in'))) +
  plot_annotation(tag_levels = 'A', title = "Phillip Island")
hooded_plover_nest_plot_FPhooded_plover_nest_plot_MPhooded_plover_nest_plot_BChooded_plover_nest_plot_BSChooded_plover_nest_plot_PIhatch_dates_BSC_MP_FP_BC_PI <- 
  bind_rows(nest_data_BSC, nest_data_MP, nest_data_FP, nest_data_BC, nest_data_PI) %>% 
  filter(Fate == "0") %>% 
  mutate(hatch_date = ifelse(Fate == "0" & !is.na(clutch_comp), clutch_comp + 28, 
                              ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10,
                                                   ifelse(state_1st_ob == "2/3 adult size, fluffy", chick_1st_ob - 19,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob, NA)))))), 
                                     ifelse(Fate == "0" & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob), NA, NA))) %>% as.Date())MP_chick_data <-
  suppressMessages(
    bind_rows(
    read_excel(paste0("data/", "MP Chicks sightings 2006_07 to 2023_24.xlsx"), 
               sheet = paste0("MP", " ", "2023", "_", str_sub("2024", 3, 4)), 
               col_types = "text", na = "n/a"),
    read_excel(paste0("data/", "MP Chicks sightings 2006_07 to 2023_24.xlsx"),
               sheet = paste0("MP", " ", "2022", "_", str_sub("2023", 3, 4)),
               col_types = "text", na = "n/a"),
    read_excel(paste0("data/", "MP Chicks sightings 2006_07 to 2023_24.xlsx"),
               sheet = paste0("MP", " ", "2021", "_", str_sub("2022", 3, 4)),
               col_types = "text", na = "n/a"),
    read_excel(paste0("data/", "MP Chicks sightings 2006_07 to 2023_24.xlsx"),
               sheet = paste0("MP", " ", "2020", "_", str_sub("2021", 3, 4)),
               col_types = "text", na = "n/a"),
    read_excel(paste0("data/", "MP Chicks sightings 2006_07 to 2023_24.xlsx"),
               sheet = paste0("MP", " ", "2019", "_", str_sub("2020", 3, 4)),
               col_types = "text", na = "n/a"),
    read_excel(paste0("data/", "MP Chicks sightings 2006_07 to 2023_24.xlsx"),
               sheet = paste0("MP", " ", "2018", "_", str_sub("2019", 3, 4)),
               col_types = "text", na = "n/a"),
    read_excel(paste0("data/", "MP Chicks sightings 2006_07 to 2023_24.xlsx"),
               sheet = paste0("MP", " ", "2017", "_", str_sub("2018", 3, 4)),
               col_types = "text", na = "n/a"),
    read_excel(paste0("data/", "MP Chicks sightings 2006_07 to 2023_24.xlsx"),
               sheet = paste0("MP", " ", "2016", "_", str_sub("2017", 3, 4)),
               col_types = "text", na = "n/a"),
    read_excel(paste0("data/", "MP Chicks sightings 2006_07 to 2023_24.xlsx"),
               sheet = paste0("MP", " ", "2015", "_", str_sub("2016", 3, 4)),
               col_types = "text", na = "n/a"),
    read_excel(paste0("data/", "MP Chicks sightings 2006_07 to 2023_24.xlsx"),
               sheet = paste0("MP", " ", "2014", "_", str_sub("2015", 3, 4)),
               col_types = "text", na = "n/a"),
    read_excel(paste0("data/", "MP Chicks sightings 2006_07 to 2023_24.xlsx"),
               sheet = paste0("MP", " ", "2013", "_", str_sub("2014", 3, 4)),
               col_types = "text", na = "n/a"),
    read_excel(paste0("data/", "MP Chicks sightings 2006_07 to 2023_24.xlsx"),
               sheet = paste0("MP", " ", "2012", "_", str_sub("2013", 3, 4)),
               col_types = "text", na = "n/a"))) %>% 
    rename(region = Region, 
           site = Site,
           nest_ID = Nest_ID,
           date = `Observation Date_code`,
           n_adults_seen = `# adult birds`,
           n_juvs_seen = `# juvenile or sub-adults`,
           n_chicks_seen = `# chicks_updated`,
           habitat = Habitat,
           chick_age = `Chick description`,
           management_type = Management,
           lat = `Observation Latitude`,
           lon = `Observation Longitude`) %>% 
    mutate(season = str_sub(nest_ID, 1, 6)) %>% 
    dplyr::select(region, season, site, nest_ID, date, n_adults_seen, n_juvs_seen, 
                  n_chicks_seen, habitat, chick_age, lat, lon) %>%
    left_join(., hatch_dates_BSC_MP_FP_BC_PI %>% 
                select(nest_ID, hatch_date, chick_management_status, 
                       chick_management_type), by = "nest_ID") %>% 
  rename(management_type = chick_management_type,
         management_status = chick_management_status)
# age key for descriptions of chick developmental stage (email from Jas)
age_offsets <- c(
  "1/3 adult size, fluffy" = -3,
  "1/2 adult size, fluffy" = -10,
  "2/3 adult size, fluffy" = -19,
  "Adult size, mottled grey" = -30,
  "Fledged" = -35,
  "wet in nest" = 0
)
# calculate hatch dates from the chick data (first observation and developmental stage)
hatch_dates_from_chick_data <- MP_chick_data %>%
  mutate(date = dmy(date)) %>%    # convert from "DDMMYYYY" to Date
  group_by(nest_ID) %>%
  slice_min(order_by = date, n = 1, with_ties = FALSE) %>%
  mutate(hatch_date2 = date + age_offsets[chick_age]) %>%
  select(nest_ID, hatch_date2) %>%
  ungroup()
# merge data
MP_chick_data_clean_hatch_dates <- 
  MP_chick_data %>%
  left_join(., hatch_dates_from_chick_data, by = "nest_ID") %>% 
  filter(hatch_date == hatch_date2 | 
           (is.na(hatch_date) & !is.na(hatch_date2)) | 
           (!is.na(hatch_date) & is.na(hatch_date2)))
#### assess errors in hatch dates ----
# check for nest_IDs with differences in the two hatch_dates, these need to be checked
MP_chick_data_clean_hatch_dates <- 
  MP_chick_data %>%
  left_join(., hatch_dates_from_chick_data, by = "nest_ID") %>% 
  select(nest_ID, hatch_date, hatch_date2, chick_age, date) %>% 
  distinct() %>%
  mutate(date = dmy(date)) %>%    # convert from "DDMMYYYY" to Date%>%
  group_by(nest_ID) %>%
  slice_min(order_by = date, n = 1, with_ties = FALSE) %>% 
  mutate(hatch_date_diff = hatch_date - hatch_date2) %>% 
  mutate(hatch_date_diff = ifelse(is.na(hatch_date_diff), 0, hatch_date_diff))  %>% 
  arrange(desc(abs(hatch_date_diff))) %>% 
  filter(hatch_date_diff == 0 & 
           (!is.na(hatch_date) & !is.na(hatch_date2)) | 
           (is.na(hatch_date) & !is.na(hatch_date2)))
#### wrangle management data ----
MP_chick_data_issues <- 
  MP_chick_data %>% 
  filter(nest_ID %in% MP_chick_data_clean_hatch_dates$nest_ID) %>% 
  mutate(management_type = tolower(management_type)) %>%
  mutate(habitat = tolower(habitat)) %>%
  mutate(management_type = str_replace(management_type, "acess", "access")) %>%
  mutate(management_type = str_replace(management_type, "and", ",")) %>%
  mutate(management_type = str_replace(management_type, "temporary", "")) %>%
  mutate(management_type = str_replace_all(management_type, " ", "")) %>%
  mutate(management_type = str_replace_all(management_type, "shelters", "")) %>%
  mutate(management_type = str_replace_all(management_type, "banners", "")) %>%
  mutate(management_type = str_replace_all(management_type, ",,", ",")) %>%
  mutate(sign_access = ifelse(str_detect(management_type, "signaccess"), 1, 0)) %>%
  mutate(sign_nest = ifelse(str_detect(management_type, "signnest"), 1, 0)) %>%
  mutate(rope_fence = ifelse(str_detect(management_type, "ropefence"), 1, 0)) %>%
  mutate(perm_fence = ifelse(str_detect(management_type, "permanentfence"), 1, 0)) %>%
  mutate(wardens = ifelse(str_detect(management_type, "wardens"), 1, 0)) %>% 
  mutate(none = ifelse(str_detect(management_type, "none"), 1, 
                       ifelse(is.na(management_type) | management_type == "", 1, 0))) %>%
  mutate(other = ifelse(str_detect(management_type, "other"), 1, 0)) %>%
  mutate(management_level = ifelse((sign_access == 1 | perm_fence == 1) & sign_nest == 1 & rope_fence == 1 & wardens == 1, 4,
                                   ifelse(rope_fence == 1, 3,
                                          ifelse(sign_nest == 1, 2,
                                                 ifelse(sign_access == 1 | perm_fence == 1, 1,
                                                        ifelse(none == 1, 0, NA)))))) %>%
  mutate(sign_nest_no_sign_access = ifelse(sign_access == 0 & sign_nest == 1, 1, 0)) %>%
  mutate(fence_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & rope_fence == 1, 1, 0)) %>%
  mutate(wardens_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & wardens == 1, 1, 0)) %>%
  mutate(wardens_no_fence = ifelse(rope_fence == 1 & wardens == 1, 1, 0)) %>%
  mutate(just_wardens = ifelse(rope_fence == 0 & sign_access == 0 & sign_nest == 0 & wardens == 1, 1, 0)) %>%
  dplyr::select(-other, -sign_nest_no_sign_access, -fence_no_sign, 
                -wardens_no_sign, -wardens_no_fence, -just_wardens) %>%
  mutate(management_status = ifelse(management_level == 0 & !is.na(management_level), "N", 
                                    ifelse(management_level > 0 & !is.na(management_level), "Y", 
                                           NA))) %>% 
  group_by(season) %>%
  mutate(season = as.factor(season),
         habitat = as.factor(habitat),
         management_status = as.factor(management_status)) %>% 
  mutate(region = ifelse(str_detect(region, "Mornington"), "MP",
                                    ifelse(str_detect(region, "Fleurieu"), "FP",
                                                      ifelse(str_detect(region, "Bellarine"), "BSC", NA)))) %>%
  mutate(site = as.factor(site)) %>%
  mutate(issue1 = ifelse(nchar(date) != 8, "observation date is not 8 characters; ", NA)) %>% 
  mutate(issue2 = ifelse(is.na(date), "observation date missing; ", NA)) %>% 
  mutate(issue3 = ifelse(management_status %!in% c("Y", "N"), "Nest managed? is not Y or N; ", NA)) %>%
  mutate(issue4 = ifelse(is.na(management_level), "Management type is not sufficient for making levels; ", NA)) %>%
  left_join(., hatch_dates_from_chick_data, by = "nest_ID") %>%
  mutate(hatch_date_diff = ifelse(is.na(hatch_date) & !is.na(hatch_date2), 0,
                                  hatch_date - hatch_date2)) %>% 
  mutate(issue5 = ifelse(hatch_date_diff != 0 , "Double check dates because hatch dates from chick data do not match hatch dates from nest data; ", NA)) %>%
  mutate(obs_date_diff = ifelse(hatch_date_diff == 0, 0,
                                ifelse(!is.na(hatch_date) & is.na(hatch_date2), hatch_date - dmy(date), NA))) %>% 
  mutate(issue6 = ifelse(obs_date_diff > 0, "Double check dates because hatch date from nest data is after first chick observation; ", NA)) %>%
  mutate(issue7 = ifelse(is.na(hatch_date) & is.na(hatch_date2), "Hatch dates derived from chick data and nest data are missing ; ", NA)) %>% 
  mutate(issues = ifelse(is.na(issue1) & is.na(issue2) & is.na(issue3) & 
                           is.na(issue4) & is.na(issue5) & is.na(issue6) & is.na(issue7), NA, 
                         paste0(issue1, issue2, issue3, 
                                issue4, issue5, issue6, issue7))) %>% 
  mutate(issues = str_remove_all(issues, "NA")) %>% 
  mutate(issues = ifelse(is.na(issues), "usable", issues)) %>% 
  dplyr::select(-issue1, -issue2, -issue3, 
                -issue4, -issue5, -issue6, -issue7) %>%
  arrange(issues)
# view issues interactively in RStudio Viewer
MP_chick_data_issues %>% 
  filter(issues != "usable") %>% 
  dplyr::select(season, nest_ID, date, management_status, management_level, 
                hatch_date, hatch_date2, hatch_date_diff, issues)  %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')MP_chick_data_issues %>% select(-c(date, management_status, management_level)) %>% 
  distinct() %>% 
  pull(issues) %>% 
  table().
Nest managed? is not Y or N; Management type is not sufficient for making levels;  
                                                                               147 
                                                                            usable 
                                                                              2161 MP_chick_data_clean <-
  MP_chick_data_issues %>% 
  filter(issues == "usable") %>% 
  # mutate(hatch_date = ifelse(!is.na(hatch_date) & is.na(hatch_date2), hatch_date, hatch_date2) %>% as.Date()) %>% 
  mutate(date = dmy(date)) %>% 
  select(region, season, site, nest_ID, hatch_date, date, 
         n_adults_seen, n_juvs_seen, n_chicks_seen, lat, lon, 
         management_level, management_status) %>% 
  group_by(nest_ID) %>% 
  arrange(date) %>% 
  ungroup() %>% 
  mutate(n_adults_seen = ifelse(is.na(n_adults_seen), 0, n_adults_seen),
         n_juvs_seen = ifelse(is.na(n_juvs_seen), 0, n_juvs_seen),
         n_chicks_seen = ifelse(is.na(n_chicks_seen), 0, n_chicks_seen)) %>% 
  mutate(n_offspring_seen = as.numeric(n_juvs_seen) + as.numeric(n_chicks_seen)) %>% 
  mutate(offspring_seen = ifelse(n_offspring_seen > 0, 1, 0)) %>% 
  mutate(brood_age = (date - hatch_date) %>% as.numeric()) %>% 
  group_by(nest_ID) %>% 
  mutate(management_level_max = max(management_level),
         management_status_max = max(as.character(management_status)) %>% as.factor())# assess how often management levels and status changed over the chick obs
MP_chick_data_clean %>% 
  group_by(nest_ID) %>% 
  summarise(n_management_level = n_distinct(management_level),
            n_management_status = n_distinct(management_status)) %>% 
  arrange(desc(n_management_level))# A tibble: 196 × 3
   nest_ID                                n_management_level n_management_status
   <chr>                                               <int>               <int>
 1 201213_Gunnamatta Pair 4 (BJ & LS)_1                    1                   1
 2 201213_Gunnamatta Pair 5 (DU & ??)_4                    1                   1
 3 201213_Moana crt access (east edge)_1                   1                   1
 4 201213_Point King Rd, Portsea_1                         1                   1
 5 201213_Portsea Farnsworth/SLSC west_2                   1                   1
 6 201213_Rye Big Rock_2                                   1                   1
 7 201213_Rye car park east_1                              1                   1
 8 201314_Heyfield Pair 2 (east side) Ry…                  1                   1
 9 201314_Koonya East_3                                    1                   1
10 201314_Koonya West_4                                    1                   1
# ℹ 186 more rowsMP_chick_data_clean %>%
  pull(brood_age) %>%
  as.numeric() %>%
  hist(main = "Distribution of brood age",
       xlab = "Days difference")# which nest_IDs have issues with dates
MP_chick_data_clean %>% 
  filter(brood_age < 0) %>% 
  pull(nest_ID) %>% unique()character(0)MP_chick_data_clean_ <- 
  MP_chick_data_clean %>% 
  filter(brood_age >= 0) %>%
  bind_rows(., data.frame(nest_ID = "junk", brood_age = c(1:35), offspring_seen = 1)) %>% 
  filter(brood_age <= 35)
MP_chick_data_clean_ %>% 
  select(nest_ID, brood_age, offspring_seen) %>% 
  as.data.frame() %>% 
  arrange(nest_ID, brood_age)                                                                  nest_ID
1                                    201213_Gunnamatta Pair 4 (BJ & LS)_1
2                                    201213_Gunnamatta Pair 4 (BJ & LS)_1
3                                    201213_Gunnamatta Pair 4 (BJ & LS)_1
4                                    201213_Gunnamatta Pair 5 (DU & ??)_4
5                                    201213_Gunnamatta Pair 5 (DU & ??)_4
6                                   201213_Moana crt access (east edge)_1
7                                   201213_Moana crt access (east edge)_1
8                                   201213_Moana crt access (east edge)_1
9                                   201213_Moana crt access (east edge)_1
10                                  201213_Moana crt access (east edge)_1
11                                  201213_Moana crt access (east edge)_1
12                                  201213_Moana crt access (east edge)_1
13                                  201213_Moana crt access (east edge)_1
14                                  201213_Moana crt access (east edge)_1
15                                  201213_Moana crt access (east edge)_1
16                                  201213_Moana crt access (east edge)_1
17                                  201213_Moana crt access (east edge)_1
18                                  201213_Moana crt access (east edge)_1
19                                  201213_Moana crt access (east edge)_1
20                                  201213_Moana crt access (east edge)_1
21                                  201213_Moana crt access (east edge)_1
22                                  201213_Moana crt access (east edge)_1
23                                  201213_Moana crt access (east edge)_1
24                                  201213_Moana crt access (east edge)_1
25                                        201213_Point King Rd, Portsea_1
26                                        201213_Point King Rd, Portsea_1
27                                        201213_Point King Rd, Portsea_1
28                                        201213_Point King Rd, Portsea_1
29                                        201213_Point King Rd, Portsea_1
30                                        201213_Point King Rd, Portsea_1
31                                        201213_Point King Rd, Portsea_1
32                                        201213_Point King Rd, Portsea_1
33                                        201213_Point King Rd, Portsea_1
34                                        201213_Point King Rd, Portsea_1
35                                        201213_Point King Rd, Portsea_1
36                                        201213_Point King Rd, Portsea_1
37                                  201213_Portsea Farnsworth/SLSC west_2
38                                  201213_Portsea Farnsworth/SLSC west_2
39                                  201213_Portsea Farnsworth/SLSC west_2
40                                  201213_Portsea Farnsworth/SLSC west_2
41                                                  201213_Rye Big Rock_2
42                                                  201213_Rye Big Rock_2
43                                                  201213_Rye Big Rock_2
44                                                  201213_Rye Big Rock_2
45                                             201213_Rye car park east_1
46                                             201213_Rye car park east_1
47                                             201213_Rye car park east_1
48                                             201213_Rye car park east_1
49                                             201213_Rye car park east_1
50                                             201213_Rye car park east_1
51                                             201213_Rye car park east_1
52                                             201213_Rye car park east_1
53                                             201213_Rye car park east_1
54                                             201213_Rye car park east_1
55                               201314_Heyfield Pair 2 (east side) Rye_1
56                               201314_Heyfield Pair 2 (east side) Rye_1
57                                                   201314_Koonya West_4
58                                                   201314_Koonya West_4
59                                                   201314_Koonya West_4
60                                                   201314_Koonya West_4
61                                         201314_Moana crt access west_2
62                                         201314_Moana crt access west_2
63                                         201314_Moana crt access west_2
64                                         201314_Moana crt access west_2
65                                         201314_Moana crt access west_2
66                                         201314_Moana crt access west_2
67                                         201314_Moana crt access west_2
68                                         201314_Moana crt access west_2
69                                         201314_Moana crt access west_2
70                                         201314_Moana crt access west_2
71                                         201314_Moana crt access west_2
72                                         201314_Moana crt access west_2
73                                         201314_Moana crt access west_2
74                                   201314_Moana crt east (St Andrews)_1
75                                   201314_Moana crt east (St Andrews)_1
76                                   201314_Moana crt east (St Andrews)_1
77                                   201314_Moana crt east (St Andrews)_1
78                                   201314_Moana crt east (St Andrews)_1
79                                   201314_Moana crt east (St Andrews)_1
80                                   201314_Moana crt east (St Andrews)_1
81                                        201314_Point King Rd, Portsea_1
82                                        201314_Point King Rd, Portsea_1
83                                        201314_Point King Rd, Portsea_1
84                                        201314_Point King Rd, Portsea_1
85                                        201314_Point King Rd, Portsea_2
86                                        201314_Point King Rd, Portsea_2
87                                        201314_Point King Rd, Portsea_2
88                                        201314_Point King Rd, Portsea_2
89                                        201314_Point King Rd, Portsea_2
90                                        201314_Point King Rd, Portsea_2
91                                        201314_Point King Rd, Portsea_2
92                                        201314_Point King Rd, Portsea_2
93                                        201314_Point King Rd, Portsea_2
94                                        201314_Point King Rd, Portsea_2
95                                        201314_Point King Rd, Portsea_2
96                                        201314_Point King Rd, Portsea_2
97                        201314_Portsea Franklin rd access (west edge)_1
98                        201314_Portsea Franklin rd access (west edge)_1
99                                             201314_Rye car park west_1
100                                            201314_Rye car park west_1
101                                       201314_St Andrews Boags Rocks_5
102                                       201314_St Andrews Boags Rocks_5
103                                       201314_St Andrews Boags Rocks_5
104                                       201314_St Andrews Boags Rocks_5
105                                       201314_St Andrews Boags Rocks_5
106                                       201314_St Andrews Boags Rocks_5
107                                       201314_St Andrews Boags Rocks_5
108                                       201314_St Andrews Boags Rocks_5
109                                       201314_St Andrews Boags Rocks_5
110                                       201314_St Andrews Boags Rocks_5
111                                       201314_St Andrews Boags Rocks_5
112                                       201314_St Andrews Boags Rocks_5
113                                       201314_St Andrews Boags Rocks_5
114                                       201314_St Andrews Boags Rocks_5
115                                       201314_St Andrews Boags Rocks_5
116                                       201314_St Andrews Boags Rocks_5
117                                    201314_St. Andrews car park east_1
118                                    201314_St. Andrews car park east_1
119                                    201314_St. Andrews car park east_1
120                                    201314_St. Andrews car park east_1
121                                               201415_Gunida Crt Rye_1
122                                               201415_Gunida Crt Rye_1
123                                               201415_Gunida Crt Rye_1
124                                               201415_Gunida Crt Rye_1
125                                  201415_Gunnamatta Pair 4 (BJ & LS)_1
126                                  201415_Gunnamatta Pair 4 (BJ & LS)_1
127                                  201415_Gunnamatta Pair 4 (BJ & LS)_1
128                                  201415_Gunnamatta Pair 4 (BJ & LS)_1
129                              201415_Heyfield Pair 2 (east side) Rye_1
130                              201415_Heyfield Pair 2 (east side) Rye_1
131                              201415_Heyfield Pair 2 (east side) Rye_1
132                              201415_Heyfield Pair 2 (east side) Rye_1
133                              201415_Heyfield Pair 2 (east side) Rye_1
134                              201415_Heyfield Pair 2 (east side) Rye_1
135                              201415_Heyfield Pair 2 (east side) Rye_1
136                              201415_Heyfield Pair 2 (east side) Rye_1
137                              201415_Heyfield Pair 2 (east side) Rye_1
138                              201415_Heyfield Pair 2 (east side) Rye_1
139                                                  201415_Koonya East_1
140                                                  201415_Koonya East_1
141                                                  201415_Koonya East_1
142                                                  201415_Koonya East_1
143                                                  201415_Koonya East_1
144                                                  201415_Koonya East_1
145                                                  201415_Koonya East_1
146                                                  201415_Koonya East_1
147                                                  201415_Koonya East_1
148                                                  201415_Koonya East_1
149                                                  201415_Koonya East_1
150                                                  201415_Koonya East_1
151                                                  201415_Koonya East_1
152                                                  201415_Koonya East_1
153                                                  201415_Koonya East_1
154                                                  201415_Koonya East_1
155                                                  201415_Koonya East_1
156                                                  201415_Koonya East_1
157                                                  201415_Koonya East_1
158                                                  201415_Koonya East_1
159                                                  201415_Koonya East_1
160                                                  201415_Koonya East_1
161                                 201415_Moana crt access (east edge)_3
162                                 201415_Moana crt access (east edge)_3
163                                 201415_Moana crt access (east edge)_3
164                                 201415_Moana crt access (east edge)_3
165                                 201415_Moana crt access (east edge)_3
166                                 201415_Moana crt access (east edge)_3
167                                 201415_Moana crt access (east edge)_3
168                                 201415_Moana crt access (east edge)_3
169                                 201415_Moana crt access (east edge)_3
170                                 201415_Moana crt access (east edge)_3
171                                 201415_Moana crt access (east edge)_3
172                                 201415_Moana crt access (east edge)_3
173                                 201415_Moana crt access (east edge)_3
174                                 201415_Moana crt access (east edge)_3
175                                 201415_Moana crt access (east edge)_3
176                                         201415_Portsea Sphinx rocks_1
177                                         201415_Portsea Sphinx rocks_1
178                                         201415_Portsea Sphinx rocks_1
179                                            201415_Rye car park east_1
180                                            201415_Rye car park east_1
181                                            201415_Rye car park east_1
182                                            201415_Rye car park east_1
183                                    201415_St. Andrews car park east_2
184                                    201415_St. Andrews car park east_2
185                                    201415_St. Andrews car park east_2
186                                    201415_St. Andrews car park east_2
187                                              201516_Coppins Lookout_1
188                                              201516_Coppins Lookout_1
189                                              201516_Coppins Lookout_2
190                                              201516_Coppins Lookout_2
191                                              201516_Coppins Lookout_2
192                                              201516_Coppins Lookout_2
193                                              201516_Coppins Lookout_2
194                                                      201516_Fowlers_4
195                                                      201516_Fowlers_4
196                                                      201516_Fowlers_4
197                                                      201516_Fowlers_4
198                                                      201516_Fowlers_4
199                                                      201516_Fowlers_4
200                                                      201516_Fowlers_4
201                                                      201516_Fowlers_4
202                                                      201516_Fowlers_4
203                                                      201516_Fowlers_4
204                                                      201516_Fowlers_4
205                                                      201516_Fowlers_4
206                                                      201516_Fowlers_4
207                                                      201516_Fowlers_4
208                                                      201516_Fowlers_4
209                                                      201516_Fowlers_4
210                                                      201516_Fowlers_4
211                                                      201516_Fowlers_4
212                                                      201516_Fowlers_4
213                                                      201516_Fowlers_4
214                                                      201516_Fowlers_4
215                                                      201516_Fowlers_4
216                                                      201516_Fowlers_4
217                                                      201516_Fowlers_4
218                                                      201516_Fowlers_4
219                                                      201516_Fowlers_4
220                                                      201516_Fowlers_4
221                                                      201516_Fowlers_4
222                                                      201516_Fowlers_4
223                                                      201516_Fowlers_4
224                                                      201516_Fowlers_4
225                                                      201516_Fowlers_4
226                                                      201516_Fowlers_4
227                                                      201516_Fowlers_4
228                                                      201516_Fowlers_4
229                                                      201516_Fowlers_4
230                                                      201516_Fowlers_4
231                                                      201516_Fowlers_4
232                                                      201516_Fowlers_4
233                                                      201516_Fowlers_4
234                                                      201516_Fowlers_4
235                                                      201516_Fowlers_4
236                                                      201516_Fowlers_4
237                                                      201516_Fowlers_4
238                                                      201516_Fowlers_4
239                                                      201516_Fowlers_4
240                                                      201516_Fowlers_4
241                                                      201516_Fowlers_4
242                                                      201516_Fowlers_4
243                                                      201516_Fowlers_4
244                                            201516_Gunnamatta Pair 1_2
245                                            201516_Gunnamatta Pair 1_2
246                                            201516_Gunnamatta Pair 1_2
247                                            201516_Gunnamatta Pair 1_2
248                                            201516_Gunnamatta Pair 1_2
249                                            201516_Gunnamatta Pair 1_2
250                                            201516_Gunnamatta Pair 1_2
251                                            201516_Gunnamatta Pair 1_2
252                                            201516_Gunnamatta Pair 1_2
253                                            201516_Gunnamatta Pair 1_3
254                                            201516_Gunnamatta Pair 1_3
255                                            201516_Gunnamatta Pair 1_3
256                                            201516_Gunnamatta Pair 1_3
257                                            201516_Gunnamatta Pair 1_3
258                                            201516_Gunnamatta Pair 1_3
259                                            201516_Gunnamatta Pair 1_3
260                                            201516_Gunnamatta Pair 3_2
261                                            201516_Gunnamatta Pair 3_2
262                                            201516_Gunnamatta Pair 3_2
263                                            201516_Gunnamatta Pair 3_2
264                                            201516_Gunnamatta Pair 3_2
265                                            201516_Gunnamatta Pair 3_2
266                                            201516_Gunnamatta Pair 3_2
267                                            201516_Gunnamatta Pair 3_2
268                                       201516_Gunnamatta Pair 5 (DU)_1
269                                       201516_Gunnamatta Pair 5 (DU)_1
270                                            201516_Gunnamatta Pair 6_3
271                                            201516_Gunnamatta Pair 6_3
272                                            201516_Gunnamatta Pair 6_3
273                                            201516_Gunnamatta Pair 6_3
274                                            201516_Gunnamatta Pair 6_3
275                                            201516_Gunnamatta Pair 6_3
276                                            201516_Gunnamatta Pair 6_3
277                              201516_Heyfield Pair 2 (east side) Rye_1
278                              201516_Heyfield Pair 2 (east side) Rye_1
279                              201516_Heyfield Pair 2 (east side) Rye_1
280                              201516_Heyfield Pair 2 (east side) Rye_1
281                              201516_Heyfield Pair 2 (east side) Rye_1
282                                      201516_Miami drive east access_2
283                                      201516_Miami drive east access_2
284                                      201516_Miami drive east access_2
285                                      201516_Miami drive east access_2
286                                      201516_Miami drive east access_2
287                                      201516_Miami drive east access_2
288                                      201516_Miami drive east access_2
289                                      201516_Miami drive east access_3
290                                      201516_Miami drive east access_3
291                                      201516_Miami drive east access_3
292                                      201516_Miami drive east access_3
293                                      201516_Miami drive east access_3
294                                      201516_Miami drive east access_3
295                                      201516_Miami drive east access_3
296                                      201516_Miami drive east access_3
297                                      201516_Miami drive east access_3
298                                      201516_Miami drive east access_3
299                                      201516_Miami drive east access_3
300                                      201516_Miami drive east access_3
301                                      201516_Miami drive east access_3
302                                      201516_Miami drive east access_3
303                                      201516_Miami drive east access_3
304                                      201516_Miami drive east access_3
305                                      201516_Miami drive east access_3
306                                      201516_Miami drive east access_3
307                                      201516_Miami drive east access_3
308                                      201516_Miami drive east access_3
309                                      201516_Miami drive east access_3
310                                      201516_Miami drive east access_3
311                                      201516_Miami drive east access_3
312                                      201516_Miami drive east access_3
313                                      201516_Miami drive east access_3
314                                      201516_Miami drive east access_3
315                                      201516_Miami drive east access_3
316                                      201516_Miami drive east access_3
317                                      201516_Miami drive east access_3
318                                      201516_Miami drive east access_3
319                                      201516_Miami drive east access_3
320                                      201516_Miami drive east access_3
321                                      201516_Miami drive east access_3
322                                      201516_Miami drive east access_3
323                                      201516_Miami drive east access_3
324                                      201516_Miami drive east access_3
325                                      201516_Miami drive east access_3
326                                      201516_Miami drive east access_3
327                                      201516_Miami drive east access_3
328                                      201516_Miami drive east access_3
329                                      201516_Miami drive east access_3
330                                      201516_Miami drive east access_3
331                                      201516_Miami drive east access_3
332                                      201516_Miami drive east access_3
333                                      201516_Miami drive east access_3
334                                      201516_Miami drive east access_3
335                                      201516_Miami drive east access_3
336                                      201516_Miami drive east access_3
337                                      201516_Miami drive east access_3
338                                 201516_Moana crt access (east edge)_1
339                                 201516_Moana crt access (east edge)_1
340                                 201516_Moana crt access (east edge)_1
341                                 201516_Moana crt access (east edge)_1
342                                 201516_Moana crt access (east edge)_1
343                                 201516_Moana crt access (east edge)_1
344                                 201516_Moana crt access (east edge)_1
345                                 201516_Moana crt access (east edge)_1
346                                 201516_Moana crt access (east edge)_1
347                                 201516_Moana crt access (east edge)_1
348                                 201516_Moana crt access (east edge)_2
349                                 201516_Moana crt access (east edge)_2
350                                 201516_Moana crt access (east edge)_2
351                                 201516_Moana crt access (east edge)_2
352                                 201516_Moana crt access (east edge)_2
353                                 201516_Moana crt access (east edge)_2
354                                 201516_Moana crt access (east edge)_2
355                                 201516_Moana crt access (east edge)_2
356                                 201516_Moana crt access (east edge)_2
357                                 201516_Moana crt access (east edge)_2
358                                 201516_Moana crt access (east edge)_2
359                                 201516_Moana crt access (east edge)_2
360                                 201516_Moana crt access (east edge)_2
361                                 201516_Moana crt access (east edge)_2
362                                 201516_Moana crt access (east edge)_2
363                                 201516_Moana crt access (east edge)_2
364                                 201516_Moana crt access (east edge)_2
365                                 201516_Moana crt access (east edge)_2
366                                 201516_Moana crt access (east edge)_2
367                                 201516_Moana crt access (east edge)_2
368                                 201516_Moana crt access (east edge)_2
369                                 201516_Moana crt access (east edge)_2
370                                 201516_Moana crt access (east edge)_2
371                                 201516_Moana crt access (east edge)_2
372                                 201516_Moana crt access (east edge)_2
373                                 201516_Moana crt access (east edge)_2
374                                 201516_Moana crt access (east edge)_2
375                                 201516_Moana crt access (east edge)_2
376                                 201516_Moana crt access (east edge)_2
377                                 201516_Moana crt access (east edge)_2
378                                 201516_Moana crt access (east edge)_2
379                                 201516_Moana crt access (east edge)_2
380                                 201516_Moana crt access (east edge)_2
381                                 201516_Moana crt access (east edge)_2
382                                 201516_Moana crt access (east edge)_2
383                                 201516_Moana crt access (east edge)_2
384                                 201516_Moana crt access (east edge)_2
385                                 201516_Moana crt access (east edge)_2
386                                 201516_Moana crt access (east edge)_2
387                                 201516_Moana crt access (east edge)_2
388                                 201516_Moana crt access (east edge)_2
389                                 201516_Moana crt access (east edge)_2
390                                 201516_Moana crt access (east edge)_2
391                                 201516_Moana crt access (east edge)_2
392                                 201516_Moana crt access (east edge)_2
393                                 201516_Moana crt access (east edge)_2
394                                 201516_Moana crt access (east edge)_2
395                                 201516_Moana crt access (east edge)_2
396                                 201516_Moana crt access (east edge)_2
397                                 201516_Moana crt access (east edge)_2
398                                 201516_Moana crt access (east edge)_2
399                                 201516_Moana crt access (east edge)_2
400                                 201516_Moana crt access (east edge)_2
401                                 201516_Moana crt access (east edge)_2
402                                 201516_Moana crt access (east edge)_2
403                                 201516_Moana crt access (east edge)_2
404                                 201516_Moana crt access (east edge)_2
405                                 201516_Moana crt access (east edge)_2
406                                 201516_Moana crt access (east edge)_2
407                                 201516_Moana crt access (east edge)_2
408                                 201516_Moana crt access (east edge)_2
409                                 201516_Moana crt access (east edge)_2
410                                 201516_Moana crt access (east edge)_2
411                                 201516_Moana crt access (east edge)_2
412                                 201516_Moana crt access (east edge)_2
413                                 201516_Moana crt access (east edge)_2
414                                 201516_Moana crt access (east edge)_2
415                                 201516_Moana crt access (east edge)_2
416                                 201516_Moana crt access (east edge)_2
417                                 201516_Moana crt access (east edge)_2
418                                        201516_Moana crt access west_2
419                                        201516_Moana crt access west_2
420                                        201516_Moana crt access west_2
421                                        201516_Moana crt access west_2
422                                        201516_Moana crt access west_2
423                                        201516_Moana crt access west_2
424                                        201516_Moana crt access west_2
425                                        201516_Moana crt access west_2
426                                        201516_Moana crt access west_2
427                                        201516_Moana crt access west_2
428                                        201516_Moana crt access west_2
429                                        201516_Moana crt access west_2
430                                        201516_Moana crt access west_2
431                                        201516_Moana crt access west_2
432                                        201516_Moana crt access west_2
433                                        201516_Moana crt access west_2
434                                        201516_Moana crt access west_2
435                                        201516_Moana crt access west_2
436                                        201516_Moana crt access west_3
437                                        201516_Moana crt access west_3
438                                        201516_Moana crt access west_3
439                                        201516_Moana crt access west_3
440                                        201516_Moana crt access west_3
441                                        201516_Moana crt access west_3
442                                        201516_Moana crt access west_3
443                                        201516_Moana crt access west_3
444                                        201516_Moana crt access west_3
445                                        201516_Moana crt access west_3
446                                        201516_Moana crt access west_3
447                                        201516_Moana crt access west_3
448                                        201516_Moana crt access west_3
449                                        201516_Moana crt access west_3
450                                        201516_Moana crt access west_3
451                                        201516_Moana crt access west_3
452                                        201516_Moana crt access west_3
453                                        201516_Moana crt access west_3
454                                        201516_Moana crt access west_3
455                                        201516_Moana crt access west_3
456                                        201516_Moana crt access west_3
457                                        201516_Moana crt access west_3
458                                        201516_Moana crt access west_3
459                                        201516_Moana crt access west_3
460                                        201516_Moana crt access west_3
461                                        201516_Moana crt access west_3
462                                        201516_Moana crt access west_3
463                                        201516_Moana crt access west_3
464                                        201516_Moana crt access west_3
465                                        201516_Moana crt access west_3
466                                        201516_Moana crt access west_3
467                                        201516_Moana crt access west_3
468                                        201516_Moana crt access west_3
469                                        201516_Moana crt access west_3
470                                        201516_Moana crt access west_3
471                                        201516_Moana crt access west_3
472                                        201516_Moana crt access west_3
473                                        201516_Moana crt access west_3
474                                        201516_Moana crt access west_3
475                                        201516_Moana crt access west_3
476                                        201516_Moana crt access west_3
477                                        201516_Moana crt access west_3
478                                        201516_Moana crt access west_3
479                                        201516_Moana crt access west_3
480                                        201516_Moana crt access west_3
481                                        201516_Moana crt access west_3
482                                        201516_Moana crt access west_3
483                                        201516_Moana crt access west_3
484                                        201516_Moana crt access west_3
485                                        201516_Moana crt access west_3
486                                        201516_Moana crt access west_3
487                                        201516_Moana crt access west_3
488                                        201516_Moana crt access west_3
489                                        201516_Moana crt access west_3
490                                        201516_Moana crt access west_3
491                                        201516_Moana crt access west_3
492                                        201516_Moana crt access west_3
493                                                    201516_Montforts_1
494                                                    201516_Montforts_1
495                                                    201516_Montforts_1
496                                                    201516_Montforts_1
497                                                    201516_Montforts_1
498                                                    201516_Montforts_1
499                                                    201516_Montforts_1
500                                                    201516_Montforts_1
501                                                    201516_Montforts_1
502                                                    201516_Montforts_1
503                                                    201516_Montforts_1
504                                                    201516_Montforts_1
505                                                    201516_Montforts_1
506                                                    201516_Montforts_1
507                                                    201516_Montforts_1
508                                                    201516_Montforts_1
509                                 201516_Portsea Farnsworth/SLSC west_3
510                                 201516_Portsea Farnsworth/SLSC west_3
511                                 201516_Portsea Farnsworth/SLSC west_3
512                                 201516_Portsea Farnsworth/SLSC west_3
513                                 201516_Portsea Farnsworth/SLSC west_3
514                                 201516_Portsea Farnsworth/SLSC west_3
515                                 201516_Portsea Farnsworth/SLSC west_3
516                                 201516_Portsea Farnsworth/SLSC west_3
517                                 201516_Portsea Farnsworth/SLSC west_3
518                                 201516_Portsea Farnsworth/SLSC west_3
519                                 201516_Portsea Farnsworth/SLSC west_3
520                                 201516_Portsea Farnsworth/SLSC west_3
521                                 201516_Portsea Farnsworth/SLSC west_3
522                                 201516_Portsea Farnsworth/SLSC west_3
523                                 201516_Portsea Farnsworth/SLSC west_3
524                                 201516_Portsea Farnsworth/SLSC west_3
525                                 201516_Portsea Farnsworth/SLSC west_3
526                                   201516_Portsea Franklin rd access_1
527                                   201516_Portsea Franklin rd access_1
528                                   201516_Portsea Franklin rd access_1
529                                   201516_Portsea Franklin rd access_1
530                                   201516_Portsea Franklin rd access_1
531                                   201516_Portsea Franklin rd access_1
532                                   201516_Portsea Franklin rd access_1
533                                   201516_Portsea Franklin rd access_1
534                                   201516_Portsea Franklin rd access_1
535                                   201516_Portsea Franklin rd access_1
536                                   201516_Portsea Franklin rd access_3
537                                   201516_Portsea Franklin rd access_3
538                                   201516_Portsea Franklin rd access_3
539                                   201516_Portsea Franklin rd access_3
540                                   201516_Portsea Franklin rd access_3
541                                   201516_Portsea Franklin rd access_3
542                                   201516_Portsea Franklin rd access_3
543                                   201516_Portsea Franklin rd access_3
544                                   201516_Portsea Franklin rd access_3
545                                   201516_Portsea Franklin rd access_3
546                                   201516_Portsea Franklin rd access_3
547                                   201516_Portsea Franklin rd access_3
548                                   201516_Portsea Franklin rd access_3
549                                   201516_Portsea Franklin rd access_3
550                                   201516_Portsea Franklin rd access_3
551                                   201516_Portsea Franklin rd access_3
552                                   201516_Portsea Franklin rd access_3
553                                   201516_Portsea Franklin rd access_3
554                                   201516_Portsea Franklin rd access_3
555                                   201516_Portsea Franklin rd access_3
556                                   201516_Portsea Franklin rd access_3
557                                   201516_Portsea Franklin rd access_3
558                                   201516_Portsea Franklin rd access_3
559                                   201516_Portsea Franklin rd access_3
560                                   201516_Portsea Franklin rd access_3
561                                   201516_Portsea Franklin rd access_3
562                                                 201516_Rye Big Rock_4
563                                                 201516_Rye Big Rock_4
564                                                 201516_Rye Big Rock_4
565                                                 201516_Rye Big Rock_4
566                                                 201516_Rye Big Rock_4
567                                                 201516_Rye Big Rock_4
568                                                 201516_Rye Big Rock_4
569                                                 201516_Rye Big Rock_4
570                                                 201516_Rye Big Rock_4
571                                                 201516_Rye Big Rock_4
572                                                 201516_Rye Big Rock_4
573                                                 201516_Rye Big Rock_4
574                                                 201516_Rye Big Rock_4
575                                                 201516_Rye Big Rock_4
576                                            201516_Rye car park west_1
577                                            201516_Rye car park west_1
578                                            201516_Rye car park west_1
579                                            201516_Rye car park west_1
580                                            201516_Rye car park west_1
581                                            201516_Rye car park west_3
582                                            201516_Rye car park west_3
583                                            201516_Rye car park west_3
584                                            201516_Rye car park west_3
585                                            201516_Rye car park west_3
586                                            201516_Rye car park west_3
587                                            201516_Rye car park west_3
588                                      201516_St Andrews carpark west_1
589                                      201516_St Andrews carpark west_1
590                                      201516_St Andrews carpark west_1
591                                      201516_St Andrews carpark west_1
592                                      201516_St Andrews carpark west_2
593                                      201516_St Andrews carpark west_2
594                                      201516_St Andrews carpark west_2
595                                      201516_St Andrews carpark west_2
596                                      201516_St Andrews carpark west_2
597                                      201516_St Andrews carpark west_2
598                                      201516_St Andrews carpark west_2
599                                      201516_St Andrews carpark west_2
600                                      201516_St Andrews carpark west_2
601                                      201516_St Andrews carpark west_2
602                                      201516_St Andrews carpark west_2
603                                      201516_St Andrews carpark west_2
604                                      201516_St Andrews carpark west_2
605                                      201516_St Andrews carpark west_2
606                                      201516_St Andrews carpark west_2
607                                      201516_St Andrews carpark west_2
608                                      201516_St Andrews carpark west_2
609                                      201516_St Andrews carpark west_2
610                                      201516_St Andrews carpark west_2
611                                      201516_St Andrews carpark west_2
612                                      201516_St Andrews carpark west_2
613                                      201516_St Andrews carpark west_2
614                                      201516_St Andrews carpark west_2
615                                      201516_St Andrews carpark west_2
616                                      201516_St Andrews carpark west_2
617                                      201516_St Andrews carpark west_2
618                                      201516_St Andrews carpark west_2
619                                      201516_St Andrews carpark west_2
620                                      201516_St Andrews carpark west_2
621                                      201516_St Andrews carpark west_2
622                                      201516_St Andrews carpark west_2
623                                      201516_St Andrews carpark west_2
624                                      201516_St Andrews carpark west_2
625                                      201516_St Andrews carpark west_2
626                                      201516_St Andrews carpark west_2
627                                      201516_St Andrews carpark west_2
628                                      201516_St Andrews carpark west_2
629                                      201516_St Andrews carpark west_2
630                                      201516_St Andrews carpark west_2
631                                      201516_St Andrews carpark west_2
632                                      201516_St Andrews carpark west_2
633                                      201516_St Andrews carpark west_2
634                                      201516_St Andrews carpark west_2
635                                      201516_St Andrews carpark west_2
636                                      201516_St Andrews carpark west_2
637                                      201516_St Andrews carpark west_2
638                                      201516_St Andrews carpark west_2
639                                      201516_St Andrews carpark west_2
640                                    201516_St. Andrews car park east_1
641                                    201516_St. Andrews car park east_1
642                                    201516_St. Andrews car park east_1
643                                    201516_St. Andrews car park east_1
644                                    201516_St. Andrews car park east_1
645                                    201516_St. Andrews car park east_1
646                                    201516_St. Andrews car park east_1
647                                    201516_St. Andrews car park east_1
648                                    201516_St. Andrews car park east_1
649                                    201516_St. Andrews car park east_1
650                                    201516_St. Andrews car park east_2
651                                    201516_St. Andrews car park east_2
652                                    201516_St. Andrews car park east_2
653                                    201516_St. Andrews car park east_2
654                                    201516_St. Andrews car park east_2
655                                    201516_St. Andrews car park east_2
656                                    201516_St. Andrews car park east_2
657                                    201516_St. Andrews car park east_2
658                                    201516_St. Andrews car park east_2
659                                    201516_St. Andrews car park east_2
660                                    201516_St. Andrews car park east_2
661                                    201516_St. Andrews car park east_2
662                                    201516_St. Andrews car park east_2
663                                    201516_St. Andrews car park east_2
664                                    201516_St. Andrews car park east_2
665                                    201516_St. Andrews car park east_2
666                                    201516_St. Andrews car park east_2
667                                    201516_St. Andrews car park east_2
668                                    201516_St. Andrews car park east_2
669                                    201516_St. Andrews car park east_2
670                                    201516_St. Andrews car park east_2
671                                    201516_St. Andrews car park east_2
672                                    201516_St. Andrews car park east_2
673                                    201516_St. Andrews car park east_2
674                                    201516_St. Andrews car park east_2
675                                    201516_St. Andrews car park east_2
676                                    201516_St. Andrews car park east_2
677                                    201516_St. Andrews car park east_2
678                                    201516_St. Andrews car park east_2
679                                    201516_St. Andrews car park east_2
680                                    201516_St. Andrews car park east_2
681                                    201516_St. Andrews car park east_2
682                                    201516_St. Andrews car park east_2
683                                    201516_St. Andrews car park east_2
684                                    201516_St. Andrews car park east_2
685                                    201516_St. Andrews car park east_2
686                                    201516_St. Andrews car park east_2
687                                    201516_St. Andrews car park east_2
688                                    201516_St. Andrews car park east_2
689                                    201516_St. Andrews car park east_2
690                                    201516_St. Andrews car park east_2
691                                    201516_St. Andrews car park east_2
692                                    201516_St. Andrews car park east_2
693                                    201516_St. Andrews car park east_2
694                                    201516_St. Andrews car park east_2
695                                    201516_St. Andrews car park east_2
696                                    201516_St. Andrews car park east_2
697                                              201617_Coppins Lookout_4
698                                              201617_Coppins Lookout_4
699                                              201617_Coppins Lookout_4
700                                              201617_Coppins Lookout_4
701                                              201617_Coppins Lookout_4
702                                              201617_Coppins Lookout_4
703                                              201617_Coppins Lookout_4
704                                              201617_Coppins Lookout_4
705                                              201617_Coppins Lookout_4
706                                              201617_Coppins Lookout_4
707                                                      201617_Fowlers_3
708                                                      201617_Fowlers_3
709                                                      201617_Fowlers_3
710                                                      201617_Fowlers_3
711                                                      201617_Fowlers_3
712                                                      201617_Fowlers_3
713                                                      201617_Fowlers_3
714                                                      201617_Fowlers_3
715                                                      201617_Fowlers_4
716                                                      201617_Fowlers_4
717                                                      201617_Fowlers_4
718                                                      201617_Fowlers_4
719                                                      201617_Fowlers_4
720                                                      201617_Fowlers_4
721                                                      201617_Fowlers_4
722                                                      201617_Fowlers_4
723                                                      201617_Fowlers_4
724                                                      201617_Fowlers_4
725                                                      201617_Fowlers_4
726                                                      201617_Fowlers_4
727                                                      201617_Fowlers_4
728                                                      201617_Fowlers_4
729                                                      201617_Fowlers_4
730                                                      201617_Fowlers_4
731                                                      201617_Fowlers_4
732                                                      201617_Fowlers_4
733                                                      201617_Fowlers_4
734                                                      201617_Fowlers_4
735                                                      201617_Fowlers_4
736                                                      201617_Fowlers_4
737                                                      201617_Fowlers_4
738                                                      201617_Fowlers_4
739                                                      201617_Fowlers_4
740                                                      201617_Fowlers_4
741                                                      201617_Fowlers_4
742                                                      201617_Fowlers_4
743                                                      201617_Fowlers_4
744                                                      201617_Fowlers_4
745                                                      201617_Fowlers_4
746                                                      201617_Fowlers_4
747                                                      201617_Fowlers_4
748                                                      201617_Fowlers_4
749                                                      201617_Fowlers_4
750                                                      201617_Fowlers_4
751                                                      201617_Fowlers_4
752                                                      201617_Fowlers_4
753                                                      201617_Fowlers_4
754                                                      201617_Fowlers_4
755                                                      201617_Fowlers_4
756                                                      201617_Fowlers_4
757                                                      201617_Fowlers_4
758                                                      201617_Fowlers_4
759                                                      201617_Fowlers_4
760                                                      201617_Fowlers_4
761                                                      201617_Fowlers_4
762                                                      201617_Fowlers_4
763                                                      201617_Fowlers_4
764                                                      201617_Fowlers_4
765                                                      201617_Fowlers_4
766                                                      201617_Fowlers_4
767                                                      201617_Fowlers_4
768                                                      201617_Fowlers_4
769                                               201617_Gunida Crt Rye_1
770                                               201617_Gunida Crt Rye_1
771                                               201617_Gunida Crt Rye_1
772                                               201617_Gunida Crt Rye_1
773                                               201617_Gunida Crt Rye_4
774                                               201617_Gunida Crt Rye_4
775                                               201617_Gunida Crt Rye_4
776                                               201617_Gunida Crt Rye_4
777                                               201617_Gunida Crt Rye_4
778                                               201617_Gunida Crt Rye_4
779                                               201617_Gunida Crt Rye_4
780                                               201617_Gunida Crt Rye_4
781                                               201617_Gunida Crt Rye_4
782                                               201617_Gunida Crt Rye_4
783                                               201617_Gunida Crt Rye_4
784                                               201617_Gunida Crt Rye_4
785                                               201617_Gunida Crt Rye_4
786                                               201617_Gunida Crt Rye_4
787                                               201617_Gunida Crt Rye_4
788                                               201617_Gunida Crt Rye_4
789                                    201617_Gunnamatta Fingal Tk (P4)_3
790                                    201617_Gunnamatta Fingal Tk (P4)_3
791                                    201617_Gunnamatta Fingal Tk (P4)_3
792                                    201617_Gunnamatta Fingal Tk (P4)_3
793                                    201617_Gunnamatta Fingal Tk (P4)_3
794                                    201617_Gunnamatta Fingal Tk (P4)_3
795                                    201617_Gunnamatta Fingal Tk (P4)_3
796                                    201617_Gunnamatta Fingal Tk (P4)_3
797                                    201617_Gunnamatta Fingal Tk (P4)_3
798                                    201617_Gunnamatta Fingal Tk (P4)_3
799                                    201617_Gunnamatta Fingal Tk (P4)_3
800                                    201617_Gunnamatta Fingal Tk (P4)_3
801                                    201617_Gunnamatta Fingal Tk (P4)_3
802                                    201617_Gunnamatta Fingal Tk (P4)_3
803                                    201617_Gunnamatta Fingal Tk (P4)_3
804                                    201617_Gunnamatta Fingal Tk (P4)_3
805                               201617_Gunnamatta Fingal Tk East (P5)_4
806                               201617_Gunnamatta Fingal Tk East (P5)_4
807                                    201617_Gunnamatta Fingal Tk West_2
808                                    201617_Gunnamatta Fingal Tk West_2
809                                    201617_Gunnamatta Fingal Tk West_2
810                                    201617_Gunnamatta Fingal Tk West_2
811                                    201617_Gunnamatta Fingal Tk West_2
812                                    201617_Gunnamatta Fingal Tk West_2
813                                    201617_Gunnamatta Fingal Tk West_2
814                                    201617_Gunnamatta Fingal Tk West_2
815                                    201617_Gunnamatta Fingal Tk West_2
816                                    201617_Gunnamatta Fingal Tk West_2
817                                    201617_Gunnamatta Fingal Tk West_2
818                                    201617_Gunnamatta Fingal Tk West_2
819                                    201617_Gunnamatta Fingal Tk West_2
820                                    201617_Gunnamatta Fingal Tk West_2
821                                    201617_Gunnamatta Fingal Tk West_2
822                                    201617_Gunnamatta Fingal Tk West_2
823                                    201617_Gunnamatta Fingal Tk West_2
824                                    201617_Gunnamatta Fingal Tk West_2
825                                    201617_Gunnamatta Fingal Tk West_2
826                                    201617_Gunnamatta Fingal Tk West_2
827                                    201617_Gunnamatta Fingal Tk West_2
828                                    201617_Gunnamatta Fingal Tk West_2
829                                    201617_Gunnamatta Fingal Tk West_2
830                                    201617_Gunnamatta Fingal Tk West_2
831                                    201617_Gunnamatta Fingal Tk West_2
832                                    201617_Gunnamatta Fingal Tk West_2
833                                    201617_Gunnamatta Fingal Tk West_2
834                                    201617_Gunnamatta Fingal Tk West_2
835                                    201617_Gunnamatta Fingal Tk West_2
836                                    201617_Gunnamatta Fingal Tk West_2
837                                    201617_Gunnamatta Fingal Tk West_2
838                                    201617_Gunnamatta Fingal Tk West_2
839                                    201617_Gunnamatta Fingal Tk West_2
840                                    201617_Gunnamatta Fingal Tk West_2
841                                    201617_Gunnamatta Fingal Tk West_2
842                                    201617_Gunnamatta Fingal Tk West_2
843                                    201617_Gunnamatta Fingal Tk West_2
844                                    201617_Gunnamatta Fingal Tk West_2
845                                    201617_Gunnamatta Fingal Tk West_2
846                                    201617_Gunnamatta Fingal Tk West_2
847                                    201617_Gunnamatta Fingal Tk West_2
848                                    201617_Gunnamatta Fingal Tk West_2
849                                    201617_Gunnamatta Fingal Tk West_2
850                                    201617_Gunnamatta Fingal Tk West_2
851                                 201617_Gunnamatta No Dogs East (P1)_2
852                                 201617_Gunnamatta No Dogs East (P1)_2
853                                 201617_Gunnamatta No Dogs East (P1)_2
854                                 201617_Gunnamatta No Dogs East (P1)_2
855                                 201617_Gunnamatta No Dogs East (P1)_2
856                                 201617_Gunnamatta No Dogs East (P1)_2
857                                 201617_Gunnamatta No Dogs East (P1)_2
858                                 201617_Gunnamatta No Dogs East (P1)_2
859                                 201617_Gunnamatta No Dogs East (P1)_2
860                                 201617_Gunnamatta No Dogs East (P1)_2
861                                 201617_Gunnamatta No Dogs East (P1)_2
862                                 201617_Gunnamatta No Dogs East (P1)_2
863                                 201617_Gunnamatta No Dogs East (P1)_2
864                                 201617_Gunnamatta No Dogs East (P1)_2
865                                 201617_Gunnamatta No Dogs East (P1)_2
866                                 201617_Gunnamatta No Dogs East (P1)_2
867                                 201617_Gunnamatta No Dogs East (P1)_2
868                                 201617_Gunnamatta No Dogs East (P1)_2
869                                 201617_Gunnamatta No Dogs East (P1)_2
870                                 201617_Gunnamatta No Dogs East (P1)_2
871                                 201617_Gunnamatta No Dogs East (P1)_2
872                                 201617_Gunnamatta No Dogs East (P1)_2
873                                 201617_Gunnamatta No Dogs East (P1)_2
874                                 201617_Gunnamatta No Dogs East (P1)_2
875                                 201617_Gunnamatta No Dogs East (P1)_2
876                                 201617_Gunnamatta No Dogs East (P1)_2
877                                 201617_Gunnamatta No Dogs East (P1)_2
878                                 201617_Gunnamatta No Dogs East (P1)_2
879                                 201617_Gunnamatta No Dogs East (P1)_2
880                                 201617_Gunnamatta No Dogs East (P1)_2
881                                 201617_Gunnamatta No Dogs East (P1)_2
882                                 201617_Gunnamatta No Dogs East (P1)_2
883                                 201617_Gunnamatta No Dogs East (P1)_2
884                                 201617_Gunnamatta No Dogs East (P1)_2
885                                 201617_Gunnamatta No Dogs East (P1)_2
886                                 201617_Gunnamatta No Dogs East (P1)_2
887                                 201617_Gunnamatta No Dogs East (P1)_2
888                                 201617_Gunnamatta No Dogs East (P1)_2
889                                 201617_Gunnamatta No Dogs East (P1)_2
890                                 201617_Gunnamatta No Dogs East (P1)_2
891                                 201617_Gunnamatta No Dogs East (P1)_2
892                                 201617_Gunnamatta No Dogs East (P1)_2
893                                 201617_Gunnamatta No Dogs East (P1)_2
894                              201617_Heyfield Pair 2 (east side) Rye_1
895                              201617_Heyfield Pair 2 (east side) Rye_1
896                              201617_Heyfield Pair 2 (east side) Rye_1
897                              201617_Heyfield Pair 2 (east side) Rye_1
898                              201617_Heyfield Pair 2 (east side) Rye_1
899                              201617_Heyfield Pair 2 (east side) Rye_1
900                              201617_Heyfield Pair 2 (east side) Rye_3
901                              201617_Heyfield Pair 2 (east side) Rye_3
902                              201617_Heyfield Pair 2 (east side) Rye_3
903                              201617_Heyfield Pair 2 (east side) Rye_3
904                              201617_Heyfield Pair 2 (east side) Rye_3
905                              201617_Heyfield Pair 2 (east side) Rye_3
906                              201617_Heyfield Pair 2 (east side) Rye_3
907                              201617_Heyfield Pair 2 (east side) Rye_3
908                              201617_Heyfield Pair 2 (east side) Rye_3
909                              201617_Heyfield Pair 2 (east side) Rye_3
910                              201617_Heyfield Pair 2 (east side) Rye_3
911                              201617_Heyfield Pair 2 (east side) Rye_3
912                              201617_Heyfield Pair 2 (east side) Rye_3
913                              201617_Heyfield Pair 2 (east side) Rye_3
914                              201617_Heyfield Pair 2 (east side) Rye_4
915                              201617_Heyfield Pair 2 (east side) Rye_4
916                              201617_Heyfield Pair 2 (east side) Rye_4
917                              201617_Heyfield Pair 2 (east side) Rye_4
918                              201617_Heyfield Pair 2 (east side) Rye_4
919                              201617_Heyfield Pair 2 (east side) Rye_4
920                              201617_Heyfield Pair 2 (east side) Rye_4
921                              201617_Heyfield Pair 2 (east side) Rye_4
922                              201617_Heyfield Pair 2 (east side) Rye_4
923                              201617_Heyfield Pair 2 (east side) Rye_4
924                              201617_Heyfield Pair 2 (east side) Rye_4
925                              201617_Heyfield Pair 2 (east side) Rye_4
926                              201617_Heyfield Pair 2 (east side) Rye_4
927                                 201617_Moana crt access (east edge)_2
928                                 201617_Moana crt access (east edge)_2
929                                 201617_Moana crt access (east edge)_2
930                                 201617_Moana crt access (east edge)_2
931                                 201617_Moana crt access (east edge)_2
932                                 201617_Moana crt access (east edge)_2
933                                 201617_Moana crt access (east edge)_2
934                                 201617_Moana crt access (east edge)_2
935                                 201617_Moana crt access (east edge)_2
936                                 201617_Moana crt access (east edge)_2
937                                 201617_Moana crt access (east edge)_2
938                                 201617_Moana crt access (east edge)_2
939                                 201617_Moana crt access (east edge)_2
940                                 201617_Moana crt access (east edge)_2
941                                 201617_Moana crt access (east edge)_2
942                                 201617_Moana crt access (east edge)_2
943                                 201617_Moana crt access (east edge)_2
944                                 201617_Moana crt access (east edge)_2
945                                 201617_Moana crt access (east edge)_2
946                                 201617_Moana crt access (east edge)_2
947                                 201617_Moana crt access (east edge)_2
948                                 201617_Moana crt access (east edge)_2
949                                 201617_Moana crt access (east edge)_2
950                                 201617_Moana crt access (east edge)_2
951                                 201617_Moana crt access (east edge)_2
952                                 201617_Moana crt access (east edge)_2
953                                 201617_Moana crt access (east edge)_2
954                                 201617_Moana crt access (east edge)_2
955                                 201617_Moana crt access (east edge)_2
956                                 201617_Moana crt access (east edge)_2
957                                 201617_Moana crt access (east edge)_2
958                                 201617_Moana crt access (east edge)_2
959                                 201617_Moana crt access (east edge)_2
960                                 201617_Moana crt access (east edge)_2
961                                 201617_Moana crt access (east edge)_2
962                                 201617_Moana crt access (east edge)_2
963                                 201617_Moana crt access (east edge)_2
964                                 201617_Moana crt access (east edge)_2
965                                 201617_Moana crt access (east edge)_2
966                                 201617_Moana crt access (east edge)_2
967                                 201617_Moana crt access (east edge)_2
968                                 201617_Moana crt access (east edge)_2
969                                 201617_Moana crt access (east edge)_2
970                                 201617_Moana crt access (east edge)_2
971                                 201617_Moana crt access (east edge)_2
972                                 201617_Moana crt access (east edge)_2
973                                 201617_Moana crt access (east edge)_2
974                                        201617_Moana crt access west_3
975                                        201617_Moana crt access west_3
976                                        201617_Moana crt access west_3
977                                        201617_Moana crt access west_3
978                                        201617_Moana crt access west_3
979                                        201617_Moana crt access west_3
980                                        201617_Moana crt access west_3
981                                        201617_Moana crt access west_3
982                                        201617_Moana crt access west_3
983                                        201617_Moana crt access west_3
984                                        201617_Moana crt access west_3
985                                        201617_Moana crt access west_3
986                                        201617_Moana crt access west_3
987                                        201617_Moana crt access west_3
988                                        201617_Moana crt access west_3
989                                        201617_Moana crt access west_3
990                                        201617_Moana crt access west_3
991                                        201617_Moana crt access west_3
992                                        201617_Moana crt access west_3
993                                        201617_Moana crt access west_3
994                                        201617_Moana crt access west_3
995                                        201617_Moana crt access west_3
996                                        201617_Moana crt access west_3
997                                        201617_Moana crt access west_3
998                                        201617_Moana crt access west_3
999                                        201617_Moana crt access west_3
1000                                       201617_Moana crt access west_3
1001                                       201617_Moana crt access west_3
1002                                                   201617_Montforts_1
1003                                                   201617_Montforts_1
1004                                                   201617_Montforts_1
1005                                                   201617_Montforts_1
1006                                                   201617_Montforts_1
1007                                                   201617_Montforts_1
1008                                                   201617_Montforts_1
1009                                                   201617_Montforts_1
1010                                                   201617_Montforts_1
1011                                                   201617_Montforts_1
1012                                                   201617_Montforts_1
1013                                                   201617_Montforts_1
1014                                                   201617_Montforts_1
1015                                                   201617_Montforts_1
1016                                                   201617_Montforts_1
1017                                                   201617_Montforts_1
1018                                                   201617_Montforts_1
1019                                                   201617_Montforts_1
1020                                                   201617_Montforts_1
1021                                                   201617_Montforts_1
1022                                                   201617_Montforts_1
1023                                                   201617_Montforts_1
1024                                                   201617_Montforts_1
1025                                                   201617_Montforts_1
1026                                                   201617_Montforts_1
1027                                                   201617_Montforts_1
1028                                                   201617_Montforts_1
1029                                                   201617_Montforts_1
1030                                                   201617_Montforts_1
1031                                                   201617_Montforts_1
1032                                                   201617_Montforts_2
1033                                                   201617_Montforts_2
1034                                                   201617_Montforts_2
1035                                                   201617_Montforts_2
1036                                                   201617_Montforts_2
1037                                                   201617_Montforts_2
1038                                                   201617_Montforts_2
1039                                                   201617_Montforts_2
1040                                                   201617_Montforts_2
1041                                                   201617_Montforts_2
1042                                                   201617_Montforts_2
1043                                                   201617_Montforts_2
1044                                201617_Portsea Farnsworth/SLSC west_1
1045                                201617_Portsea Farnsworth/SLSC west_1
1046                                201617_Portsea Farnsworth/SLSC west_1
1047                                201617_Portsea Farnsworth/SLSC west_1
1048                                201617_Portsea Farnsworth/SLSC west_1
1049                                201617_Portsea Farnsworth/SLSC west_1
1050                                201617_Portsea Farnsworth/SLSC west_1
1051                                201617_Portsea Farnsworth/SLSC west_1
1052                                201617_Portsea Farnsworth/SLSC west_1
1053                                201617_Portsea Farnsworth/SLSC west_1
1054                                201617_Portsea Farnsworth/SLSC west_1
1055                                201617_Portsea Farnsworth/SLSC west_1
1056                                201617_Portsea Farnsworth/SLSC west_1
1057                                201617_Portsea Farnsworth/SLSC west_1
1058                                201617_Portsea Farnsworth/SLSC west_1
1059                                201617_Portsea Farnsworth/SLSC west_1
1060                                201617_Portsea Farnsworth/SLSC west_1
1061                                201617_Portsea Farnsworth/SLSC west_1
1062                                201617_Portsea Farnsworth/SLSC west_1
1063                                201617_Portsea Farnsworth/SLSC west_1
1064                                201617_Portsea Farnsworth/SLSC west_1
1065                                201617_Portsea Farnsworth/SLSC west_1
1066                                201617_Portsea Farnsworth/SLSC west_1
1067                                201617_Portsea Farnsworth/SLSC west_1
1068                                201617_Portsea Farnsworth/SLSC west_1
1069                                201617_Portsea Farnsworth/SLSC west_1
1070                                201617_Portsea Farnsworth/SLSC west_1
1071                                201617_Portsea Farnsworth/SLSC west_1
1072                                201617_Portsea Farnsworth/SLSC west_1
1073                                201617_Portsea Farnsworth/SLSC west_1
1074         201617_Pt Nepean (authorised personnel only) - Borgs Rocks_1
1075         201617_Pt Nepean (authorised personnel only) - Borgs Rocks_1
1076 201617_Pt Nepean (authorised personnel only) - Sierra Nevada Rocks_2
1077 201617_Pt Nepean (authorised personnel only) - Sierra Nevada Rocks_2
1078 201617_Pt Nepean (authorised personnel only) - Sierra Nevada Rocks_2
1079 201617_Pt Nepean (authorised personnel only) - Sierra Nevada Rocks_2
1080              201617_Pt Nepean (authorised personnel only) - Spooks_3
1081              201617_Pt Nepean (authorised personnel only) - Spooks_3
1082              201617_Pt Nepean (authorised personnel only) - Spooks_3
1083              201617_Pt Nepean (authorised personnel only) - Spooks_3
1084              201617_Pt Nepean (authorised personnel only) - Spooks_3
1085              201617_Pt Nepean (authorised personnel only) - Spooks_3
1086              201617_Pt Nepean (authorised personnel only) - Spooks_3
1087              201617_Pt Nepean (authorised personnel only) - Spooks_3
1088                                                201617_Rye Big Rock_2
1089                                                201617_Rye Big Rock_2
1090                                                201617_Rye Big Rock_2
1091                                                201617_Rye Big Rock_2
1092                                                201617_Rye Big Rock_2
1093                                                201617_Rye Big Rock_2
1094                                                201617_Rye Big Rock_2
1095                                                201617_Rye Big Rock_2
1096                                                201617_Rye Big Rock_2
1097                                                201617_Rye Big Rock_2
1098                                                201617_Rye Big Rock_2
1099                                                201617_Rye Big Rock_2
1100                                                201617_Rye Big Rock_2
1101                                                201617_Rye Big Rock_2
1102                                                201617_Rye Big Rock_2
1103                                                201617_Rye Big Rock_2
1104                                                201617_Rye Big Rock_2
1105                                                201617_Rye Big Rock_2
1106                                                201617_Rye Big Rock_2
1107                                                201617_Rye Big Rock_2
1108                                                201617_Rye Big Rock_3
1109                                                201617_Rye Big Rock_3
1110                                           201617_Rye car park west_2
1111                                           201617_Rye car park west_2
1112                                           201617_Rye car park west_2
1113                                           201617_Rye car park west_2
1114                                           201617_Rye car park west_2
1115                                           201617_Rye car park west_2
1116                                           201617_Rye car park west_2
1117                                           201617_Rye car park west_2
1118                                           201617_Rye car park west_2
1119                                         201617_Somers, Sandy Point_1
1120                                         201617_Somers, Sandy Point_1
1121                                         201617_Somers, Sandy Point_1
1122                                         201617_Somers, Sandy Point_1
1123                                         201617_Somers, Sandy Point_1
1124                                     201617_St Andrews carpark west_5
1125                                     201617_St Andrews carpark west_5
1126                                     201617_St Andrews carpark west_5
1127                                     201617_St Andrews carpark west_5
1128                                     201617_St Andrews carpark west_5
1129                                     201617_St Andrews carpark west_5
1130                                     201617_St Andrews carpark west_5
1131                                     201617_St Andrews carpark west_5
1132                                     201617_St Andrews carpark west_5
1133                                     201617_St Andrews carpark west_5
1134                                     201617_St Andrews carpark west_5
1135                                     201617_St Andrews carpark west_5
1136                                     201617_St Andrews carpark west_5
1137                                     201617_St Andrews carpark west_5
1138                                     201617_St Andrews carpark west_5
1139                                     201617_St Andrews carpark west_5
1140                                     201617_St Andrews carpark west_5
1141                                     201617_St Andrews carpark west_5
1142                                     201617_St Andrews carpark west_5
1143                                     201617_St Andrews carpark west_5
1144                                     201617_St Andrews carpark west_5
1145                                     201617_St Andrews carpark west_5
1146                                     201617_St Andrews carpark west_5
1147                                     201617_St Andrews carpark west_5
1148                                     201617_St Andrews carpark west_5
1149                                201718_Alison Ave next bay west Rye_1
1150                                201718_Alison Ave next bay west Rye_1
1151                                201718_Alison Ave next bay west Rye_1
1152                                201718_Alison Ave next bay west Rye_1
1153                                201718_Alison Ave next bay west Rye_1
1154                                201718_Alison Ave next bay west Rye_1
1155                                201718_Alison Ave next bay west Rye_1
1156                                201718_Alison Ave next bay west Rye_1
1157                                201718_Alison Ave next bay west Rye_1
1158                                201718_Alison Ave next bay west Rye_1
1159                                201718_Alison Ave next bay west Rye_1
1160                                201718_Alison Ave next bay west Rye_1
1161                                201718_Alison Ave next bay west Rye_1
1162                                201718_Alison Ave next bay west Rye_1
1163                                201718_Alison Ave next bay west Rye_1
1164                                201718_Alison Ave next bay west Rye_1
1165                                201718_Alison Ave next bay west Rye_1
1166                                201718_Alison Ave next bay west Rye_1
1167                                201718_Alison Ave next bay west Rye_1
1168                                201718_Alison Ave next bay west Rye_1
1169                                201718_Alison Ave next bay west Rye_1
1170                                201718_Alison Ave next bay west Rye_1
1171                                201718_Alison Ave next bay west Rye_1
1172                                201718_Alison Ave next bay west Rye_1
1173                                201718_Alison Ave next bay west Rye_1
1174                                201718_Alison Ave next bay west Rye_1
1175                                201718_Alison Ave next bay west Rye_1
1176                                201718_Alison Ave next bay west Rye_1
1177                                201718_Alison Ave next bay west Rye_1
1178                                201718_Alison Ave next bay west Rye_1
1179                                201718_Alison Ave next bay west Rye_1
1180                                201718_Alison Ave next bay west Rye_1
1181                                201718_Alison Ave next bay west Rye_1
1182                                201718_Alison Ave next bay west Rye_1
1183                                201718_Alison Ave next bay west Rye_1
1184                                201718_Alison Ave next bay west Rye_1
1185                                201718_Alison Ave next bay west Rye_1
1186                                201718_Alison Ave next bay west Rye_1
1187                                         201718_Alison ave west Rye_1
1188                                         201718_Alison ave west Rye_1
1189                                         201718_Alison ave west Rye_1
1190                                         201718_Alison ave west Rye_1
1191                                         201718_Alison ave west Rye_1
1192                                         201718_Alison ave west Rye_1
1193                                         201718_Alison ave west Rye_1
1194                                         201718_Alison ave west Rye_1
1195                                         201718_Alison ave west Rye_1
1196                                         201718_Alison ave west Rye_1
1197                                         201718_Alison ave west Rye_1
1198                                         201718_Alison ave west Rye_1
1199                                         201718_Alison ave west Rye_1
1200                                         201718_Alison ave west Rye_1
1201                                         201718_Alison ave west Rye_1
1202                                         201718_Alison ave west Rye_1
1203                                         201718_Alison ave west Rye_1
1204                                         201718_Alison ave west Rye_1
1205                                         201718_Alison ave west Rye_1
1206                                         201718_Alison ave west Rye_1
1207                                         201718_Alison ave west Rye_1
1208                                         201718_Alison ave west Rye_1
1209                                         201718_Alison ave west Rye_1
1210                                             201718_Coppins Lookout_3
1211                                             201718_Coppins Lookout_3
1212                                             201718_Coppins Lookout_3
1213                                             201718_Coppins Lookout_3
1214                                             201718_Coppins Lookout_3
1215                                             201718_Coppins Lookout_3
1216                                             201718_Coppins Lookout_3
1217                                             201718_Coppins Lookout_3
1218                                             201718_Coppins Lookout_3
1219                                             201718_Coppins Lookout_3
1220                                             201718_Coppins Lookout_3
1221                                             201718_Coppins Lookout_3
1222                                             201718_Coppins Lookout_3
1223                                             201718_Coppins Lookout_3
1224                                             201718_Coppins Lookout_3
1225                                             201718_Coppins Lookout_3
1226                                             201718_Coppins Lookout_3
1227                                             201718_Coppins Lookout_3
1228                                             201718_Coppins Lookout_3
1229                                             201718_Coppins Lookout_3
1230                                             201718_Coppins Lookout_3
1231                                             201718_Coppins Lookout_3
1232                                             201718_Coppins Lookout_3
1233                                             201718_Coppins Lookout_3
1234                                             201718_Coppins Lookout_3
1235                                             201718_Coppins Lookout_3
1236                                             201718_Coppins Lookout_3
1237                                             201718_Coppins Lookout_3
1238                                             201718_Coppins Lookout_3
1239                                             201718_Coppins Lookout_3
1240                                             201718_Coppins Lookout_3
1241                                             201718_Coppins Lookout_3
1242                                             201718_Coppins Lookout_3
1243                                             201718_Coppins Lookout_3
1244                                             201718_Coppins Lookout_3
1245                                             201718_Coppins Lookout_3
1246                                             201718_Coppins Lookout_3
1247                                             201718_Coppins Lookout_3
1248                                             201718_Coppins Lookout_3
1249                                             201718_Coppins Lookout_3
1250                                             201718_Coppins Lookout_3
1251                                             201718_Coppins Lookout_3
1252                                             201718_Coppins Lookout_3
1253                                             201718_Coppins Lookout_3
1254                                             201718_Coppins Lookout_3
1255                                             201718_Coppins Lookout_3
1256                                             201718_Coppins Lookout_3
1257                                             201718_Coppins Lookout_3
1258                                             201718_Coppins Lookout_3
1259                                             201718_Coppins Lookout_3
1260                                             201718_Coppins Lookout_3
1261                                             201718_Coppins Lookout_3
1262                                             201718_Coppins Lookout_3
1263                                             201718_Coppins Lookout_3
1264                                             201718_Coppins Lookout_3
1265                             201718_Heyfield Pair 2 (east side) Rye_1
1266                             201718_Heyfield Pair 2 (east side) Rye_1
1267                             201718_Heyfield Pair 2 (east side) Rye_1
1268                             201718_Heyfield Pair 2 (east side) Rye_1
1269                             201718_Heyfield Pair 2 (east side) Rye_1
1270                             201718_Heyfield Pair 2 (east side) Rye_1
1271                             201718_Heyfield Pair 2 (east side) Rye_1
1272                             201718_Heyfield Pair 2 (east side) Rye_2
1273                             201718_Heyfield Pair 2 (east side) Rye_2
1274                             201718_Heyfield Pair 2 (east side) Rye_2
1275                             201718_Heyfield Pair 2 (east side) Rye_2
1276                             201718_Heyfield Pair 2 (east side) Rye_2
1277                             201718_Heyfield Pair 2 (east side) Rye_2
1278                             201718_Heyfield Pair 2 (east side) Rye_2
1279                             201718_Heyfield Pair 2 (east side) Rye_2
1280                             201718_Heyfield Pair 2 (east side) Rye_2
1281                             201718_Heyfield Pair 2 (east side) Rye_2
1282                             201718_Heyfield Pair 2 (east side) Rye_2
1283                             201718_Heyfield Pair 2 (east side) Rye_2
1284                             201718_Heyfield Pair 2 (east side) Rye_2
1285                             201718_Heyfield Pair 2 (east side) Rye_2
1286                             201718_Heyfield Pair 2 (east side) Rye_2
1287                             201718_Heyfield Pair 2 (east side) Rye_2
1288                             201718_Heyfield Pair 2 (east side) Rye_2
1289                             201718_Heyfield Pair 2 (east side) Rye_2
1290                             201718_Heyfield Pair 2 (east side) Rye_2
1291                             201718_Heyfield Pair 2 (east side) Rye_2
1292                             201718_Heyfield Pair 2 (east side) Rye_2
1293                             201718_Heyfield Pair 2 (east side) Rye_2
1294                             201718_Heyfield Pair 2 (east side) Rye_2
1295                             201718_Heyfield Pair 2 (east side) Rye_2
1296                             201718_Heyfield Pair 2 (east side) Rye_2
1297                             201718_Heyfield Pair 2 (east side) Rye_2
1298                             201718_Heyfield Pair 2 (east side) Rye_2
1299                             201718_Heyfield Pair 2 (east side) Rye_2
1300                             201718_Heyfield Pair 2 (east side) Rye_2
1301                             201718_Heyfield Pair 2 (east side) Rye_2
1302                             201718_Heyfield Pair 2 (east side) Rye_2
1303                             201718_Heyfield Pair 2 (east side) Rye_2
1304                             201718_Heyfield Pair 2 (east side) Rye_2
1305                             201718_Heyfield Pair 2 (east side) Rye_2
1306                             201718_Heyfield Pair 2 (east side) Rye_2
1307                             201718_Heyfield Pair 2 (east side) Rye_2
1308                             201718_Heyfield Pair 2 (east side) Rye_2
1309                             201718_Heyfield Pair 2 (east side) Rye_2
1310                             201718_Heyfield Pair 2 (east side) Rye_2
1311                             201718_Heyfield Pair 2 (east side) Rye_2
1312                             201718_Heyfield Pair 2 (east side) Rye_2
1313                                                 201718_Koonya East_2
1314                                                 201718_Koonya East_2
1315                                                 201718_Koonya East_2
1316                                                 201718_Koonya East_2
1317                                                 201718_Koonya East_2
1318                                                 201718_Koonya East_2
1319                                                 201718_Koonya East_2
1320                                                 201718_Koonya East_2
1321                                                 201718_Koonya East_2
1322                                                 201718_Koonya East_2
1323                                                 201718_Koonya East_2
1324                                                 201718_Koonya East_2
1325                                                 201718_Koonya East_2
1326                                                 201718_Koonya East_2
1327                                                 201718_Koonya East_2
1328                                                 201718_Koonya East_2
1329                                                 201718_Koonya East_2
1330                                                 201718_Koonya East_2
1331                                                 201718_Koonya East_2
1332                                                 201718_Koonya East_2
1333                                                 201718_Koonya East_2
1334                                                 201718_Koonya East_2
1335                                                 201718_Koonya East_2
1336                                                 201718_Koonya East_2
1337                                                 201718_Koonya East_2
1338                                                 201718_Koonya East_2
1339                                                 201718_Koonya East_2
1340                                                 201718_Koonya East_2
1341                                                 201718_Koonya East_2
1342                                                 201718_Koonya East_2
1343                                                 201718_Koonya East_2
1344                                                 201718_Koonya East_2
1345                                                 201718_Koonya East_2
1346                                                 201718_Koonya East_2
1347                                                 201718_Koonya East_2
1348                                                 201718_Koonya East_2
1349                                                 201718_Koonya East_2
1350                                                 201718_Koonya East_2
1351                                                 201718_Koonya East_2
1352                                                 201718_Koonya East_2
1353                                                 201718_Koonya East_2
1354                                                 201718_Koonya East_2
1355                                                 201718_Koonya East_2
1356                                                 201718_Koonya East_2
1357                                                 201718_Koonya East_2
1358                                                 201718_Koonya East_2
1359                                                 201718_Koonya East_2
1360                                                 201718_Koonya East_2
1361                                                 201718_Koonya East_2
1362                                                 201718_Koonya East_2
1363                                                 201718_Koonya East_2
1364                                                 201718_Koonya East_2
1365                                                 201718_Koonya East_2
1366                                                 201718_Koonya East_2
1367                                                 201718_Koonya East_2
1368                                                 201718_Koonya East_2
1369                                                 201718_Koonya West_4
1370                                                 201718_Koonya West_4
1371                                                 201718_Koonya West_4
1372                                                 201718_Koonya West_4
1373                                                 201718_Koonya West_4
1374                                                 201718_Koonya West_4
1375                                                 201718_Koonya West_4
1376                                                 201718_Koonya West_4
1377                                                 201718_Koonya West_4
1378                                                 201718_Koonya West_4
1379                                     201718_Miami drive east access_1
1380                                     201718_Miami drive east access_1
1381                                     201718_Miami drive east access_1
1382                                     201718_Miami drive east access_1
1383                                     201718_Miami drive east access_1
1384                                     201718_Miami drive east access_1
1385                                     201718_Miami drive east access_1
1386                                     201718_Miami drive east access_1
1387                                     201718_Miami drive east access_1
1388                                     201718_Miami drive east access_1
1389                                     201718_Miami drive east access_1
1390                                     201718_Miami drive east access_1
1391                                     201718_Miami drive east access_1
1392                                     201718_Miami drive east access_1
1393                                     201718_Miami drive east access_1
1394                                                   201718_Montforts_2
1395                                                   201718_Montforts_2
1396                                                   201718_Montforts_2
1397                                                   201718_Montforts_2
1398                                                   201718_Montforts_2
1399                                                   201718_Montforts_2
1400                                                   201718_Montforts_2
1401                                                   201718_Montforts_2
1402                                                   201718_Montforts_2
1403                                                   201718_Montforts_2
1404                                                   201718_Montforts_2
1405                                                   201718_Montforts_2
1406                                                   201718_Montforts_2
1407                                                   201718_Montforts_2
1408                                                   201718_Montforts_2
1409                                                   201718_Montforts_2
1410                                                   201718_Montforts_2
1411                                                   201718_Montforts_2
1412                                                   201718_Montforts_2
1413                                                   201718_Montforts_2
1414                                                   201718_Montforts_2
1415                                                   201718_Montforts_2
1416                                                   201718_Montforts_2
1417                                                   201718_Montforts_2
1418                                                   201718_Montforts_2
1419                                                   201718_Montforts_2
1420                                                   201718_Montforts_2
1421                                                   201718_Montforts_2
1422                                                   201718_Montforts_2
1423                                                   201718_Montforts_2
1424                                                   201718_Montforts_2
1425                                                   201718_Montforts_2
1426                                201718_Portsea Farnsworth/SLSC west_3
1427                                201718_Portsea Farnsworth/SLSC west_3
1428                                201718_Portsea Farnsworth/SLSC west_3
1429                                201718_Portsea Farnsworth/SLSC west_3
1430                                201718_Portsea Farnsworth/SLSC west_3
1431                                201718_Portsea Farnsworth/SLSC west_3
1432                                201718_Portsea Farnsworth/SLSC west_3
1433                                201718_Portsea Farnsworth/SLSC west_3
1434                                201718_Portsea Farnsworth/SLSC west_3
1435                                201718_Portsea Farnsworth/SLSC west_3
1436                                201718_Portsea Farnsworth/SLSC west_3
1437                                201718_Portsea Farnsworth/SLSC west_3
1438                                201718_Portsea Farnsworth/SLSC west_3
1439                                201718_Portsea Farnsworth/SLSC west_3
1440                                201718_Portsea Farnsworth/SLSC west_3
1441                                201718_Portsea Farnsworth/SLSC west_3
1442                                201718_Portsea Farnsworth/SLSC west_3
1443                                201718_Portsea Farnsworth/SLSC west_3
1444                                201718_Portsea Farnsworth/SLSC west_3
1445                                201718_Portsea Farnsworth/SLSC west_3
1446                                201718_Portsea Farnsworth/SLSC west_3
1447                                201718_Portsea Farnsworth/SLSC west_3
1448                                201718_Portsea Farnsworth/SLSC west_3
1449                                201718_Portsea Farnsworth/SLSC west_3
1450                                201718_Portsea Farnsworth/SLSC west_3
1451                                201718_Portsea Farnsworth/SLSC west_3
1452                                201718_Portsea Farnsworth/SLSC west_3
1453                                201718_Portsea Farnsworth/SLSC west_3
1454                                201718_Portsea Farnsworth/SLSC west_3
1455                                201718_Portsea Farnsworth/SLSC west_3
1456                                201718_Portsea Farnsworth/SLSC west_3
1457                                201718_Portsea Farnsworth/SLSC west_3
1458                                201718_Portsea Farnsworth/SLSC west_3
1459                                201718_Portsea Farnsworth/SLSC west_3
1460                                201718_Portsea Farnsworth/SLSC west_3
1461                                201718_Portsea Farnsworth/SLSC west_3
1462                                201718_Portsea Farnsworth/SLSC west_3
1463                                201718_Portsea Farnsworth/SLSC west_3
1464                                201718_Portsea Farnsworth/SLSC west_3
1465                                201718_Portsea Farnsworth/SLSC west_3
1466                                201718_Portsea Farnsworth/SLSC west_3
1467                                201718_Portsea Farnsworth/SLSC west_3
1468                                    201718_Portsea Franklin rd west_1
1469                                    201718_Portsea Franklin rd west_1
1470                                    201718_Portsea Franklin rd west_1
1471                                    201718_Portsea Franklin rd west_1
1472                                    201718_Portsea Franklin rd west_1
1473                                    201718_Portsea Franklin rd west_1
1474                                    201718_Portsea Franklin rd west_1
1475                                    201718_Portsea Franklin rd west_1
1476                                    201718_Portsea Franklin rd west_1
1477                                    201718_Portsea Franklin rd west_1
1478                                    201718_Portsea Franklin rd west_1
1479                                    201718_Portsea Franklin rd west_1
1480                                    201718_Portsea Franklin rd west_1
1481                                    201718_Portsea Franklin rd west_1
1482                                    201718_Portsea Franklin rd west_1
1483                                    201718_Portsea Franklin rd west_1
1484                                    201718_Portsea Franklin rd west_1
1485                                    201718_Portsea Franklin rd west_1
1486                                    201718_Portsea Franklin rd west_1
1487                                    201718_Portsea Franklin rd west_1
1488                                    201718_Portsea Franklin rd west_1
1489                                    201718_Portsea Franklin rd west_1
1490                                    201718_Portsea Franklin rd west_1
1491                                    201718_Portsea Franklin rd west_5
1492                                    201718_Portsea Franklin rd west_5
1493                                    201718_Portsea Franklin rd west_5
1494                                    201718_Portsea Franklin rd west_5
1495                                    201718_Portsea Franklin rd west_5
1496                                    201718_Portsea Franklin rd west_5
1497                                    201718_Portsea Franklin rd west_5
1498                                    201718_Portsea Franklin rd west_5
1499                                    201718_Portsea Franklin rd west_5
1500                                    201718_Portsea Franklin rd west_5
1501                                    201718_Portsea Franklin rd west_5
1502                                    201718_Portsea Franklin rd west_5
1503                                    201718_Portsea Franklin rd west_5
1504                                    201718_Portsea Franklin rd west_5
1505                                    201718_Portsea Franklin rd west_5
1506                                    201718_Portsea Franklin rd west_5
1507                                    201718_Portsea Franklin rd west_5
1508                                    201718_Portsea Franklin rd west_5
1509                                    201718_Portsea Franklin rd west_5
1510                                    201718_Portsea Franklin rd west_5
1511                                    201718_Portsea Franklin rd west_5
1512                                    201718_Portsea Franklin rd west_5
1513                                    201718_Portsea Franklin rd west_5
1514                                    201718_Portsea Franklin rd west_5
1515                                    201718_Portsea Franklin rd west_5
1516                                    201718_Portsea Franklin rd west_5
1517                                    201718_Portsea Franklin rd west_5
1518                                        201718_Portsea Sphinx rocks_1
1519                                        201718_Portsea Sphinx rocks_1
1520                                        201718_Portsea Sphinx rocks_1
1521                                        201718_Portsea Sphinx rocks_1
1522                                        201718_Portsea Sphinx rocks_1
1523                                        201718_Portsea Sphinx rocks_1
1524                                        201718_Portsea Sphinx rocks_1
1525                                        201718_Portsea Sphinx rocks_1
1526                                        201718_Portsea Sphinx rocks_1
1527                                        201718_Portsea Sphinx rocks_1
1528                                        201718_Portsea Sphinx rocks_1
1529                                        201718_Portsea Sphinx rocks_1
1530                                        201718_Portsea Sphinx rocks_1
1531                                        201718_Portsea Sphinx rocks_1
1532                                        201718_Portsea Sphinx rocks_1
1533                                        201718_Portsea Sphinx rocks_1
1534                                        201718_Portsea Sphinx rocks_1
1535                                        201718_Portsea Sphinx rocks_1
1536                                        201718_Portsea Sphinx rocks_1
1537                                        201718_Portsea Sphinx rocks_1
1538                                        201718_Portsea Sphinx rocks_1
1539                                        201718_Portsea Sphinx rocks_1
1540                                        201718_Portsea Sphinx rocks_1
1541                                        201718_Portsea Sphinx rocks_1
1542                                        201718_Portsea Sphinx rocks_1
1543                                        201718_Portsea Sphinx rocks_1
1544                                        201718_Portsea Sphinx rocks_1
1545                                        201718_Portsea Sphinx rocks_1
1546                                        201718_Portsea Sphinx rocks_1
1547                                        201718_Portsea Sphinx rocks_1
1548                                        201718_Portsea Sphinx rocks_1
1549                                        201718_Portsea Sphinx rocks_1
1550                                     201718_St Andrews carpark west_3
1551                                     201718_St Andrews carpark west_3
1552                                     201718_St Andrews carpark west_3
1553                                     201718_St Andrews carpark west_3
1554                                     201718_St Andrews carpark west_3
1555                                     201718_St Andrews carpark west_3
1556                                     201718_St Andrews carpark west_3
1557                                     201718_St Andrews carpark west_3
1558                                   201718_St. Andrews car park east_1
1559                                   201718_St. Andrews car park east_1
1560                                   201718_St. Andrews car park east_1
1561                                   201718_St. Andrews car park east_1
1562                                   201718_St. Andrews car park east_1
1563                                   201718_St. Andrews car park east_1
1564                                   201718_St. Andrews car park east_1
1565                                   201718_St. Andrews car park east_1
1566                                   201718_St. Andrews car park east_1
1567                                         201819_Alison Ave West Rye_2
1568                                         201819_Alison Ave West Rye_2
1569                                         201819_Alison Ave West Rye_2
1570                                         201819_Alison Ave West Rye_3
1571                                         201819_Alison Ave West Rye_3
1572                                         201819_Alison Ave West Rye_3
1573                                         201819_Alison Ave West Rye_3
1574                                         201819_Alison Ave West Rye_3
1575                                         201819_Alison Ave West Rye_3
1576                                         201819_Alison Ave West Rye_3
1577                                         201819_Alison Ave West Rye_3
1578                                                     201819_Fowlers_1
1579                                                     201819_Fowlers_1
1580                                                     201819_Fowlers_1
1581                                                     201819_Fowlers_1
1582                                                     201819_Fowlers_1
1583                                                     201819_Fowlers_1
1584                                                     201819_Fowlers_1
1585                                                     201819_Fowlers_1
1586                                                     201819_Fowlers_1
1587                                                     201819_Fowlers_2
1588                                                     201819_Fowlers_2
1589                                                     201819_Fowlers_2
1590                                                     201819_Fowlers_2
1591                                                     201819_Fowlers_2
1592                                                     201819_Fowlers_2
1593                                                     201819_Fowlers_2
1594                                                     201819_Fowlers_2
1595                                                     201819_Fowlers_2
1596                                                     201819_Fowlers_2
1597                                                     201819_Fowlers_2
1598                                                     201819_Fowlers_2
1599                                                     201819_Fowlers_2
1600                                                     201819_Fowlers_2
1601                                                     201819_Fowlers_2
1602                                                     201819_Fowlers_2
1603                                                     201819_Fowlers_2
1604                                                     201819_Fowlers_2
1605                                                     201819_Fowlers_2
1606                                                     201819_Fowlers_2
1607                                                     201819_Fowlers_2
1608                                                     201819_Fowlers_2
1609                                                     201819_Fowlers_2
1610                                                     201819_Fowlers_2
1611                                                     201819_Fowlers_2
1612                                                     201819_Fowlers_2
1613                                                     201819_Fowlers_2
1614                                                     201819_Fowlers_2
1615                                                     201819_Fowlers_2
1616                                              201819_Gunida Crt Rye_1
1617                                              201819_Gunida Crt Rye_1
1618                                              201819_Gunida Crt Rye_1
1619                                              201819_Gunida Crt Rye_1
1620                                              201819_Gunida Crt Rye_1
1621                                              201819_Gunida Crt Rye_1
1622                                              201819_Gunida Crt Rye_1
1623                                              201819_Gunida Crt Rye_1
1624                                              201819_Gunida Crt Rye_2
1625                                              201819_Gunida Crt Rye_2
1626                                              201819_Gunida Crt Rye_2
1627                                              201819_Gunida Crt Rye_2
1628                                              201819_Gunida Crt Rye_2
1629                                              201819_Gunida Crt Rye_2
1630                                              201819_Gunida Crt Rye_2
1631                                              201819_Gunida Crt Rye_2
1632                                              201819_Gunida Crt Rye_2
1633                                              201819_Gunida Crt Rye_2
1634                                              201819_Gunida Crt Rye_2
1635                                              201819_Gunida Crt Rye_2
1636                                              201819_Gunida Crt Rye_2
1637                                              201819_Gunida Crt Rye_2
1638                                              201819_Gunida Crt Rye_2
1639                                              201819_Gunida Crt Rye_2
1640                                              201819_Gunida Crt Rye_2
1641                                              201819_Gunida Crt Rye_2
1642                                              201819_Gunida Crt Rye_2
1643                                              201819_Gunida Crt Rye_2
1644                                              201819_Gunida Crt Rye_2
1645                                              201819_Gunida Crt Rye_2
1646                                              201819_Gunida Crt Rye_2
1647                                              201819_Gunida Crt Rye_2
1648                                              201819_Gunida Crt Rye_2
1649                                              201819_Gunida Crt Rye_2
1650                                              201819_Gunida Crt Rye_2
1651                                              201819_Gunida Crt Rye_2
1652                                              201819_Gunida Crt Rye_2
1653                                              201819_Gunida Crt Rye_2
1654                                              201819_Gunida Crt Rye_2
1655                                              201819_Gunida Crt Rye_2
1656                                              201819_Gunida Crt Rye_2
1657                                              201819_Gunida Crt Rye_2
1658                                              201819_Gunida Crt Rye_2
1659                                              201819_Gunida Crt Rye_2
1660                                              201819_Gunida Crt Rye_2
1661                               201819_Gunnamatta SLSC Far East (P1)_2
1662                               201819_Gunnamatta SLSC Far East (P1)_2
1663                               201819_Gunnamatta SLSC Far East (P1)_2
1664                               201819_Gunnamatta SLSC Far East (P1)_2
1665                               201819_Gunnamatta SLSC Far East (P1)_2
1666                               201819_Gunnamatta SLSC Far East (P1)_2
1667                               201819_Gunnamatta SLSC Far East (P1)_2
1668                               201819_Gunnamatta SLSC Far East (P1)_2
1669                                                 201819_Koonya West_1
1670                                                 201819_Koonya West_1
1671                                                 201819_Koonya West_1
1672                                                 201819_Koonya West_1
1673                                                 201819_Koonya West_1
1674                                                 201819_Koonya West_1
1675                                                 201819_Koonya West_1
1676                                                 201819_Koonya West_1
1677                                                 201819_Koonya West_1
1678                                                 201819_Koonya West_1
1679                                                 201819_Koonya West_1
1680                                                 201819_Koonya West_1
1681                                                 201819_Koonya West_1
1682                                                 201819_Koonya West_1
1683                                                 201819_Koonya West_1
1684                                                 201819_Koonya West_1
1685                                                 201819_Koonya West_1
1686                                                 201819_Koonya West_1
1687                                                 201819_Koonya West_1
1688                                                 201819_Koonya West_1
1689                                                 201819_Koonya West_1
1690                                                 201819_Koonya West_1
1691                                                 201819_Koonya West_1
1692                                                 201819_Koonya West_1
1693                                                 201819_Koonya West_1
1694                                                 201819_Koonya West_1
1695                                                 201819_Koonya West_1
1696                                                 201819_Koonya West_1
1697                                                 201819_Koonya West_1
1698                                                 201819_Koonya West_1
1699                                                 201819_Koonya West_1
1700                                                 201819_Koonya West_1
1701                                                 201819_Koonya West_1
1702                                                 201819_Koonya West_1
1703                                                 201819_Koonya West_1
1704                                                 201819_Koonya West_1
1705                                                 201819_Koonya West_1
1706                                                 201819_Koonya West_1
1707                                                 201819_Koonya West_1
1708                                                 201819_Koonya West_1
1709                                                 201819_Koonya West_1
1710                                                 201819_Koonya West_1
1711                                                 201819_Koonya West_1
1712                                                 201819_Koonya West_1
1713                                                 201819_Koonya West_1
1714                                                 201819_Koonya West_1
1715                                                 201819_Koonya West_1
1716                                                 201819_Koonya West_1
1717                                                 201819_Koonya West_1
1718                                                 201819_Koonya West_1
1719                                                 201819_Koonya West_1
1720                                                 201819_Koonya West_1
1721                                                 201819_Koonya West_1
1722                                                 201819_Koonya West_1
1723                                                 201819_Koonya West_1
1724                                                 201819_Koonya West_1
1725                                                 201819_Koonya West_1
1726                                                 201819_Koonya West_1
1727                                                 201819_Koonya West_1
1728                                                 201819_Koonya West_1
1729                                                 201819_Koonya West_1
1730                                                 201819_Koonya West_1
1731                                                 201819_Koonya West_1
1732                                                 201819_Koonya West_1
1733                                     201819_Miami drive east access_2
1734                                     201819_Miami drive east access_2
1735                                     201819_Miami drive east access_2
1736                                     201819_Miami drive east access_2
1737                                     201819_Miami drive east access_2
1738                                     201819_Miami drive east access_2
1739                                     201819_Miami drive east access_2
1740                                     201819_Miami drive east access_2
1741                                     201819_Miami drive east access_2
1742                                     201819_Miami drive east access_2
1743                                     201819_Miami drive east access_2
1744                                     201819_Miami drive east access_2
1745                                     201819_Miami drive east access_2
1746                                     201819_Miami drive east access_2
1747                                     201819_Miami drive east access_2
1748                                     201819_Miami drive east access_2
1749                                     201819_Miami drive east access_2
1750                                     201819_Miami drive east access_2
1751                                     201819_Miami drive east access_2
1752                                     201819_Miami drive east access_2
1753                                     201819_Miami drive east access_2
1754                                     201819_Miami drive east access_2
1755                                     201819_Miami drive east access_2
1756                                     201819_Miami drive east access_2
1757                                     201819_Miami drive east access_2
1758                                     201819_Miami drive east access_2
1759                                     201819_Miami drive east access_2
1760                                     201819_Miami drive east access_2
1761                                     201819_Miami drive east access_2
1762                                     201819_Miami drive east access_2
1763                                201819_Moana crt access (east edge)_2
1764                                201819_Moana crt access (east edge)_2
1765                                201819_Moana crt access (east edge)_2
1766 201819_Pt Nepean (authorised personnel only) - Sierra Nevada Rocks_1
1767 201819_Pt Nepean (authorised personnel only) - Sierra Nevada Rocks_1
1768              201819_Pt Nepean (authorised personnel only) - Spooks_1
1769              201819_Pt Nepean (authorised personnel only) - Spooks_1
1770                                           201819_Rye car park west_1
1771                                           201819_Rye car park west_1
1772                                           201819_Rye car park west_1
1773                                           201819_Rye car park west_1
1774                                           201819_Rye car park west_1
1775                                           201819_Rye car park west_1
1776                                           201819_Rye car park west_1
1777                                           201819_Rye car park west_1
1778                                      201819_St Andrews Boags Rocks_5
1779                                      201819_St Andrews Boags Rocks_5
1780                                      201819_St Andrews Boags Rocks_5
1781                                      201819_St Andrews Boags Rocks_5
1782                                      201819_St Andrews Boags Rocks_5
1783                                   201819_St. Andrews car park east_1
1784                                   201819_St. Andrews car park east_1
1785                                   201819_St. Andrews car park east_1
1786                                   201819_St. Andrews car park east_1
1787                                   201819_St. Andrews car park east_1
1788                                   201819_St. Andrews car park east_1
1789                                   201819_St. Andrews car park east_1
1790                                   201819_St. Andrews car park east_1
1791                                   201819_St. Andrews car park east_1
1792                                   201819_St. Andrews car park east_1
1793                                   201819_St. Andrews car park east_1
1794                                   201819_St. Andrews car park east_1
1795                                   201819_St. Andrews car park east_1
1796                                   201819_St. Andrews car park east_1
1797                                   201819_St. Andrews car park east_1
1798                                   201819_St. Andrews car park east_1
1799                                   201819_St. Andrews car park east_1
1800                                   201819_St. Andrews car park east_1
1801                                   201819_St. Andrews car park east_1
1802                                   201819_St. Andrews car park east_1
1803                                   201819_St. Andrews car park east_1
1804                                         201920_Alison ave east Rye_1
1805                                         201920_Alison ave east Rye_1
1806                                         201920_Alison ave east Rye_1
1807                                         201920_Alison ave east Rye_1
1808                                         201920_Alison ave east Rye_1
1809                                         201920_Alison ave east Rye_1
1810                                         201920_Alison ave east Rye_1
1811                                         201920_Alison ave east Rye_1
1812                                         201920_Alison ave east Rye_1
1813                                         201920_Alison ave east Rye_1
1814                                         201920_Alison ave east Rye_1
1815                                         201920_Alison ave east Rye_1
1816                                         201920_Alison ave east Rye_1
1817                                         201920_Alison ave east Rye_1
1818                                         201920_Alison ave east Rye_1
1819                                         201920_Alison ave east Rye_1
1820                                         201920_Alison ave east Rye_1
1821                                         201920_Alison ave east Rye_1
1822                                         201920_Alison ave east Rye_1
1823                                         201920_Alison ave east Rye_1
1824                                         201920_Alison ave east Rye_1
1825                                         201920_Alison ave east Rye_1
1826                                         201920_Alison ave east Rye_1
1827                                                     201920_Fowlers_2
1828                                                     201920_Fowlers_2
1829                                                     201920_Fowlers_2
1830                                                     201920_Fowlers_2
1831                                                     201920_Fowlers_2
1832                                                     201920_Fowlers_2
1833                                                     201920_Fowlers_2
1834                                                     201920_Fowlers_2
1835                                                     201920_Fowlers_2
1836                                                     201920_Fowlers_2
1837                                                     201920_Fowlers_2
1838                                                     201920_Fowlers_2
1839                                                     201920_Fowlers_2
1840                                                     201920_Fowlers_2
1841                                              201920_Gunida Crt Rye_1
1842                                              201920_Gunida Crt Rye_1
1843                                              201920_Gunida Crt Rye_1
1844                                              201920_Gunida Crt Rye_1
1845                                              201920_Gunida Crt Rye_1
1846                                              201920_Gunida Crt Rye_2
1847                                              201920_Gunida Crt Rye_2
1848                                              201920_Gunida Crt Rye_2
1849                                              201920_Gunida Crt Rye_2
1850                                              201920_Gunida Crt Rye_2
1851                                              201920_Gunida Crt Rye_2
1852                             201920_Heyfield Pair 1 (west side) Rye_1
1853                             201920_Heyfield Pair 1 (west side) Rye_1
1854                             201920_Heyfield Pair 1 (west side) Rye_1
1855                             201920_Heyfield Pair 1 (west side) Rye_1
1856                             201920_Heyfield Pair 1 (west side) Rye_1
1857                             201920_Heyfield Pair 1 (west side) Rye_1
1858                             201920_Heyfield Pair 1 (west side) Rye_1
1859                             201920_Heyfield Pair 1 (west side) Rye_1
1860                             201920_Heyfield Pair 1 (west side) Rye_1
1861                             201920_Heyfield Pair 1 (west side) Rye_1
1862                             201920_Heyfield Pair 1 (west side) Rye_1
1863                             201920_Heyfield Pair 1 (west side) Rye_1
1864                             201920_Heyfield Pair 1 (west side) Rye_1
1865                             201920_Heyfield Pair 1 (west side) Rye_1
1866                             201920_Heyfield Pair 1 (west side) Rye_1
1867                             201920_Heyfield Pair 1 (west side) Rye_1
1868                             201920_Heyfield Pair 1 (west side) Rye_1
1869                             201920_Heyfield Pair 1 (west side) Rye_1
1870                             201920_Heyfield Pair 1 (west side) Rye_1
1871                             201920_Heyfield Pair 1 (west side) Rye_1
1872                             201920_Heyfield Pair 2 (east side) Rye_2
1873                             201920_Heyfield Pair 2 (east side) Rye_2
1874                             201920_Heyfield Pair 2 (east side) Rye_2
1875                             201920_Heyfield Pair 2 (east side) Rye_2
1876                             201920_Heyfield Pair 2 (east side) Rye_2
1877                             201920_Heyfield Pair 2 (east side) Rye_2
1878                             201920_Heyfield Pair 2 (east side) Rye_2
1879                             201920_Heyfield Pair 2 (east side) Rye_2
1880                             201920_Heyfield Pair 2 (east side) Rye_2
1881                                                   201920_Montforts_1
1882                                                   201920_Montforts_1
1883                                                   201920_Montforts_1
1884                                                   201920_Montforts_1
1885                                                   201920_Montforts_1
1886                                                   201920_Montforts_1
1887                                                   201920_Montforts_1
1888                                                   201920_Montforts_1
1889                                                   201920_Montforts_1
1890                                                   201920_Montforts_1
1891                                                   201920_Montforts_1
1892                                                   201920_Montforts_1
1893                                                   201920_Montforts_1
1894                                                   201920_Montforts_1
1895                                                   201920_Montforts_1
1896                                                   201920_Montforts_1
1897                                                   201920_Montforts_1
1898                                                   201920_Montforts_1
1899                                                   201920_Montforts_1
1900                                                   201920_Montforts_1
1901                                                   201920_Montforts_1
1902                                                   201920_Montforts_1
1903                                                   201920_Montforts_1
1904                                                   201920_Montforts_1
1905                                    201920_Portsea Franklin rd west_4
1906                                    201920_Portsea Franklin rd west_4
1907                                    201920_Portsea Franklin rd west_4
1908                                    201920_Portsea Franklin rd west_4
1909                                    201920_Portsea Franklin rd west_4
1910                                    201920_Portsea Franklin rd west_4
1911                                    201920_Portsea Franklin rd west_4
1912                                    201920_Portsea Franklin rd west_4
1913                                    201920_Portsea Franklin rd west_4
1914                                    201920_Portsea Franklin rd west_4
1915                                    201920_Portsea Franklin rd west_4
1916                                    201920_Portsea Franklin rd west_4
1917                                    201920_Portsea Franklin rd west_4
1918                                    201920_Portsea Franklin rd west_4
1919                                       201920_Pt Nepean, Nepean Bay_1
1920                                       201920_Pt Nepean, Nepean Bay_1
1921                                       201920_Pt Nepean, Nepean Bay_1
1922                                       201920_Pt Nepean, Nepean Bay_1
1923                                       201920_Pt Nepean, Nepean Bay_1
1924                                       201920_Pt Nepean, Nepean Bay_1
1925                                       201920_Pt Nepean, Nepean Bay_1
1926                                       201920_Pt Nepean, Nepean Bay_1
1927                                       201920_Pt Nepean, Nepean Bay_1
1928                                       201920_Pt Nepean, Nepean Bay_1
1929                                       201920_Pt Nepean, Nepean Bay_1
1930                                       201920_Pt Nepean, Nepean Bay_1
1931                                       201920_Pt Nepean, Nepean Bay_1
1932                                       201920_Pt Nepean, Nepean Bay_1
1933                                       201920_Pt Nepean, Nepean Bay_1
1934                                       201920_Pt Nepean, Nepean Bay_1
1935                                       201920_Pt Nepean, Nepean Bay_1
1936                                       201920_Pt Nepean, Nepean Bay_1
1937                                                201920_Rye Big Rock_2
1938                                                201920_Rye Big Rock_2
1939                                                201920_Rye Big Rock_2
1940                                                201920_Rye Big Rock_2
1941                                                201920_Rye Big Rock_2
1942                                                201920_Rye Big Rock_2
1943                                                201920_Rye Big Rock_2
1944                                                201920_Rye Big Rock_2
1945                                                201920_Rye Big Rock_2
1946                                                201920_Rye Big Rock_2
1947                                                201920_Rye Big Rock_2
1948                                                201920_Rye Big Rock_2
1949                                                201920_Rye Big Rock_2
1950                                                201920_Rye Big Rock_2
1951                                                201920_Rye Big Rock_2
1952                                                201920_Rye Big Rock_2
1953                                                201920_Rye Big Rock_2
1954                                                201920_Rye Big Rock_2
1955                                                201920_Rye Big Rock_2
1956                                                201920_Rye Big Rock_2
1957                                                201920_Rye Big Rock_2
1958                                                201920_Rye Big Rock_2
1959                                                201920_Rye Big Rock_2
1960                                                201920_Rye Big Rock_2
1961                                                201920_Rye Big Rock_2
1962                                                201920_Rye Big Rock_2
1963                                                201920_Rye Big Rock_2
1964                                                201920_Rye Big Rock_2
1965                                                201920_Rye Big Rock_2
1966                                                201920_Rye Big Rock_2
1967                                                201920_Rye Big Rock_2
1968                                                201920_Rye Big Rock_2
1969                                            202021_Balnarring Beach_3
1970                                            202021_Balnarring Beach_3
1971                                            202021_Balnarring Beach_3
1972                                            202021_Balnarring Beach_3
1973                                            202021_Balnarring Beach_3
1974                                            202021_Balnarring Beach_3
1975                                            202021_Balnarring Beach_3
1976                                            202021_Balnarring Beach_3
1977                                            202021_Balnarring Beach_3
1978                                            202021_Balnarring Beach_3
1979                                            202021_Balnarring Beach_3
1980                                            202021_Balnarring Beach_3
1981                                            202021_Balnarring Beach_3
1982                                            202021_Balnarring Beach_3
1983                                            202021_Balnarring Beach_3
1984                                            202021_Balnarring Beach_3
1985                                            202021_Balnarring Beach_3
1986                                            202021_Balnarring Beach_3
1987                                            202021_Balnarring Beach_3
1988                                               202021_Brewster, Rye_4
1989                                               202021_Brewster, Rye_4
1990                                               202021_Brewster, Rye_4
1991                                               202021_Brewster, Rye_4
1992                                               202021_Brewster, Rye_4
1993                                               202021_Brewster, Rye_4
1994                                               202021_Brewster, Rye_4
1995                                               202021_Brewster, Rye_4
1996                                               202021_Brewster, Rye_4
1997                                               202021_Brewster, Rye_4
1998                                 202021_Flinders, Mushroom Reef, HP_3
1999                                 202021_Flinders, Mushroom Reef, HP_3
2000                                 202021_Flinders, Mushroom Reef, HP_3
2001                                 202021_Flinders, Mushroom Reef, HP_3
2002                                 202021_Flinders, Mushroom Reef, HP_3
2003                                 202021_Flinders, Mushroom Reef, HP_3
2004                                 202021_Flinders, Mushroom Reef, HP_3
2005                                 202021_Flinders, Mushroom Reef, HP_3
2006                                 202021_Flinders, Mushroom Reef, HP_3
2007                                 202021_Flinders, Mushroom Reef, HP_3
2008                                 202021_Flinders, Mushroom Reef, HP_3
2009                                 202021_Flinders, Mushroom Reef, HP_3
2010                                 202021_Flinders, Mushroom Reef, HP_3
2011                                 202021_Flinders, Mushroom Reef, HP_3
2012                                 202021_Flinders, Mushroom Reef, HP_3
2013                                 202021_Flinders, Mushroom Reef, HP_3
2014                                 202021_Flinders, Mushroom Reef, HP_3
2015                                 202021_Flinders, Mushroom Reef, HP_3
2016                                 202021_Flinders, Mushroom Reef, HP_3
2017                                 202021_Flinders, Mushroom Reef, HP_3
2018                                 202021_Flinders, Mushroom Reef, HP_3
2019                                 202021_Flinders, Mushroom Reef, HP_3
2020                                 202021_Flinders, Mushroom Reef, HP_3
2021                                 202021_Flinders, Mushroom Reef, HP_3
2022                                 202021_Flinders, Mushroom Reef, HP_3
2023                                 202021_Flinders, Mushroom Reef, HP_3
2024                                 202021_Flinders, Mushroom Reef, HP_3
2025                                 202021_Flinders, Mushroom Reef, HP_3
2026                                 202021_Flinders, Mushroom Reef, HP_3
2027                                 202021_Flinders, Mushroom Reef, HP_3
2028                                 202021_Flinders, Mushroom Reef, HP_3
2029                                 202021_Flinders, Mushroom Reef, HP_3
2030                                 202021_Flinders, Mushroom Reef, HP_3
2031                                 202021_Flinders, Mushroom Reef, HP_3
2032                                                     202021_Fowlers_2
2033                                                     202021_Fowlers_2
2034                                                     202021_Fowlers_2
2035                                                     202021_Fowlers_2
2036                                                     202021_Fowlers_2
2037                                                     202021_Fowlers_2
2038                                                     202021_Fowlers_2
2039                                                     202021_Fowlers_2
2040                                                     202021_Fowlers_4
2041                                                     202021_Fowlers_4
2042                                                     202021_Fowlers_4
2043                                                     202021_Fowlers_4
2044                                                     202021_Fowlers_4
2045                                                     202021_Fowlers_4
2046                                                     202021_Fowlers_4
2047                                                     202021_Fowlers_4
2048                                                     202021_Fowlers_4
2049                                                     202021_Fowlers_4
2050                                                     202021_Fowlers_4
2051                                                     202021_Fowlers_4
2052                                                     202021_Fowlers_4
2053                                                     202021_Fowlers_4
2054                                                     202021_Fowlers_4
2055                                                     202021_Fowlers_4
2056                                                     202021_Fowlers_4
2057                                                     202021_Fowlers_4
2058                                                     202021_Fowlers_4
2059                                                     202021_Fowlers_4
2060                                                     202021_Fowlers_4
2061                                                     202021_Fowlers_4
2062                                                     202021_Fowlers_4
2063                                                     202021_Fowlers_4
2064                                                     202021_Fowlers_4
2065                                                     202021_Fowlers_4
2066                               202021_Gunnamatta SLSC Far East (P1)_1
2067                               202021_Gunnamatta SLSC Far East (P1)_1
2068                               202021_Gunnamatta SLSC Far East (P1)_1
2069                               202021_Gunnamatta SLSC Far East (P1)_1
2070                               202021_Gunnamatta SLSC Far East (P1)_1
2071                               202021_Gunnamatta SLSC Far East (P1)_1
2072                               202021_Gunnamatta SLSC Far East (P1)_1
2073                               202021_Gunnamatta SLSC Far East (P1)_1
2074                               202021_Gunnamatta SLSC Far East (P1)_1
2075                               202021_Gunnamatta SLSC Far East (P1)_3
2076                               202021_Gunnamatta SLSC Far East (P1)_3
2077                               202021_Gunnamatta SLSC Far East (P1)_3
2078                               202021_Gunnamatta SLSC Far East (P1)_3
2079                               202021_Gunnamatta SLSC Far East (P1)_3
2080                               202021_Gunnamatta SLSC Far East (P1)_3
2081                               202021_Gunnamatta SLSC Far East (P1)_3
2082                               202021_Gunnamatta SLSC Far East (P1)_3
2083                               202021_Gunnamatta SLSC Far East (P1)_3
2084                               202021_Gunnamatta SLSC Far East (P1)_3
2085                               202021_Gunnamatta SLSC Far East (P1)_3
2086                               202021_Gunnamatta SLSC Far East (P1)_3
2087                               202021_Gunnamatta SLSC Far East (P1)_3
2088                               202021_Gunnamatta SLSC Far East (P1)_3
2089                             202021_Heyfield Pair 1 (west side) Rye_1
2090                             202021_Heyfield Pair 1 (west side) Rye_1
2091                             202021_Heyfield Pair 1 (west side) Rye_1
2092                             202021_Heyfield Pair 1 (west side) Rye_1
2093                             202021_Heyfield Pair 1 (west side) Rye_1
2094                             202021_Heyfield Pair 1 (west side) Rye_1
2095                             202021_Heyfield Pair 1 (west side) Rye_1
2096                             202021_Heyfield Pair 1 (west side) Rye_1
2097                             202021_Heyfield Pair 1 (west side) Rye_1
2098                             202021_Heyfield Pair 1 (west side) Rye_1
2099                             202021_Heyfield Pair 1 (west side) Rye_1
2100                             202021_Heyfield Pair 1 (west side) Rye_1
2101                             202021_Heyfield Pair 1 (west side) Rye_1
2102                             202021_Heyfield Pair 1 (west side) Rye_1
2103                             202021_Heyfield Pair 1 (west side) Rye_1
2104                             202021_Heyfield Pair 1 (west side) Rye_1
2105                             202021_Heyfield Pair 1 (west side) Rye_1
2106                             202021_Heyfield Pair 1 (west side) Rye_1
2107                             202021_Heyfield Pair 1 (west side) Rye_1
2108                             202021_Heyfield Pair 1 (west side) Rye_1
2109                             202021_Heyfield Pair 1 (west side) Rye_1
2110                             202021_Heyfield Pair 1 (west side) Rye_1
2111                             202021_Heyfield Pair 1 (west side) Rye_1
2112                             202021_Heyfield Pair 1 (west side) Rye_1
2113                             202021_Heyfield Pair 1 (west side) Rye_1
2114                             202021_Heyfield Pair 1 (west side) Rye_1
2115                             202021_Heyfield Pair 1 (west side) Rye_1
2116                             202021_Heyfield Pair 1 (west side) Rye_1
2117                             202021_Heyfield Pair 1 (west side) Rye_1
2118                             202021_Heyfield Pair 1 (west side) Rye_1
2119                             202021_Heyfield Pair 1 (west side) Rye_1
2120                             202021_Heyfield Pair 1 (west side) Rye_1
2121                             202021_Heyfield Pair 1 (west side) Rye_1
2122                             202021_Heyfield Pair 1 (west side) Rye_1
2123                             202021_Heyfield Pair 1 (west side) Rye_1
2124                             202021_Heyfield Pair 1 (west side) Rye_1
2125                             202021_Heyfield Pair 1 (west side) Rye_1
2126                             202021_Heyfield Pair 1 (west side) Rye_1
2127                             202021_Heyfield Pair 1 (west side) Rye_1
2128                             202021_Heyfield Pair 1 (west side) Rye_1
2129                             202021_Heyfield Pair 1 (west side) Rye_1
2130                             202021_Heyfield Pair 1 (west side) Rye_1
2131                             202021_Heyfield Pair 1 (west side) Rye_1
2132                             202021_Heyfield Pair 2 (east side) Rye_1
2133                             202021_Heyfield Pair 2 (east side) Rye_1
2134                             202021_Heyfield Pair 2 (east side) Rye_1
2135                             202021_Heyfield Pair 2 (east side) Rye_1
2136                             202021_Heyfield Pair 2 (east side) Rye_1
2137                             202021_Heyfield Pair 2 (east side) Rye_1
2138                             202021_Heyfield Pair 2 (east side) Rye_1
2139                             202021_Heyfield Pair 2 (east side) Rye_1
2140                             202021_Heyfield Pair 2 (east side) Rye_1
2141                             202021_Heyfield Pair 2 (east side) Rye_1
2142                             202021_Heyfield Pair 2 (east side) Rye_1
2143                             202021_Heyfield Pair 2 (east side) Rye_1
2144                             202021_Heyfield Pair 2 (east side) Rye_1
2145                             202021_Heyfield Pair 2 (east side) Rye_1
2146                             202021_Heyfield Pair 2 (east side) Rye_1
2147                             202021_Heyfield Pair 2 (east side) Rye_2
2148                             202021_Heyfield Pair 2 (east side) Rye_2
2149                             202021_Heyfield Pair 2 (east side) Rye_2
2150                             202021_Heyfield Pair 2 (east side) Rye_2
2151                             202021_Heyfield Pair 2 (east side) Rye_2
2152                             202021_Heyfield Pair 2 (east side) Rye_2
2153                             202021_Heyfield Pair 2 (east side) Rye_2
2154                             202021_Heyfield Pair 2 (east side) Rye_2
2155                             202021_Heyfield Pair 2 (east side) Rye_2
2156                             202021_Heyfield Pair 2 (east side) Rye_2
2157                             202021_Heyfield Pair 2 (east side) Rye_2
2158                             202021_Heyfield Pair 2 (east side) Rye_2
2159                             202021_Heyfield Pair 2 (east side) Rye_2
2160                             202021_Heyfield Pair 2 (east side) Rye_2
2161                             202021_Heyfield Pair 2 (east side) Rye_2
2162                             202021_Heyfield Pair 2 (east side) Rye_2
2163                             202021_Heyfield Pair 2 (east side) Rye_2
2164                             202021_Heyfield Pair 2 (east side) Rye_2
2165                             202021_Heyfield Pair 2 (east side) Rye_2
2166                             202021_Heyfield Pair 2 (east side) Rye_2
2167                             202021_Heyfield Pair 2 (east side) Rye_2
2168                             202021_Heyfield Pair 2 (east side) Rye_2
2169                             202021_Heyfield Pair 2 (east side) Rye_2
2170                             202021_Heyfield Pair 2 (east side) Rye_2
2171                             202021_Heyfield Pair 2 (east side) Rye_2
2172                             202021_Heyfield Pair 2 (east side) Rye_2
2173                                                   202021_Montforts_1
2174                                                   202021_Montforts_1
2175                                                   202021_Montforts_1
2176                                                   202021_Montforts_1
2177                                                   202021_Montforts_1
2178                                                   202021_Montforts_1
2179                                                   202021_Montforts_1
2180                                                   202021_Montforts_1
2181                                                   202021_Montforts_1
2182                                                   202021_Montforts_1
2183                                                   202021_Montforts_1
2184                                                   202021_Montforts_1
2185                                                   202021_Montforts_1
2186                                                   202021_Montforts_1
2187                                                   202021_Montforts_1
2188                                                   202021_Montforts_1
2189                                                   202021_Montforts_2
2190                                                   202021_Montforts_2
2191                                                   202021_Montforts_2
2192                                                   202021_Montforts_2
2193                                                   202021_Montforts_2
2194                                                   202021_Montforts_2
2195                                                   202021_Montforts_2
2196                                                   202021_Montforts_2
2197                                                   202021_Montforts_2
2198                                                   202021_Montforts_2
2199                                                   202021_Montforts_2
2200                                                   202021_Montforts_2
2201                                                   202021_Montforts_2
2202                                                   202021_Montforts_2
2203                                                   202021_Montforts_2
2204                                                   202021_Montforts_2
2205                                                   202021_Montforts_2
2206                                                   202021_Montforts_2
2207                                                   202021_Montforts_2
2208                                                   202021_Montforts_2
2209                                                   202021_Montforts_2
2210                                                   202021_Montforts_2
2211                                  202021_Portsea Franklin rd access_3
2212                                  202021_Portsea Franklin rd access_3
2213                                  202021_Portsea Franklin rd access_3
2214                                  202021_Portsea Franklin rd access_3
2215                                  202021_Portsea Franklin rd access_3
2216                                  202021_Portsea Franklin rd access_3
2217                                  202021_Portsea Franklin rd access_3
2218                                  202021_Portsea Franklin rd access_3
2219                                  202021_Portsea Franklin rd access_3
2220                                  202021_Portsea Franklin rd access_3
2221                                  202021_Portsea Franklin rd access_3
2222                                  202021_Portsea Franklin rd access_3
2223                                  202021_Portsea Franklin rd access_3
2224                                  202021_Portsea Franklin rd access_3
2225                                  202021_Portsea Franklin rd access_3
2226                                  202021_Portsea Franklin rd access_3
2227                                  202021_Portsea Franklin rd access_3
2228                                  202021_Portsea Franklin rd access_3
2229                                  202021_Portsea Franklin rd access_3
2230                                  202021_Portsea Franklin rd access_3
2231                                  202021_Portsea Franklin rd access_3
2232                                  202021_Portsea Franklin rd access_3
2233                                    202021_Portsea Franklin rd west_4
2234                                    202021_Portsea Franklin rd west_4
2235                                    202021_Portsea Franklin rd west_4
2236                                    202021_Portsea Franklin rd west_4
2237                                    202021_Portsea Franklin rd west_4
2238                                    202021_Portsea Franklin rd west_4
2239                                    202021_Portsea Franklin rd west_4
2240                                    202021_Portsea Franklin rd west_4
2241                                    202021_Portsea Franklin rd west_4
2242                                    202021_Portsea Franklin rd west_4
2243                                    202021_Portsea Franklin rd west_4
2244                                    202021_Portsea Franklin rd west_4
2245                                    202021_Portsea Franklin rd west_4
2246                                    202021_Portsea Franklin rd west_4
2247                                    202021_Portsea Franklin rd west_4
2248                                    202021_Portsea Franklin rd west_4
2249                                    202021_Portsea Franklin rd west_4
2250                                    202021_Portsea Franklin rd west_4
2251                                        202021_Portsea Sphinx rocks_1
2252                                        202021_Portsea Sphinx rocks_1
2253                                        202021_Portsea Sphinx rocks_1
2254                                        202021_Portsea Sphinx rocks_1
2255                                        202021_Portsea Sphinx rocks_1
2256                                        202021_Portsea Sphinx rocks_1
2257                                        202021_Portsea Sphinx rocks_1
2258                                        202021_Portsea Sphinx rocks_1
2259                                        202021_Portsea Sphinx rocks_1
2260              202021_Pt Nepean (authorised personnel only) - Spooks_2
2261              202021_Pt Nepean (authorised personnel only) - Spooks_2
2262              202021_Pt Nepean (authorised personnel only) - Spooks_2
2263              202021_Pt Nepean (authorised personnel only) - Spooks_2
2264                                       202021_Pt Nepean, Nepean Bay_1
2265                                       202021_Pt Nepean, Nepean Bay_1
2266                                       202021_Pt Nepean, Nepean Bay_1
2267                                       202021_Pt Nepean, Nepean Bay_1
2268                                       202021_Pt Nepean, Nepean Bay_1
2269                                       202021_Pt Nepean, Nepean Bay_1
2270                                       202021_Pt Nepean, Nepean Bay_1
2271                                       202021_Pt Nepean, Nepean Bay_1
2272                                       202021_Pt Nepean, Nepean Bay_1
2273                                       202021_Pt Nepean, Nepean Bay_1
2274                                       202021_Pt Nepean, Nepean Bay_1
2275                                       202021_Pt Nepean, Nepean Bay_1
2276                                      202021_St Andrews Boags Rocks_2
2277                                      202021_St Andrews Boags Rocks_2
2278                                      202021_St Andrews Boags Rocks_2
2279                                      202021_St Andrews Boags Rocks_2
2280                                      202021_St Andrews Boags Rocks_2
2281                                      202021_St Andrews Boags Rocks_2
2282                                      202021_St Andrews Boags Rocks_2
2283                                      202021_St Andrews Boags Rocks_2
2284                                      202021_St Andrews Boags Rocks_2
2285                                      202021_St Andrews Boags Rocks_2
2286                                      202021_St Andrews Boags Rocks_2
2287                                      202021_St Andrews Boags Rocks_2
2288                                      202021_St Andrews Boags Rocks_2
2289                                      202021_St Andrews Boags Rocks_2
2290                                      202021_St Andrews Boags Rocks_2
2291                                      202021_St Andrews Boags Rocks_2
2292                                      202021_St Andrews Boags Rocks_2
2293                                      202021_St Andrews Boags Rocks_2
2294                                      202021_St Andrews Boags Rocks_2
2295                                      202021_St Andrews Boags Rocks_2
2296                                      202021_St Andrews Boags Rocks_2
2297                                      202021_St Andrews Boags Rocks_2
2298                                      202021_St Andrews Boags Rocks_2
2299                                      202021_St Andrews Boags Rocks_2
2300                                    202122_Alison Ave east bay, Rye_2
2301                                    202122_Alison Ave east bay, Rye_2
2302                                    202122_Alison Ave east bay, Rye_2
2303                                             202122_Alison Ave, Rye_1
2304                                             202122_Alison Ave, Rye_1
2305                                             202122_Alison Ave, Rye_1
2306                                             202122_Alison Ave, Rye_1
2307                                             202122_Alison Ave, Rye_1
2308                                             202122_Alison Ave, Rye_1
2309                                             202122_Alison Ave, Rye_1
2310                                             202122_Alison Ave, Rye_1
2311                                             202122_Alison Ave, Rye_1
2312                                             202122_Alison Ave, Rye_1
2313                                             202122_Alison Ave, Rye_2
2314                                             202122_Alison Ave, Rye_2
2315                                             202122_Alison Ave, Rye_2
2316                                             202122_Alison Ave, Rye_2
2317                                             202122_Alison Ave, Rye_2
2318                                             202122_Alison Ave, Rye_2
2319                                             202122_Alison Ave, Rye_2
2320                                             202122_Alison Ave, Rye_2
2321                                             202122_Alison Ave, Rye_2
2322                                                     202122_Fowlers_4
2323                                                     202122_Fowlers_4
2324                                                     202122_Fowlers_4
2325                                                     202122_Fowlers_4
2326                                                     202122_Fowlers_4
2327                                                     202122_Fowlers_4
2328                             202122_Gunnamatta Fingal Tk (P4)_BJ&14_2
2329                             202122_Gunnamatta Fingal Tk (P4)_BJ&14_2
2330                             202122_Gunnamatta Fingal Tk (P4)_BJ&14_2
2331                             202122_Gunnamatta Fingal Tk (P4)_BJ&14_2
2332                             202122_Gunnamatta Fingal Tk (P4)_BJ&14_2
2333                             202122_Gunnamatta Fingal Tk (P4)_BJ&14_2
2334                             202122_Gunnamatta Fingal Tk (P4)_BJ&14_2
2335                              202122_Gunnamatta Fingal Tk East (P5)_2
2336                              202122_Gunnamatta Fingal Tk East (P5)_2
2337                              202122_Gunnamatta Fingal Tk East (P5)_2
2338                              202122_Gunnamatta Fingal Tk East (P5)_2
2339                              202122_Gunnamatta Fingal Tk East (P5)_2
2340                              202122_Gunnamatta Fingal Tk East (P5)_2
2341                              202122_Gunnamatta Fingal Tk East (P5)_2
2342                             202122_Heyfield Pair 1 (west side) Rye_2
2343                             202122_Heyfield Pair 1 (west side) Rye_2
2344                             202122_Heyfield Pair 1 (west side) Rye_2
2345                             202122_Heyfield Pair 1 (west side) Rye_2
2346                             202122_Heyfield Pair 1 (west side) Rye_3
2347                             202122_Heyfield Pair 1 (west side) Rye_3
2348                             202122_Heyfield Pair 1 (west side) Rye_3
2349                             202122_Heyfield Pair 1 (west side) Rye_3
2350                             202122_Heyfield Pair 1 (west side) Rye_4
2351                             202122_Heyfield Pair 1 (west side) Rye_4
2352                             202122_Heyfield Pair 1 (west side) Rye_4
2353                             202122_Heyfield Pair 1 (west side) Rye_4
2354                             202122_Heyfield Pair 1 (west side) Rye_4
2355                             202122_Heyfield Pair 1 (west side) Rye_4
2356                             202122_Heyfield Pair 1 (west side) Rye_4
2357                             202122_Heyfield Pair 1 (west side) Rye_4
2358                             202122_Heyfield Pair 1 (west side) Rye_4
2359                             202122_Heyfield Pair 1 (west side) Rye_4
2360                             202122_Heyfield Pair 1 (west side) Rye_4
2361                             202122_Heyfield Pair 1 (west side) Rye_4
2362                             202122_Heyfield Pair 2 (east side) Rye_3
2363                             202122_Heyfield Pair 2 (east side) Rye_3
2364                             202122_Heyfield Pair 2 (east side) Rye_3
2365                             202122_Heyfield Pair 2 (east side) Rye_3
2366                             202122_Heyfield Pair 2 (east side) Rye_3
2367                             202122_Heyfield Pair 2 (east side) Rye_3
2368                             202122_Heyfield Pair 2 (east side) Rye_3
2369                             202122_Heyfield Pair 2 (east side) Rye_3
2370                             202122_Heyfield Pair 2 (east side) Rye_3
2371                             202122_Heyfield Pair 2 (east side) Rye_3
2372                             202122_Heyfield Pair 2 (east side) Rye_3
2373                             202122_Heyfield Pair 2 (east side) Rye_3
2374                             202122_Heyfield Pair 2 (east side) Rye_3
2375                             202122_Heyfield Pair 2 (east side) Rye_3
2376                             202122_Heyfield Pair 2 (east side) Rye_3
2377                             202122_Heyfield Pair 2 (east side) Rye_3
2378                             202122_Heyfield Pair 2 (east side) Rye_3
2379                                                 202122_Koonya East_1
2380                                                 202122_Koonya East_1
2381                                                 202122_Koonya East_1
2382                                                 202122_Koonya East_1
2383                                                 202122_Koonya East_1
2384                                                 202122_Koonya East_1
2385                                                 202122_Koonya East_1
2386                                                 202122_Koonya East_1
2387                                                 202122_Koonya East_1
2388                                                 202122_Koonya East_1
2389                                                 202122_Koonya East_1
2390                                                 202122_Koonya East_1
2391                                                 202122_Koonya East_2
2392                                                 202122_Koonya East_2
2393                                                 202122_Koonya East_2
2394                                                 202122_Koonya East_2
2395                                                 202122_Koonya East_2
2396                                                 202122_Koonya East_2
2397                                                 202122_Koonya East_2
2398                                                 202122_Koonya East_2
2399                                                 202122_Koonya West_1
2400                                                 202122_Koonya West_1
2401                                                 202122_Koonya West_1
2402                                                 202122_Koonya West_1
2403                                                 202122_Koonya West_1
2404                                                 202122_Koonya West_1
2405                                                 202122_Koonya West_1
2406                                                 202122_Koonya West_4
2407                                                 202122_Koonya West_4
2408                                                 202122_Koonya West_4
2409                                                 202122_Koonya West_4
2410                                                 202122_Koonya West_4
2411                                                 202122_Koonya West_4
2412                                                 202122_Koonya West_4
2413                                                 202122_Koonya West_4
2414                                                 202122_Koonya West_4
2415                                     202122_Miami drive east access_1
2416                                     202122_Miami drive east access_1
2417                                     202122_Miami drive east access_1
2418                                     202122_Miami drive east access_1
2419                                     202122_Miami drive east access_1
2420                                     202122_Miami drive east access_1
2421                                     202122_Miami drive east access_1
2422                                     202122_Miami drive east access_1
2423                                     202122_Miami drive east access_1
2424                                     202122_Miami drive east access_1
2425                                202122_Portsea Farnsworth/SLSC west_1
2426                                202122_Portsea Farnsworth/SLSC west_1
2427                                202122_Portsea Farnsworth/SLSC west_1
2428                                202122_Portsea Farnsworth/SLSC west_1
2429                                202122_Portsea Farnsworth/SLSC west_1
2430                                202122_Portsea Farnsworth/SLSC west_1
2431                                202122_Portsea Farnsworth/SLSC west_1
2432                                           202122_Rye car park east_1
2433                                           202122_Rye car park east_1
2434                                           202122_Rye car park east_1
2435                                           202122_Rye car park east_1
2436                                           202122_Rye car park east_1
2437                                           202122_Rye car park east_1
2438                                           202122_Rye car park east_1
2439                                           202122_Rye car park east_1
2440                                           202122_Rye car park east_1
2441                                           202122_Rye car park east_1
2442                                           202122_Rye car park east_1
2443                                           202122_Rye car park east_2
2444                                           202122_Rye car park east_2
2445                                           202122_Rye car park east_2
2446                                           202122_Rye car park east_2
2447                                           202122_Rye car park east_2
2448                                           202122_Rye car park east_2
2449                                           202122_Rye car park east_2
2450                                           202122_Rye car park east_2
2451                                           202122_Rye car park east_2
2452                                           202122_Rye car park east_2
2453                                           202122_Rye car park east_2
2454                                           202122_Rye car park east_2
2455                                           202122_Rye car park east_2
2456                                           202122_Rye car park east_2
2457                                           202122_Rye car park east_2
2458                                           202122_Rye car park east_2
2459                                           202122_Rye car park east_2
2460                                           202122_Rye car park east_2
2461                                           202122_Rye car park east_2
2462                                           202122_Rye car park east_2
2463                                           202122_Rye car park east_2
2464                                           202122_Rye car park east_2
2465                                      202122_St Andrews Boags Rocks_1
2466                                      202122_St Andrews Boags Rocks_1
2467                                      202122_St Andrews Boags Rocks_1
2468                                      202122_St Andrews Boags Rocks_1
2469                                      202122_St Andrews Boags Rocks_1
2470                                      202122_St Andrews Boags Rocks_1
2471                                      202122_St Andrews Boags Rocks_1
2472                                      202122_St Andrews Boags Rocks_1
2473                                      202122_St Andrews Boags Rocks_1
2474                                      202122_St Andrews Boags Rocks_1
2475                                      202122_St Andrews Boags Rocks_1
2476                                      202122_St Andrews Boags Rocks_1
2477                                      202122_St Andrews Boags Rocks_1
2478                                      202122_St Andrews Boags Rocks_1
2479                                   202122_St. Andrews car park east_5
2480                                   202122_St. Andrews car park east_5
2481                                   202122_St. Andrews car park east_5
2482                                   202122_St. Andrews car park east_5
2483                                   202122_St. Andrews car park east_5
2484                                   202122_St. Andrews car park east_5
2485                                   202122_St. Andrews car park east_5
2486                                   202122_St. Andrews car park east_5
2487                                    202223_Alison Ave east bay, Rye_2
2488                                    202223_Alison Ave east bay, Rye_2
2489                                    202223_Alison Ave east bay, Rye_2
2490                                    202223_Alison Ave east bay, Rye_2
2491                                    202223_Alison Ave east bay, Rye_2
2492                                    202223_Alison Ave east bay, Rye_2
2493                                    202223_Alison Ave east bay, Rye_2
2494                                    202223_Alison Ave east bay, Rye_2
2495                                    202223_Alison Ave east bay, Rye_2
2496                                    202223_Alison Ave east bay, Rye_2
2497                                    202223_Alison Ave east bay, Rye_2
2498                                    202223_Alison Ave east bay, Rye_2
2499                                    202223_Alison Ave east bay, Rye_2
2500                                             202223_Alison Ave, Rye_1
2501                                             202223_Alison Ave, Rye_1
2502                                             202223_Alison Ave, Rye_1
2503                                             202223_Alison Ave, Rye_1
2504                                             202223_Alison Ave, Rye_2
2505                                             202223_Alison Ave, Rye_2
2506                                             202223_Alison Ave, Rye_2
2507                                             202223_Alison Ave, Rye_2
2508                                             202223_Alison Ave, Rye_2
2509                                             202223_Alison Ave, Rye_2
2510                                             202223_Alison Ave, Rye_2
2511                                             202223_Alison Ave, Rye_2
2512                                             202223_Alison Ave, Rye_2
2513                                             202223_Alison Ave, Rye_2
2514                                             202223_Alison Ave, Rye_2
2515                                             202223_Alison Ave, Rye_2
2516                                             202223_Alison Ave, Rye_2
2517                                             202223_Alison Ave, Rye_2
2518                                             202223_Alison Ave, Rye_3
2519                                             202223_Alison Ave, Rye_3
2520                                             202223_Alison Ave, Rye_3
2521                                             202223_Alison Ave, Rye_3
2522                                             202223_Alison Ave, Rye_3
2523                                             202223_Alison Ave, Rye_3
2524                                             202223_Alison Ave, Rye_3
2525                                             202223_Alison Ave, Rye_3
2526                                             202223_Alison Ave, Rye_3
2527                                             202223_Alison Ave, Rye_3
2528                                             202223_Alison Ave, Rye_3
2529                                             202223_Alison Ave, Rye_3
2530                                             202223_Alison Ave, Rye_3
2531                                             202223_Alison Ave, Rye_3
2532                                             202223_Coppins Lookout_1
2533                                             202223_Coppins Lookout_1
2534                                             202223_Coppins Lookout_1
2535                                             202223_Coppins Lookout_1
2536                                             202223_Coppins Lookout_1
2537                                             202223_Coppins Lookout_1
2538                                             202223_Coppins Lookout_1
2539                                             202223_Coppins Lookout_1
2540                                             202223_Coppins Lookout_1
2541                                             202223_Coppins Lookout_1
2542                                             202223_Coppins Lookout_1
2543                                             202223_Coppins Lookout_1
2544                                             202223_Coppins Lookout_1
2545                                             202223_Coppins Lookout_1
2546                                             202223_Coppins Lookout_1
2547                                             202223_Coppins Lookout_1
2548                                             202223_Coppins Lookout_1
2549                                             202223_Coppins Lookout_1
2550                                             202223_Coppins Lookout_1
2551                                   202223_Gunnamatta Fingal Tk (P4)_3
2552                                   202223_Gunnamatta Fingal Tk (P4)_3
2553                                   202223_Gunnamatta Fingal Tk (P4)_3
2554                                   202223_Gunnamatta Fingal Tk (P4)_3
2555                              202223_Gunnamatta Fingal Tk East (P5)_1
2556                              202223_Gunnamatta Fingal Tk East (P5)_1
2557                              202223_Gunnamatta Fingal Tk East (P5)_1
2558                              202223_Gunnamatta Fingal Tk East (P5)_1
2559                              202223_Gunnamatta Fingal Tk East (P5)_1
2560                              202223_Gunnamatta Fingal Tk East (P5)_1
2561                              202223_Gunnamatta Fingal Tk East (P5)_1
2562                              202223_Gunnamatta Fingal Tk East (P5)_1
2563                              202223_Gunnamatta Fingal Tk East (P5)_2
2564                              202223_Gunnamatta Fingal Tk East (P5)_2
2565                              202223_Gunnamatta Fingal Tk East (P5)_2
2566                              202223_Gunnamatta Fingal Tk East (P5)_2
2567                              202223_Gunnamatta Fingal Tk East (P5)_2
2568                              202223_Gunnamatta Fingal Tk East (P5)_2
2569                              202223_Gunnamatta Fingal Tk East (P5)_2
2570                              202223_Gunnamatta Fingal Tk East (P5)_2
2571                              202223_Gunnamatta Fingal Tk East (P5)_2
2572                              202223_Gunnamatta Fingal Tk East (P5)_2
2573                              202223_Gunnamatta Fingal Tk East (P5)_2
2574                              202223_Gunnamatta Fingal Tk East (P5)_2
2575                                   202223_Gunnamatta Fingal Tk West_1
2576                                   202223_Gunnamatta Fingal Tk West_1
2577                                   202223_Gunnamatta Fingal Tk West_1
2578                                   202223_Gunnamatta Fingal Tk West_1
2579                                   202223_Gunnamatta Fingal Tk West_1
2580                                   202223_Gunnamatta Fingal Tk West_1
2581                                   202223_Gunnamatta Fingal Tk West_1
2582                                   202223_Gunnamatta Fingal Tk West_1
2583                                   202223_Gunnamatta Fingal Tk West_1
2584                             202223_Heyfield Pair 1 (west side) Rye_3
2585                             202223_Heyfield Pair 1 (west side) Rye_3
2586                             202223_Heyfield Pair 1 (west side) Rye_3
2587                             202223_Heyfield Pair 1 (west side) Rye_3
2588                             202223_Heyfield Pair 1 (west side) Rye_3
2589                             202223_Heyfield Pair 1 (west side) Rye_3
2590                             202223_Heyfield Pair 1 (west side) Rye_3
2591                             202223_Heyfield Pair 1 (west side) Rye_3
2592                             202223_Heyfield Pair 1 (west side) Rye_3
2593                             202223_Heyfield Pair 1 (west side) Rye_3
2594                             202223_Heyfield Pair 1 (west side) Rye_3
2595                             202223_Heyfield Pair 1 (west side) Rye_3
2596                             202223_Heyfield Pair 1 (west side) Rye_3
2597                             202223_Heyfield Pair 1 (west side) Rye_3
2598                             202223_Heyfield Pair 1 (west side) Rye_3
2599                             202223_Heyfield Pair 2 (east side) Rye_1
2600                             202223_Heyfield Pair 2 (east side) Rye_1
2601                             202223_Heyfield Pair 2 (east side) Rye_1
2602                             202223_Heyfield Pair 2 (east side) Rye_1
2603                             202223_Heyfield Pair 2 (east side) Rye_1
2604                             202223_Heyfield Pair 2 (east side) Rye_1
2605                             202223_Heyfield Pair 2 (east side) Rye_1
2606                             202223_Heyfield Pair 2 (east side) Rye_1
2607                             202223_Heyfield Pair 2 (east side) Rye_1
2608                             202223_Heyfield Pair 2 (east side) Rye_1
2609                             202223_Heyfield Pair 2 (east side) Rye_1
2610                             202223_Heyfield Pair 2 (east side) Rye_1
2611                             202223_Heyfield Pair 2 (east side) Rye_1
2612                             202223_Heyfield Pair 2 (east side) Rye_1
2613                             202223_Heyfield Pair 2 (east side) Rye_1
2614                             202223_Heyfield Pair 2 (east side) Rye_2
2615                             202223_Heyfield Pair 2 (east side) Rye_2
2616                             202223_Heyfield Pair 2 (east side) Rye_2
2617                             202223_Heyfield Pair 2 (east side) Rye_2
2618                             202223_Heyfield Pair 2 (east side) Rye_2
2619                             202223_Heyfield Pair 2 (east side) Rye_2
2620                             202223_Heyfield Pair 2 (east side) Rye_2
2621                             202223_Heyfield Pair 2 (east side) Rye_2
2622                             202223_Heyfield Pair 2 (east side) Rye_2
2623                             202223_Heyfield Pair 2 (east side) Rye_2
2624                             202223_Heyfield Pair 2 (east side) Rye_2
2625                                                 202223_Koonya East_1
2626                                                 202223_Koonya East_1
2627                                                 202223_Koonya East_1
2628                                                 202223_Koonya East_1
2629                                                 202223_Koonya East_1
2630                                                 202223_Koonya East_1
2631                                                 202223_Koonya East_1
2632                                                 202223_Koonya East_1
2633                                                 202223_Koonya East_2
2634                                                 202223_Koonya East_2
2635                                                 202223_Koonya East_2
2636                                                 202223_Koonya East_2
2637                                                 202223_Koonya East_2
2638                                                 202223_Koonya East_2
2639                                                 202223_Koonya East_2
2640                                                 202223_Koonya West_1
2641                                                 202223_Koonya West_1
2642                                                 202223_Koonya West_1
2643                                                 202223_Koonya West_1
2644                                     202223_Miami drive east access_4
2645                                     202223_Miami drive east access_4
2646                                     202223_Miami drive east access_4
2647                                     202223_Miami drive east access_4
2648                                     202223_Miami drive east access_4
2649                                     202223_Miami drive east access_4
2650                                     202223_Miami drive east access_4
2651                                     202223_Miami drive east access_4
2652                                     202223_Miami drive east access_4
2653                                     202223_Miami drive east access_4
2654                                     202223_Miami drive east access_4
2655                                     202223_Miami drive east access_4
2656                                     202223_Miami drive east access_4
2657                                     202223_Miami drive east access_4
2658                                     202223_Miami drive east access_4
2659                                     202223_Miami drive east access_4
2660                                     202223_Miami drive east access_4
2661                                     202223_Miami drive east access_4
2662                                                   202223_Montforts_2
2663                                                   202223_Montforts_2
2664                                                   202223_Montforts_2
2665                                                   202223_Montforts_2
2666                                                   202223_Montforts_2
2667                                                   202223_Montforts_2
2668                                                   202223_Montforts_2
2669                                                   202223_Montforts_2
2670                                                   202223_Montforts_2
2671                                                   202223_Montforts_2
2672                                                   202223_Montforts_2
2673                                                   202223_Montforts_2
2674                                                   202223_Montforts_2
2675                                                   202223_Montforts_2
2676                                                   202223_Montforts_2
2677                                                   202223_Point Leo_1
2678                                                   202223_Point Leo_1
2679                                                   202223_Point Leo_1
2680                                    202223_Portsea Franklin rd west_1
2681                                    202223_Portsea Franklin rd west_1
2682                                    202223_Portsea Franklin rd west_1
2683                                    202223_Portsea Franklin rd west_1
2684                                    202223_Portsea Franklin rd west_1
2685                                       202223_Portsea London Bridge_1
2686                                       202223_Portsea London Bridge_1
2687                                       202223_Portsea London Bridge_1
2688                                       202223_Portsea London Bridge_1
2689                                                202223_Rye Big Rock_2
2690                                                202223_Rye Big Rock_2
2691                                                202223_Rye Big Rock_2
2692                                                202223_Rye Big Rock_2
2693                                                202223_Rye Big Rock_2
2694                                                202223_Rye Big Rock_2
2695                                                202223_Rye Big Rock_2
2696                                                202223_Rye Big Rock_2
2697                                                202223_Rye Big Rock_2
2698                                                202223_Rye Big Rock_2
2699                                                202223_Rye Big Rock_2
2700                                                202223_Rye Big Rock_2
2701                                                202223_Rye Big Rock_2
2702                                                202223_Rye Big Rock_2
2703                                                202223_Rye Big Rock_2
2704                                                202223_Rye Big Rock_2
2705                                                202223_Rye Big Rock_2
2706                                                202223_Rye Big Rock_2
2707                                                202223_Rye Big Rock_2
2708                                                202223_Rye Big Rock_2
2709                                                202223_Rye Big Rock_2
2710                                                202223_Rye Big Rock_2
2711                                           202223_Rye car park east_1
2712                                           202223_Rye car park east_1
2713                                           202223_Rye car park east_1
2714                                           202223_Rye car park east_1
2715                                           202223_Rye car park east_1
2716                                           202223_Rye car park east_1
2717                                           202223_Rye car park east_1
2718                                           202223_Rye car park east_1
2719                                           202223_Rye car park east_1
2720                                           202223_Rye car park east_1
2721                                           202223_Rye car park east_1
2722                                           202223_Rye car park east_1
2723                                           202223_Rye car park east_1
2724                                           202223_Rye car park east_1
2725                                           202223_Rye car park east_1
2726                                           202223_Rye car park east_1
2727                                           202223_Rye car park east_1
2728                                           202223_Rye car park east_1
2729                                           202223_Rye car park east_2
2730                                           202223_Rye car park east_2
2731                                           202223_Rye car park east_2
2732                                           202223_Rye car park east_2
2733                                           202223_Rye car park east_2
2734                                           202223_Rye car park east_2
2735                                           202223_Rye car park east_2
2736                                           202223_Rye car park east_2
2737                                           202223_Rye car park east_2
2738                                           202223_Rye car park east_2
2739                                           202223_Rye car park east_2
2740                                           202223_Rye car park east_2
2741                                           202223_Rye car park east_2
2742                                           202223_Rye car park east_2
2743                                           202223_Rye car park east_2
2744                                           202223_Rye car park east_2
2745                                           202223_Rye car park east_2
2746                                           202223_Rye car park east_2
2747                                           202223_Rye car park east_2
2748                                           202223_Rye car park east_2
2749                                           202223_Rye car park east_2
2750                                           202223_Rye car park east_2
2751                                           202223_Rye car park east_2
2752                                           202223_Rye car park east_2
2753                                           202223_Rye car park east_2
2754                                           202223_Rye car park east_2
2755                                           202223_Rye car park east_2
2756                                           202223_Rye car park east_2
2757                                           202223_Rye car park east_2
2758                                           202223_Rye car park east_2
2759                                           202223_Rye car park east_2
2760                                    202324_Alison Ave east bay, Rye_2
2761                                    202324_Alison Ave east bay, Rye_2
2762                                    202324_Alison Ave east bay, Rye_2
2763                                    202324_Alison Ave east bay, Rye_2
2764                                    202324_Alison Ave east bay, Rye_2
2765                                    202324_Alison Ave east bay, Rye_2
2766                                    202324_Alison Ave east bay, Rye_2
2767                                    202324_Alison Ave east bay, Rye_2
2768                                    202324_Alison Ave east bay, Rye_2
2769                                    202324_Alison Ave east bay, Rye_2
2770                                    202324_Alison Ave east bay, Rye_2
2771                                             202324_Alison Ave, Rye_2
2772                                             202324_Alison Ave, Rye_2
2773                                             202324_Alison Ave, Rye_2
2774                                             202324_Alison Ave, Rye_2
2775                                             202324_Alison Ave, Rye_2
2776                                             202324_Alison Ave, Rye_2
2777                                             202324_Alison Ave, Rye_2
2778                                             202324_Alison Ave, Rye_2
2779                                             202324_Alison Ave, Rye_2
2780                                             202324_Alison Ave, Rye_2
2781                                             202324_Alison Ave, Rye_2
2782                                             202324_Alison Ave, Rye_2
2783                                             202324_Alison Ave, Rye_2
2784                                             202324_Alison Ave, Rye_2
2785                                             202324_Alison Ave, Rye_2
2786                                             202324_Alison Ave, Rye_2
2787                                             202324_Alison Ave, Rye_2
2788                                             202324_Alison Ave, Rye_2
2789                                               202324_Brewster, Rye_3
2790                                               202324_Brewster, Rye_3
2791                                               202324_Brewster, Rye_3
2792                                               202324_Brewster, Rye_3
2793                                               202324_Brewster, Rye_3
2794                                               202324_Brewster, Rye_3
2795                                               202324_Brewster, Rye_3
2796                                               202324_Brewster, Rye_3
2797                                               202324_Brewster, Rye_3
2798                                               202324_Brewster, Rye_3
2799                                               202324_Brewster, Rye_3
2800                                               202324_Brewster, Rye_3
2801                                               202324_Brewster, Rye_3
2802                                                     202324_Fowlers_5
2803                                                     202324_Fowlers_5
2804                                                     202324_Fowlers_5
2805                                                     202324_Fowlers_5
2806                                                     202324_Fowlers_5
2807                                  202324_Gunnamatta Car Park 1 (P6)_1
2808                                  202324_Gunnamatta Car Park 1 (P6)_1
2809                                  202324_Gunnamatta Car Park 1 (P6)_1
2810                                   202324_Gunnamatta Fingal Tk West_2
2811                                   202324_Gunnamatta Fingal Tk West_2
2812                                   202324_Gunnamatta Fingal Tk West_2
2813                                   202324_Gunnamatta Fingal Tk West_2
2814                                   202324_Gunnamatta Fingal Tk West_2
2815                                   202324_Gunnamatta Fingal Tk West_2
2816                                   202324_Gunnamatta Fingal Tk West_2
2817                                   202324_Gunnamatta Fingal Tk West_2
2818                             202324_Heyfield Pair 1 (west side) Rye_1
2819                             202324_Heyfield Pair 1 (west side) Rye_1
2820                             202324_Heyfield Pair 1 (west side) Rye_1
2821                             202324_Heyfield Pair 1 (west side) Rye_1
2822                             202324_Heyfield Pair 1 (west side) Rye_1
2823                             202324_Heyfield Pair 1 (west side) Rye_1
2824                             202324_Heyfield Pair 1 (west side) Rye_1
2825                             202324_Heyfield Pair 1 (west side) Rye_1
2826                             202324_Heyfield Pair 1 (west side) Rye_1
2827                             202324_Heyfield Pair 1 (west side) Rye_1
2828                             202324_Heyfield Pair 1 (west side) Rye_1
2829                             202324_Heyfield Pair 1 (west side) Rye_1
2830                             202324_Heyfield Pair 2 (east side) Rye_1
2831                             202324_Heyfield Pair 2 (east side) Rye_1
2832                             202324_Heyfield Pair 2 (east side) Rye_1
2833                             202324_Heyfield Pair 2 (east side) Rye_1
2834                             202324_Heyfield Pair 2 (east side) Rye_1
2835                             202324_Heyfield Pair 2 (east side) Rye_1
2836                             202324_Heyfield Pair 2 (east side) Rye_1
2837                             202324_Heyfield Pair 2 (east side) Rye_1
2838                             202324_Heyfield Pair 2 (east side) Rye_1
2839                             202324_Heyfield Pair 2 (east side) Rye_1
2840                             202324_Heyfield Pair 2 (east side) Rye_1
2841                             202324_Heyfield Pair 2 (east side) Rye_1
2842                             202324_Heyfield Pair 2 (east side) Rye_1
2843                             202324_Heyfield Pair 2 (east side) Rye_1
2844                             202324_Heyfield Pair 2 (east side) Rye_1
2845                             202324_Heyfield Pair 2 (east side) Rye_1
2846                             202324_Heyfield Pair 2 (east side) Rye_1
2847                             202324_Heyfield Pair 2 (east side) Rye_2
2848                             202324_Heyfield Pair 2 (east side) Rye_2
2849                             202324_Heyfield Pair 2 (east side) Rye_2
2850                             202324_Heyfield Pair 2 (east side) Rye_2
2851                             202324_Heyfield Pair 2 (east side) Rye_2
2852                             202324_Heyfield Pair 2 (east side) Rye_2
2853                             202324_Heyfield Pair 2 (east side) Rye_2
2854                             202324_Heyfield Pair 2 (east side) Rye_2
2855                             202324_Heyfield Pair 2 (east side) Rye_2
2856                             202324_Heyfield Pair 2 (east side) Rye_2
2857                             202324_Heyfield Pair 2 (east side) Rye_2
2858                             202324_Heyfield Pair 2 (east side) Rye_2
2859                             202324_Heyfield Pair 2 (east side) Rye_2
2860                             202324_Heyfield Pair 2 (east side) Rye_2
2861                             202324_Heyfield Pair 2 (east side) Rye_2
2862                                                 202324_Koonya East_3
2863                                                 202324_Koonya East_3
2864                                                 202324_Koonya East_3
2865                                                 202324_Koonya East_3
2866                                                 202324_Koonya East_3
2867                                                 202324_Koonya East_3
2868                                                 202324_Koonya East_3
2869                                                 202324_Koonya East_3
2870                                                 202324_Koonya East_3
2871                                                 202324_Koonya East_3
2872                                     202324_Miami drive east access_4
2873                                     202324_Miami drive east access_4
2874                                     202324_Miami drive east access_4
2875                                     202324_Miami drive east access_4
2876                                     202324_Miami drive east access_4
2877                                     202324_Miami drive east access_4
2878                                     202324_Miami drive east access_4
2879                                     202324_Miami drive east access_4
2880                                     202324_Miami drive east access_4
2881                                     202324_Miami drive east access_4
2882                                     202324_Miami drive east access_4
2883                                     202324_Miami drive east access_4
2884                                     202324_Miami drive east access_4
2885                                     202324_Miami drive east access_4
2886                                     202324_Miami drive east access_4
2887                                     202324_Miami drive east access_4
2888                                     202324_Miami drive east access_4
2889                                     202324_Miami drive east access_4
2890                                     202324_Miami drive east access_4
2891                                     202324_Miami drive east access_4
2892                                                   202324_Montforts_2
2893                                                   202324_Montforts_2
2894                                                   202324_Montforts_2
2895                                                   202324_Montforts_2
2896                                                   202324_Montforts_2
2897                                                   202324_Montforts_2
2898                                                   202324_Montforts_2
2899                                                   202324_Montforts_2
2900                                                   202324_Montforts_2
2901                                                   202324_Montforts_2
2902                                                   202324_Montforts_2
2903                                                   202324_Montforts_2
2904                                                   202324_Montforts_2
2905                                                   202324_Montforts_2
2906                                                   202324_Montforts_2
2907                                                   202324_Montforts_2
2908                                                   202324_Montforts_2
2909                                                   202324_Montforts_2
2910                                                   202324_Montforts_2
2911                                                   202324_Montforts_2
2912                                                   202324_Montforts_2
2913                                                   202324_Montforts_2
2914                                                   202324_Montforts_2
2915                                                   202324_Montforts_2
2916                                                   202324_Montforts_2
2917                                                   202324_Montforts_2
2918                                                   202324_Montforts_2
2919                                                   202324_Point Leo_1
2920                                                   202324_Point Leo_1
2921                                202324_Portsea Farnsworth/SLSC west_2
2922                                202324_Portsea Farnsworth/SLSC west_2
2923                                202324_Portsea Farnsworth/SLSC west_2
2924                                202324_Portsea Farnsworth/SLSC west_2
2925                                202324_Portsea Farnsworth/SLSC west_2
2926                                202324_Portsea Farnsworth/SLSC west_2
2927                                202324_Portsea Farnsworth/SLSC west_2
2928                                202324_Portsea Farnsworth/SLSC west_2
2929                                           202324_Rye car park east_1
2930                                           202324_Rye car park east_1
2931                                           202324_Rye car park east_1
2932                                           202324_Rye car park east_1
2933                                           202324_Rye car park east_1
2934                                           202324_Rye car park east_1
2935                                           202324_Rye car park east_1
2936                                           202324_Rye car park east_3
2937                                           202324_Rye car park east_3
2938                                           202324_Rye car park east_3
2939                                           202324_Rye car park east_3
2940                                           202324_Rye car park east_3
2941                                           202324_Rye car park east_3
2942                                           202324_Rye car park east_3
2943                                           202324_Rye car park east_3
2944                                           202324_Rye car park east_3
2945                                           202324_Rye car park east_3
2946                                           202324_Rye car park east_3
2947                                           202324_Rye car park east_3
2948                                           202324_Rye car park east_3
2949                                           202324_Rye car park east_3
2950                                           202324_Rye car park east_3
2951                                           202324_Rye car park east_3
2952                                           202324_Rye car park east_3
2953                                           202324_Rye car park east_3
2954                                           202324_Rye car park east_3
2955                                           202324_Rye car park east_3
2956                                           202324_Rye car park east_3
2957                                           202324_Rye car park east_3
2958                                           202324_Rye car park west_1
2959                                           202324_Rye car park west_1
2960                                           202324_Rye car park west_1
2961                                   202324_St. Andrews car park east_2
2962                                   202324_St. Andrews car park east_2
2963                                   202324_St. Andrews car park east_2
2964                                   202324_St. Andrews car park east_2
2965                                   202324_St. Andrews car park east_2
2966                                   202324_St. Andrews car park east_2
2967                                   202324_St. Andrews car park east_2
2968                                   202324_St. Andrews car park east_2
2969                                   202324_St. Andrews car park east_2
2970                                   202324_St. Andrews car park east_2
2971                                   202324_St. Andrews car park east_2
2972                                   202324_St. Andrews car park east_2
2973                                   202324_St. Andrews car park east_2
2974                                                                 junk
2975                                                                 junk
2976                                                                 junk
2977                                                                 junk
2978                                                                 junk
2979                                                                 junk
2980                                                                 junk
2981                                                                 junk
2982                                                                 junk
2983                                                                 junk
2984                                                                 junk
2985                                                                 junk
2986                                                                 junk
2987                                                                 junk
2988                                                                 junk
2989                                                                 junk
2990                                                                 junk
2991                                                                 junk
2992                                                                 junk
2993                                                                 junk
2994                                                                 junk
2995                                                                 junk
2996                                                                 junk
2997                                                                 junk
2998                                                                 junk
2999                                                                 junk
3000                                                                 junk
3001                                                                 junk
3002                                                                 junk
3003                                                                 junk
3004                                                                 junk
3005                                                                 junk
3006                                                                 junk
3007                                                                 junk
3008                                                                 junk
     brood_age offspring_seen
1            3              1
2            4              0
3            6              0
4            3              1
5            5              0
6            3              1
7            4              1
8            5              1
9            6              1
10           7              1
11           9              1
12          10              1
13          12              1
14          13              1
15          15              0
16          15              1
17          16              1
18          19              1
19          20              1
20          23              1
21          25              1
22          26              1
23          26              1
24          32              1
25           3              1
26           4              1
27           8              1
28           9              1
29          14              1
30          15              1
31          16              1
32          17              1
33          20              1
34          22              1
35          27              1
36          31              0
37           3              1
38           4              1
39           4              1
40          15              0
41           3              1
42           8              1
43          10              1
44          16              0
45           3              1
46           6              1
47           6              1
48           7              1
49          12              1
50          13              1
51          19              1
52          19              0
53          24              1
54          33              1
55           3              1
56          11              0
57           3              1
58           4              1
59           6              1
60           8              0
61           3              1
62           4              1
63           4              1
64           5              1
65           6              1
66           7              1
67          10              0
68          11              1
69          12              1
70          13              1
71          16              1
72          17              1
73          18              0
74           3              1
75           3              1
76           4              1
77           7              1
78          17              0
79          18              1
80          22              0
81           3              1
82           7              1
83           7              0
84           7              0
85           3              1
86           3              1
87           4              1
88           4              1
89           5              1
90           5              1
91           6              1
92           6              1
93           8              1
94           9              0
95          10              1
96          10              0
97           3              1
98           6              0
99           3              1
100          9              0
101          3              1
102          5              1
103          7              1
104         11              1
105         14              1
106         18              1
107         21              1
108         22              1
109         24              1
110         26              1
111         26              1
112         26              1
113         28              1
114         31              1
115         34              1
116         35              1
117          3              1
118          7              0
119         14              0
120         18              0
121          3              1
122          5              1
123          8              1
124         11              0
125          3              1
126          8              1
127         11              1
128         15              0
129          3              1
130          5              1
131          6              0
132          7              1
133          9              1
134         11              1
135         15              1
136         16              1
137         19              1
138         20              0
139          3              1
140          4              1
141          5              1
142          5              0
143          7              1
144          8              1
145         13              1
146         14              1
147         15              1
148         20              1
149         22              1
150         24              1
151         25              1
152         26              1
153         29              1
154         30              1
155         31              1
156         32              1
157         33              1
158         34              1
159         34              1
160         35              1
161          3              1
162          4              1
163          5              1
164          6              1
165          7              1
166         10              1
167         11              1
168         12              1
169         14              1
170         16              1
171         17              1
172         18              1
173         20              1
174         25              1
175         28              0
176          3              1
177         11              1
178         31              0
179          3              1
180         11              1
181         16              1
182         23              0
183          3              1
184          6              1
185          8              0
186          9              0
187          3              1
188          5              0
189          3              1
190          3              1
191          4              1
192          4              0
193          5              0
194          3              1
195          3              1
196          3              1
197          4              1
198          4              1
199          4              1
200          5              1
201          6              1
202          6              1
203          7              1
204          8              1
205          9              1
206         10              1
207         11              1
208         12              1
209         12              1
210         12              1
211         13              1
212         14              1
213         15              1
214         15              1
215         16              1
216         18              1
217         19              1
218         19              1
219         19              1
220         20              1
221         22              1
222         22              1
223         22              1
224         23              1
225         24              1
226         24              1
227         25              1
228         25              1
229         26              1
230         28              1
231         28              1
232         28              1
233         28              1
234         29              1
235         29              0
236         29              1
237         29              1
238         30              1
239         31              1
240         31              1
241         32              1
242         32              0
243         34              1
244          3              1
245          4              1
246          5              1
247          6              1
248          7              1
249          7              1
250          9              0
251         10              0
252         11              0
253          3              1
254          4              0
255          5              1
256          7              0
257          7              0
258          8              0
259          9              0
260          3              1
261          3              0
262          4              1
263          4              1
264          6              0
265          7              0
266          8              0
267          8              0
268          3              1
269          5              0
270          3              1
271          4              0
272          4              1
273          4              1
274          5              1
275          5              1
276          6              0
277          3              1
278          3              1
279          5              0
280          6              0
281          9              0
282          3              1
283          4              1
284          4              1
285          4              1
286          4              1
287          5              0
288          5              0
289          3              1
290          3              0
291          4              1
292          5              1
293          5              1
294          6              1
295          7              1
296          8              1
297          8              1
298         10              1
299         11              1
300         11              1
301         12              1
302         12              1
303         13              1
304         14              1
305         15              0
306         15              1
307         16              1
308         17              1
309         17              1
310         18              1
311         18              1
312         19              1
313         20              1
314         20              1
315         21              1
316         22              1
317         22              1
318         23              1
319         23              1
320         24              1
321         24              1
322         25              1
323         26              1
324         26              1
325         26              1
326         27              1
327         28              1
328         29              1
329         29              1
330         29              1
331         30              1
332         31              1
333         31              1
334         32              1
335         33              1
336         34              1
337         34              1
338          3              1
339          4              1
340          5              1
341          6              1
342         10              0
343         14              0
344         16              1
345         19              0
346         23              0
347         24              0
348          3              1
349          3              0
350          4              1
351          4              1
352          5              1
353          5              1
354          6              1
355          6              1
356          6              1
357          6              1
358          7              1
359          7              1
360          7              1
361          8              1
362          9              1
363          9              1
364          9              1
365         10              1
366         10              1
367         10              1
368         10              1
369         10              1
370         10              1
371         11              1
372         11              1
373         11              1
374         11              1
375         11              1
376         11              1
377         12              1
378         12              1
379         12              1
380         13              1
381         13              1
382         13              1
383         13              1
384         13              1
385         13              1
386         14              1
387         14              1
388         15              1
389         15              1
390         15              1
391         16              1
392         17              1
393         17              1
394         18              1
395         18              1
396         18              1
397         19              1
398         19              1
399         19              1
400         19              1
401         20              1
402         20              1
403         20              1
404         21              1
405         21              1
406         21              0
407         22              1
408         22              1
409         23              1
410         23              1
411         23              1
412         24              1
413         24              1
414         25              1
415         25              1
416         26              0
417         26              0
418          3              1
419          3              1
420          3              1
421          4              1
422          5              1
423          5              1
424          5              1
425          6              1
426          6              1
427          6              0
428          6              1
429          7              1
430          7              1
431          8              1
432          8              1
433          9              0
434          9              0
435          9              0
436          3              1
437          3              0
438          3              1
439          4              1
440          4              1
441          5              1
442          5              1
443          6              1
444          7              1
445          7              1
446          7              1
447          8              1
448          9              1
449         10              1
450         10              1
451         10              1
452         10              1
453         11              1
454         12              1
455         12              1
456         13              1
457         14              1
458         15              1
459         15              0
460         16              1
461         16              1
462         18              1
463         19              1
464         20              0
465         20              1
466         21              1
467         22              1
468         23              1
469         23              1
470         24              1
471         24              1
472         25              1
473         25              1
474         25              1
475         26              1
476         26              1
477         28              1
478         28              1
479         29              1
480         29              1
481         30              1
482         30              1
483         30              1
484         32              1
485         33              1
486         33              1
487         33              1
488         33              1
489         34              1
490         34              1
491         34              1
492         35              1
493          3              1
494          4              1
495          4              1
496          5              1
497          8              1
498         13              1
499         17              1
500         17              1
501         18              1
502         19              1
503         20              1
504         22              0
505         22              1
506         25              0
507         27              0
508         32              0
509          3              1
510          4              0
511          5              0
512          7              1
513          7              1
514          8              1
515          8              1
516          8              1
517          9              1
518          9              1
519         10              0
520         10              1
521         10              0
522         10              0
523         11              0
524         11              0
525         12              0
526          3              1
527          3              0
528          3              0
529          4              1
530          6              0
531          8              1
532          9              0
533         14              0
534         15              0
535         16              0
536          3              1
537          4              1
538          4              1
539          4              1
540          5              1
541          6              1
542          7              1
543          8              1
544          9              1
545          9              1
546         10              1
547         12              1
548         13              1
549         13              1
550         13              1
551         14              1
552         15              0
553         16              1
554         16              1
555         16              1
556         17              1
557         17              1
558         18              0
559         18              0
560         19              0
561         19              0
562          3              1
563          3              1
564          4              1
565          4              1
566          4              1
567          6              1
568          7              1
569          9              1
570         10              1
571         11              1
572         11              1
573         12              0
574         13              0
575         14              0
576          3              1
577          4              0
578          6              0
579          7              0
580          8              0
581          3              1
582          4              1
583          5              0
584          5              0
585          6              0
586          7              0
587          8              0
588          3              1
589          7              0
590          8              0
591          9              0
592          3              1
593          3              1
594          4              0
595          5              1
596          6              1
597          7              1
598          8              1
599          9              1
600          9              1
601         10              1
602         10              1
603         11              1
604         11              1
605         11              1
606         13              1
607         14              1
608         15              1
609         16              1
610         17              1
611         17              1
612         18              1
613         18              1
614         19              1
615         20              1
616         21              1
617         21              1
618         22              1
619         22              1
620         24              1
621         24              1
622         25              1
623         25              1
624         26              1
625         27              1
626         27              1
627         27              1
628         28              1
629         28              1
630         29              1
631         30              1
632         30              1
633         31              1
634         32              1
635         33              1
636         34              1
637         34              1
638         34              1
639         35              1
640          3              1
641          4              0
642         10              1
643         10              1
644         13              1
645         17              0
646         18              0
647         19              0
648         21              0
649         24              0
650          3              1
651          3              0
652          4              1
653          5              1
654          7              0
655          7              1
656          8              0
657          9              0
658          9              1
659         10              1
660         10              1
661         11              1
662         11              1
663         11              1
664         13              1
665         15              1
666         16              1
667         17              1
668         17              1
669         18              1
670         18              1
671         19              1
672         20              1
673         21              0
674         21              1
675         22              1
676         22              1
677         24              1
678         24              1
679         25              1
680         25              1
681         26              1
682         27              1
683         27              1
684         27              1
685         28              1
686         28              1
687         29              1
688         30              1
689         31              1
690         32              1
691         33              1
692         33              1
693         34              1
694         34              1
695         34              1
696         35              1
697          3              1
698          5              1
699          6              1
700          6              1
701          7              1
702          7              1
703          8              1
704          8              1
705          9              1
706         10              0
707          3              1
708          5              1
709          5              1
710          7              1
711          8              1
712         10              1
713         12              0
714         15              0
715          3              1
716          3              0
717          4              1
718          4              1
719          4              1
720          5              1
721          5              0
722          6              1
723          7              1
724          7              1
725          7              0
726          7              1
727          8              1
728          8              0
729          8              0
730          9              1
731          9              1
732         10              1
733         10              1
734         10              1
735         11              1
736         11              1
737         11              1
738         12              1
739         12              1
740         13              1
741         14              1
742         14              1
743         15              1
744         16              1
745         17              1
746         17              1
747         18              1
748         19              1
749         19              1
750         20              1
751         20              1
752         21              1
753         23              1
754         24              1
755         25              1
756         26              1
757         26              1
758         27              1
759         27              1
760         27              1
761         28              1
762         29              1
763         31              1
764         31              1
765         32              1
766         33              1
767         34              1
768         35              1
769          3              1
770          4              1
771          5              0
772          6              0
773          3              1
774          4              1
775          5              1
776          5              0
777          6              1
778          6              1
779          7              1
780          8              1
781          9              1
782         10              1
783         10              1
784         11              1
785         11              1
786         12              0
787         12              0
788         13              0
789          3              1
790          4              1
791          4              0
792          5              1
793          6              1
794          7              1
795          9              1
796         10              1
797         10              1
798         11              1
799         12              1
800         13              1
801         14              1
802         15              0
803         15              0
804         16              0
805          3              1
806          4              0
807          3              1
808          3              1
809          4              1
810          4              1
811          4              1
812          5              1
813          6              1
814          7              1
815          8              1
816          9              1
817          9              1
818         10              1
819         11              1
820         11              1
821         12              1
822         13              1
823         14              1
824         15              1
825         15              1
826         16              1
827         16              1
828         17              1
829         17              1
830         18              1
831         19              1
832         20              1
833         20              1
834         21              1
835         21              1
836         22              1
837         23              1
838         24              1
839         24              1
840         25              1
841         26              1
842         27              1
843         28              1
844         29              1
845         30              1
846         31              1
847         31              1
848         32              1
849         33              1
850         35              1
851          3              1
852          3              1
853          4              1
854          4              1
855          4              1
856          4              1
857          5              1
858          6              1
859          7              0
860          8              1
861          9              1
862          9              1
863         10              1
864         11              1
865         11              1
866         12              1
867         13              1
868         14              1
869         15              1
870         15              1
871         16              1
872         16              1
873         17              1
874         17              1
875         18              1
876         19              1
877         20              1
878         20              1
879         21              1
880         22              1
881         23              1
882         24              1
883         25              1
884         26              1
885         27              1
886         28              1
887         29              1
888         30              1
889         31              1
890         31              1
891         32              1
892         33              1
893         35              1
894          3              1
895          5              0
896          6              1
897          7              1
898          9              0
899         10              0
900          3              1
901          4              0
902          4              1
903          5              1
904          7              1
905          7              1
906          7              1
907          8              1
908          9              1
909          9              0
910          9              1
911         10              1
912         11              0
913         13              0
914          3              1
915          4              1
916          5              1
917          5              0
918          6              1
919          7              1
920          7              1
921          8              0
922          8              0
923          8              0
924          9              0
925          9              0
926         10              0
927          3              1
928          3              0
929          3              1
930          4              1
931          4              1
932          4              1
933          4              1
934          4              1
935          5              1
936          5              1
937          5              1
938          5              1
939          6              1
940          6              1
941          7              1
942          7              1
943          8              1
944          9              1
945          9              1
946         10              1
947         11              1
948         11              1
949         11              1
950         11              1
951         12              1
952         12              1
953         13              1
954         13              0
955         13              1
956         14              1
957         14              1
958         15              1
959         15              1
960         16              1
961         16              1
962         17              1
963         17              1
964         18              1
965         18              1
966         19              1
967         20              1
968         21              1
969         22              1
970         23              1
971         24              1
972         24              0
973         24              0
974          3              1
975          4              1
976          4              1
977          5              1
978          5              1
979          5              1
980          6              1
981          6              1
982          6              1
983          7              1
984          7              1
985          8              1
986          8              1
987          9              1
988          9              1
989          9              1
990         10              1
991         10              1
992         11              1
993         11              1
994         12              1
995         13              1
996         13              1
997         14              1
998         14              1
999         14              1
1000        15              0
1001        15              0
1002         3              1
1003         4              1
1004         5              0
1005         6              1
1006         7              1
1007         9              1
1008        13              1
1009        13              1
1010        16              1
1011        17              1
1012        18              0
1013        18              1
1014        19              0
1015        20              1
1016        20              1
1017        20              0
1018        21              1
1019        22              1
1020        22              1
1021        23              1
1022        24              1
1023        24              1
1024        25              1
1025        26              1
1026        27              1
1027        29              1
1028        31              1
1029        32              0
1030        33              1
1031        35              1
1032         3              1
1033         4              0
1034         5              1
1035         5              1
1036         5              0
1037         6              1
1038         7              1
1039         8              0
1040         9              0
1041        10              0
1042        11              0
1043        11              0
1044         3              1
1045         4              1
1046         5              1
1047         7              1
1048         9              1
1049        11              1
1050        11              1
1051        12              1
1052        12              1
1053        13              1
1054        14              1
1055        14              1
1056        14              1
1057        15              1
1058        16              1
1059        17              1
1060        18              1
1061        19              1
1062        20              1
1063        20              1
1064        21              1
1065        21              1
1066        22              1
1067        24              1
1068        25              1
1069        26              1
1070        28              0
1071        28              0
1072        29              0
1073        30              0
1074         3              1
1075         7              0
1076         3              1
1077         6              1
1078        14              0
1079        27              0
1080         3              1
1081        11              1
1082        18              1
1083        21              1
1084        24              1
1085        28              1
1086        31              1
1087        35              1
1088         3              1
1089         4              1
1090         5              1
1091         5              1
1092         5              1
1093         6              1
1094         6              1
1095         7              1
1096         7              1
1097         8              0
1098         8              1
1099         8              1
1100         9              1
1101         9              1
1102        10              1
1103        11              1
1104        12              0
1105        12              0
1106        13              0
1107        13              0
1108         3              1
1109         4              0
1110         3              1
1111         3              1
1112         4              1
1113         4              1
1114         5              1
1115         5              0
1116         7              0
1117         7              0
1118         7              0
1119         3              1
1120        11              1
1121        19              1
1122        19              0
1123        26              1
1124         3              1
1125         4              1
1126         4              1
1127         5              1
1128         6              1
1129         6              1
1130         7              1
1131         7              1
1132         8              1
1133         8              1
1134         9              1
1135        10              1
1136        11              1
1137        12              1
1138        13              1
1139        14              1
1140        15              1
1141        16              1
1142        18              1
1143        19              1
1144        20              1
1145        21              0
1146        22              0
1147        22              0
1148        25              0
1149         3              1
1150         3              0
1151         4              0
1152         4              0
1153         5              1
1154         5              1
1155         6              0
1156         7              1
1157         7              1
1158         8              1
1159         8              1
1160         9              0
1161        10              1
1162        12              1
1163        12              1
1164        12              1
1165        13              1
1166        13              1
1167        14              1
1168        14              1
1169        16              1
1170        17              1
1171        17              1
1172        18              1
1173        19              1
1174        19              1
1175        20              1
1176        21              1
1177        21              0
1178        22              1
1179        23              1
1180        24              1
1181        25              1
1182        26              0
1183        27              0
1184        28              0
1185        28              0
1186        29              0
1187         3              1
1188         4              0
1189        10              1
1190        10              1
1191        10              1
1192        11              1
1193        13              1
1194        17              1
1195        20              1
1196        21              1
1197        22              1
1198        24              1
1199        25              1
1200        26              1
1201        27              1
1202        27              1
1203        29              1
1204        31              0
1205        32              0
1206        33              0
1207        34              0
1208        34              0
1209        35              0
1210         3              1
1211         3              1
1212         4              1
1213         4              1
1214         5              1
1215         6              0
1216         7              1
1217         8              1
1218         9              1
1219         9              1
1220        10              1
1221        10              1
1222        11              1
1223        11              1
1224        12              1
1225        12              1
1226        14              1
1227        15              1
1228        15              1
1229        16              1
1230        16              1
1231        17              1
1232        18              1
1233        19              1
1234        20              1
1235        20              1
1236        21              1
1237        21              1
1238        21              1
1239        22              0
1240        23              1
1241        23              1
1242        24              1
1243        24              1
1244        25              1
1245        26              1
1246        27              1
1247        27              1
1248        27              1
1249        28              1
1250        29              1
1251        29              1
1252        29              1
1253        30              1
1254        30              1
1255        31              1
1256        32              1
1257        32              1
1258        33              1
1259        34              1
1260        34              1
1261        34              1
1262        34              1
1263        35              1
1264        35              1
1265         3              1
1266         3              1
1267         4              0
1268         5              0
1269         5              0
1270         6              0
1271         7              0
1272         3              1
1273         4              1
1274         4              1
1275         5              1
1276         5              1
1277         6              1
1278         8              0
1279         9              1
1280        10              1
1281        11              1
1282        11              1
1283        12              0
1284        12              1
1285        12              1
1286        13              1
1287        15              0
1288        15              1
1289        16              1
1290        18              1
1291        19              0
1292        20              1
1293        22              0
1294        22              1
1295        23              1
1296        24              1
1297        24              1
1298        25              0
1299        26              1
1300        27              1
1301        27              1
1302        28              1
1303        30              1
1304        30              1
1305        31              1
1306        33              1
1307        33              1
1308        34              1
1309        34              1
1310        35              0
1311        35              1
1312        35              1
1313         3              1
1314         4              1
1315         5              1
1316         6              1
1317         7              1
1318         8              1
1319         8              1
1320         9              1
1321         9              1
1322        10              1
1323        10              1
1324        11              1
1325        12              1
1326        13              1
1327        14              1
1328        15              1
1329        15              1
1330        16              1
1331        16              1
1332        17              1
1333        19              1
1334        19              0
1335        20              1
1336        21              1
1337        22              1
1338        22              1
1339        22              1
1340        23              1
1341        23              1
1342        23              0
1343        24              1
1344        24              1
1345        25              1
1346        26              1
1347        27              1
1348        27              1
1349        27              1
1350        28              1
1351        28              1
1352        29              1
1353        29              1
1354        29              1
1355        30              1
1356        30              1
1357        31              1
1358        32              1
1359        32              1
1360        32              1
1361        32              0
1362        33              1
1363        33              1
1364        33              1
1365        34              1
1366        34              1
1367        34              1
1368        35              1
1369         3              1
1370         3              1
1371         4              1
1372         4              0
1373         4              1
1374         4              1
1375         5              0
1376         6              0
1377         8              0
1378        11              0
1379         3              1
1380         5              1
1381         6              1
1382         8              1
1383        13              1
1384        14              1
1385        14              1
1386        15              1
1387        19              1
1388        22              1
1389        24              1
1390        26              1
1391        29              1
1392        31              1
1393        32              1
1394         3              1
1395         4              1
1396         4              1
1397         5              1
1398         8              1
1399         9              1
1400        11              1
1401        12              1
1402        13              1
1403        14              1
1404        15              1
1405        16              1
1406        17              1
1407        18              0
1408        19              1
1409        20              1
1410        21              1
1411        22              0
1412        23              1
1413        24              1
1414        25              1
1415        25              1
1416        28              1
1417        29              1
1418        30              1
1419        31              1
1420        32              1
1421        33              1
1422        33              1
1423        34              1
1424        34              1
1425        35              1
1426         3              1
1427         3              1
1428         4              1
1429         4              1
1430         6              1
1431         6              1
1432         8              1
1433         9              1
1434        11              1
1435        11              1
1436        11              0
1437        12              1
1438        13              1
1439        13              1
1440        15              1
1441        16              1
1442        17              1
1443        18              1
1444        19              1
1445        20              1
1446        21              0
1447        22              1
1448        23              1
1449        24              1
1450        25              1
1451        25              1
1452        26              1
1453        26              1
1454        27              1
1455        27              1
1456        28              1
1457        29              1
1458        29              1
1459        30              1
1460        31              1
1461        31              1
1462        32              1
1463        33              1
1464        33              1
1465        34              1
1466        34              1
1467        35              1
1468         3              1
1469         4              1
1470         6              1
1471         6              1
1472         7              1
1473         8              1
1474         9              1
1475        10              0
1476        11              1
1477        11              1
1478        12              1
1479        13              1
1480        13              1
1481        14              1
1482        16              1
1483        17              0
1484        18              1
1485        20              1
1486        21              1
1487        22              1
1488        25              0
1489        25              0
1490        27              0
1491         3              1
1492         4              0
1493         4              0
1494         4              1
1495         6              1
1496         6              1
1497         8              1
1498         9              1
1499        10              0
1500        11              1
1501        11              1
1502        12              1
1503        13              1
1504        13              1
1505        13              1
1506        14              1
1507        15              1
1508        16              1
1509        17              1
1510        18              1
1511        19              1
1512        19              1
1513        20              0
1514        21              0
1515        22              0
1516        22              0
1517        24              0
1518         3              1
1519         3              1
1520         4              1
1521         4              0
1522         5              1
1523         5              1
1524         5              0
1525         6              1
1526         6              0
1527         7              1
1528         8              1
1529         9              1
1530        10              1
1531        11              1
1532        12              1
1533        13              1
1534        13              1
1535        15              1
1536        15              1
1537        17              1
1538        17              1
1539        19              1
1540        19              1
1541        20              1
1542        22              1
1543        22              1
1544        24              1
1545        24              0
1546        25              0
1547        25              1
1548        26              0
1549        27              1
1550         3              1
1551         3              0
1552         4              1
1553         5              1
1554         6              0
1555         7              0
1556         7              0
1557        10              0
1558         3              1
1559         4              1
1560         5              0
1561         6              0
1562         6              0
1563         8              0
1564         9              0
1565         9              0
1566        11              0
1567         3              1
1568         7              1
1569         9              0
1570         3              1
1571         3              1
1572         4              1
1573         4              1
1574         5              1
1575         6              0
1576         7              0
1577         8              0
1578         3              1
1579         4              1
1580         5              0
1581         8              1
1582        10              1
1583        11              0
1584        18              0
1585        20              0
1586        21              0
1587         3              1
1588         4              1
1589         5              1
1590         5              1
1591         6              1
1592         7              1
1593         7              1
1594         7              1
1595         8              1
1596         8              1
1597         9              1
1598         9              1
1599        10              1
1600        11              1
1601        12              1
1602        13              1
1603        14              1
1604        15              1
1605        16              1
1606        17              1
1607        18              1
1608        19              0
1609        20              1
1610        21              1
1611        22              1
1612        22              0
1613        23              1
1614        26              0
1615        28              0
1616         3              1
1617         5              1
1618         6              1
1619         7              0
1620         8              0
1621         8              0
1622         9              0
1623        12              0
1624         3              1
1625         7              1
1626         7              0
1627         8              0
1628         9              1
1629        11              1
1630        12              1
1631        13              1
1632        14              1
1633        15              1
1634        16              1
1635        16              1
1636        18              1
1637        19              1
1638        20              1
1639        21              1
1640        21              1
1641        22              1
1642        23              1
1643        23              1
1644        23              0
1645        24              1
1646        24              0
1647        25              0
1648        26              1
1649        27              1
1650        28              1
1651        28              1
1652        29              1
1653        29              1
1654        30              1
1655        31              1
1656        32              1
1657        33              1
1658        34              1
1659        35              1
1660        35              1
1661         3              1
1662        11              1
1663        14              0
1664        15              0
1665        15              0
1666        15              0
1667        16              0
1668        18              0
1669         3              1
1670         3              0
1671         4              1
1672         4              1
1673         4              1
1674         5              1
1675         5              1
1676         5              1
1677         6              1
1678         6              1
1679         6              1
1680         6              1
1681         7              1
1682         7              1
1683         8              1
1684         8              1
1685         8              1
1686         9              1
1687         9              1
1688        10              1
1689        10              1
1690        11              1
1691        12              1
1692        12              1
1693        13              1
1694        13              1
1695        13              1
1696        14              1
1697        14              1
1698        15              1
1699        15              1
1700        15              1
1701        15              1
1702        16              1
1703        16              1
1704        17              1
1705        18              1
1706        18              1
1707        19              1
1708        19              1
1709        19              1
1710        20              1
1711        21              1
1712        21              0
1713        21              1
1714        22              1
1715        22              1
1716        23              1
1717        23              1
1718        24              1
1719        25              1
1720        26              1
1721        27              1
1722        28              1
1723        28              1
1724        29              1
1725        30              1
1726        31              1
1727        32              1
1728        32              1
1729        33              1
1730        34              1
1731        35              1
1732        35              1
1733         3              1
1734         5              1
1735         6              1
1736         7              1
1737         8              1
1738        10              1
1739        16              1
1740        17              1
1741        17              1
1742        19              1
1743        21              1
1744        22              1
1745        22              1
1746        22              0
1747        23              0
1748        24              1
1749        24              1
1750        26              1
1751        27              1
1752        28              1
1753        29              1
1754        30              1
1755        31              1
1756        31              1
1757        32              1
1758        32              1
1759        33              1
1760        33              1
1761        34              1
1762        35              1
1763         3              1
1764         4              1
1765         7              0
1766         3              1
1767        18              0
1768         3              1
1769         9              0
1770         3              1
1771         4              0
1772         6              1
1773         8              1
1774        11              0
1775        12              0
1776        13              0
1777        15              0
1778         3              1
1779         4              0
1780         4              0
1781         5              0
1782         5              0
1783         3              1
1784         6              1
1785         7              1
1786         9              1
1787        11              1
1788        12              1
1789        13              1
1790        16              1
1791        22              0
1792        23              1
1793        26              1
1794        26              0
1795        27              1
1796        28              1
1797        29              1
1798        30              1
1799        30              1
1800        30              0
1801        32              1
1802        33              1
1803        35              1
1804         3              1
1805         5              1
1806         6              1
1807         7              1
1808         9              1
1809        10              1
1810        11              1
1811        14              1
1812        15              1
1813        16              1
1814        18              1
1815        20              1
1816        21              1
1817        23              1
1818        24              1
1819        27              1
1820        27              0
1821        28              1
1822        29              1
1823        30              1
1824        32              1
1825        33              1
1826        34              1
1827         3              1
1828        10              1
1829        12              0
1830        13              1
1831        16              1
1832        17              1
1833        19              1
1834        24              1
1835        25              1
1836        29              1
1837        31              1
1838        31              0
1839        32              1
1840        34              1
1841         3              1
1842         4              0
1843         5              1
1844         7              0
1845        13              0
1846         3              1
1847         5              1
1848         5              0
1849         6              0
1850         6              0
1851        15              0
1852         3              1
1853         3              0
1854         4              1
1855         5              1
1856         6              1
1857         6              1
1858         7              1
1859         7              1
1860         8              1
1861         9              1
1862        11              1
1863        13              1
1864        14              1
1865        16              1
1866        17              1
1867        17              1
1868        19              0
1869        21              0
1870        22              0
1871        26              0
1872         3              1
1873         3              1
1874         4              1
1875         5              1
1876         6              1
1877         8              1
1878         8              1
1879        13              0
1880        17              0
1881         3              1
1882         4              1
1883         5              1
1884         6              1
1885         8              1
1886         9              1
1887        10              1
1888        11              1
1889        12              1
1890        12              0
1891        13              1
1892        14              1
1893        15              1
1894        15              1
1895        20              0
1896        20              1
1897        22              1
1898        23              1
1899        24              1
1900        25              1
1901        27              1
1902        29              1
1903        30              1
1904        34              1
1905         3              1
1906         4              1
1907         6              1
1908         7              1
1909         8              1
1910         8              1
1911        10              1
1912        11              1
1913        12              1
1914        13              0
1915        14              0
1916        16              0
1917        17              0
1918        21              0
1919         3              1
1920         4              1
1921         6              1
1922         7              0
1923         8              1
1924         9              1
1925        11              1
1926        12              1
1927        14              0
1928        14              1
1929        16              1
1930        17              1
1931        19              1
1932        22              1
1933        23              1
1934        28              1
1935        34              1
1936        35              1
1937         3              1
1938         4              1
1939         4              1
1940         5              0
1941         7              1
1942         7              1
1943         8              1
1944         9              1
1945        10              1
1946        11              0
1947        11              1
1948        12              1
1949        13              1
1950        13              1
1951        15              1
1952        15              0
1953        16              1
1954        18              1
1955        19              1
1956        20              1
1957        21              1
1958        23              1
1959        25              1
1960        26              1
1961        27              1
1962        29              1
1963        29              1
1964        30              1
1965        32              0
1966        33              1
1967        34              1
1968        35              1
1969         3              1
1970         4              1
1971         6              1
1972         8              1
1973         9              1
1974        10              1
1975        12              1
1976        13              1
1977        14              1
1978        17              1
1979        20              1
1980        21              1
1981        23              1
1982        25              1
1983        27              1
1984        28              1
1985        31              1
1986        33              1
1987        34              1
1988         3              1
1989         3              0
1990         4              1
1991         4              0
1992         6              1
1993         6              1
1994         8              0
1995        10              0
1996        11              0
1997        13              0
1998         3              1
1999         4              1
2000         4              1
2001         5              1
2002         7              1
2003         7              1
2004         8              1
2005         8              1
2006         9              1
2007        10              1
2008        12              1
2009        12              1
2010        13              1
2011        14              1
2012        14              1
2013        15              1
2014        16              1
2015        17              1
2016        17              1
2017        18              1
2018        19              0
2019        20              1
2020        21              1
2021        22              1
2022        24              1
2023        25              1
2024        25              1
2025        29              1
2026        30              1
2027        31              1
2028        32              1
2029        34              1
2030        34              1
2031        35              1
2032         3              1
2033         4              1
2034         7              1
2035        10              1
2036        12              0
2037        13              0
2038        15              0
2039        16              0
2040         3              1
2041         5              1
2042         7              1
2043         8              1
2044         8              1
2045        11              1
2046        12              1
2047        13              0
2048        14              1
2049        15              0
2050        18              1
2051        19              1
2052        21              1
2053        23              1
2054        23              1
2055        25              1
2056        27              1
2057        28              1
2058        29              1
2059        30              1
2060        30              1
2061        31              1
2062        33              1
2063        34              1
2064        35              1
2065        35              1
2066         3              1
2067         4              1
2068         6              1
2069         6              1
2070         7              0
2071         8              0
2072         9              0
2073        10              0
2074        11              0
2075         3              1
2076         3              1
2077         4              0
2078         6              1
2079         8              1
2080         9              1
2081        13              1
2082        15              1
2083        17              1
2084        20              1
2085        20              1
2086        24              0
2087        27              0
2088        29              0
2089         3              1
2090         4              1
2091         4              1
2092         5              1
2093         5              1
2094         5              1
2095         6              1
2096         6              1
2097         7              1
2098         8              1
2099         9              1
2100        10              1
2101        11              1
2102        11              1
2103        11              1
2104        12              1
2105        12              1
2106        14              1
2107        15              1
2108        17              1
2109        18              1
2110        19              1
2111        19              1
2112        20              1
2113        21              1
2114        22              1
2115        22              1
2116        23              1
2117        24              1
2118        24              1
2119        25              1
2120        25              1
2121        26              1
2122        27              1
2123        27              0
2124        28              1
2125        29              1
2126        30              1
2127        31              1
2128        31              1
2129        32              1
2130        32              1
2131        33              1
2132         3              1
2133         3              0
2134         3              0
2135         4              1
2136         4              1
2137         5              1
2138         6              0
2139         7              0
2140         8              0
2141         9              0
2142         9              0
2143         9              0
2144        10              0
2145        15              0
2146        16              0
2147         3              1
2148         5              1
2149         6              1
2150         7              1
2151         8              1
2152        10              1
2153        11              1
2154        12              1
2155        13              1
2156        14              1
2157        16              1
2158        21              1
2159        24              1
2160        25              1
2161        26              1
2162        26              1
2163        27              1
2164        28              1
2165        28              1
2166        29              1
2167        30              1
2168        31              1
2169        32              1
2170        33              1
2171        34              1
2172        35              1
2173         3              1
2174         4              1
2175         6              0
2176         8              1
2177        11              1
2178        13              1
2179        14              1
2180        17              1
2181        19              1
2182        21              1
2183        23              1
2184        25              1
2185        27              1
2186        30              1
2187        33              1
2188        34              1
2189         3              1
2190         4              1
2191         4              1
2192         5              1
2193         6              1
2194         7              1
2195         7              1
2196         8              1
2197         9              1
2198        10              0
2199        12              1
2200        12              1
2201        18              1
2202        21              1
2203        21              1
2204        23              1
2205        26              1
2206        28              1
2207        30              1
2208        31              1
2209        32              1
2210        34              1
2211         3              1
2212         6              1
2213         9              1
2214        10              1
2215        11              1
2216        12              1
2217        14              1
2218        15              1
2219        15              1
2220        16              1
2221        17              1
2222        17              1
2223        18              1
2224        20              1
2225        21              1
2226        23              1
2227        24              1
2228        25              1
2229        29              1
2230        31              1
2231        33              1
2232        35              1
2233         3              1
2234         5              1
2235         7              1
2236         8              1
2237        10              0
2238        12              0
2239        16              1
2240        19              1
2241        23              1
2242        24              1
2243        26              1
2244        27              0
2245        28              1
2246        29              1
2247        31              1
2248        33              1
2249        34              1
2250        35              1
2251         3              1
2252         6              1
2253         9              1
2254         9              1
2255        18              1
2256        22              1
2257        29              0
2258        31              0
2259        35              0
2260         3              1
2261        15              1
2262        24              1
2263        31              1
2264         3              1
2265         7              1
2266         8              1
2267        10              0
2268        11              0
2269        12              1
2270        16              0
2271        20              1
2272        24              1
2273        30              0
2274        31              0
2275        35              0
2276         3              1
2277         4              1
2278         5              1
2279         5              1
2280         6              1
2281         7              1
2282         9              1
2283        10              1
2284        11              1
2285        12              1
2286        13              1
2287        16              1
2288        19              1
2289        20              1
2290        23              1
2291        25              1
2292        27              1
2293        28              1
2294        28              1
2295        29              1
2296        30              1
2297        32              1
2298        33              1
2299        35              1
2300         3              1
2301         4              0
2302         6              0
2303         3              1
2304         4              1
2305         4              1
2306         6              1
2307         7              1
2308         7              1
2309         9              1
2310        15              1
2311        16              0
2312        16              0
2313         3              1
2314         4              1
2315         4              1
2316         4              1
2317         5              1
2318         6              1
2319         7              1
2320         9              0
2321        12              0
2322         3              1
2323         4              0
2324         8              0
2325         8              0
2326         9              0
2327        10              0
2328         3              1
2329         4              1
2330         6              1
2331         7              1
2332        10              1
2333        13              0
2334        16              0
2335         3              1
2336         3              1
2337         7              1
2338         8              0
2339        10              1
2340        11              0
2341        14              0
2342         3              1
2343         4              0
2344         6              0
2345         7              0
2346         3              1
2347         3              1
2348         3              1
2349         4              0
2350         3              1
2351         3              0
2352         4              1
2353         4              1
2354         5              1
2355         5              1
2356         6              1
2357         7              1
2358         7              0
2359         7              1
2360         7              1
2361         8              0
2362         3              1
2363         4              1
2364         4              1
2365         4              0
2366         4              1
2367         5              1
2368         5              1
2369         6              1
2370         6              1
2371         6              0
2372         6              1
2373         7              1
2374         7              1
2375         8              0
2376         9              0
2377         9              0
2378        10              0
2379         3              1
2380         3              1
2381         4              1
2382         5              1
2383         5              1
2384         7              1
2385         7              1
2386        10              1
2387        11              1
2388        11              1
2389        13              0
2390        15              0
2391         3              1
2392         3              1
2393         4              1
2394         4              0
2395         5              1
2396         6              1
2397         7              0
2398         9              0
2399         3              1
2400         3              1
2401         4              1
2402         5              1
2403         7              1
2404         8              0
2405         8              0
2406         3              1
2407         3              1
2408         4              1
2409         4              1
2410         5              1
2411         6              1
2412         7              0
2413         8              0
2414         8              0
2415         3              1
2416         4              1
2417         4              1
2418         6              1
2419         7              1
2420         7              1
2421         9              1
2422        10              1
2423        11              0
2424        13              0
2425         3              1
2426         5              0
2427         6              1
2428        10              1
2429        12              0
2430        14              1
2431        20              0
2432         3              1
2433         4              1
2434         5              1
2435         5              1
2436         6              1
2437         7              1
2438         7              1
2439         8              1
2440         8              0
2441         9              0
2442         9              0
2443         3              1
2444         3              1
2445         4              1
2446         4              0
2447         4              1
2448         6              1
2449         6              1
2450         6              1
2451         7              1
2452         7              1
2453         7              1
2454         8              1
2455         8              1
2456         9              1
2457         9              1
2458        10              1
2459        11              1
2460        12              1
2461        12              1
2462        13              1
2463        14              1
2464        15              0
2465         3              1
2466         4              1
2467         4              1
2468         4              0
2469         5              1
2470         5              1
2471         6              1
2472         7              1
2473         8              1
2474        10              1
2475        11              1
2476        12              1
2477        14              1
2478        15              0
2479         3              1
2480         4              0
2481         4              1
2482         5              1
2483         6              1
2484         7              0
2485         9              0
2486        11              0
2487         3              1
2488         5              1
2489         5              1
2490         7              1
2491         8              1
2492        11              1
2493        12              0
2494        13              1
2495        15              1
2496        17              0
2497        18              0
2498        20              0
2499        22              0
2500         3              1
2501         6              0
2502        13              0
2503        17              0
2504         3              1
2505         5              1
2506         6              1
2507         6              1
2508         7              1
2509         9              1
2510        12              1
2511        12              0
2512        14              1
2513        16              1
2514        17              1
2515        19              1
2516        22              0
2517        23              0
2518         3              1
2519         4              0
2520         4              1
2521         4              1
2522         6              1
2523         9              1
2524        10              1
2525        11              1
2526        12              1
2527        13              1
2528        14              1
2529        16              1
2530        17              0
2531        24              0
2532         3              1
2533         4              1
2534         4              0
2535         5              1
2536         5              1
2537         6              1
2538         7              0
2539         8              1
2540        10              1
2541        11              1
2542        12              1
2543        14              1
2544        15              0
2545        16              1
2546        18              0
2547        19              0
2548        20              0
2549        21              0
2550        24              0
2551         3              1
2552         5              0
2553         7              0
2554        11              0
2555         3              1
2556         4              1
2557        15              0
2558        17              0
2559        22              0
2560        24              1
2561        32              1
2562        33              1
2563         3              1
2564         4              1
2565         5              1
2566         7              1
2567        11              1
2568        14              1
2569        17              1
2570        18              0
2571        20              0
2572        22              0
2573        26              0
2574        34              1
2575         3              1
2576         4              1
2577         9              1
2578        12              1
2579        15              1
2580        19              1
2581        26              0
2582        28              0
2583        29              0
2584         3              1
2585         3              1
2586         4              1
2587         4              1
2588         4              1
2589         5              1
2590         6              1
2591         8              1
2592        11              1
2593        11              1
2594        12              1
2595        12              1
2596        16              1
2597        18              0
2598        19              0
2599         3              1
2600         4              1
2601         8              1
2602        10              1
2603        14              1
2604        23              1
2605        23              1
2606        25              1
2607        26              1
2608        27              1
2609        27              1
2610        30              1
2611        30              1
2612        34              1
2613        35              1
2614         3              1
2615         3              1
2616         4              1
2617         4              1
2618         6              1
2619         8              1
2620        10              1
2621        11              1
2622        16              0
2623        17              0
2624        18              0
2625         3              1
2626         5              1
2627         6              1
2628         7              1
2629         7              1
2630         9              0
2631        13              0
2632        20              0
2633         3              1
2634         4              1
2635         5              0
2636         9              0
2637         9              0
2638        10              0
2639        11              0
2640         3              1
2641         4              1
2642        10              0
2643        11              0
2644         3              1
2645         3              1
2646         4              0
2647         4              1
2648         5              0
2649         5              1
2650         6              1
2651         7              1
2652         9              1
2653         9              1
2654        10              1
2655        10              1
2656        11              1
2657        13              1
2658        13              1
2659        16              1
2660        17              0
2661        18              1
2662         3              1
2663         4              1
2664         4              0
2665         6              1
2666         7              1
2667        10              1
2668        13              1
2669        13              1
2670        16              1
2671        17              1
2672        19              1
2673        23              1
2674        26              0
2675        27              0
2676        28              0
2677         3              1
2678         6              1
2679        11              0
2680         3              1
2681         5              1
2682        15              1
2683        24              0
2684        28              0
2685         3              1
2686         3              1
2687         3              0
2688         6              0
2689         3              1
2690         4              1
2691         5              1
2692         7              1
2693         7              1
2694         7              1
2695         8              1
2696         9              1
2697        12              1
2698        15              1
2699        17              1
2700        17              1
2701        20              1
2702        20              1
2703        23              1
2704        23              1
2705        24              1
2706        26              1
2707        27              1
2708        29              1
2709        31              1
2710        33              1
2711         3              1
2712         3              1
2713         6              0
2714         7              1
2715         7              1
2716         8              1
2717         8              1
2718        11              1
2719        14              1
2720        15              1
2721        16              1
2722        21              0
2723        23              1
2724        24              1
2725        26              1
2726        27              0
2727        28              0
2728        30              0
2729         3              1
2730         3              0
2731         4              1
2732         5              1
2733         6              1
2734         8              1
2735        10              1
2736        10              1
2737        10              0
2738        11              0
2739        11              1
2740        13              1
2741        14              1
2742        15              0
2743        15              1
2744        16              1
2745        17              1
2746        18              1
2747        20              1
2748        21              0
2749        22              1
2750        24              1
2751        25              1
2752        26              1
2753        27              1
2754        27              1
2755        28              1
2756        30              1
2757        31              1
2758        34              1
2759        34              1
2760         3              1
2761         4              1
2762         7              1
2763         9              1
2764         9              1
2765        10              1
2766        12              0
2767        15              0
2768        16              0
2769        17              0
2770        19              0
2771         3              1
2772         6              0
2773         7              1
2774        11              0
2775        12              1
2776        13              0
2777        13              1
2778        13              1
2779        17              1
2780        20              1
2781        22              1
2782        24              1
2783        27              1
2784        27              1
2785        29              1
2786        30              1
2787        30              1
2788        32              1
2789         3              1
2790         5              1
2791         7              1
2792        13              0
2793        18              1
2794        19              1
2795        23              1
2796        26              1
2797        29              1
2798        30              1
2799        33              1
2800        33              1
2801        35              0
2802         3              1
2803         5              1
2804         5              1
2805         8              0
2806         9              0
2807         3              1
2808         4              0
2809         6              0
2810         3              1
2811         8              1
2812        12              1
2813        17              1
2814        22              1
2815        26              1
2816        29              1
2817        35              1
2818         3              1
2819         4              1
2820         5              1
2821         8              0
2822        10              1
2823        10              1
2824        14              1
2825        19              1
2826        25              1
2827        25              1
2828        27              1
2829        34              1
2830         3              1
2831         5              1
2832         6              1
2833         6              1
2834         7              1
2835        10              1
2836        12              1
2837        14              1
2838        16              1
2839        20              1
2840        21              1
2841        24              1
2842        25              1
2843        28              1
2844        31              1
2845        32              1
2846        35              1
2847         3              1
2848         4              1
2849         4              1
2850         5              1
2851         7              1
2852        10              1
2853        13              1
2854        14              1
2855        17              1
2856        21              1
2857        25              1
2858        28              1
2859        31              0
2860        31              0
2861        32              0
2862         3              1
2863         4              1
2864         4              1
2865         4              1
2866         4              0
2867         5              1
2868         6              0
2869         7              0
2870         8              0
2871         9              1
2872         3              1
2873         4              1
2874         4              1
2875         5              1
2876         7              1
2877         8              1
2878        10              1
2879        12              1
2880        14              1
2881        15              1
2882        17              1
2883        21              1
2884        23              1
2885        24              1
2886        27              1
2887        29              1
2888        30              1
2889        31              1
2890        32              1
2891        35              1
2892         3              1
2893         4              1
2894         6              0
2895         6              1
2896         9              1
2897        10              1
2898        10              1
2899        11              1
2900        13              1
2901        14              1
2902        14              1
2903        16              1
2904        16              1
2905        17              1
2906        18              1
2907        19              1
2908        20              1
2909        22              1
2910        22              1
2911        25              1
2912        26              1
2913        28              1
2914        30              1
2915        32              1
2916        32              1
2917        33              1
2918        35              1
2919         3              1
2920         9              0
2921         3              1
2922         3              1
2923         6              1
2924         7              1
2925        12              1
2926        14              1
2927        17              0
2928        18              0
2929         3              1
2930         4              1
2931         9              1
2932        10              0
2933        13              1
2934        14              0
2935        16              0
2936         3              1
2937         3              1
2938         4              1
2939         4              1
2940         5              1
2941         6              1
2942         9              1
2943        10              1
2944        12              1
2945        14              1
2946        16              1
2947        17              1
2948        19              1
2949        23              1
2950        25              1
2951        26              1
2952        29              1
2953        31              1
2954        32              1
2955        33              1
2956        34              1
2957        34              1
2958         3              1
2959         4              1
2960        10              0
2961         3              1
2962         4              1
2963         5              1
2964         7              1
2965         7              1
2966         9              1
2967         9              1
2968        10              1
2969        11              0
2970        12              0
2971        14              0
2972        16              0
2973        17              0
2974         1              1
2975         2              1
2976         3              1
2977         4              1
2978         5              1
2979         6              1
2980         7              1
2981         8              1
2982         9              1
2983        10              1
2984        11              1
2985        12              1
2986        13              1
2987        14              1
2988        15              1
2989        16              1
2990        17              1
2991        18              1
2992        19              1
2993        20              1
2994        21              1
2995        22              1
2996        23              1
2997        24              1
2998        25              1
2999        26              1
3000        27              1
3001        28              1
3002        29              1
3003        30              1
3004        31              1
3005        32              1
3006        33              1
3007        34              1
3008        35              1library(tidyselect)
MP_chick_data_clean_wide <- 
  MP_chick_data_clean_ %>%
  mutate(offspring_seen = as.character(offspring_seen)) %>% 
  pivot_wider(
    id_cols = c(nest_ID, management_level_max, management_status_max, season, region, hatch_date),
    names_from = brood_age,
    values_from = offspring_seen,
    values_fn = list(offspring_seen = max), # in case of duplicates
    values_fill = ".",                      # fill missing with "." (no survey effort)
    names_prefix = "age_"
  )
# Get the age columns in numeric order
age_cols <- names(MP_chick_data_clean_wide)[-c(1:6)] %>%           # drop nest_ID
  sub("age_", "", .) %>%                     # remove prefix
  as.numeric() %>%                            # convert to numeric
  sort() %>%                                  # sort numerically
  paste0("age_", .)                           # add prefix back
# Reorder the dataframe
MP_chick_data_clean_wide <- MP_chick_data_clean_wide %>%
  select(nest_ID, management_level_max, management_status_max, season, region, hatch_date, all_of(age_cols))
MP_chick_ch <-
  MP_chick_data_clean_wide %>%
  unite(
    col = ch,
    starts_with("age_"),  # all age_ columns
    sep = "",             # no separator, just paste values together
    remove = TRUE        # keep the original columns
  ) %>%
  filter(str_detect(ch, "1")) %>%
  mutate(ch = paste0("1", str_sub(ch, start = 2, end = nchar(ch)))) %>% 
  mutate(hatch_date_j = as.numeric(format(hatch_date + 180, "%j"))) %>% 
  mutate(management_level_max = as.factor(management_level_max)) %>% 
  mutate(region = as.factor(region)) %>% 
  ungroup() %>% 
  rename(mgmt_l = management_level_max,
         mgmt_s = management_status_max,
         date_j = hatch_date_j) %>% 
  filter(nest_ID != "junk") %>% 
  select(-hatch_date, -nest_ID)# Create processed RMARK data format as CJS with "Year" as group
MP_chicks.proc <- process.data(MP_chick_ch, model = "CJS",
                               groups = c("season", "region", 
                                          "mgmt_l", "mgmt_s"))
# Create the design data
MP_chicks.ddl <- make.design.data(MP_chicks.proc)
# create a quadratic time variable
time <- c(0:(MP_chicks.proc$nocc[1]-1))
Quadratic <- time^2
Cubic <- time^3
quad_time <- data.frame(time, Quadratic, Cubic)
MP_chicks.ddl$p <- merge_design.covariates(MP_chicks.ddl$Phi, 
                                              quad_time, bygroup = FALSE, bytime = TRUE)
MP_chicks.ddl$Phi <- merge_design.covariates(MP_chicks.ddl$Phi, 
                                                quad_time, bygroup = FALSE, bytime = TRUE)# First assess the best model structure of encounter probability (p) while
# keeping survival (Phi) constant
MP_chicks_p=function() 
{
  # Constant Phi
  Phi.dot <- 
    list(formula = ~1)
  
  # Constant p
  p.dot <- 
    list(formula = ~1)
  
  # p varies linearly with chick age
  p.age <- 
    list(formula = ~Time)
  
  # p varies quadratically with chick age
  p.quadage <- 
    list(formula = ~Quadratic)
  
  # p varies across year
  p.season <- 
    list(formula = ~season)
  
  # p varies across the hatch date
  p.date <- 
    list(formula = ~date_j)
  
  # interaction between year and age
  p.year.x.age <- 
    list(formula = ~season * Time)
  
  # interaction between year and quadratic age
  p.year.x.quadage <- 
    list(formula = ~season * Quadratic)
  
  # interaction between year and hatch date
  p.year.x.date <- 
    list(formula = ~season * date_j)
  
  # additive effect between year and age
  p.year.age <- 
    list(formula = ~season + Time)
  
  # additive effect between year and quadratic age
  p.year.quadage <- 
    list(formula = ~season + Quadratic)
  
  # additive effect between year and hatch date
  p.year.date <- 
    list(formula = ~season + date_j)
  
  # create model list for all a priori models above that begin with Phi. or p.
  cml <- create.model.list("CJS") 
  
  # runs model list in program MARK
  model.list <- mark.wrapper(model.list = cml, data = MP_chicks.proc, 
                             ddl = MP_chicks.ddl, 
                             threads = 4, brief = TRUE, delete = TRUE)
  
  # store completed model list
  return(model.list) 
}
# Run model selection to determine best structure of p
MP_chicks_p_run <- MP_chicks_p()
 Model: Phi(~1)p(~Time)  npar= 3  lnl =  1582.291 AICc = 1588.3032
 Model: Phi(~1)p(~date_j)  npar= 3  lnl =  1583.0461 AICc = 1589.0583
 Model: Phi(~1)p(~1)  npar= 2  lnl =  1591.0946 AICc = 1595.1006
 Model: Phi(~1)p(~Quadratic)  npar= 3  lnl =  1576.1152 AICc = 1582.1273
 Model: Phi(~1)p(~season)  npar= 13  lnl =  1575.0537 AICc = 1601.23894173028
 Model: Phi(~1)p(~season + Time)  npar= 14  lnl =  1569.5771 AICc = 1597.79094928717
 Model: Phi(~1)p(~season + date_j)  npar= 14  lnl =  1568.2765 AICc = 1596.49034928717
 Model: Phi(~1)p(~season + Quadratic)  npar= 14  lnl =  1563.471 AICc = 1591.68484928717
 Model: Phi(~1)p(~season * Time)  npar= 25  lnl =  1530.2174 AICc = 1580.88304260113
 Model: Phi(~1)p(~season * date_j)  npar= 25  lnl =  1548.0958 AICc = 1598.76144260113
 Model: Phi(~1)p(~season * Quadratic)  npar= 25  lnl =  1527.9514 AICc = 1578.61704260113# inspect p AIC table to find top model
MP_chicks_p_run # best structure: p(~season + Quadratic)                           model npar     AICc DeltaAICc       weight  Deviance
11 Phi(~1)p(~season * Quadratic)   25 1578.617  0.000000 6.621620e-01  688.7392
9       Phi(~1)p(~season * Time)   25 1580.883  2.266000 2.132596e-01  691.0051
4           Phi(~1)p(~Quadratic)    3 1582.127  3.510309 1.144749e-01  736.9029
1                Phi(~1)p(~Time)    3 1588.303  9.686109 5.219782e-03  743.0788
2              Phi(~1)p(~date_j)    3 1589.058 10.441209 3.578364e-03 1583.0461
8  Phi(~1)p(~season + Quadratic)   14 1591.685 13.067807 9.623346e-04  724.2588
3                   Phi(~1)p(~1)    2 1595.101 16.483630 1.744172e-04  751.8823
7     Phi(~1)p(~season + date_j)   14 1596.490 17.873307 8.706128e-05 1568.2765
6       Phi(~1)p(~season + Time)   14 1597.791 19.173907 4.543634e-05  730.3649
10    Phi(~1)p(~season * date_j)   25 1598.761 20.144400 2.796813e-05 1548.0958
5              Phi(~1)p(~season)   13 1601.239 22.621899 8.103661e-06  735.8415saveRDS(MP_chicks_p_run, "output/MP_chicks_p_run.rds")MP_chicks_p_run <- readRDS("output/MP_chicks_p_run.rds")
# Extract estimates of survival from top model
Chick_p_reals <- MP_chicks_p_run[[4]]$results$real
# wrangle dataframe to get annual estimates (grouped by "Year")
Groups <- data.frame(str_split_fixed(rownames(Chick_p_reals), " ", n = 5))
Chick_p_reals <- cbind(Groups, Chick_p_reals)
Chick_p_reals$season <- unlist(substr(Chick_p_reals$X2, 2, 7))
Chick_p_reals$age <- as.numeric(sub("^a", "", Chick_p_reals$X4))
ggplot() +
  geom_line(data = Chick_p_reals, aes(x = age, y = estimate, color = as.numeric(season), group = season)) +
  geom_ribbon(data = Chick_p_reals, aes(x = age, ymin = lcl, ymax = ucl, fill = as.numeric(season), group = season), alpha = 0.2) +
  scale_color_gradient(
    low = "black",
    high = "red",
    name = "season"
  ) +
  scale_fill_gradient(
    low = "black",
    high = "red",
    name = "season"
  ) +
  ylab("daily detection probability of a brood") +
  xlab("brood age (days)")Chick_p_reals <- Chick_p_reals[which(Chick_p_reals$X1 == "p"),]
# clean dataframe
Chick_p_reals <- Chick_p_reals[,-c(1:11)]
Chick_p_reals$Age <- "Chick"
row.names(Chick_p_reals) <- NULL# Find best structure of Phi while using p(~Year * Day_of_Season)
MP_chicks_Phi <- function() 
{
  # Constant Phi
  Phi.dot <- 
    list(formula = ~1)
  
  # Phi varies with chick age
  Phi.age <-
    list(formula = ~Time)
  # Phi varies quadratically with chick age
  Phi.quadage <-
    list(formula = ~Quadratic)
  # Phi varies by year
  Phi.season <-
    list(formula = ~season)
  # Phi varies by hatch date
  Phi.date <-
    list(formula = ~date_j)
  
  # Phi varies by management level
  Phi.mgmt_l <-
    list(formula = ~mgmt_l)
  
  # Phi varies by management status
  Phi.mgmt_s <-
    list(formula = ~mgmt_s)
  # interaction between hatch date and age
  Phi.date.x.age <-
    list(formula = ~date_j * Time)
  # interaction between hatch date and quadratic age
  Phi.date.x.quadage <-
    list(formula = ~date_j * Quadratic)
  # interaction between year and hatch date
  Phi.season.x.date <-
    list(formula = ~season * date_j)
  
  # interaction between hatch date and age and management level
  Phi.date.x.mgmt_l <-
    list(formula = ~date_j * mgmt_l)
  # interaction between hatch date and quadratic age and management level
  Phi.age.x.mgmt_l <-
    list(formula = ~Time * mgmt_l)
  # interaction between year and hatch date and management level
  Phi.quadage.x.mgmt_l <-
    list(formula = ~Quadratic * mgmt_l)
  
  # interaction between hatch date and age and management level
  Phi.date.mgmt_l <-
    list(formula = ~date_j + mgmt_l)
  # interaction between hatch date and quadratic age and management level
  Phi.age.mgmt_l <-
    list(formula = ~Time + mgmt_l)
  # interaction between year and hatch date and management level
  Phi.quadage.mgmt_l <-
    list(formula = ~Quadratic + mgmt_l)
  
  # interaction between hatch date and age and management status
  Phi.date.x.mgmt_s <-
    list(formula = ~date_j * mgmt_s)
  # interaction between hatch date and quadratic age and management status
  Phi.age.x.mgmt_s <-
    list(formula = ~Time * mgmt_s)
  # interaction between year and hatch date and management status
  Phi.quadage.x.mgmt_s <-
    list(formula = ~Quadratic * mgmt_s)
  
  # interaction between hatch date and age and management status
  Phi.date.mgmt_s <-
    list(formula = ~date_j + mgmt_s)
  # interaction between hatch date and quadratic age and management status
  Phi.age.mgmt_s <-
    list(formula = ~Time + mgmt_s)
  # interaction between year and hatch date and management status
  Phi.quadage.mgmt_s <-
    list(formula = ~Quadratic + mgmt_s)
  # # additive effect of hach date and age and management level
  # Phi.date.age.mgmt_l <-
  #   list(formula = ~date_j + Time + mgmt_l)
  # 
  # # additive effect of hatch date and quadratic age and management level
  # Phi.date.quadage.mgmt_l <-
  #   list(formula = ~date_j + Quadratic + mgmt_l)
  # 
  # # interaction between hatch date and age and management level
  # Phi.date.x.age.mgmt_l <-
  #   list(formula = ~date_j * Time + mgmt_l)
  # 
  # # interaction between hatch date and quadratic age and management level
  # Phi.date.x.quadage.mgmt_l <-
  #   list(formula = ~date_j * Quadratic + mgmt_l)
  # 
  # # interaction between year and hatch date and management level
  # Phi.season.x.date.mgmt_l <-
  #   list(formula = ~season * date_j + mgmt_l)
  # 
  # # additive between year and hatch date and management level
  # Phi.season.date.mgmt_l <-
  #   list(formula = ~season + date_j + mgmt_l)
  # 
  # # additive effect of hach date and age and management status
  # Phi.date.age.mgmt_s <-
  #   list(formula = ~date_j + Time + mgmt_s)
  # 
  # # additive effect of hatch date and quadratic age and management status
  # Phi.date.quadage.mgmt_s <-
  #   list(formula = ~date_j + Quadratic + mgmt_s)
  # 
  # # interaction between hatch date and age and management status
  # Phi.date.x.age.mgmt_s <-
  #   list(formula = ~date_j * Time + mgmt_s)
  # 
  # # interaction between hatch date and quadratic age and management status
  # Phi.date.x.quadage.mgmt_s <-
  #   list(formula = ~date_j * Quadratic + mgmt_s)
  # 
  # # interaction between year and hatch date and management status
  # Phi.season.x.date.mgmt_s <-
  #   list(formula = ~season * date_j + mgmt_s)
  # 
  # # additive between year and hatch date and management status
  # Phi.season.date.mgmt_s <-
  #   list(formula = ~season + date_j + mgmt_s)
  # 
  # # best structure of p determined from previous analysis
  # p.year.x.quadage <- 
  #   list(formula = ~season * Quadratic)
  
    # best structure of p determined from previous analysis
  p.quadage <- 
    list(formula = ~Quadratic)
  
  # create model list for all a priori models above that begin with Phi. or p.
  cml <- create.model.list("CJS")
  
  # runs model list in program MARK
  model.list <- mark.wrapper(model.list = cml, data = MP_chicks.proc, 
                             ddl = MP_chicks.ddl,
                             threads = 4, brief = TRUE, delete = TRUE)
  
  # store completed model list
  return(model.list) 
}
# Run model selection to determine best structure of Phi
MP_chicks_Phi_run <- MP_chicks_Phi()
 Model: Phi(~Time)p(~Quadratic)  npar= 4  lnl =  1571.8926 AICc = 1579.9128
 Model: Phi(~Time + mgmt_l)p(~Quadratic)  npar= 8  lnl =  1564.8084 AICc = 1580.8815
 Model: Phi(~Time + mgmt_s)p(~Quadratic)  npar= 5  lnl =  1568.5068 AICc = 1578.5372
 Model: Phi(~Time * mgmt_l)p(~Quadratic)  npar= 12  lnl =  1557.9676 AICc = 1582.1263
 Model: Phi(~Time * mgmt_s)p(~Quadratic)  npar= 6  lnl =  1567.4724 AICc = 1579.515
 Model: Phi(~date_j)p(~Quadratic)  npar= 4  lnl =  1573.6091 AICc = 1581.6294
 Model: Phi(~date_j + mgmt_l)p(~Quadratic)  npar= 8  lnl =  1564.6766 AICc = 1580.7497
 Model: Phi(~date_j + mgmt_s)p(~Quadratic)  npar= 5  lnl =  1598.401 AICc = 1608.4314
 Model: Phi(~date_j * Time)p(~Quadratic)  npar= 6  lnl =  1568.565 AICc = 1580.6076
 Model: Phi(~date_j * mgmt_l)p(~Quadratic)  npar= 12  lnl =  1559.6915 AICc = 1583.8502
 Model: Phi(~date_j * mgmt_s)p(~Quadratic)  npar= 6  lnl =  1564.7165 AICc = 1576.7591
 Model: Phi(~date_j * Quadratic)p(~Quadratic)  npar= 6  lnl =  1564.2472 AICc = 1576.2898
 Model: Phi(~1)p(~Quadratic)  npar= 3  lnl =  1576.1152 AICc = 1582.1273
 Model: Phi(~mgmt_l)p(~Quadratic)  npar= 7  lnl =  1568.286 AICc = 1582.3429
 Model: Phi(~mgmt_s)p(~Quadratic)  npar= 4  lnl =  1572.555 AICc = 1580.5752
 Model: Phi(~Quadratic)p(~Quadratic)  npar= 4  lnl =  1568.0157 AICc = 1576.0359
 Model: Phi(~Quadratic + mgmt_l)p(~Quadratic)  npar= 8  lnl =  1561.0391 AICc = 1577.1122
 Model: Phi(~Quadratic + mgmt_s)p(~Quadratic)  npar= 5  lnl =  1564.5767 AICc = 1574.6071
 Model: Phi(~Quadratic * mgmt_l)p(~Quadratic)  npar= 12  lnl =  1553.9182 AICc = 1578.0769
 Model: Phi(~Quadratic * mgmt_s)p(~Quadratic)  npar= 6  lnl =  1562.7958 AICc = 1574.83839634888
 Model: Phi(~season)p(~Quadratic)  npar= 14  lnl =  1551.0913 AICc = 1579.3051
 Model: Phi(~season * date_j)p(~Quadratic)  npar= 26  lnl =  1533.7517 AICc = 1586.471# inspect Phi AIC table to find top model
MP_chicks_Phi_run # best structure: Phi(~Year * Day_of_Season)                                   model npar     AICc  DeltaAICc       weight
17 Phi(~Quadratic + mgmt_s)p(~Quadratic)    5 1574.607  0.0000000 2.322058e-01
20 Phi(~Quadratic * mgmt_s)p(~Quadratic)    6 1574.838  0.2312858 2.068474e-01
18          Phi(~Quadratic)p(~Quadratic)    4 1576.036  1.4288529 1.136584e-01
12 Phi(~date_j * Quadratic)p(~Quadratic)    6 1576.290  1.6826858 1.001112e-01
11    Phi(~date_j * mgmt_s)p(~Quadratic)    6 1576.759  2.1519858 7.917267e-02
16 Phi(~Quadratic + mgmt_l)p(~Quadratic)    8 1577.112  2.5050859 6.635911e-02
19 Phi(~Quadratic * mgmt_l)p(~Quadratic)   12 1578.077  3.4697873 4.096551e-02
2       Phi(~Time + mgmt_s)p(~Quadratic)    5 1578.537  3.9301000 3.254338e-02
21             Phi(~season)p(~Quadratic)   14 1579.305  4.6980387 2.216700e-02
5       Phi(~Time * mgmt_s)p(~Quadratic)    6 1579.515  4.9078858 1.995902e-02
3                Phi(~Time)p(~Quadratic)    4 1579.913  5.3057529 1.635850e-02
15             Phi(~mgmt_s)p(~Quadratic)    4 1580.575  5.9681529 1.174641e-02
9       Phi(~date_j * Time)p(~Quadratic)    6 1580.608  6.0004858 1.155804e-02
6     Phi(~date_j + mgmt_l)p(~Quadratic)    8 1580.750  6.1425859 1.076533e-02
1       Phi(~Time + mgmt_l)p(~Quadratic)    8 1580.881  6.2743859 1.007877e-02
8              Phi(~date_j)p(~Quadratic)    4 1581.629  7.0222529 6.934421e-03
4       Phi(~Time * mgmt_l)p(~Quadratic)   12 1582.126  7.5191873 5.408817e-03
13                  Phi(~1)p(~Quadratic)    3 1582.127  7.5202414 5.405967e-03
14             Phi(~mgmt_l)p(~Quadratic)    7 1582.343  7.7357134 4.853826e-03
10    Phi(~date_j * mgmt_l)p(~Quadratic)   12 1583.850  9.2430873 2.284347e-03
22    Phi(~season * date_j)p(~Quadratic)   26 1586.471 11.8638518 6.161272e-04
7     Phi(~date_j + mgmt_s)p(~Quadratic)    5 1608.431 33.8243000 1.049590e-08
    Deviance
17  725.3644
20  723.5835
18  728.8034
12 1564.2472
11 1564.7165
16  721.8269
19  714.7060
2   729.2945
21  711.8790
5   728.2602
3   732.6803
15  733.3427
9  1568.5650
6  1564.6766
1   725.5962
8  1573.6091
4   718.7554
13  736.9029
14  729.0738
10 1559.6915
22 1533.7517
7  1598.4010saveRDS(MP_chicks_Phi_run, "output/MP_chicks_Phi_run.rds")MP_chicks_Phi_run <- readRDS("output/MP_chicks_Phi_run.rds")
# Extract estimates of survival from top models
Chick_dot_surv <- MP_chicks_Phi_run[[13]]$results$real
Chick_quadage_surv <- MP_chicks_Phi_run[[18]]$results$real
Chick_hatch_date_surv <- MP_chicks_Phi_run[[8]]$results$real
Chick_mgmt_s_surv <- MP_chicks_Phi_run[[15]]$results$real
Chick_mgmt_l_surv <- MP_chicks_Phi_run[[14]]$results$real
Chick_mgmt_s_x_quadage_surv <- MP_chicks_Phi_run[[20]]$results$real
Chick_mgmt_s_quadage_surv <- MP_chicks_Phi_run[[17]]$results$real
Chick_mgmt_l_quadage_surv <- MP_chicks_Phi_run[[16]]$results$real
Groups <- data.frame(str_split_fixed(rownames(Chick_dot_surv), " ", n = 5))
Chick_dot_surv <- cbind(Groups, Chick_dot_surv)
Chick_dot_surv$season <- unlist(substr(Chick_dot_surv$X2, 2, 7))
Chick_dot_surv$age <- as.numeric(sub("^a", "", Chick_dot_surv$X4))
Chick_dot_surv$mgmt_s <- unlist(substr(Chick_dot_surv$X2, 11, 11))
Groups <- data.frame(str_split_fixed(rownames(Chick_quadage_surv), " ", n = 5))
Chick_quadage_surv <- cbind(Groups, Chick_quadage_surv)
Chick_quadage_surv$season <- unlist(substr(Chick_quadage_surv$X2, 2, 7))
Chick_quadage_surv$age <- as.numeric(sub("^a", "", Chick_quadage_surv$X4))
Chick_quadage_surv$mgmt_s <- unlist(substr(Chick_quadage_surv$X2, 11, 11))
Groups <- data.frame(str_split_fixed(rownames(Chick_hatch_date_surv), " ", n = 5))
Chick_hatch_date_surv <- cbind(Groups, Chick_hatch_date_surv)
Chick_hatch_date_surv$season <- unlist(substr(Chick_hatch_date_surv$X2, 2, 7))
Chick_hatch_date_surv$age <- as.numeric(sub("^a", "", Chick_hatch_date_surv$X4))
Chick_hatch_date_surv$mgmt_s <- unlist(substr(Chick_hatch_date_surv$X2, 11, 11))
Groups <- data.frame(str_split_fixed(rownames(Chick_mgmt_s_surv), " ", n = 5))
Chick_mgmt_s_surv <- cbind(Groups, Chick_mgmt_s_surv)
Chick_mgmt_s_surv$season <- unlist(substr(Chick_mgmt_s_surv$X2, 2, 7))
Chick_mgmt_s_surv$age <- as.numeric(sub("^a", "", Chick_mgmt_s_surv$X4))
Chick_mgmt_s_surv$mgmt_s <- unlist(substr(Chick_mgmt_s_surv$X2, 11, 11))
Groups <- data.frame(str_split_fixed(rownames(Chick_mgmt_l_surv), " ", n = 5))
Chick_mgmt_l_surv <- cbind(Groups, Chick_mgmt_l_surv)
Chick_mgmt_l_surv$season <- unlist(substr(Chick_mgmt_l_surv$X2, 2, 7))
Chick_mgmt_l_surv$age <- as.numeric(sub("^a", "", Chick_mgmt_l_surv$X4))
Chick_mgmt_l_surv$mgmt_l <- unlist(substr(Chick_mgmt_l_surv$X2, 10, 10))
Groups <- data.frame(str_split_fixed(rownames(Chick_mgmt_s_quadage_surv), " ", n = 5))
Chick_mgmt_s_quadage_surv <- cbind(Groups, Chick_mgmt_s_quadage_surv)
Chick_mgmt_s_quadage_surv$season <- unlist(substr(Chick_mgmt_s_quadage_surv$X2, 2, 7))
Chick_mgmt_s_quadage_surv$age <- as.numeric(sub("^a", "", Chick_mgmt_s_quadage_surv$X4))
Chick_mgmt_s_quadage_surv$mgmt_s <- unlist(substr(Chick_mgmt_s_quadage_surv$X2, 11, 11))
Groups <- data.frame(str_split_fixed(rownames(Chick_mgmt_s_x_quadage_surv), " ", n = 5))
Chick_mgmt_s_x_quadage_surv <- cbind(Groups, Chick_mgmt_s_x_quadage_surv)
Chick_mgmt_s_x_quadage_surv$season <- unlist(substr(Chick_mgmt_s_x_quadage_surv$X2, 2, 7))
Chick_mgmt_s_x_quadage_surv$age <- as.numeric(sub("^a", "", Chick_mgmt_s_x_quadage_surv$X4))
Chick_mgmt_s_x_quadage_surv$mgmt_s <- unlist(substr(Chick_mgmt_s_x_quadage_surv$X2, 11, 11))
Groups <- data.frame(str_split_fixed(rownames(Chick_mgmt_l_quadage_surv), " ", n = 5))
Chick_mgmt_l_quadage_surv <- cbind(Groups, Chick_mgmt_l_quadage_surv)
Chick_mgmt_l_quadage_surv$season <- unlist(substr(Chick_mgmt_l_quadage_surv$X2, 2, 7))
Chick_mgmt_l_quadage_surv$age <- as.numeric(sub("^a", "", Chick_mgmt_l_quadage_surv$X4))
Chick_mgmt_l_quadage_surv$mgmt_l <- unlist(substr(Chick_mgmt_l_quadage_surv$X2, 10, 10))
# constant survival
ggplot() +
  geom_line(data = Chick_dot_surv, aes(x = age, y = estimate, color = as.numeric(season), group = season)) +
  geom_ribbon(data = Chick_dot_surv, aes(x = age, ymin = lcl, ymax = ucl, fill = as.numeric(season), group = season), alpha = 0.2) +
  scale_color_gradient(
    low = "black",
    high = "red",
    name = "season"
  ) +
  scale_fill_gradient(
    low = "black",
    high = "red",
    name = "season"
  ) +
  ylab("daily brood survival") +
  xlab("brood age (days)")# quadratic age-dependent survival
ggplot() +
  geom_line(data = filter(Chick_quadage_surv, X1 == "Phi"), 
            aes(x = age, y = estimate)) +
  geom_ribbon(data = filter(Chick_quadage_surv, X1 == "Phi"), 
              aes(x = age, ymin = lcl, ymax = ucl), alpha = 0.2) +
  ylab("daily brood survival") +
  xlab("brood age (days)")# quadratic age-dependent survival and management status
ggplot() +
  geom_line(data = filter(Chick_mgmt_s_quadage_surv, X1 == "Phi"), 
            aes(x = age, y = estimate, color = mgmt_s)) +
  geom_ribbon(data = filter(Chick_mgmt_s_quadage_surv, X1 == "Phi"), 
              aes(x = age, ymin = lcl, ymax = ucl, fill = mgmt_s), alpha = 0.2) +
  ylab("daily brood survival") +
  xlab("brood age (days)")# quadratic age-dependent survival and management level
ggplot() +
  geom_line(data = filter(Chick_mgmt_l_quadage_surv, X1 == "Phi"), 
            aes(x = age, y = estimate, color = mgmt_l)) +
  geom_ribbon(data = filter(Chick_mgmt_l_quadage_surv, X1 == "Phi"), 
              aes(x = age, ymin = lcl, ymax = ucl, fill = mgmt_l), alpha = 0.2) +
  ylab("daily brood survival") +
  xlab("brood age (days)")# quadratic age-dependent survival and management status
ggplot() +
  geom_line(data = filter(Chick_mgmt_s_x_quadage_surv, X1 == "Phi"), 
            aes(x = age, y = estimate, color = mgmt_s)) +
  geom_ribbon(data = filter(Chick_mgmt_s_x_quadage_surv, X1 == "Phi"), 
              aes(x = age, ymin = lcl, ymax = ucl, fill = mgmt_s), alpha = 0.2) +
  ylab("daily brood survival") +
  xlab("brood age (days)")# management status-dependent survival
ggplot() +
  geom_point(data = filter(Chick_mgmt_s_surv, X1 == "Phi"), 
            aes(x = mgmt_s, y = estimate, color = mgmt_s)) +
  geom_errorbar(data = filter(Chick_mgmt_s_surv, X1 == "Phi"), 
              aes(x = mgmt_s, ymin = lcl, ymax = ucl, color = mgmt_s)) +
  ylab("daily brood survival") +
  xlab("managed?") +
  scale_y_continuous(limits = c(0, 1))# management level-dependent survival
ggplot() +
  geom_point(data = filter(Chick_mgmt_l_surv, X1 == "Phi"), 
            aes(x = mgmt_l, y = estimate, color = mgmt_l)) +
  geom_errorbar(data = filter(Chick_mgmt_l_surv, X1 == "Phi"), 
              aes(x = mgmt_l, ymin = lcl, ymax = ucl, color = mgmt_l)) +
  ylab("daily brood survival") +
  xlab("managed?") +
  scale_y_continuous(limits = c(0, 1))filter(Chick_mgmt_s_surv, X1 == "Phi") %>% 
  mutate(fledgling_success = estimate^35)                          X1          X2 X3 X4 X5  estimate        se       lcl
Phi g201213MP0N c1 a0 t1 Phi g201213MP0N c1 a0 t1 0.9151093 0.0349744 0.8168670
Phi g201213MP3Y c1 a0 t1 Phi g201213MP3Y c1 a0 t1 0.9673442 0.0033289 0.9601507
                               ucl fixed note season age mgmt_s
Phi g201213MP0N c1 a0 t1 0.9630341            201213   0      N
Phi g201213MP3Y c1 a0 t1 0.9732754            201213   0      Y
                         fledgling_success
Phi g201213MP0N c1 a0 t1        0.04482847
Phi g201213MP3Y c1 a0 t1        0.31284997# seasonal dependent survival (hatch date)
# ggplot() +
#   geom_line(data = Chick_p_reals, aes(x = age, y = estimate, color = as.numeric(season), group = season)) +
#   geom_ribbon(data = Chick_p_reals, aes(x = age, ymin = lcl, ymax = ucl, fill = as.numeric(season), group = season), alpha = 0.2) +
#   scale_color_gradient(
#     low = "black",
#     high = "red",
#     name = "season"
#   ) +
#   scale_fill_gradient(
#     low = "black",
#     high = "red",
#     name = "season"
#   ) +
#   ylab("detection probability of a brood") +
#   xlab("brood age (days)")We can see in our model selection of nest survival all three sites that our variable “fun days” (a measure of the number of weekends or holidays a nest is exposed to) was the best at explaining variation in daily nest survival. To interpret this effect, it essentially means that if a nest is initiated on, for example, a Friday right before a long period of consecutive holidays, this nest is expected to have extremely low survival compared to a nest initiated on, for example, a Monday at the early or late part of the season when there are no holidays.
Despite “fun days” having such a strong relationship to daily nest survival, our threat variables (e.g., maximum number of dogs off leash counted, maximum number of humans counted, etc.) all showed little relationship with daily nest survival, which we interpret as a methodological effect: the surveys conducted to quantify specific threats were too infrequent to capture a meaningful measure of the pressure that these threats have on nest survival. To link “Fun days” to the threats, we here do an exploratory relationship between fundays and the threats.
library(lme4)
library(gtsummary)
library(ggeffects)
library(effects)
threat_data__scaled_FP <- 
  threat_data__ %>% 
  mutate(no_fun = ifelse(funday == 0, 1, 0),
                 fun = ifelse(funday == 1, 1, 0)) %>% 
          filter(region == "FP") %>% 
  mutate(humans_s = scale(humans_),
         dogs_s = scale(dogs_),
         pred_birds_s = scale(pred_birds_),
         gull_s = scale(gulls_),
         dogs_off_s = scale(dogs_off_),
         obs_date2_s = scale(obs_date2))
threat_data__scaled_MP <- 
  threat_data__ %>% 
  mutate(no_fun = ifelse(funday == 0, 1, 0),
                 fun = ifelse(funday == 1, 1, 0)) %>% 
          filter(region == "MP") %>% 
  mutate(humans_s = scale(humans_),
         dogs_s = scale(dogs_),
         pred_birds_s = scale(pred_birds_),
         gull_s = scale(gulls_),
         dogs_off_s = scale(dogs_off_),
         obs_date2_s = scale(obs_date2))
threat_data__scaled_BC <- 
  threat_data__ %>% 
  mutate(no_fun = ifelse(funday == 0, 1, 0),
                 fun = ifelse(funday == 1, 1, 0)) %>% 
          filter(region == "BC") %>% 
  mutate(humans_s = scale(humans_),
         dogs_s = scale(dogs_),
         pred_birds_s = scale(pred_birds_),
         gull_s = scale(gulls_),
         dogs_off_s = scale(dogs_off_),
         obs_date2_s = scale(obs_date2))
threat_data__scaled_PI <- 
  threat_data__ %>% 
  mutate(no_fun = ifelse(funday == 0, 1, 0),
                 fun = ifelse(funday == 1, 1, 0)) %>% 
          filter(region == "PI") %>% 
  mutate(humans_s = scale(humans_),
         dogs_s = scale(dogs_),
         pred_birds_s = scale(pred_birds_),
         gull_s = scale(gulls_),
         dogs_off_s = scale(dogs_off_),
         obs_date2_s = scale(obs_date2))
threat_data__scaled_BSC <- 
  threat_data__ %>% 
  mutate(no_fun = ifelse(funday == 0, 1, 0),
                 fun = ifelse(funday == 1, 1, 0)) %>% 
          filter(region == "BSC") %>% 
  mutate(humans_s = scale(humans_),
         dogs_s = scale(dogs_),
         pred_birds_s = scale(pred_birds_),
         gull_s = scale(gulls_),
         dogs_off_s = scale(dogs_off_),
         obs_date2_s = scale(obs_date2))strong relationship between the number of humans detected and the occurrence of a weekend or a holiday at all 3 regions
humans_fun_day_FP_ <-
  glmer(humans_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_FP,
        family = "poisson")
humans_fun_day_MP_ <-
  glmer(humans_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_MP,
        family = "poisson")
humans_fun_day_BC_ <-
  glmer(humans_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_BC,
        family = "poisson")
humans_fun_day_BSC_ <-
  glmer(humans_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_BSC,
        family = "poisson")
humans_fun_day_PI_ <-
  glmer(humans_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_PI,
        family = "poisson")Fleurieu Peninsula
tbl_regression(humans_fun_day_FP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | 0.86 | 0.54, 1.2 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | 12 | 11, 13 | <0.001 | 
| poly(obs_date2, 3)2 | -16 | -17, -15 | <0.001 | 
| poly(obs_date2, 3)3 | -15 | -16, -14 | <0.001 | 
| Weekends & Holidays | 0.57 | 0.56, 0.58 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Mornington Peninsula
tbl_regression(humans_fun_day_MP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -0.04 | -0.41, 0.33 | 0.8 | 
| Date | |||
| poly(obs_date2, 3)1 | 12 | 11, 14 | <0.001 | 
| poly(obs_date2, 3)2 | -15 | -16, -13 | <0.001 | 
| poly(obs_date2, 3)3 | 0.78 | -0.62, 2.2 | 0.3 | 
| Weekends & Holidays | 0.93 | 0.92, 0.95 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Bellarine / Surf Coast
tbl_regression(humans_fun_day_BSC_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | 0.70 | 0.39, 1.0 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | 16 | 15, 18 | <0.001 | 
| poly(obs_date2, 3)2 | -6.7 | -8.0, -5.4 | <0.001 | 
| poly(obs_date2, 3)3 | -12 | -14, -11 | <0.001 | 
| Weekends & Holidays | 0.73 | 0.71, 0.76 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Bass Coast
tbl_regression(humans_fun_day_BC_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -0.07 | -0.41, 0.28 | 0.7 | 
| Date | |||
| poly(obs_date2, 3)1 | 9.7 | 8.5, 11 | <0.001 | 
| poly(obs_date2, 3)2 | -7.5 | -8.7, -6.3 | <0.001 | 
| poly(obs_date2, 3)3 | 0.95 | -0.29, 2.2 | 0.13 | 
| Weekends & Holidays | 0.85 | 0.82, 0.87 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Phillip Island
tbl_regression(humans_fun_day_PI_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | 0.55 | 0.27, 0.83 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | 16 | 14, 17 | <0.001 | 
| poly(obs_date2, 3)2 | -13 | -14, -12 | <0.001 | 
| poly(obs_date2, 3)3 | -11 | -12, -9.4 | <0.001 | 
| Weekends & Holidays | 0.88 | 0.86, 0.91 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
humans_fun_day_FP__fits <-
  as.data.frame(effect(term = "funday", mod = humans_fun_day_FP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_FP[, "funday"], na.rm = TRUE), max(threat_data__scaled_FP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "FP")
humans_fun_day_MP__fits <-
  as.data.frame(effect(term = "funday", mod = humans_fun_day_MP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_MP[, "funday"], na.rm = TRUE), max(threat_data__scaled_MP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "MP")
humans_fun_day_BC__fits <-
  as.data.frame(effect(term = "funday", mod = humans_fun_day_BC_,
                       xlevels = list(funday = seq(min(threat_data__scaled_BC[, "funday"], na.rm = TRUE), max(threat_data__scaled_BC[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "BC")
humans_fun_day_PI__fits <-
  as.data.frame(effect(term = "funday", mod = humans_fun_day_PI_,
                       xlevels = list(funday = seq(min(threat_data__scaled_PI[, "funday"], na.rm = TRUE), max(threat_data__scaled_PI[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "PI")
humans_fun_day_BSC__fits <-
  as.data.frame(effect(term = "funday", mod = humans_fun_day_BSC_,
                       xlevels = list(funday = seq(min(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), max(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "BSC")
humans_fun_day__fits <- 
  bind_rows(humans_fun_day_FP__fits,
            humans_fun_day_MP__fits, 
            humans_fun_day_BSC__fits, 
            humans_fun_day_BC__fits, 
            humans_fun_day_PI__fits) %>%
  mutate(funday = ifelse(funday == 0, "no", "yes"))
row.names(humans_fun_day__fits) <- NULL
ggplot() +
  geom_line(data = humans_fun_day__fits, 
            aes(x = funday, y = fit, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2, size = 2) +
  geom_errorbar(data = humans_fun_day__fits, 
                aes(ymin = lower, ymax = upper, 
                    x = funday, 
                    y = fit, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = humans_fun_day__fits, 
             aes(x = funday, y = fit, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  luke_theme +
  theme(legend.position = "top",
        legend.justification = c(1, 0),
        strip.background = element_blank(),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 10)) +
  ylab("number of humans detected (± 95% CI)") +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
labels = c("BSC" = "Bellarine/Surf Coast", 
                                 "FP" = "Fleurieu Peninsula",
                                 "MP" = "Mornington Peninsula",
                                 "BC" = "Bass Coast",
                                 "PI" = "Phillip Island")) +
  scale_fill_brewer(palette = "Dark2", 
                      name = "Region", 
labels = c("BSC" = "Bellarine/Surf Coast", 
                                 "FP" = "Fleurieu Peninsula",
                                 "MP" = "Mornington Peninsula",
                                 "BC" = "Bass Coast",
                                 "PI" = "Phillip Island")) +
  scale_x_discrete(labels = c("weekday", "weekend/holiday"))strong relationship between the number of dogs detected and the occurrence of a weekend or a holiday at all 3 regions
dogs_fun_day_FP_ <-
  glmer(dogs_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_FP,
        family = "poisson")
dogs_fun_day_MP_ <-
  glmer(dogs_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_MP,
        family = "poisson")
dogs_fun_day_BC_ <-
  glmer(dogs_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_BC,
        family = "poisson")
dogs_fun_day_BSC_ <-
  glmer(dogs_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_BSC,
        family = "poisson")
dogs_fun_day_PI_ <-
  glmer(dogs_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_PI,
        family = "poisson")Fleurieu Peninsula
tbl_regression(dogs_fun_day_FP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -0.50 | -0.95, -0.06 | 0.025 | 
| Date | |||
| poly(obs_date2, 3)1 | 5.9 | 4.4, 7.4 | <0.001 | 
| poly(obs_date2, 3)2 | -10 | -12, -8.6 | <0.001 | 
| poly(obs_date2, 3)3 | -10 | -12, -8.6 | <0.001 | 
| Weekends & Holidays | 0.30 | 0.28, 0.32 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Mornington Peninsula
tbl_regression(dogs_fun_day_MP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -3.1 | -3.7, -2.5 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | -10 | -16, -4.1 | <0.001 | 
| poly(obs_date2, 3)2 | -0.45 | -6.5, 5.6 | 0.9 | 
| poly(obs_date2, 3)3 | 1.8 | -4.1, 7.7 | 0.6 | 
| Weekends & Holidays | 0.70 | 0.62, 0.77 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Bellarine / Surf Coast
tbl_regression(dogs_fun_day_BSC_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -0.14 | -0.45, 0.16 | 0.4 | 
| Date | |||
| poly(obs_date2, 3)1 | 2.8 | 0.71, 4.9 | 0.009 | 
| poly(obs_date2, 3)2 | 2.0 | -0.13, 4.2 | 0.065 | 
| poly(obs_date2, 3)3 | -4.3 | -6.5, -2.2 | <0.001 | 
| Weekends & Holidays | 0.53 | 0.49, 0.57 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Bass Coast
tbl_regression(dogs_fun_day_BC_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -1.0 | -1.4, -0.71 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | 2.1 | -0.08, 4.3 | 0.059 | 
| poly(obs_date2, 3)2 | 2.0 | -0.08, 4.1 | 0.059 | 
| poly(obs_date2, 3)3 | 1.2 | -0.82, 3.2 | 0.2 | 
| Weekends & Holidays | 0.43 | 0.38, 0.48 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Phillip Island
tbl_regression(dogs_fun_day_PI_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -2.0 | -2.6, -1.4 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | 10 | 7.8, 13 | <0.001 | 
| poly(obs_date2, 3)2 | -3.9 | -6.7, -1.2 | 0.005 | 
| poly(obs_date2, 3)3 | -8.6 | -11, -5.8 | <0.001 | 
| Weekends & Holidays | 0.62 | 0.57, 0.67 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
dogs_fun_day_FP__fits <-
  as.data.frame(effect(term = "funday", mod = dogs_fun_day_FP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_FP[, "funday"], na.rm = TRUE), max(threat_data__scaled_FP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "FP")
dogs_fun_day_MP__fits <-
  as.data.frame(effect(term = "funday", mod = dogs_fun_day_MP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_MP[, "funday"], na.rm = TRUE), max(threat_data__scaled_MP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "MP")
dogs_fun_day_BC__fits <-
  as.data.frame(effect(term = "funday", mod = dogs_fun_day_BC_,
                       xlevels = list(funday = seq(min(threat_data__scaled_BC[, "funday"], na.rm = TRUE), max(threat_data__scaled_BC[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "BC")
dogs_fun_day_PI__fits <-
  as.data.frame(effect(term = "funday", mod = dogs_fun_day_PI_,
                       xlevels = list(funday = seq(min(threat_data__scaled_PI[, "funday"], na.rm = TRUE), max(threat_data__scaled_PI[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "PI")
dogs_fun_day_BSC__fits <-
  as.data.frame(effect(term = "funday", mod = dogs_fun_day_BSC_,
                       xlevels = list(funday = seq(min(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), max(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "BSC")
dogs_fun_day__fits <- 
  bind_rows(dogs_fun_day_FP__fits,
            dogs_fun_day_MP__fits, 
            dogs_fun_day_BSC__fits, 
            dogs_fun_day_BC__fits, 
            dogs_fun_day_PI__fits) %>%
  mutate(funday = ifelse(funday == 0, "no", "yes"))
row.names(dogs_fun_day__fits) <- NULL
ggplot() +
  geom_line(data = dogs_fun_day__fits, 
            aes(x = funday, y = fit, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2, size = 2) +
  geom_errorbar(data = dogs_fun_day__fits, 
                aes(ymin = lower, ymax = upper, 
                    x = funday, 
                    y = fit, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = dogs_fun_day__fits, 
             aes(x = funday, y = fit, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  luke_theme +
  theme(legend.position = "top",
        legend.justification = c(1, 0),
        strip.background = element_blank(),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 10)) +
  ylab("number of dogs detected (± 95% CI)") +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
labels = c("BSC" = "Bellarine/Surf Coast", 
                                 "FP" = "Fleurieu Peninsula",
                                 "MP" = "Mornington Peninsula",
                                 "BC" = "Bass Coast",
                                 "PI" = "Phillip Island")) +
  scale_fill_brewer(palette = "Dark2",
                    name = "Region", 
labels = c("BSC" = "Bellarine/Surf Coast", 
                                 "FP" = "Fleurieu Peninsula",
                                 "MP" = "Mornington Peninsula",
                                 "BC" = "Bass Coast",
                                 "PI" = "Phillip Island")) +
  scale_x_discrete(labels = c("weekday", "weekend/holiday"))strong relationship between the number of dogs off leash detected and the occurrence of a weekend or a holiday at all 3 regions
dogs_off_fun_day_FP_ <-
  glmer(dogs_off_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_FP,
        family = "poisson")
dogs_off_fun_day_MP_ <-
  glmer(dogs_off_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_MP,
        family = "poisson")
dogs_off_fun_day_BC_ <-
  glmer(dogs_off_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_BC,
        family = "poisson")
dogs_off_fun_day_BSC_ <-
  glmer(dogs_off_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_BSC,
        family = "poisson")
dogs_off_fun_day_PI_ <-
  glmer(dogs_off_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_PI,
        family = "poisson")Fleurieu Peninsula
tbl_regression(dogs_off_fun_day_FP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -0.89 | -1.3, -0.46 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | 5.6 | 3.8, 7.4 | <0.001 | 
| poly(obs_date2, 3)2 | 9.4 | 7.6, 11 | <0.001 | 
| poly(obs_date2, 3)3 | -10 | -12, -8.3 | <0.001 | 
| Weekends & Holidays | 0.23 | 0.21, 0.25 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Mornington Peninsula
tbl_regression(dogs_off_fun_day_MP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -3.4 | -4.1, -2.8 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | -9.6 | -17, -2.6 | 0.008 | 
| poly(obs_date2, 3)2 | 6.2 | -0.90, 13 | 0.087 | 
| poly(obs_date2, 3)3 | 7.5 | 0.50, 14 | 0.036 | 
| Weekends & Holidays | 0.57 | 0.48, 0.67 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Bellarine / Surf Coast
tbl_regression(dogs_off_fun_day_BSC_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -0.48 | -0.79, -0.18 | 0.002 | 
| Date | |||
| poly(obs_date2, 3)1 | -3.4 | -5.9, -0.94 | 0.007 | 
| poly(obs_date2, 3)2 | 5.5 | 3.0, 8.1 | <0.001 | 
| poly(obs_date2, 3)3 | 0.06 | -2.4, 2.5 | >0.9 | 
| Weekends & Holidays | 0.40 | 0.35, 0.46 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Bass Coast
tbl_regression(dogs_off_fun_day_BC_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -1.3 | -1.6, -0.99 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | 0.23 | -2.4, 2.9 | 0.9 | 
| poly(obs_date2, 3)2 | 3.9 | 1.5, 6.4 | 0.002 | 
| poly(obs_date2, 3)3 | 2.5 | 0.25, 4.8 | 0.030 | 
| Weekends & Holidays | 0.35 | 0.29, 0.41 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Phillip Island
tbl_regression(dogs_off_fun_day_PI_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -2.5 | -3.0, -1.9 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | 1.3 | -2.0, 4.6 | 0.5 | 
| poly(obs_date2, 3)2 | 6.4 | 3.0, 9.8 | <0.001 | 
| poly(obs_date2, 3)3 | -4.0 | -7.4, -0.57 | 0.022 | 
| Weekends & Holidays | 0.58 | 0.51, 0.65 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
dogs_off_fun_day_FP__fits <-
  as.data.frame(effect(term = "funday", mod = dogs_off_fun_day_FP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_FP[, "funday"], na.rm = TRUE), max(threat_data__scaled_FP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "FP")
dogs_off_fun_day_MP__fits <-
  as.data.frame(effect(term = "funday", mod = dogs_off_fun_day_MP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_MP[, "funday"], na.rm = TRUE), max(threat_data__scaled_MP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "MP")
dogs_off_fun_day_BC__fits <-
  as.data.frame(effect(term = "funday", mod = dogs_off_fun_day_BC_,
                       xlevels = list(funday = seq(min(threat_data__scaled_BC[, "funday"], na.rm = TRUE), max(threat_data__scaled_BC[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "BC")
dogs_off_fun_day_PI__fits <-
  as.data.frame(effect(term = "funday", mod = dogs_off_fun_day_PI_,
                       xlevels = list(funday = seq(min(threat_data__scaled_PI[, "funday"], na.rm = TRUE), max(threat_data__scaled_PI[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "PI")
dogs_off_fun_day_BSC__fits <-
  as.data.frame(effect(term = "funday", mod = dogs_off_fun_day_BSC_,
                       xlevels = list(funday = seq(min(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), max(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "BSC")
dogs_off_fun_day__fits <- 
  bind_rows(dogs_off_fun_day_FP__fits, 
            dogs_off_fun_day_MP__fits, 
            dogs_off_fun_day_BSC__fits, 
            dogs_off_fun_day_BC__fits, 
            dogs_off_fun_day_PI__fits) %>% 
  mutate(funday = ifelse(funday == 0, "no", "yes"))
row.names(dogs_off_fun_day__fits) <- NULL
ggplot() +
  geom_line(data = dogs_off_fun_day__fits, 
            aes(x = funday, y = fit, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2, size = 2) +
  geom_errorbar(data = dogs_off_fun_day__fits, 
                aes(ymin = lower, ymax = upper, 
                    x = funday, 
                    y = fit, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = dogs_off_fun_day__fits, 
             aes(x = funday, y = fit, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  luke_theme +
  theme(legend.position = "top",
        legend.justification = c(1, 0),
        strip.background = element_blank(),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 10)) +
  ylab("number of dogs off leash detected (± 95% CI)") +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
labels = c("BSC" = "Bellarine/Surf Coast", 
                                 "FP" = "Fleurieu Peninsula",
                                 "MP" = "Mornington Peninsula",
                                 "BC" = "Bass Coast",
                                 "PI" = "Phillip Island")) +
  scale_fill_brewer(palette = "Dark2",
                    name = "Region", 
labels = c("BSC" = "Bellarine/Surf Coast", 
                                 "FP" = "Fleurieu Peninsula",
                                 "MP" = "Mornington Peninsula",
                                 "BC" = "Bass Coast",
                                 "PI" = "Phillip Island")) +
  scale_x_discrete(labels = c("weekday", "weekend/holiday"))weak negative relationship at Fleurieu Peninsula and Mornington Peninsula between the number of corvids detected and the occurrence of a weekend or a holiday
pred_birds_fun_day_FP_ <-
  glmer(pred_birds_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_FP,
        family = "poisson")
pred_birds_fun_day_MP_ <-
  glmer(pred_birds_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_MP,
        family = "poisson")
pred_birds_fun_day_BC_ <-
  glmer(pred_birds_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_BC,
        family = "poisson")
pred_birds_fun_day_BSC_ <-
  glmer(pred_birds_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_BSC,
        family = "poisson")
pred_birds_fun_day_PI_ <-
  glmer(pred_birds_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_PI,
        family = "poisson")Fleurieu Peninsula
tbl_regression(pred_birds_fun_day_FP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -1.2 | -1.5, -0.88 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | -7.6 | -11, -4.3 | <0.001 | 
| poly(obs_date2, 3)2 | -31 | -34, -27 | <0.001 | 
| poly(obs_date2, 3)3 | 8.1 | 4.8, 11 | <0.001 | 
| Weekends & Holidays | -0.12 | -0.16, -0.08 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Mornington Peninsula
tbl_regression(pred_birds_fun_day_MP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -1.7 | -2.0, -1.3 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | 28 | 23, 34 | <0.001 | 
| poly(obs_date2, 3)2 | -61 | -67, -56 | <0.001 | 
| poly(obs_date2, 3)3 | 13 | 6.2, 19 | <0.001 | 
| Weekends & Holidays | -0.44 | -0.49, -0.39 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Bellarine / Surf Coast
tbl_regression(pred_birds_fun_day_BSC_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -1.5 | -1.8, -1.1 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | 0.04 | -4.3, 4.4 | >0.9 | 
| poly(obs_date2, 3)2 | -40 | -45, -36 | <0.001 | 
| poly(obs_date2, 3)3 | 8.3 | 3.1, 14 | 0.002 | 
| Weekends & Holidays | -0.03 | -0.09, 0.04 | 0.4 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Bass Coast
tbl_regression(pred_birds_fun_day_BC_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -1.2 | -1.7, -0.63 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | -10 | -14, -6.3 | <0.001 | 
| poly(obs_date2, 3)2 | -34 | -38, -29 | <0.001 | 
| poly(obs_date2, 3)3 | 5.9 | 1.3, 10 | 0.013 | 
| Weekends & Holidays | -0.17 | -0.24, -0.10 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Phillip Island
tbl_regression(pred_birds_fun_day_PI_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -0.58 | -0.82, -0.34 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | -15 | -18, -12 | <0.001 | 
| poly(obs_date2, 3)2 | -25 | -28, -22 | <0.001 | 
| poly(obs_date2, 3)3 | 21 | 18, 24 | <0.001 | 
| Weekends & Holidays | -0.41 | -0.47, -0.35 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
pred_birds_fun_day_FP__fits <-
  as.data.frame(effect(term = "funday", mod = pred_birds_fun_day_FP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_FP[, "funday"], na.rm = TRUE), max(threat_data__scaled_FP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "FP")
pred_birds_fun_day_MP__fits <-
  as.data.frame(effect(term = "funday", mod = pred_birds_fun_day_MP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_MP[, "funday"], na.rm = TRUE), max(threat_data__scaled_MP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "MP")
pred_birds_fun_day_BC__fits <-
  as.data.frame(effect(term = "funday", mod = pred_birds_fun_day_BC_,
                       xlevels = list(funday = seq(min(threat_data__scaled_BC[, "funday"], na.rm = TRUE), max(threat_data__scaled_BC[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "BC")
pred_birds_fun_day_PI__fits <-
  as.data.frame(effect(term = "funday", mod = pred_birds_fun_day_PI_,
                       xlevels = list(funday = seq(min(threat_data__scaled_PI[, "funday"], na.rm = TRUE), max(threat_data__scaled_PI[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "PI")
pred_birds_fun_day_BSC__fits <-
  as.data.frame(effect(term = "funday", mod = pred_birds_fun_day_BSC_,
                       xlevels = list(funday = seq(min(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), max(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "BSC")
pred_birds_fun_day__fits <- 
  bind_rows(pred_birds_fun_day_FP__fits, 
            pred_birds_fun_day_MP__fits, 
            pred_birds_fun_day_BSC__fits, 
            pred_birds_fun_day_PI__fits, 
            pred_birds_fun_day_BC__fits) %>% 
  mutate(funday = ifelse(funday == 0, "no", "yes"))
row.names(pred_birds_fun_day__fits) <- NULL
ggplot() +
  geom_line(data = pred_birds_fun_day__fits, 
            aes(x = funday, y = fit, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2, size = 2) +
  geom_errorbar(data = pred_birds_fun_day__fits, 
                aes(ymin = lower, ymax = upper, 
                    x = funday, 
                    y = fit, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = pred_birds_fun_day__fits, 
             aes(x = funday, y = fit, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  luke_theme +
  theme(legend.position = "top",
        legend.justification = c(1, 0),
        strip.background = element_blank(),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 10)) +
  ylab("number of magpies and ravens detected (± 95% CI)") +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
labels = c("BSC" = "Bellarine/Surf Coast", 
                                 "FP" = "Fleurieu Peninsula",
                                 "MP" = "Mornington Peninsula",
                                 "BC" = "Bass Coast",
                                 "PI" = "Phillip Island")) +
  scale_fill_brewer(palette = "Dark2",
                    name = "Region", 
labels = c("BSC" = "Bellarine/Surf Coast", 
                                 "FP" = "Fleurieu Peninsula",
                                 "MP" = "Mornington Peninsula",
                                 "BC" = "Bass Coast",
                                 "PI" = "Phillip Island")) +
  scale_x_discrete(labels = c("weekday", "weekend/holiday"))negative relationship (albeit only significant at Mornington Peninsula) between the number of corvids detected and the occurrence of a weekend or a holiday
gulls_fun_day_FP_ <-
  glmer(gulls_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_FP,
        family = "poisson")
gulls_fun_day_MP_ <-
  glmer(gulls_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_MP,
        family = "poisson")
gulls_fun_day_BC_ <-
  glmer(gulls_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_BC,
        family = "poisson")
gulls_fun_day_PI_ <-
  glmer(gulls_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_PI,
        family = "poisson")
gulls_fun_day_BSC_ <-
  glmer(gulls_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_BSC,
        family = "poisson")Fleurieu Peninsula
tbl_regression(gulls_fun_day_FP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -1.1 | -1.4, -0.74 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | 0.06 | -3.1, 3.2 | >0.9 | 
| poly(obs_date2, 3)2 | -36 | -40, -33 | <0.001 | 
| poly(obs_date2, 3)3 | 6.9 | 3.7, 10 | <0.001 | 
| Weekends & Holidays | -0.06 | -0.09, -0.03 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Mornington Peninsula
tbl_regression(gulls_fun_day_MP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -1.6 | -2.0, -1.2 | <0.001 | 
| Date | |||
| poly(obs_date2, 3)1 | 34 | 29, 39 | <0.001 | 
| poly(obs_date2, 3)2 | -68 | -73, -63 | <0.001 | 
| poly(obs_date2, 3)3 | 13 | 7.1, 18 | <0.001 | 
| Weekends & Holidays | -0.42 | -0.46, -0.37 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
Bellarine / Surf Coast
tbl_regression(gulls_fun_day_BC_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))| Characteristic | log(IRR) | 95% CI | p-value | 
|---|---|---|---|
| (Intercept) | -0.90 | -1.6, -0.18 | 0.015 | 
| Date | |||
| poly(obs_date2, 3)1 | -8.9 | -13, -5.3 | <0.001 | 
| poly(obs_date2, 3)2 | -69 | -74, -65 | <0.001 | 
| poly(obs_date2, 3)3 | -36 | -41, -31 | <0.001 | 
| Weekends & Holidays | -0.25 | -0.30, -0.21 | <0.001 | 
| Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio | |||
gulls_fun_day_FP__fits <-
  as.data.frame(effect(term = "funday", mod = gulls_fun_day_FP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_FP[, "funday"], na.rm = TRUE), max(threat_data__scaled_FP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "FP")
gulls_fun_day_MP__fits <-
  as.data.frame(effect(term = "funday", mod = gulls_fun_day_MP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_MP[, "funday"], na.rm = TRUE), max(threat_data__scaled_MP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "MP")
gulls_fun_day_BC__fits <-
  as.data.frame(effect(term = "funday", mod = gulls_fun_day_BC_,
                       xlevels = list(funday = seq(min(threat_data__scaled_BC[, "funday"], na.rm = TRUE), max(threat_data__scaled_BC[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "BC")
gulls_fun_day_BSC__fits <-
  as.data.frame(effect(term = "funday", mod = gulls_fun_day_BSC_,
                       xlevels = list(funday = seq(min(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), max(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "BSC")
gulls_fun_day_PI__fits <-
  as.data.frame(effect(term = "funday", mod = gulls_fun_day_PI_,
                       xlevels = list(funday = seq(min(threat_data__scaled_PI[, "funday"], na.rm = TRUE), max(threat_data__scaled_PI[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "PI")
gulls_fun_day__fits <- 
  bind_rows(gulls_fun_day_FP__fits, 
            gulls_fun_day_MP__fits, 
            gulls_fun_day_BSC__fits, 
            gulls_fun_day_BC__fits, 
            gulls_fun_day_PI__fits) %>% 
  mutate(funday = ifelse(funday == 0, "no", "yes"))
row.names(gulls_fun_day__fits) <- NULL
ggplot() +
  geom_line(data = gulls_fun_day__fits, 
            aes(x = funday, y = fit, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2, size = 2) +
  geom_errorbar(data = gulls_fun_day__fits, 
                aes(ymin = lower, ymax = upper, 
                    x = funday, 
                    y = fit, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = gulls_fun_day__fits, 
             aes(x = funday, y = fit, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  luke_theme +
  theme(legend.position = "top",
        legend.justification = c(1, 0),
        strip.background = element_blank(),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 10)) +
  ylab("number of gulls detected (± 95% CI)") +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
labels = c("BSC" = "Bellarine/Surf Coast", 
                                 "FP" = "Fleurieu Peninsula",
                                 "MP" = "Mornington Peninsula",
                                 "BC" = "Bass Coast",
                                 "PI" = "Phillip Island")) +
  scale_fill_brewer(palette = "Dark2",
                    name = "Region", 
labels = c("BSC" = "Bellarine/Surf Coast", 
                                 "FP" = "Fleurieu Peninsula",
                                 "MP" = "Mornington Peninsula",
                                 "BC" = "Bass Coast",
                                 "PI" = "Phillip Island")) +
  scale_x_discrete(labels = c("weekday", "weekend/holiday"))