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

## ----design, warning = FALSE--------------------------------------------------
library(tidycreel)

data(example_sections_calendar)
data(example_sections_counts)
data(example_sections_interviews)

sections_df <- data.frame(
  section = c("North", "Central", "South"),
  stringsAsFactors = FALSE
)

design <- creel_design(example_sections_calendar, date = date, strata = day_type)
design <- add_sections(design, sections_df, section_col = section)
design <- add_counts(design, example_sections_counts)
design <- add_interviews(
  design, example_sections_interviews,
  catch = catch_total,
  effort = hours_fished,
  harvest = catch_kept,
  trip_status = trip_status,
  trip_duration = trip_duration
)
print(design)

## ----effort-------------------------------------------------------------------
effort_est <- estimate_effort(design)
print(effort_est$estimates)

## ----catch_rate, warning = FALSE----------------------------------------------
cpue_est <- estimate_catch_rate(design)
print(cpue_est$estimates)

## ----catch_rate_lake, warning = FALSE-----------------------------------------
# Lake-wide catch rate: build an unsectioned design using the same data
design_nosections <- creel_design(example_sections_calendar, date = date, strata = day_type)
design_nosections <- add_counts(design_nosections, example_sections_counts)
design_nosections <- add_interviews(
  design_nosections, example_sections_interviews,
  catch = catch_total, effort = hours_fished,
  harvest = catch_kept, trip_status = trip_status, trip_duration = trip_duration
)
estimate_catch_rate(design_nosections)$estimates

## ----total_catch, warning = FALSE---------------------------------------------
catch_est <- estimate_total_catch(design, aggregate_sections = TRUE)
print(catch_est$estimates)

## ----total_harvest, warning = FALSE-------------------------------------------
harvest_est <- estimate_total_harvest(design, aggregate_sections = TRUE)
print(harvest_est$estimates)

## ----variance_methods---------------------------------------------------------
# Default: accounts for cross-section covariance (shared-calendar designs)
estimate_effort(design, method = "correlated")$estimates

# Alternative: Cochran 5.2 additivity (independent crews, non-overlapping calendars)
estimate_effort(design, method = "independent")$estimates

## ----missing_section, warning = TRUE------------------------------------------
north_central_counts <- example_sections_counts[
  example_sections_counts$section != "South",
]

design_missing <- creel_design(example_sections_calendar, date = date, strata = day_type)
design_missing <- add_sections(design_missing, sections_df, section_col = section)
design_missing <- suppressWarnings(add_counts(design_missing, north_central_counts))

estimate_effort(design_missing, missing_sections = "warn")$estimates

