From a6bdd49abbf082aae520004d1a3dbaf353d79f3e Mon Sep 17 00:00:00 2001 From: Mohamad Date: Wed, 25 Nov 2020 22:35:33 -0500 Subject: [PATCH] small fixes --- DESCRIPTION | 3 +- NAMESPACE | 6 +- R/predict.R | 32 +-- R/traveltimeHMM.R | 2 +- R/zzz.R | 0 README.md | 12 +- docs/articles/traveltimeHMM.html | 14 +- docs/index.html | 14 +- docs/reference/index.html | 2 +- docs/reference/predict.traveltimeHMM.HMM.html | 191 ++++++++++++++ docs/reference/predict.traveltimeHMM.html | 236 ++++++++++++++++++ .../predict.traveltimeHMM.no_dependence.html | 199 +++++++++++++++ docs/reference/time_bins_functional.html | 6 +- docs/reference/traveltimeHMM.html | 24 +- ...me.HMM.Rd => predict.traveltimeHMM.HMM.Rd} | 11 +- ...traveltime.Rd => predict.traveltimeHMM.Rd} | 27 +- ...=> predict.traveltimeHMM.no_dependence.Rd} | 21 +- man/time_bins_functional.Rd | 6 +- man/traveltimeHMM.Rd | 22 +- man/tripset.Rd | 6 +- 20 files changed, 751 insertions(+), 83 deletions(-) create mode 100644 R/zzz.R create mode 100644 docs/reference/predict.traveltimeHMM.HMM.html create mode 100644 docs/reference/predict.traveltimeHMM.html create mode 100644 docs/reference/predict.traveltimeHMM.no_dependence.html rename man/{predict.traveltime.HMM.Rd => predict.traveltimeHMM.HMM.Rd} (85%) rename man/{predict.traveltime.Rd => predict.traveltimeHMM.Rd} (78%) rename man/{predict.traveltime.no_dependence.Rd => predict.traveltimeHMM.no_dependence.Rd} (82%) diff --git a/DESCRIPTION b/DESCRIPTION index 670e514..cf2d79c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -26,7 +26,7 @@ BugReports: https://github.com/melmasri/traveltimeHMM/issues License: GPL-3 Encoding: UTF-8 LazyData: true -RoxygenNote: 6.1.1 +RoxygenNote: 7.1.1 Suggests: testthat, knitr, @@ -41,4 +41,3 @@ Suggests: kableExtra VignetteBuilder: knitr Depends: R (>= 2.10) - diff --git a/NAMESPACE b/NAMESPACE index 70a35df..7ec8807 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,8 +1,8 @@ # Generated by roxygen2: do not edit by hand -S3method(predict,traveltime) -S3method(predict,traveltime.HMM) -S3method(predict,traveltime.no_dependence) +S3method(predict,traveltimeHMM) +S3method(predict,traveltimeHMM.HMM) +S3method(predict,traveltimeHMM.no_dependence) export(forwardback) export(gaussian_param_by_factor) export(getValidE) diff --git a/R/predict.R b/R/predict.R index bc6c3fb..9f0898c 100644 --- a/R/predict.R +++ b/R/predict.R @@ -1,12 +1,12 @@ #' Predict the travel time for a trip using a \code{traveltimeHMM} model object #' -#' \code{predict.traveltime} performs a point prediction by simulation using parameter estimates provided by a \code{traveltimeHMM} model object. +#' \code{predict.traveltimeHMM} performs a point prediction by simulation using parameter estimates provided by a \code{traveltimeHMM} model object. #' Prediction can be performed for a single trip only. #' #' The function begins by validating and, if required, replacing the value of the parameter \code{logE} #' (see explanation alongside \code{logE} in the \emph{Arguments} section). It then transfers execution -#' to the appropriate function according to the selected model: \code{predict.traveltime.HMM} for -#' models of the \code{HMM} family, or \code{predict.traveltime.no_dependence} otherwise. +#' to the appropriate function according to the selected model: \code{predict.traveltimeHMM} for +#' models of the \code{HMM} family, or \code{predict.traveltimeHMM.no_dependence} otherwise. #' #' @param object A model object (a list) provided through the execution of function \code{timetravelHMM}. #' The list includes information on model as well as estimates for its parameters. @@ -27,7 +27,7 @@ #' @param time_bins.fun A functional to map real time to specified time bins, see `?rules2timebins`. #' @param ... not used. #' -#' @return \code{predict.traveltime} returns a numerical vector of size \code{n} representing the point prediction of total travel time, in seconds, for each run. +#' @return \code{predict.traveltimeHMM} returns a numerical vector of size \code{n} representing the point prediction of total travel time, in seconds, for each run. #' #' @examples #' \dontrun{ @@ -41,19 +41,19 @@ #' single_trip <- subset(tripset, tripID==2700) #' #' # We need to supply the time stamp of the very first link traversal (third parameter) -#' pred <- predict.traveltime(fit, single_trip,single_trip$time[1]) +#' pred <- predict(fit, single_trip,single_trip$time[1]) #' #' hist(pred) # histogram of prediction samples #' mean(pred) # travel time point estimate #' sum(single_trip$traveltime) # observed travel time #' #' ?traveltimeHMM # for help on traveltimeHMM, the estimation function -#' ?predict.traveltime # for help on predict.traveltime, the prediction function +#' ?predict.traveltimeHMM # for help on predict.traveltimeHMM, the prediction function #' } #' @references #' {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.} #' @export -predict.traveltime<-function(object, tripdata, starttime = Sys.time(), n = 1000, logE = NULL,time_bins.fun = time_bins, ... ){ +predict.traveltimeHMM<-function(object, tripdata, starttime = Sys.time(), n = 1000, logE = NULL,time_bins.fun = time_bins, ... ){ # We first perform basic checks. 'tripdata' must be a list, data frame or data table # that minimally includes objects 'linkID' and 'length', the latter having @@ -66,18 +66,18 @@ predict.traveltime<-function(object, tripdata, starttime = Sys.time(), n = 1000 stop('length of objects do not match!') # Models of the HMM family ('HMM', 'trip-HMM') are handled by function 'predict.traveltime.HMM' - # whilst others are handled by function 'predict.traveltime.no_dependence' + # whilst others are handled by function 'predict.traveltimeHMM.no_dependence' # (both functions are below). if(grepl('HMM', object$model)) - predict.traveltime.HMM(object, tripdata, starttime, n, logE, time_bins = time_bins.fun, ...) + predict.traveltimeHMM.HMM(object, tripdata, starttime, n, logE, time_bins = time_bins.fun, ...) else - predict.traveltime.no_dependence(object, tripdata , starttime, n, logE, time_bins = time_bins.fun, ...) + predict.traveltimeHMM.no_dependence(object, tripdata , starttime, n, logE, time_bins = time_bins.fun, ...) } #' Predict the travel time for a trip using a \code{traveltimeHMM} model object that is not of the HMM family #' @keywords internal #' -#' \code{predict.traveltime.no_dependence} performs a point prediction by simulation using parameter estimates provided by a \code{traveltimeHMM} model object that is not of the \code{HMM} family (see man page for \code{predict.traveltime}). +#' \code{predict.traveltimeHMM.no_dependence} performs a point prediction by simulation using parameter estimates provided by a \code{traveltimeHMM} model object that is not of the \code{HMM} family (see man page for \code{predict.traveltimeHMM}). #' #' The function implements Algorithm 2 from Woodard et al., 2017. However, the state transition matrix #' and initial state probability vector are not handled as they were not generated at the estimation stage. @@ -95,13 +95,13 @@ predict.traveltime<-function(object, tripdata, starttime = Sys.time(), n = 1000 #' @param time_bins a functional map between real time and time bins, see `?rules2timebins`. #' @param ... not used. #' -#' @return \code{predict.traveltime.no_dependence} returns a vector of size \code{n} of representing the point prediction of total travel time, in seconds, for each run. +#' @return \code{predict.traveltimeHMM.no_dependence} returns a vector of size \code{n} of representing the point prediction of total travel time, in seconds, for each run. #' #' @importFrom stats rnorm runif #' @references #' {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.} #' @export -predict.traveltime.no_dependence <- function(object, tripdata, starttime, n = 1000, logE = NULL, time_bins = time_bins, ...) { +predict.traveltimeHMM.no_dependence <- function(object, tripdata, starttime, n = 1000, logE = NULL, time_bins = time_bins, ...) { linkIds = tripdata$linkID # Contains IDs of all links for a given trip len = tripdata$length # Contains the length (in km) of each link in 'linkIds' logE <- getValidE(object, logE, n) # Get a valid vector for 'logE'; see comments in function for details. @@ -143,7 +143,7 @@ predict.traveltime.no_dependence <- function(object, tripdata, starttime, n = 10 #' Predict the travel time for a trip using a \code{traveltimeHMM} model object of the HMM family #' @keywords internal #' -#' \code{predict.traveltime.HMM} performs a point prediction by simulation using parameter estimates provided by a \code{traveltimeHMM} model object of the \code{HMM} family (see man page for \code{predict.traveltime}). +#' \code{predict.traveltime.HMM} performs a point prediction by simulation using parameter estimates provided by a \code{traveltimeHMM} model object of the \code{HMM} family (see man page for \code{predict.traveltimeHMM}). #' #' The function implements Algorithm 2 from Woodard et al., 2017, including its handling #' of the state transition matrix and initial state probability vector. @@ -161,13 +161,13 @@ predict.traveltime.no_dependence <- function(object, tripdata, starttime, n = 10 #' @param time_bins a functional map between real time and time bins, see `?rules2timebins`. #' @param ... not used. #' -#' @return \code{predict.traveltime.HMM} returns a vector of size \code{n} of representing the point prediction of total travel time, in seconds, for each run. +#' @return \code{predict.traveltimeHMM.HMM} returns a vector of size \code{n} of representing the point prediction of total travel time, in seconds, for each run. #' #' @importFrom stats rnorm runif #' @references #' {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.} #' @export -predict.traveltime.HMM <- function(object, tripdata, starttime, n, logE, time_bins = time_bins, ...) { +predict.traveltimeHMM.HMM <- function(object, tripdata, starttime, n, logE, time_bins = time_bins, ...) { linkIds = tripdata$linkID # Contains IDs of all links for a given trip len = tripdata$length # Contains the length (in km) of each link in 'linkIds' logE <- getValidE(object, logE, n) # Get a valid vector for 'logE'; see comments in function for details. diff --git a/R/traveltimeHMM.R b/R/traveltimeHMM.R index 99f9329..a55325f 100644 --- a/R/traveltimeHMM.R +++ b/R/traveltimeHMM.R @@ -445,7 +445,7 @@ traveltimeHMM <- function(logspeeds = NULL, trips = NULL, timeBins = NULL, linkI nB = nB, nObs = nObs, model = model) - class(obj) <- append(class(obj),"traveltime", after=0) + class(obj) <- append(class(obj),"traveltimeHMM", after=0) invisible(obj) } diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index f3f8ffd..2e6c1cb 100644 --- a/README.md +++ b/README.md @@ -37,12 +37,12 @@ library(traveltimeHMM) data(tripset) head(tripset) #> tripID linkID timeBin logspeed traveltime length time -#> 1 2700 10469 Weekday 1.692292 13.000000 70.61488 2014-04-28 03:07:27 -#> 2 2700 10444 Weekday 2.221321 18.927792 174.50487 2014-04-28 03:07:41 -#> 3 2700 10460 Weekday 2.203074 8.589937 77.76295 2014-04-28 03:07:58 -#> 4 2700 10462 Weekday 1.924290 14.619859 100.15015 2014-04-28 03:08:07 -#> 5 2700 10512 Weekday 1.804293 5.071986 30.81574 2014-04-28 03:08:21 -#> 6 2700 5890 Weekday 2.376925 31.585355 340.22893 2014-04-28 03:08:26 +#> 1 2700 10469 Weekday 1.692292 13.000000 70.61488 2014-04-28 06:07:27 +#> 2 2700 10444 Weekday 2.221321 18.927792 174.50487 2014-04-28 06:07:41 +#> 3 2700 10460 Weekday 2.203074 8.589937 77.76295 2014-04-28 06:07:58 +#> 4 2700 10462 Weekday 1.924290 14.619859 100.15015 2014-04-28 06:08:07 +#> 5 2700 10512 Weekday 1.804293 5.071986 30.81574 2014-04-28 06:08:21 +#> 6 2700 5890 Weekday 2.376925 31.585355 340.22893 2014-04-28 06:08:26 ``` To fit a simple `HMM` model use the following code diff --git a/docs/articles/traveltimeHMM.html b/docs/articles/traveltimeHMM.html index 8edcad5..e978941 100644 --- a/docs/articles/traveltimeHMM.html +++ b/docs/articles/traveltimeHMM.html @@ -71,7 +71,7 @@

