randomizations performs data-stream social network randomization. The function accepts a
data.table with relocation data, individual identifiers and a randomization
data.table is randomized either using
daily between-individual methods, or within-individual daily
trajectory method described by Spiegel et al. (2016).
1 2 3
one of 'daily', 'step' or 'trajectory' - see details
Character string of ID column name
generated from spatial grouping functions - see details
Character vector of X coordinate and Y coordinate column names
field used for providing date time or time group - see details
List of fields in DT to split the randomization process by
The number of iterations to randomize
DT must be a
data.table. If your data is a
data.frame, you can convert it by reference using
types are provided:
step - randomizes identities of relocations between individuals within each time step.
daily - randomizes identities of relocations between individuals within each day.
trajectory - randomizes daily trajectories within individuals (Spiegel et al. 2016).
Depending on the
datetime must be a certain format:
step - datetime is integer group created by
daily - datetime is
trajectory - datetime is
datetime, (and optional
splitBy) arguments expect the names of respective columns in
DT which correspond to the individual identifier, date time, and additional grouping columns. The
coords argument is only required when the
type is "trajectory", since the coordinates are required for recalculating spatial groups with
Please note that if the data extends over multiple years, a column indicating the year should be provided to the
splitBy argument. This will ensure randomizations only occur within each year.
group argument is expected only when
type is 'step' or 'daily'.
For example, using
iterations is set to 1 if not provided. Take caution with a large value for
iterations with large input
randomizations returns the random date time or random id along with the original
DT, depending on the randomization
type. The length of the returned
data.table is the original number of rows multiplied by the number of iterations + 1. For example, 3 iterations will return 4x - one observed and three randomized.
Two columns are always returned:
observed - if the rows represent the observed (TRUE/FALSE)
iteration - iteration of rows (where 0 is the observed)
In addition, depending on the randomization type, random ID or random date time columns are returned:
randomID each time step
randomID for each day and
jul indicating julian day
trajectory - a random date time ("random" prefixed to
datetime argument), observed
randomJul indicating the random day relocations are swapped to.
Other Social network tools:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
# Load data.table library(data.table) # Read example data DT <- fread(system.file("extdata", "DT.csv", package = "spatsoc")) # Date time columns DT[, datetime := as.POSIXct(datetime)] DT[, yr := year(datetime)] # Temporal grouping group_times(DT, datetime = 'datetime', threshold = '5 minutes') # Spatial grouping with timegroup group_pts(DT, threshold = 5, id = 'ID', coords = c('X', 'Y'), timegroup = 'timegroup') # Randomization: step randStep <- randomizations( DT, type = 'step', id = 'ID', group = 'group', datetime = 'timegroup', splitBy = 'yr', iterations = 2 ) # Randomization: daily randDaily <- randomizations( DT, type = 'daily', id = 'ID', group = 'group', datetime = 'datetime', splitBy = 'yr', iterations = 2 ) # Randomization: trajectory randTraj <- randomizations( DT, type = 'trajectory', id = 'ID', group = NULL, coords = c('X', 'Y'), datetime = 'datetime', splitBy = 'yr', iterations = 2 )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.