# Research data and code: Marsh terns (Chlidonias) diet and foraging

## Study title
Multidimensional niche partitioning between two sympatric marsh terns: chick diet and foraging habitat use

## Study summary
This repository contains the raw data and R code used to analyse (1) chick diet (prey delivered to nestlings) and
(2) adult foraging habitat use in sympatrically breeding White-winged Terns (*Chlidonias leucopterus*) and Black Terns
(*Chlidonias niger*) in the Bug River valley (eastern Poland).

The package is anonymised for peer review (no personal identifiers; colonies and nests are coded by ID only).

## Folder overview
- `data/`
  - `chick_diet_raw.csv` – prey items identified to order from nest video recordings (raw table).
  - `foraging_observations_raw.csv` – counts of foraging adults from repeated 2-minute transect scans (raw table).
- `code/`
  - `chick_diet/scripts/` – PERMANOVA, NMDS, niche metrics and GLMMs for chick diet.
  - `foraging/scripts/` – GLMM for habitat use, post-hoc contrasts and figures.
  - `foraging/run_all_original.R` – original helper script from the foraging code bundle (kept for provenance).
- `outputs/`
  - Empty by default. Running scripts will write intermediate objects and figures here.
- `docs/`
  - Original README files supplied with the separate code bundles (kept for provenance).

## Data files and metadata

### `data/chick_diet_raw.csv`
Each row is a prey item delivered to a nestling during video recording and identified to order.
Prey were identified to order without separating life stage (larva vs imago). Fish (`Pisces`) were treated as a single
group (not resolved to order).

Columns:
- `ID` – nest identifier (unique code).
- `day` – day of season (integer, as in the manuscript).
- `year` – year of recording.
- `species` – tern species (`niger` or `leucopterus`).
- `prey` – prey order (or `Pisces`).
- `n_chicks` – brood size at the time of recording.
- `age_chicks` – chick age (days; as used in analyses).

### `data/foraging_observations_raw.csv`
Each row is a single 2-minute transect scan for a given colony-session and habitat type.

Columns:
- `id` – colony identifier (unique code).
- `localisation` – locality label (as in the manuscript).
- `year` – year of observation.
- `season` – season progression (days since 1 June, as used in analyses).
- `hour` – observation time (decimal hours, as used in analyses).
- `species` – tern species (`niger` or `leucopterus`).
- `habitat` – habitat type (`meadow`, `oxbow`, `river`; naming follows the manuscript/code).
- `foraging` – number of foraging individuals recorded in the 2-minute scan.
- `breeding` – estimated number of breeding pairs in the colony (species-specific), recorded after each session.

## Software and package versions
Analyses were run in R (see manuscript for the R version used). To reproduce results on your system, run in R:

- `sessionInfo()` to capture your R version and package versions.

The scripts load the required packages directly. If you use a package management system (e.g. `renv`), you can adapt
the workflow accordingly.

## How to run the analyses
1. Download/unzip this repository and set the working directory to the repository root.
2. Run the scripts in order:

### Chick diet
Run, in order:
- `code/chick_diet/scripts/01_PERMANOVA_no_weather.R`
- `code/chick_diet/scripts/02_NMDS.R`
- `code/chick_diet/scripts/03_Niche_metrics.R`
- `code/chick_diet/scripts/04_GLMM_orders.R`

### Foraging habitat use
Run, in order:
- `code/foraging/scripts/01_import_and_prep.R`
- `code/foraging/scripts/02_model.R`
- `code/foraging/scripts/03_posthoc_and_plots.R`

Outputs (tables/figures and intermediate R objects) will be written to `outputs/`.

## Notes
- File names are intentionally short and descriptive.
- Raw data are provided prior to filtering or statistical transformations; all transformations are performed in code.
