Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dyadic pairing with GPS data #7

Closed
qwebber opened this issue Jan 3, 2019 · 2 comments · Fixed by #27
Closed

dyadic pairing with GPS data #7

qwebber opened this issue Jan 3, 2019 · 2 comments · Fixed by #27
Labels
type: enhancement new features, improvements

Comments

@qwebber
Copy link
Contributor

qwebber commented Jan 3, 2019

It would be interesting to have a function that detects the number of consecutive relocations for a pair of individuals (dyad) based on the buffer/threshold setting provided in group_times.

@robitalec robitalec added the type: enhancement new features, improvements label Jan 3, 2019
@robitalec
Copy link
Member

Cool Quinn!
What kinds of definitions would be useful for dyad pairs?
Simply n consecutive grouping from group_pts for a pair of individuals?

@robitalec
Copy link
Member

robitalec commented Mar 25, 2020

This has been initially implemented by dyad_id. Further plans to extend to triads, etc if there is interest.

For now, the workflow is generate edges, and assign a dyad id.

# Load packages
library(spatsoc)
library(data.table)

# Read example data
DT <- fread(system.file("extdata", "DT.csv", package = "spatsoc"))

# Cast the character column to POSIXct
DT[, datetime := as.POSIXct(datetime, tz = 'UTC')]

# Temporal grouping
group_times(DT, datetime = 'datetime', threshold = '20 minutes')

# Edge list generation
edges <- edge_dist(
  DT,
  threshold = 100,
  id = 'ID',
  coords = c('X', 'Y'),
  timegroup = 'timegroup',
  returnDist = TRUE,
  fillNA = TRUE
)

# Generate dyad IDs
dyad_id(edges, 'ID1', 'ID2')

After assigning a dyadID, we can measure things like consecutive relocations together, start and end times, mean X Y for dyads, etc. (vignette coming)

# How many observations of each dyad? (N / 2 because edges have both A->B and B->A)
edges[, .N / 2, dyadID]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement new features, improvements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants