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

## ----build-design, message = FALSE--------------------------------------------
library(tidycreel)

# Load example datasets
data(example_calendar)
data(example_counts)
data(example_interviews)
data(example_catch)
data(example_lengths)

# Step 1: Define the survey calendar and stratification
design <- creel_design(example_calendar, date = date, strata = day_type)

# Step 2: Attach instantaneous count observations
design <- add_counts(design, example_counts)

# Step 3: Attach interview records (all extended v0.5.0 fields)
design <- add_interviews(design, example_interviews,
  catch          = catch_total,
  effort         = hours_fished,
  harvest        = catch_kept,
  trip_status    = trip_status,
  trip_duration  = trip_duration,
  angler_type    = angler_type,
  angler_method  = angler_method,
  species_sought = species_sought,
  n_anglers      = n_anglers,
  refused        = refused
)

# Step 4: Attach species-level catch data
design <- add_catch(design, example_catch,
  catch_uid     = interview_id,
  interview_uid = interview_id,
  species       = species,
  count         = count,
  catch_type    = catch_type
)

# Step 5: Attach fish length data (individual harvest + binned release)
design <- add_lengths(design, example_lengths,
  length_uid     = interview_id,
  interview_uid  = interview_id,
  species        = species,
  length         = length,
  length_type    = length_type,
  count          = count,
  release_format = "binned"
)

print(design)

## ----refusals-----------------------------------------------------------------
summarize_refusals(design)

## ----day-type-----------------------------------------------------------------
summarize_by_day_type(design)

## ----angler-type--------------------------------------------------------------
summarize_by_angler_type(design)

## ----method-------------------------------------------------------------------
summarize_by_method(design)

## ----species-sought-----------------------------------------------------------
summarize_by_species_sought(design)

## ----successful---------------------------------------------------------------
summarize_successful_parties(design)

## ----trip-length--------------------------------------------------------------
summarize_by_trip_length(design)

## ----cws----------------------------------------------------------------------
summarize_cws_rates(design, by = species_sought)

## ----cws-collapsed------------------------------------------------------------
summarize_cws_rates(design, by = NULL)

## ----hws----------------------------------------------------------------------
summarize_hws_rates(design, by = species_sought)

## ----lfreq-harvest------------------------------------------------------------
summarize_length_freq(design, type = "harvest", by = species, bin_width = 25)

## ----lfreq-release------------------------------------------------------------
summarize_length_freq(design, type = "release", by = species)

## ----lfreq-catch--------------------------------------------------------------
summarize_length_freq(design, type = "catch", by = species, bin_width = 25)

## ----cpue-species, message = FALSE--------------------------------------------
estimate_catch_rate(design, by = species)

## ----total-catch-species, message = FALSE-------------------------------------
estimate_total_catch(design, by = species)

## ----total-harvest-species, message = FALSE-----------------------------------
estimate_total_harvest(design, by = species)

## ----release-species, message = FALSE-----------------------------------------
estimate_release_rate(design, by = species)
estimate_total_release(design, by = species)

