## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----data---------------------------------------------------------------------
library(tidycreel)

data(example_aerial_counts)
data(example_aerial_interviews)

head(example_aerial_counts)
head(example_aerial_interviews)

## ----calendar-----------------------------------------------------------------
# Build the survey calendar from the unique count dates
aerial_cal <- data.frame(
  date = example_aerial_counts$date,
  day_type = example_aerial_counts$day_type,
  stringsAsFactors = FALSE
)

design <- creel_design(
  aerial_cal,
  date        = date,
  strata      = day_type,
  survey_type = "aerial",
  visibility_correction = "none",
  angler_ratio = 1,
  angler_ratio_se = 0,
  h_open      = 14
)

print(design)

## ----effort-no-correction-----------------------------------------------------
design <- add_counts(design, example_aerial_counts)

## ----add-interviews-----------------------------------------------------------
design <- suppressWarnings(add_interviews(
  design,
  example_aerial_interviews,
  catch       = walleye_catch,
  effort      = hours_fished,
  trip_status = trip_status
))

## ----estimate-effort----------------------------------------------------------
effort <- suppressWarnings(estimate_effort(design))
print(effort)

## ----visibility-correction----------------------------------------------------
design_corr <- creel_design(
  aerial_cal,
  date = date,
  strata = day_type,
  survey_type = "aerial",
  h_open = 14,
  visibility_correction = 0.85,
  angler_ratio = 1,
  angler_ratio_se = 0,
  visibility_se = 0.04
)

design_corr <- add_counts(design_corr, example_aerial_counts)
design_corr <- suppressWarnings(add_interviews(
  design_corr,
  example_aerial_interviews,
  catch       = walleye_catch,
  effort      = hours_fished,
  trip_status = trip_status
))

effort_corr <- suppressWarnings(estimate_effort(design_corr))
print(effort_corr)

## ----compare------------------------------------------------------------------
cat(
  "Uncorrected effort:", round(effort$estimate[[1]], 0), "angler-hours\n",
  "Corrected effort (v=0.85):", round(effort_corr$estimate[[1]], 0), "angler-hours\n"
)

## ----catch-rate---------------------------------------------------------------
catch_rate <- suppressWarnings(estimate_catch_rate(design))
print(catch_rate)

## ----total-catch--------------------------------------------------------------
total_catch <- suppressWarnings(estimate_total_catch(design))
print(total_catch)

