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

Observation-based timegroups #18

Open
rrmn opened this issue Jun 6, 2019 · 1 comment
Open

Observation-based timegroups #18

rrmn opened this issue Jun 6, 2019 · 1 comment
Assignees
Labels
type: enhancement new features, improvements type: support

Comments

@rrmn
Copy link

rrmn commented Jun 6, 2019

Hi @robitalec ,

let's take the following case

datetime <- as.POSIXct(c("2019-06-01 00:00:01",
                         "2019-06-01 00:01:38",
                         "2019-06-01 00:05:49",
                         "2019-06-01 00:06:01",
                         "2019-06-01 00:07:59",
                         "2019-06-01 00:11:04"), tz = "UTC")
user <- c(rep("A", 5), "B")

dt <- data.table(datetime, user)

What I would like to find out is whether there are any records of users that are <= 5 minutes apart from a record of another user (and also colocated, but let's leave that out for the moment)

The spatsoc way would be to slice the datetime into 5 minute pieces and see if records fall into those.

group_times(dt, datetime = "datetime", threshold = "5 minutes")

Result

              datetime user minutes  imegroup
1: 2019-06-01 00:00:01    A       0         1
2: 2019-06-01 00:01:38    A       0         1
3: 2019-06-01 00:05:49    A       5         2
4: 2019-06-01 00:06:01    A       5         2
5: 2019-06-01 00:07:59    A       5         2
6: 2019-06-01 00:11:04    B      10         3

This, however, puts rows 5 and 6 into different groups — although their observations are within the defined threshold. So, in the end, I would rather like to get something like

              datetime user timegroup
1: 2019-06-01 00:07:59    A         1
2: 2019-06-01 00:11:04    B         1

or even

          ego_datetime ego_user      alter_datetime alter_user
1: 2019-06-01 00:07:59        A 2019-06-01 00:11:04          B      

Are there any plans to do something like this? Or maybe I've missed something in the library?

There are robust methods to deal with that type of stuff, but they are quite brute-force (copious use of left joins...) and maybe / probably there is a more efficient way.

@robitalec
Copy link
Member

Hey @RomanAbashin,
The reason spatsoc was developed to work with the logic of "nearest to a fixed interval" is because animal GPS data is often collected on a fixed interval. I really appreciate your recent questions because it's helping to push the package to fit a broader and more complete application! (Thanks)

From #15, @RomanAbashin:

Having that in mind, would maybe something like a time_dist make sense for #18

The challenge I see if we try and apply this within 5 minutes without a fixed interval, is when it comes to building a network or using the downstream spatsoc functions. Functions like group_pts and group_lines use the timegroups, to take chunks of the larger data and measure distance between points or spatial overlap of lines. By using an individual-centric time grouping as opposed to a fixed interval, it scrambles the way we take these chunks (as spatsoc is designed right now).

A time_dist (likely edge_time) type function similar to edge_dist would be really neat because we'd be able to combine temporal and spatial edge-lists, that follow a similar workflow as group_times and group_pts. This way, we wouldn't need to alter the current group_* functions.

I have some ideas (a two-pass group_times and the wonderful data.table::foverlaps), I'll keep you posted.

@robitalec robitalec self-assigned this Jun 7, 2019
@robitalec robitalec added type: enhancement new features, improvements type: support labels Jun 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement new features, improvements type: support
Projects
None yet
Development

No branches or pull requests

2 participants