Project2 Presentation

A look at the questions asked

Questions:

  1. Can we use movement variables to distinguish in-flight vs perching?
  2. Of the in-flight points:
  • Are there distinct flight behaviors?

  • What are the characteristics of these behaviors?

  • What are some visual examples of flight segments?

The Eagle Data

'data.frame':   2093022 obs. of  15 variables:
 $ Animal_ID     : int  105 105 105 105 105 105 105 105 105 105 ...
 $ TimeDiff      : int  5 6 5 6 5 6 5 5 5 6 ...
 $ segment_id    : num  1 1 1 1 1 1 1 1 1 1 ...
 $ segment_length: int  10 10 10 10 10 10 10 10 10 10 ...
 $ LocalTime     : POSIXlt, format: "2019-06-25 16:44:10" "2019-06-25 16:44:16" ...
 $ Latitude      : num  41.6 41.6 41.6 41.6 41.6 ...
 $ Longitude     : num  -92.9 -92.9 -92.9 -92.9 -92.9 ...
 $ X             : num  509745 509746 509747 509747 509747 ...
 $ Y             : num  4609596 4609597 4609597 4609599 4609598 ...
 $ KPH           : num  0.07 0.07 0.2 0.16 0.11 0.07 0.09 0.05 0.07 0.25 ...
 $ Sn            : num  0.52 0.17 0.14 0.22 0.08 0.22 0.32 0.11 0.16 0.07 ...
 $ AGL           : num  9.55 9.55 9.55 9.55 11.55 ...
 $ VerticalRate  : num  -0.99 0 0 0 0.39 0 -0.19 -0.19 -0.2 -0.33 ...
 $ abs_angle     : num  0.45 0.21 0.91 3.14 2.69 0.53 0.58 0.58 2.15 0.14 ...
 $ absVR         : num  0.99 0 0 0 0.39 0 0.19 0.19 0.2 0.33 ...

Question 1 Background

  • Variables: KPH, Sn, AGL, abs_angle, VerticalRate, absVR

  • Square-root transformation to stabilize variance

  • Standardization (scaling)

  • K-means clustering with 2 centers (perch vs flight)

Question 2 Background (Just in flight points)

  • Elbow method to choose k (large sample)

  • Final choice: k = 3 clusters for behaviors was 4

  • Visualize in PCA space later

Question 1 findings

  • Can we use movement variables to distinguish in-flight vs perching?

in_flight     perch 
  1672459    420563 

Question 2 — Are there distinct flight behaviors?

Question 2 — What are the characteristics of these behaviors?

Question 2 — Visual examples of flight segments

Appendix

# Libraries
library(ggplot2)
library(dplyr)

# Load data
tmp_env <- new.env()
load("eagle_data.Rdata", envir = tmp_env)
eagle <- tmp_env[[ls(tmp_env)[1]]]

# Preprocessing
vars <- c("KPH", "Sn", "AGL", "abs_angle", "VerticalRate", "absVR")
sqrt_vars <- c("KPH", "Sn", "AGL", "abs_angle", "absVR")
for (v in sqrt_vars) {
  eagle[[v]] <- sqrt(pmax(eagle[[v]], 0))
}
feat <- eagle[, vars]
feat_scaled <- scale(feat)

# Q1: in-flight vs perch
set.seed(11)
km2 <- kmeans(feat_scaled, centers = 2, nstart = 25)
centroid_speeds <- tapply(feat_scaled[, "KPH"], km2$cluster, mean)
flight_cluster <- which.max(centroid_speeds)
eagle$movement_state <- ifelse(km2$cluster == flight_cluster, "in_flight", "perch")

# Elbow method (in-flight only)
inflight_idx <- which(eagle$movement_state == "in_flight")
X_f <- feat_scaled[inflight_idx, ]
set.seed(11)
sample_idx <- sample(seq_len(nrow(X_f)), min(100000, nrow(X_f)))
X_sample <- X_f[sample_idx, ]
wss <- numeric(10)
for (k in 1:10) {
  km <- kmeans(X_sample, centers = k, nstart = 10)
  wss[k] <- km$tot.withinss
}

# Q2: 4 behavior clusters
set.seed(11)
km_behaviors <- kmeans(X_f, centers = 4, nstart = 25)
eagle$flight_behavior <- NA_integer_
eagle$flight_behavior[inflight_idx] <- km_behaviors$cluster

# Behavior summary
behavior_summary <- aggregate(
  feat[inflight_idx, ],
  by = list(behavior = eagle$flight_behavior[inflight_idx]),
  FUN = function(x) c(mean = mean(x), sd = sd(x))
)

# Visual examples
example_segments <- eagle %>%
  filter(movement_state == "in_flight") %>%
  group_by(flight_behavior) %>%
  slice_head(n = 200) %>%
  ungroup() %>%
  mutate(LocalTime_ct = as.POSIXct(LocalTime))