Skip to content

About

Cross-species regression on sleep architecture across 42 species — how brain mass, metabolism, and predation shape sleep duration and REM.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Sleep Atlas

A data-driven investigation into sleep duration, REM architecture, and unihemispheric sleep across 42 species — from the giraffe that sleeps two hours to the dolphin that never fully closes its eyes.


Overview

Most people know that bigger animals sleep less. What most people do not know is why a lion sleeps 13.5 hours while a giraffe of similar body mass sleeps only 2. Or why dolphins sleep with half their brain at a time. Or why a platypus spends 60% of its sleep in something that looks like dreaming.

This project builds three regression models to predict sleep phenotypes from ecological traits across 42 species spanning mammals, birds, and reptiles. The goal is not just to predict sleep but to interrogate what the models learn about why sleep evolved differently across ecological niches.


Key Findings

  • Predation risk is the strongest independent ecological predictor of sleep duration (β = +1.67, p < 0.001), stronger than body size once mass is controlled for
  • Metabolic rate drops out of the sleep duration model entirely (p = 0.360) due to collinearity with body mass — the two cannot be separated at cross-species scale
  • Habitat openness predicts unihemispheric sleep with near-perfect accuracy (AUC = 0.995, log-odds = +1.88, p = 0.002) — the same neurological solution evolved independently in cetaceans, pinnipeds, and birds
  • The REM model is deliberately weak (R² = 0.318) — the platypus sits +42 percentage points above the regression line, pointing at phylogenetic structure that ecological features cannot capture
  • Sociality reduces sleep duration (β = −1.58, p = 0.003), consistent with the social sleep hypothesis

Models

Model Method Outcome R² / AUC
Sleep duration OLS regression Hours per day R² = 0.719
REM fraction OLS regression % of sleep in REM R² = 0.318
Unihemispheric sleep Logistic regression Yes / No AUC = 0.995

Predictors (all standardised): log body mass, relative metabolic rate, predator status, sociality index, habitat openness


Dataset

42 species compiled from published sleep literature, including:

  • Mammals: primates, carnivores, ungulates, rodents, bats, cetaceans, pinnipeds, monotremes, marsupials
  • Birds: migratory songbirds, waterfowl, seabirds
  • Reptiles: python, crocodile (ectotherm control cases)

Sleep duration and REM values sourced primarily from Savage & West (2007) and Lesku et al. Ecological predictors coded from published species accounts.


Repository Structure

Sleep-Atlas/
├── sleep_ecology_regression.ipynb   # Full analysis notebook
└── README.md

The notebook is self-contained. It includes the dataset, all model fits, diagnostic plots, partial dependence plots, residual analysis, variance decomposition, and an evolutionary hypothesis summary.


How to Run

Option A — JupyterLab (recommended)

pip install jupyterlab pandas numpy scikit-learn matplotlib seaborn statsmodels
jupyter lab sleep_ecology_regression.ipynb

Option B — Classic Jupyter

pip install jupyter pandas numpy scikit-learn matplotlib seaborn statsmodels
jupyter notebook sleep_ecology_regression.ipynb

Option C — Google Colab (no install)

Upload sleep_ecology_regression.ipynb at colab.research.google.com and run all cells.

Option D — VS Code

Install the Jupyter extension, open the file, click Run All.


Notebook Contents

Cell Contents
1 Imports and setup
2 Dataset (42 species, 8 columns)
3 Exploratory distributions
4 Allometric scatter plot
5 Correlation heatmap
6 VIF multicollinearity check
7 OLS regression — sleep duration
8 OLS regression — REM fraction
9 Logistic regression — unihemispheric sleep
10 Partial dependence plots (all predictors × all outcomes)
11 Residual diagnostics
12 Outlier table with biological notes
13 Incremental R² variance decomposition
14 ROC curve and species probability ranking
15 Evolutionary hypothesis summary

Notable Outliers

Species Model Residual Why
Platypus REM +42 pp Monotreme — ancestral undifferentiated sleep state
White-crowned sparrow Duration −5.2 h Migratory sleep reduction not captured by model
Lion Duration +5.0 h Apex predator in stable pride — lowest-risk sleep environment
Brown bear Duration −5.0 h Hibernation makes annual average meaningless
Crocodile Duration +4.1 h Ectotherm — model assumes endothermy throughout
Orca REM −21 pp Near-zero REM; unihemispheric architecture precludes bilateral REM state

Stack


Related Writing


Limitations

  • n = 42 species is small for the questions being asked
  • Standard OLS treats species as independent observations — phylogenetic structure is not corrected for (PGLS would be the correct next step)
  • Binary predator/prey classification oversimplifies a continuous gradient
  • Sleep values for some species are estimates from limited field data
  • Reptile inclusion assumes metabolic comparability with endotherms, which is not valid

This analysis is hypothesis-generating. The residuals are as informative as the model fits.


Author

Anas — GitHub

Analysis conducted as part of a data science portfolio project combining comparative biology with statistical modelling.

About

Cross-species regression on sleep architecture across 42 species — how brain mass, metabolism, and predation shape sleep duration and REM.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages