cafi-2019-data

Getting Started with Mo’orea CAFI Data

Welcome! This guide will help you navigate the dataset and start your analysis.


Step 1: Understand the Research Questions

Two Experiments + One Survey, One Goal:

How do cryptic invertebrates (CAFI) affect coral reef ecosystems?

Experiment 1: Maatea Size

Experiment 2: MRB Amount

Survey: Mo’orea-wide


Step 2: Choose Your Files

I want to study… CAFI communities

Use these files:

Key columns:

I want to study… Coral growth

Use these files:

Key columns:

I want to study… Coral physiology

Use these files:

Key columns:

I want to study… Fish communities

Use these files:

Key columns:


Step 3: Load Your Data

In R:

# Set working directory
setwd("path/to/Moorea_Coral_CAFI_Data")

# Load CAFI data
cafi <- read.csv("data/maatea_size_cafi_taxonomy_merged_2019_2021_v2.csv")

# Check structure
str(cafi)
head(cafi)

# Summary statistics
summary(cafi$cafi_size_mm_numeric)  # Use _numeric for calculations

In Python:

import pandas as pd
import os

# Set working directory
os.chdir("path/to/Moorea_Coral_CAFI_Data")

# Load CAFI data
cafi = pd.read_csv("data/maatea_size_cafi_taxonomy_merged_2019_2021_v2.csv")

# Check structure
print(cafi.info())
print(cafi.head())

# Summary statistics
print(cafi['cafi_size_mm_numeric'].describe())  # Use _numeric for calculations

Step 4: Understand Original vs Numeric Columns

The Problem:

Field data often includes non-numeric values that carry meaning:

The Solution:

We provide both columns:

  1. Original column (e.g., cafi_size_mm):
    • Exactly what was written in field notes
    • Preserves all information
    • Use for: Understanding what was recorded
  2. Numeric column (e.g., cafi_size_mm_numeric):
    • Only numeric values (non-numeric → NA)
    • Use for: Calculations, statistics, plots

Example:

# View original data
cafi$cafi_size_mm
#  [1] "8.5"  "<5"   "L"    "12.3" "6.1"  "<1"

# Calculate mean (use numeric column)
mean(cafi$cafi_size_mm_numeric, na.rm = TRUE)
#  [1] 8.97

# How many were too small to measure?
sum(cafi$cafi_size_mm == "<5", na.rm = TRUE)
#  [1] 234

All files share common identifiers:

coral_id - Links everything to a specific coral colony

time_point - Links to sampling time

date - Links to specific date

library(dplyr)

# Load data
cafi <- read.csv("data/maatea_size_cafi_taxonomy_merged_2019_2021_v2.csv")
phys <- read.csv("data/maatea_size_physiology_master_long_2019_2021_v3.csv")

# Count CAFI per colony
cafi_counts <- cafi %>%
  group_by(coral_id) %>%
  summarize(total_cafi = n())

# Merge
merged <- phys %>%
  left_join(cafi_counts, by = "coral_id")

# Analyze
plot(merged$total_cafi, merged$protein_mg_cm2)

Step 6: Handle Missing Data

Missing data codes:

In R:

# Remove NA values
cafi_clean <- cafi[!is.na(cafi$cafi_size_mm_numeric), ]

# Or use na.rm in functions
mean(cafi$cafi_size_mm_numeric, na.rm = TRUE)

In Python:

# Remove NA values
cafi_clean = cafi.dropna(subset=['cafi_size_mm_numeric'])

# Or use skipna in functions
cafi['cafi_size_mm_numeric'].mean(skipna=True)

Step 7: Common Pitfalls & Solutions

Pitfall 1: Using original columns in calculations

# ❌ WRONG - will error on non-numeric values
mean(cafi$cafi_size_mm)
# Error: argument is not numeric or logical

# ✅ CORRECT - use _numeric column
mean(cafi$cafi_size_mm_numeric, na.rm = TRUE)

Pitfall 2: Losing information from “<5” values

# ❌ WRONG - treats as missing
cafi_clean <- cafi[!is.na(cafi$cafi_size_mm_numeric), ]
# Lost 234 observations that were recorded as "<5"!