Introduction to traveltimeHMM: making reliable travel time predictions on road networks

Mohamad Elmasri, Aurélie Labbe, Denis Larocque, Laurent Charlin and Éric Germain

-

2019-09-03

+

2020-11-25

Source: vignettes/traveltimeHMM.Rmd @@ -98,12 +98,12 @@

data(tripset) head(tripset) #> tripID linkID timeBin logspeed traveltime length time -#> 1 2700 10469 Weekday 1.692292 13.000000 70.61488 2014-04-28 03:07:27 -#> 2 2700 10444 Weekday 2.221321 18.927792 174.50487 2014-04-28 03:07:41 -#> 3 2700 10460 Weekday 2.203074 8.589937 77.76295 2014-04-28 03:07:58 -#> 4 2700 10462 Weekday 1.924290 14.619859 100.15015 2014-04-28 03:08:07 -#> 5 2700 10512 Weekday 1.804293 5.071986 30.81574 2014-04-28 03:08:21 -#> 6 2700 5890 Weekday 2.376925 31.585355 340.22893 2014-04-28 03:08:26 +#> 1 2700 10469 Weekday 1.692292 13.000000 70.61488 2014-04-28 06:07:27 +#> 2 2700 10444 Weekday 2.221321 18.927792 174.50487 2014-04-28 06:07:41 +#> 3 2700 10460 Weekday 2.203074 8.589937 77.76295 2014-04-28 06:07:58 +#> 4 2700 10462 Weekday 1.924290 14.619859 100.15015 2014-04-28 06:08:07 +#> 5 2700 10512 Weekday 1.804293 5.071986 30.81574 2014-04-28 06:08:21 +#> 6 2700 5890 Weekday 2.376925 31.585355 340.22893 2014-04-28 06:08:26

Travel data is organized around the notions of trips and links. Links are road segments each with well-defined beginning and end points and which can be traversed. A vehicle performs a trip when it travels from a start point to an end point through a sequence of links. Thus trips can be considered as ordered sequences of links. tripset includes data for a collection of trips.