forked from AdrienHdz/traveltimeCLT
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commintng missing things form previous commit
- Loading branch information
Mohamad
committed
Nov 26, 2020
1 parent
b40403e
commit fabd4f3
Showing
11 changed files
with
144 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
#' This function allows to predict the travel time estimation on the test set. | ||
#' Predict travel time | ||
#' | ||
#' @param object an output of \code{traveltimeCLT}, of class \code{traveltimeCLT}. | ||
#' @param newdata a data frame of new trips. | ||
#' @param pred.intervals Type of prediction itervals, \code{trip-specific}, \code{population}, or \code{none}. | ||
#' @param level Tolerance levels. | ||
#' \code{predict.traveltimeCLT} predicts expected travel time (ETA) and a prediction interval based on the \code{trip-specific} and \code{population} methods. | ||
#' | ||
#' @param object An output of \code{traveltimeCLT}, of class \code{traveltimeCLT}. | ||
#' @param newdata A data frame of new trips and their road level travel information, formatted as \code{trips}, see \code{trips} or \code{data(trips); View(trips)}. | ||
#' @param level Significance levels. | ||
#' | ||
#' @details Both the \code{trip-specific} and \code{population} prediction intervals are Gaussian-based. | ||
#' | ||
#' @return Returns a data fram that inlcudes the ETA (and optionally the trips variance), with lower and upper prediction intervals (optional), for each trip in the \code{newdata}. | ||
#' @examples | ||
#' \dontrun{ | ||
#' | ||
#'} | ||
#' @import data.table | ||
#' @export | ||
predict.traveltimeCLT <- function(object, newdata, | ||
pred.interval = c('trip-specific', 'population', 'none'), | ||
level = 0.95){ | ||
predict.traveltimeCLT <- function(object, newdata, level = 0.95){ | ||
|
||
interval <- tryCatch(match.arg(pred.interval),error=function(cond){ | ||
stop("Parameter 'pred.interval' should be eiter 'trip-specific', 'population', or 'none'") | ||
}) | ||
|
||
if(!'data.table' %in% class(newdata)) newdata = data.table(newdata)[order(tripID, entry_time)] | ||
|
||
pred = newdata[, predict.traveltimeCLT.trip_specific(entry_time[1], linkID, distance_meters, | ||
object$rho$average_correlation, | ||
object$network_parameters, | ||
finaly.only = TRUE, | ||
pred.type = object$estimate | ||
),by = tripID] | ||
|
||
q = qnorm(level) | ||
if(grepl('both', object$estimate)) | ||
if(grepl('trip-specific', interval)){ | ||
if(grepl('trip-specific', object$model)){ | ||
pred = newdata[, predict.traveltimeCLT.trip_specific(entry_time[1], linkID, distance_meters, | ||
object$network_parameters, object$rho$average_correlation, | ||
finaly.only = TRUE, | ||
pred.type = object$estimate | ||
),by = tripID] | ||
q = qnorm(level) | ||
if(grepl('both', object$estimate)){ | ||
v = sqrt(object$residual_variance) | ||
pred[, lwr := ETA - q * v * sqrt(variance)] | ||
pred[, upr := ETA + q * v * sqrt(variance)] | ||
} | ||
} | ||
if(grepl('population', object$model)) | ||
pred = newdata[, predict.traveltimeCLT.population(.N, object, level = level), | ||
by = tripID] | ||
|
||
return(data.frame(pred)) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.