# ✅ CORRECT - analyze separately or impute
small_cafi <- cafi[cafi$cafi_size_mm == "<5", ]
nrow(small_cafi)  # 234 - these are real observations!

Pitfall 3: Wrong join keys

# ❌ WRONG - will create duplicates
merged <- left_join(cafi, phys, by = "coral_id")
# Problem: Multiple CAFI per coral, wrong matches!

# ✅ CORRECT - aggregate first
cafi_summary <- cafi %>%
  group_by(coral_id, time_point) %>%
  summarize(cafi_count = n())

merged <- left_join(phys, cafi_summary, by = c("coral_id", "time_point"))

Step 8: Check Metadata

For detailed methods, see:


Example Analyses

1. CAFI Diversity by Coral Size

library(dplyr)
library(ggplot2)

# Load data
cafi <- read.csv("data/maatea_size_cafi_taxonomy_merged_2019_2021_v2.csv")
sizes <- read.csv("data/maatea_size_colony_measurements_wide_2019_2021_v1.csv")

# Calculate diversity per colony
diversity <- cafi %>%
  group_by(coral_id) %>%
  summarize(
    richness = n_distinct(family, na.rm = TRUE),
    abundance = n()
  )

# Merge with size data
merged <- left_join(diversity, sizes, by = "coral_id")

# Plot
ggplot(merged, aes(x = sa_june_cm2, y = richness)) +
  geom_point() +
  geom_smooth(method = "lm") +
  labs(x = "Coral Surface Area (cm²)",
       y = "CAFI Family Richness",
       title = "CAFI Diversity Increases with Coral Size")

2. Treatment Effect on Coral Growth

library(dplyr)
library(ggplot2)

# Load data
growth <- read.csv("data/mrb_amount_coral_growth_surface_area_change_v1.csv")
treatments <- read.csv("data/mrb_amount_experimental_treatments_v1.csv")

# Merge
merged <- left_join(growth, treatments, by = "coral_id")

# Summary by treatment
summary_stats <- merged %>%
  group_by(treatment) %>%
  summarize(
    mean_growth = mean(delta_surface_area, na.rm = TRUE),
    se = sd(delta_surface_area, na.rm = TRUE) / sqrt(n()),
    n = n()
  )

# Plot
ggplot(summary_stats, aes(x = treatment, y = mean_growth)) +
  geom_bar(stat = "identity") +
  geom_errorbar(aes(ymin = mean_growth - se, ymax = mean_growth + se), width = 0.2) +
  labs(x = "CAFI Removal Treatment",
       y = "Change in Surface Area (cm²)",
       title = "Effect of CAFI Removal on Coral Growth")

3. Taxonomic Composition

library(dplyr)
library(ggplot2)

# Load data
cafi <- read.csv("data/moorea_survey_cafi_taxonomy_summer_2019_v5.csv")

# Top 10 families
top_families <- cafi %>%
  filter(!is.na(family)) %>%
  count(family, sort = TRUE) %>%
  head(10)

# Plot
ggplot(top_families, aes(x = reorder(family, n), y = n)) +
  geom_bar(stat = "identity") +
  coord_flip() +
  labs(x = "Family",
       y = "Count",
       title = "Top 10 CAFI Families in Mo'orea Survey")


Step 8: Site Locations and Metadata

GPS Coordinates

All study site coordinates are provided in metadata/site_locations.csv

Example - Load in R:

sites <- read.csv("metadata/site_locations.csv")
head(sites)

# MRB site: -17.476703, -149.813681
# Maatea site: -17.599607, -149.808107

Research Team

Team information is in metadata/personnel.csv

Principal Investigators:

Field Team:

Funding Information


Need Help?

Resources:

  1. DATA_DICTIONARY.md - Complete column descriptions
  2. README.md - Repository overview
  3. metadata/ folder - 5 .txt method overviews + 9 .xlsx data dictionaries
  4. metadata/site_locations.csv - GPS coordinates
  5. metadata/personnel.csv - Research team details
  6. GitHub Issues - Ask questions, report problems

Contact:


Happy analyzing! 🐠🪸