mob.data.array: Build mobility data array

Description Usage Arguments Value Author(s) See Also Examples

View source: R/hmob_funcs.R

Description

This function builds data arrays of total trip counts from longform mobility data (such as that produced by the parse.longform function). If time=NULL (default), route-level counts are returned. If a vector of times (e.g. week or month) is provided, an additional dimension is added to the array. If a covariate is provided in variable, the function will return total trip counts that are aggregated according to this variable (e.g. trip distance or trip duration).

Usage

1
2
3
4
5
6
7
8
9
mob.data.array(
  orig,
  dest = NULL,
  time = NULL,
  count,
  variable = NULL,
  name,
  agg.int = 1
)

Arguments

orig

a vector of origin districts

dest

a vector of destination districts

time

a vector of the time of each observation (e.g. day, week, month, year). When time = NULL (default), function returns route-level matrix.

count

a vector of total counts of each observation

variable

a vector of covariate values with which to condition trip counts (e.g. distance or trip duration)

name

a character string giving the name of the variable; expects either 'distance', 'duration', 'movement', or 'leave'

agg.int

an integer giving the interval by which to aggregate the given variable, default = 1 (not aggregated). When variable is trip duration, this is the length of generation time (in days). When variable is distance, this is the distance interval in km. Ignored when name is 'movement' or 'leave'.

Value

A 2-, 3-, or 4-dimensional array depending on input parameters. Cells in output array represent total trip counts.

Author(s)

John Giles

See Also

Other data synthesis: calc.prop.tot.trips(), calc.route.type(), calc.samp.size(), get.crossdist(), get.distance.class(), get.distance.counts(), get.distance.matrix(), get.district.names.xy(), get.district.pop(), get.duration.counts(), get.holidays(), get.sparse.mob.matrix(), get.stay.data(), get.subsamp(), get.xy.counts(), parse.longform()

Examples

 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Subset of 5 high pop density and 7 low pop density
df <- read.csv("./data/trip_durations_longform_metadata_12_dists_hi_lo_dens.csv", stringsAsFactors=F)

# Simple route-level movement matrix
m <- mob.data.array(orig=df$from,
                    dest=df$to,
                    count=df$count,
                    name='movement')
str(m)

# Week-level movement matrix
m <- mob.data.array(orig=df$from,
                    dest=df$to,
                    time=df$week,
                    count=df$count,
                    name='movement')
str(m)

# Route-level distance matrix
# Counts total trips that occur with distance intervals of width agg.int km
m <- mob.data.array(orig=df$from,
                    dest=df$to,
                    count=df$count,
                    variable=df$distance,
                    name='distance') # no aggregation so trips represent counts per each 1 km
str(m)

m <- mob.data.array(orig=df$from,
                    dest=df$to,
                    count=df$count,
                    variable=df$distance,
                    agg.int=5, # count trips per 5km intervals
                    name='distance')
str(m)

# Month-level aggregated distance matrix
m <- mob.data.array(orig=df$from,
                    dest=df$to,
                    count=df$count,
                    time=df$month,
                    variable=df$distance,
                    agg.int=5, # count trips per 5km intervals
                    name='distance')
str(m)

# Route-level duration matrix
m <- mob.data.array(orig=df$from,
                    dest=df$to,
                    count=df$count,
                    variable=df$duration,
                    name='duration') # no aggregation so counts represent total trips for all durations in 1 day increments
str(m)

# Month-level aggregated duration matrix 
m <- mob.data.array(orig=df$from,
                    dest=df$to,
                    time=df$month,
                    count=df$count,
                    variable=df$duration,
                    agg.int=3, # aggregated to a generation time of 3 days
                    name='duration')
str(m)

# Total number trips leaving each origin across all times
m <- mob.data.array(orig=df$from,
                    dest=df$to,
                    count=df$count,
                    name='leave')
str(m)

# Total number trips leaving each origin on each day of the year
m <- mob.data.array(orig=df$from,
                    dest=df$to,
                    time=df$doy,
                    count=df$count,
                    name='leave')
str(m)

gilesjohnr/hmob documentation built on Aug. 8, 2020, 1:26 a.m.