R/traveltimeHMM.R
traveltimeHMM.Rd
traveltimeHMM
estimates trip- and link- specific speed parameters from observed average speeds per unique trip and link.
traveltimeHMM( logspeeds = NULL, trips = NULL, timeBins = NULL, linkIds = NULL, data = NULL, nQ = 1L, model = c("HMM", "trip-HMM", "trip", "no-dependence"), tol.err = 10, L = 10L, max.it = 20L, verbose = FALSE, max.speed = NULL, seed = NULL, tmat.p = NULL, init.p = NULL )
logspeeds | A numeric vector of speed observations (in km/h) on the (natural) log-scale. Needs
to be provided if |
---|---|
trips | An integer or character vector of trip ids for each observation of |
timeBins | A character vector of time bins for each observation of |
linkIds | A vector of link ids (route or way) for each observation of |
data | A data frame or equivalent object that contains one column for each of
|
nQ | An integer corresponding to the number of different congestion states that the traversal
of a given link can take corresponding to |
model | Type of model as string, |
tol.err | A numeric variable representing the threshold under which the estimation algorithm will
consider it has reached acceptable estimate values. Default is |
L | An integer minimum number of observations per factor ( |
max.it | An integer for the upper limit of the iterations to be performed by the estimation
algorithm. Default is |
verbose | A boolean that triggers verbose output. Default is |
max.speed | An optional float for the maximum speed in km/h, on the linear scale
(not the log-scale, unlike for |
seed | An optional float for the seed used for the random generation of the first Markov transition matrix
and initial state vector. Default is |
tmat.p | An optional starting value for the Markov transition matrix \(\Gamma\) of size |
init.p | An optional starting value for the Markov initial state vector \(\gamma\)
of size |
traveltimeHMM
returns a list of the following parameters.
a factor of interactions (linkId x timeBin) of length nObs
. Factors are in the format linkId.timeBin
.
a factor of trip IDs.
a transition matrix with rows corresponding to levels(factors)
, and with columns being the row-wise transition matrix of that factor. For example, matrix(tmat[1,], ncol = nQ, nrow = nQ, byrow = TRUE)
is the transition matrix of levels(factors)[1]
. NULL
if hidden Markov modelling is not handled by the selected model type.
a initial state probability matrix with rows corresponding to levels(factors)
, and columns to the nQ
states. NULL
if hidden Markov modelling is not handled by the selected model type.
a matrix of standard deviations estimates for the natural logarithm of the speed (in km/h), with rows corresponding to levels(factors)
, and columns to standard deviation estimates for the nQ
states.
a matrix of mean estimates for the natural logarithm of the speed (in km/h), with rows corresponding to levels(factors)
, and columns to mean estimates for the nQ
states.
a numeric variable for the standard deviation estimate for the trip effect parameter logE
. Equals 1
if trip effect is not handled by the selected model type.
a numeric vector of trip effect estimates corresponding to levels(trip)
. Values are set to 0
if trip effect is not handled by the selected model type. Units are the same as for logspeeds
.
an integer corresponding to the number of different congestion states, equal to the parameter nQ that was passed in the function call.
an integer number of unique time bins.
an integer number of observations.
a character string corresponding to the type of model used.
Woodard, D., Nogin, G., Koch, P., Racz, D., Goldszmidt, M., Horvitz, E., 2017. Predicting travel time reliability using mobile phone GPS data. Transportation Research Part C, 75, 30-44.
# NOT RUN { data(tripset) # Fit an HMM model with 2 hidden congestion states and 20 algorithm iterations fit <- traveltimeHMM(tripset$logspeed, tripset$tripID, tripset$timeBin, tripset$linkID, nQ = 2, max.it = 20) # Perform prediction - use ?predict.traveltime for details single_trip <- subset(tripset, tripID==2700) pred <- predict.traveltime(fit, single_trip,single_trip$time[1]) hist(pred) mean(pred) sum(single_trip$traveltime) ?traveltimeHMM # for help on traveltimeHMM, the estimation function ?predict.traveltime # for help on predict.traveltime, the prediction function # }