get.duration.counts: Get matrix of trip duration counts

Description Usage Arguments Value Author(s) See Also Examples

View source: R/hmob_funcs.R

Description

The get.duration.counts function calculates a matrix or long-form dataframe of trip duration counts for a temporal interval t given an origin a and destination b. Only takes origin district because it uses distances across all destinations.

Usage

1
2
3
4
5
6
7
8
9
get.duration.counts(
  a,
  b,
  t,
  d,
  type = "matrix",
  distID = districtIDs,
  n.cores = NULL
)

Arguments

a

origin district (can take integer ID or character name)

b

destination district (can take integer ID or character name)

t

character string indicating the temporal interval the count trip distances (e.g. 'month', 'week', 'doy')

d

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

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.holidays(), get.sparse.mob.matrix(), get.stay.data(), get.subsamp(), get.xy.counts(), 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
25
26
27
28
29
30
31
data("d.42") # same as ./BeyondCommuting2/trip_lengths/trip_durations_longform_metadata_42.csv
data("districtIDs") # same as NamNames.csv
data("admin2")

orig <- 42 # "Windhoek East"
dest <- 16

# Longform dataframe 
df <- get.duration.counts(a=orig, b=dest, t='month', d=d.42, type='dataframe', n.cores=4)
head(df)

# Same data in matrix format
m <- get.duration.counts(a=orig,              # integer ID of origin district
                         b=dest,              # integer ID of destination district
                         t='month',           # temporal interval (e.g. 'month', 'week', 'doy')
                         d=d.42,              
                         type='matrix',       # return a matrix or long-form dataframe
                         distID=districtIDs,  
                         n.cores=NULL)        # number of cores to run parallel, if NULL, uses half
see(m)

par(mfrow=c(1,2))
trip.map(a=orig, b=dest)
plot3D::hist3D(x=1:nrow(m), y=1:30, z=m[,1:30],
              theta=130, phi=20, scale=F, expand=0.01,
              xlab='Month',
              ylab='Trip duration',
              zlab='Trip count',
              ticktype="detailed",
              space=0.1, lighting=T, light="diffuse", shade = 0.75)
title(get.names(orig, dest), outer=T, line=-3, cex=2)

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