traveltimeHMM
model objectR/predict.R
predict.traveltimeHMM.Rd
predict.traveltimeHMM
performs a point prediction by simulation using parameter estimates provided by a traveltimeHMM
model object.
Prediction can be performed for a single trip only.
# S3 method for traveltimeHMM predict( object, tripdata, starttime = Sys.time(), n = 1000, logE = NULL, time_bins.fun = time_bins, ... )
object | A model object (a list) provided through the execution of function |
---|---|
tripdata | A data frame of road links with information on each link's traversal. Columns minimally include objects 'linkID' and 'length', and the latter must have the same length. Rows must be in chronological order. The program assumes that the sequence of road links forms a coherent and feasible path. No verification is performed to that effect. |
starttime | The start date and time for the very first link of the trip, in POSIXct format. Default is the current date and time. |
n | Number of samples. Default is 1000. |
logE | Point estimate of trip effects. |
time_bins.fun | A functional to map real time to specified time bins, see `?rules2timebins`. |
... | not used. |
predict.traveltimeHMM
returns a numerical vector of size n
representing the point prediction of total travel time, in seconds, for each run.
The function begins by validating and, if required, replacing the value of the parameter logE
(see explanation alongside logE
in the Arguments section). It then transfers execution
to the appropriate function according to the selected model: predict.traveltimeHMM
for
models of the HMM
family, or predict.traveltimeHMM.no_dependence
otherwise.
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 a model - use ?traveltimeHMM for details fit <- traveltimeHMM(tripset$logspeed, tripset$tripID, tripset$timeBin, tripset$linkID, nQ = 2, max.it = 10) # Perform a prediction for trip #2700 using the fitted model. single_trip <- subset(tripset, tripID==2700) # We need to supply the time stamp of the very first link traversal (third parameter) 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.traveltimeHMM # for help on predict.traveltimeHMM, the prediction function # }