DOI: 10.5281/zenodo.17088072
title: Piecewise-continuous sampling: a method for minimizing bias and sampling effort for estimated metrics of animal behavior

description: # Piecewise-continuous sampling: data and code for simulations and figures

**Zenodo record for the dataset and R code** supporting the manuscript:

> *Piecewise-continuous sampling: a method for minimizing bias and sampling effort for estimated metrics of animal behavior* (Ethology, in press, 2025).

This record packages the raw observations, simulation code, and analysis scripts used to evaluate **piecewise-continuous sampling (PCS)**—a strategy that distributes multiple short, continuous observation windows across a larger time span to balance effort and error relative to continuous and instantaneous sampling.

---

## What’s included

- **`all_ant_behaviors.csv`**    Raw behavioral observations for **9 harvester-ant workers**. Each row is a timestamped observation of the task an individual ant was performing.

- **`pcsRandom.R`**    Helper functions for drawing randomized continuous sampling windows (PCS: random placement).

- **`pcsSegmented.R`**    Helper functions for drawing segmented/structured sampling windows (PCS: segmented constraints).

- **`piecewiseContinuousSampling.R`**    **Main simulation driver.** Sources `pcsRandom.R` and `pcsSegmented.R`, runs Monte Carlo simulations of PCS and comparator strategies, and writes **`SimulationResults.csv`**.

- **`finalGraphs.R`**    Analysis + plotting script. Imports **`SimulationResults.csv`** and produces the figures reported in the manuscript (error metrics, trade-offs, desirability analyses).

- **`SimulationResults.csv`**    Output generated by `piecewiseContinuousSampling.R` (included if precomputed; otherwise produced by running the script).

---

## Quick start (reproducibility)

> Requires **R (≥ 4.2 recommended)**.

1. **Install packages (once):**

        install.packages(c(          "dplyr","readr","ggplot2","ggpubr","paletteer","MASS","viridis",          "ggcorrplot","scales","RColorBrewer","tidyr","purrr","stringr","lubridate"        ))

2. **Run simulations** (from the repository root in R):

        -Run piecewiseContinuousSampling.R

        -Output: SimulationResults.csv

3. **Recreate figures/analyses:**

        finalGraphs.R  # reads SimulationResults.csv and outputs manuscript figures

**Tips**- For exact reproducibility, set a seed before simulations (e.g., `set.seed(123)`).- Key parameters (e.g., number of intervals *I*, total sampling time *n*, observation window) are documented at the top of `piecewiseContinuousSampling.R`.

---

## Outputs

- **`SimulationResults.csv`** — Aggregated simulation results (error metrics, effort, strategy settings).- **Figures** — Plots saved by `finalGraphs.R`; filenames/paths are defined within that script.

---

## Background (PCS in brief)

Continuous sampling captures fine temporal structure but is labor-intensive; instantaneous sampling reduces effort but may miss fine-scale dynamics. **Piecewise-continuous sampling (PCS)** strikes a balance by distributing multiple short, continuous intervals across a broader window, enabling researchers to tune effort vs. error. Simulations here compare PCS variants with continuous and instantaneous sampling under matched total observation times, summarizing multi-objective trade-offs via desirability functions.

---

## Metadata

**Version:** 1.0.0  **Date:** 2025

---

## Methodological notes

- Simulations compare PCS variants to continuous and instantaneous sampling under matched total observation time.  - Error metrics are computed on behavioral features defined in the scripts using `all_ant_behaviors.csv` and repeated draws to estimate variability.  - Trade-offs between effort and error are summarized via desirability functions, following the manuscript.

---

### Manuscript citation (APA, in press)

Lynch, C. M., Bespalova, I., Harrison, J. F., Pratt, S. C., Pavlic, T. P., & Fewell, J. H. (2025). Piecewise-continuous sampling: A method for minimizing bias and sampling effort for estimated metrics of animal behavior. *Ethology.* Advance online publication.