predict.traveltimeHMM: Predict the travel time for a trip using a 'traveltimeHMM'...

View source: R/predict.R

predict.traveltimeHMMR Documentation

Predict the travel time for a trip using a traveltimeHMM model object

Description

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.

Usage

## S3 method for class 'traveltimeHMM'
predict(
  object,
  tripdata,
  starttime = Sys.time(),
  n = 1000,
  logE = NULL,
  time_bins.fun = time_bins,
  ...
)

Arguments

object

A model object (a list) provided through the execution of function timetravelHMM. The list includes information on model as well as estimates for its parameters. See timetravelHMM man page.

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. logE normally needs to be a numerical vector of size n. If a single numerical value is supplied, it will be replicated into a vector. If logE is NULL the function will use either a vector of simulated values (if the model is from the trip family), or a vector of 0 otherwise. Default is NULL. NOTE: when simulating values for the vector, the value for τ is taken from the model object.

time_bins.fun

A functional to map real time to specified time bins, see '?rules2timebins'.

...

not used.

Details

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.

Value

predict.traveltimeHMM returns a numerical vector of size n representing the point prediction of total travel time, in seconds, for each run.

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.

Examples

## 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

## End(Not run)

melmasri/traveltimeHMM documentation built on Jan. 6, 2023, 10:30 p.m.