calc.route.type: Calculate observed number of trips of each route type

Description Usage Arguments Value Author(s) See Also Examples

View source: R/hmob_funcs.R

Description

This function calculates the observed number of trips of each of the four route types for each temporal unit in a mobility data array. The route types are defined by the population density of the origin and destination districts:

  1. High density to high density (HH)

  2. High density to low density (HL)

  3. Low density to high density (LH)

  4. Low density to low density (LL)

Usage

1
calc.route.type(m, hi, lo, per.route = FALSE)

Arguments

m

A 3-dimensional data array produced by the mob.data.array function containing total trip counts (dimensions are origin, destination, time)

hi

A vector of numerical district IDs in the high population density group

lo

A vector of numerical district IDs in the low population density group

per.route

logical indicating whether or not to scale number of trips by the number of routes in each route type

Value

A five column dataframe. If per.route = FALSE, then counts represent raw number of total trips. If per.route = TRUE, then counts represent total trips per route.

Author(s)

John Giles

See Also

Other data synthesis: calc.prop.tot.trips(), 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(), 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
# Subset of 5 high pop density and 7 low pop density
d <- read.csv("BeyondCommuting2/trip_lengths/trip_durations_longform_metadata_12_dists_hi_lo_dens.csv", stringsAsFactors=F)
pop <- read.csv("./data/population_data.csv")

cutoff <- 980
hi <- pop$ID_2[pop$density >= cutoff]
lo <- pop$ID_2[pop$density < cutoff]

m <- mob.data.array(orig=d$from,
                    dest=d$to,
                    time=d$day, # total trip counts for each unique day
                    count=d$count,
                    name='movement')
str(m)

par(mfrow=c(1,2))

p1 <- calc.route.type(m, hi, lo, per.route=FALSE) # Raw number of trips in each route type

plotrix::violin_plot(p1[,2:5], violin_width = 1, box_width=0.05, 
                     xlab='Route type', ylab='Raw total number trips', main=NULL,
                     x_axis_labels=c('High to high', 'High to low', 'Low to high', 'Low to low'))

p2 <- calc.route.type(m, hi, lo, per.route=TRUE) # Total number of trips per route

plotrix::violin_plot(p2[,2:5], violin_width = 1, box_width=0.05, 
                     xlab='Route type', ylab='Total trips per route', main=NULL,
                     x_axis_labels=c('High to high', 'High to low', 'Low to high', 'Low to low'))

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