get.xy.counts: Get counts of any two variables (e.g. distance vs duration)

Description Usage Arguments Value Author(s) See Also Examples

View source: R/hmob_funcs.R

Description

The get.xy.counts function counts the number of trips made conditioned on two variables (x.var and y.var) in the data set. This is set up to explore how trip duration counts vary with other variables in the data set (e.g. distance, district population size). Can be restricted to an origin district a or all origins a = NULL.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
get.xy.counts(
  a,
  d,
  x.var,
  y.var = "duration",
  x.int,
  y.int,
  type = "matrix",
  distID = districtIDs,
  n.cores = NULL
)

Arguments

a

origin district (can take integer ID or character name)

d

longform mobility data, expects d.42 data object (trip_durations_longform_metadata_42.csv) or similar

x.var

name of x variable

y.var

name of y variable (default = 'duration')

x.int

interval for aggregating x variable

y.int

interval for aggregating y variable

type

return a 'matrix' or a 'dataframe' with counts in longform (default = 'matrix')

distID

district IDs and names, expects districtIDs data object (NamNames.csv), default = districtIDs

n.cores

number cores to use when parallel computing (default = NULL, which uses half available cores)

Value

matrix or dataframe

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(), mob.data.array(), 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
data("d.42") # same as ./BeyondCommuting2/trip_lengths/trip_durations_longform_metadata_42.csv
data("districtIDs") # same as NamNames.csv

orig <- 42 # "Windhoek East"

# trip counts over distance and trip duration for an origin
m <- get.xy.counts(a=orig,               # integer ID of origin district
                   d=d.42,                  # expects "trip_durations_longform2.csv" or similar
                   x.var='distance',
                   y.var='duration',
                   x.int=50,             # distance interval for aggregating distance in km
                   y.int=50,             # duration interval for aggregating duration in days
                   type='matrix',
                   distID=districtIDs,
                   n.cores=4)
see(m)

plot3D::hist3D(x=as.numeric(rownames(m)), y=as.numeric(colnames(m)), z=log(m+1), 
               theta=120, phi=30, scale=F, expand=50,
               xlab='Distance',
               ylab='Duration',
               zlab='Log trip count',
               ticktype="detailed",
               space=0.05, lighting=T, light="diffuse")

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