diff --git a/DESCRIPTION b/DESCRIPTION index fd9b54c..24d70ec 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,7 +11,7 @@ Imports: stats, utils, graphics, methods, lattice, sp (>= 1.1-0), spacetime (>= 1.0-0), zoo Suggests: rgdal, rgeos, OpenStreetMap, RCurl, rjson, adehabitatLT, xts, knitr, rgl, forecast, MASS, spatstat, taxidata -Description: Classes and methods for trajectory data, with support for nesting individual Track objects in track sets (Tracks) and track sets for different entities in collections of Tracks. Methods include selection, generalization, aggregation, intersection, simulation, and plotting. +Description: Classes and methods for trajectory data, with support for nesting individual Track objects in track sets (Tracks) and track sets for different entities in collections of Tracks. Methods include selection, generalization, aggregation, intersection, simulation, and plotting. It further includes exploratory methods such as Kernel smoothing, Voronoi tessellation, distance analysis, K- and pair correlation functions. License: GPL (>= 2) URL: http://github.com/edzer/trajectories Additional_repositories: http://pebesma.staff.ifgi.de @@ -19,7 +19,7 @@ BugReports: http://github.com/edzer/trajectories/issues VignetteBuilder: knitr Collate: Class-Tracks.R Tracks-methods.R generalize.R stcube.R stplot.R difftrack.R compare-methods.R rtracks.R Trackstat.R -RoxygenNote: 6.0.1 +RoxygenNote: 7.0.2 NeedsCompilation: no Packaged: 2018-09-25 11:59:22 UTC; edzer Author: Edzer Pebesma [aut, cre] (), diff --git a/NAMESPACE b/NAMESPACE index b87441d..0f9c992 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -29,7 +29,9 @@ export( approxTrack, approxTracks, approxTracksCollection, rTrack, rTracks, rTracksCollection, as.Track, as.Track.arrow, as.Track.ppp, auto.arima.Track, avedistTrack, avemove, chimaps, - Kinhom.Track, pcfinhom.Track, reTrack, Track.idw, tsqTracks + Kinhom.Track, pcfinhom.Track, reTrack, + tsqTracks,unique.Track,as.list.Tracks,as.list.TracksCollection,range.Track, + idw.Track ) exportMethods( @@ -64,6 +66,17 @@ S3method(plot, arwlen) S3method(print, summary.Track) S3method(print, summary.Tracks) S3method(print, summary.TracksCollection) +S3method("as", "list.Tracks") +S3method("as", "list.TracksCollection") +S3method("unique", "Track") +S3method(range, Track) +S3method(range, Tracks) +S3method(range, TracksCollection) +S3method(stack, TracksCollection) +S3method(unstack, TracksCollection) +S3method(c, Track) +S3method(c, Tracks) +S3method(c, TracksCollection) S3method(print, arwlen) S3method(print, distrack) S3method(print, gTrack) diff --git a/R/Class-Tracks.R b/R/Class-Tracks.R index 19704e5..32c9a34 100644 --- a/R/Class-Tracks.R +++ b/R/Class-Tracks.R @@ -43,8 +43,9 @@ TrackStats = function(track) { stopifnot(!any(duration == 0)) # if (class(try(cc <- coordinates(track), silent=TRUE)) == "try-error" || # !is.matrix(cc)) - if (!is(track@sp, "SpatialPoints")) - data.frame(matrix(nrow = length(track@sp) - 1, ncol = 0)) # empty + if (!is(track@sp, "SpatialPoints")){ + data.frame(matrix(nrow = length(track@sp) - 1, ncol = 0)) # empty + } else { cc = coordinates(track@sp) ll = identical(is.projected(track), FALSE) @@ -100,7 +101,7 @@ TrackSummary = function(track) { ix = index(track@time) bb = bbox(track@sp) conn = track@connections - data.frame( + d <- data.frame( xmin = bb[1,1], xmax = bb[1,2], ymin = bb[2,1], @@ -112,6 +113,8 @@ TrackSummary = function(track) { medspeed = quantile(conn$speed, 0.5) # TODO Compute some mean direction? ) + rownames(d) <- NULL + d } # Pre-computes elements of tracksData. diff --git a/R/Tracks-methods.R b/R/Tracks-methods.R index 82defdf..6e194f9 100644 --- a/R/Tracks-methods.R +++ b/R/Tracks-methods.R @@ -20,7 +20,7 @@ setAs("Tracks", "segments", function(from) { ret = do.call(rbind, lapply(from@tracks, function(x) as(x, "segments"))) ret$Track = rep(names(from@tracks), - times = sapply(from@tracks, length) - 1) + times = sapply(from@tracks, dim) - 1) ret } ) @@ -42,7 +42,7 @@ setAs("Track", "data.frame", setAs("Tracks", "data.frame", function(from) { - l = lapply(from@tracks, function(x) rbind(as(x, "data.frame"), NA)) + l = lapply(from@tracks, function(x) as(x, "data.frame")) d = do.call(rbind, l) d$Track = rep(names(from@tracks), times = sapply(l, nrow)) d @@ -230,6 +230,7 @@ plot.TracksCollection <- function(x, y, ..., xlim = stbox(x)[,1], plot(as(x, "SpatialLines"), xlim = xlim, ylim = ylim, axes = axes, col = col, lwd = lwd, lty = lty, add = add, ...) } + setMethod("plot", "TracksCollection", plot.TracksCollection) setMethod("plot", "Tracks", function(x, ...) plot(TracksCollection(list(x)), ...)) @@ -378,10 +379,6 @@ summary.Tracks = function(object, ...) { obj } -setMethod("show", "Track", function(object) print.Track(object)) -setMethod("show", "Tracks", function(object) print.Tracks(object)) -setMethod("show", "TracksCollection", function(object) print.TracksCollection(object)) - setMethod("summary", "Tracks", summary.Tracks) print.summary.Tracks = function(x, ...) { @@ -439,14 +436,20 @@ print.summary.TracksCollection = function(x, ...) { invisible(x) } +# Provide show methods. + +setMethod("show", "Track", function(object) print.Track(object)) +setMethod("show", "Tracks", function(object) print.Tracks(object)) +setMethod("show", "TracksCollection", function(object) print.TracksCollection(object)) + # Provide selection methods. -subs.Track <- function(x, i, j, ..., drop = TRUE) { - Track(as(x, "STIDF")[i, j, ..., drop = drop]) +subs.Track <- function(x, i, ..., drop = TRUE) { + Track(as(x, "STIDF")[i, ..., drop = drop]) } setMethod("[", "Track", subs.Track) -subs.Tracks <- function(x, i, j, ... , drop = TRUE) { +subs.Tracks <- function(x, i, ... , drop = TRUE) { if (missing(i)) i = 1:length(x@tracks) else if (is(i, "Spatial")) @@ -461,34 +464,34 @@ subs.Tracks <- function(x, i, j, ... , drop = TRUE) { if (!any(i)) NULL else - Tracks(x@tracks[i], x@tracksData[i, j, drop=FALSE]) + Tracks(x@tracks[i]) } } setMethod("[", "Tracks", subs.Tracks) -subs.TracksCollection <- function(x, i, j, ... , drop = TRUE) { - if (!missing(j) && is.character(j)) { - for(tz in seq_along(x@tracksCollection)) { - for(t in seq_along(x[tz]@tracks)) { - data = x[tz][t]@data - connections = x[tz][t]@connections - if(j %in% names(data)) - data = data[j] - else - # An empty data slot is returned if the passed attribute - # does not exist. The same applies to the connections slot. - data = data.frame(matrix(nrow = dim(x[tz][t])["geometries"], ncol = 0)) - if(j %in% names(connections)) - connections = connections[j] - else - connections = data.frame(matrix(nrow = dim(x[tz][t])["geometries"] - 1, ncol = 0)) - # Write back the just processed data and connection slots. - x@tracksCollection[[tz]]@tracks[[t]]@data = data - x@tracksCollection[[tz]]@tracks[[t]]@connections = connections - } - } - } +subs.TracksCollection <- function(x, i, ... , drop = TRUE) { + # if (!missing(j) && is.character(j)) { + # for(tz in seq_along(x@tracksCollection)) { + # for(t in seq_along(x[tz]@tracks)) { + # data = x[tz][t]@data + # connections = x[tz][t]@connections + # if(j %in% names(data)) + # data = data[j] + # else + # # An empty data slot is returned if the passed attribute + # # does not exist. The same applies to the connections slot. + # data = data.frame(matrix(nrow = dim(x[tz][t])["geometries"], ncol = 0)) + # if(j %in% names(connections)) + # connections = connections[j] + # else + # connections = data.frame(matrix(nrow = dim(x[tz][t])["geometries"] - 1, ncol = 0)) + # # Write back the just processed data and connection slots. + # x@tracksCollection[[tz]]@tracks[[t]]@data = data + # x@tracksCollection[[tz]]@tracks[[t]]@connections = connections + # } + # } + # } if (missing(i)) s = 1:length(x@tracksCollection) else if (is(i, "Spatial")) @@ -531,8 +534,10 @@ subs.TracksCollection <- function(x, i, j, ... , drop = TRUE) { setMethod("[", "TracksCollection", subs.TracksCollection) + + setMethod("[[", c("Track", "ANY", "missing"), - function(x, i, j, ...) { + function(x, i, ...) { # TODO What if the attribute name coexists in both the data and # connections slot? Returning a list is inconvenient in the way that it # raises new design issues when making selections on objects of class @@ -548,19 +553,19 @@ setMethod("[[", c("Track", "ANY", "missing"), ) setMethod("[[", c("Tracks", "ANY", "missing"), - function(x, i, j, ...) { - do.call(c, lapply(x@tracks, function(t) t[[i]])) + function(x, i, ...) { + do.call(list, lapply(x@tracks, function(t) t[[i]])) } ) setMethod("[[", c("TracksCollection", "ANY", "missing"), - function(x, i, j, ...) { - do.call(c, lapply(x@tracksCollection, function(t) t[[i]])) + function(x, i, ...) { + do.call(list, lapply(x@tracksCollection, function(t) t[[i]])) } ) setReplaceMethod("[[", c("Track", "ANY", "missing", "ANY"), - function(x, i, j, value) { + function(x, i, value) { if (i %in% names(x@connections)) { warning(paste("replacing", i, "in connections slot")) x@connections[[i]] = value @@ -571,7 +576,7 @@ setReplaceMethod("[[", c("Track", "ANY", "missing", "ANY"), ) setReplaceMethod("[[", c("Tracks", "ANY", "missing", "ANY"), - function(x, i, j, value) { + function(x, i,value) { for(index in seq_along(x@tracks)) { if(i %in% names(x[index]@data)) { # "dim" (and with that "from" and "to") have to be reinitialized @@ -594,7 +599,7 @@ setReplaceMethod("[[", c("Tracks", "ANY", "missing", "ANY"), ) setReplaceMethod("[[", c("TracksCollection", "ANY", "missing", "ANY"), - function(x, i, j, value) { + function(x, i,value) { index = 1 for(tz in seq_along(x@tracksCollection)) { for(t in seq_along(x[tz]@tracks)) { @@ -719,11 +724,11 @@ setMethod("spTransform", c("TracksCollection", "CRS"), # include.lowest = FALSE, right = TRUE, dig.lab = 3, # ordered_result = FALSE, ...) -cut.Track = function(x, breaks, ..., include.lowest = TRUE, touch = TRUE) { - i = index(x) +cut.Track = function(track, breaks, ..., include.lowest = TRUE, touch = TRUE) { + i = index(track) f = cut(i, breaks, ..., include.lowest = include.lowest) - d = dim(x) # nr of pts - x = as(x, "STIDF") + d = dim(track) # nr of pts + x = as(track, "STIDF") if (! touch) spl = lapply(split(x = seq_len(d), f), function(ind) x[ind, , drop = FALSE]) else @@ -736,10 +741,10 @@ cut.Track = function(x, breaks, ..., include.lowest = TRUE, touch = TRUE) { Tracks(lapply(spl[sapply(spl, length) > 1], Track)) } -cut.Tracks = function(x, breaks, ...) do.call(c, lapply(x@tracks, cut, breaks = breaks, ...)) +cut.Tracks = function(tr, breaks, ...) do.call(c, lapply(tr@tracks, cut, breaks = breaks, ...)) -cut.TracksCollection = function(x, breaks, ...) - TracksCollection(lapply(x@tracksCollection, cut, breaks = breaks, ...)) +cut.TracksCollection = function(tc, breaks, ...) + TracksCollection(lapply(tc@tracksCollection, cut, breaks = breaks, ...)) "index<-.Track" = function(x, value) { index(x@time) = value diff --git a/R/Trackstat.R b/R/Trackstat.R index 8636ea6..5918cfc 100644 --- a/R/Trackstat.R +++ b/R/Trackstat.R @@ -1,12 +1,12 @@ -as.list.Tracks <- function(x,...){ - stopifnot(class(x)=="Tracks") - return(as.list(x@tracks,...)) +as.list.Tracks <- function(tr,...){ + stopifnot(class(tr)=="Tracks") + return(as.list(tr@tracks,...)) } -as.list.TracksCollection <- function(x,...){ - stopifnot(class(x)=="TracksCollection") - out <- lapply(X=1:length(x@tracksCollection), function(i){ - as.list.Tracks(x@tracksCollection[[i]],...) +as.list.TracksCollection <- function(tc,...){ + stopifnot(class(tc)=="TracksCollection") + out <- lapply(X=1:length(tc@tracksCollection), function(i){ + as.list.Tracks(tc@tracksCollection[[i]],...) }) return(unlist(out, recursive=FALSE)) } @@ -65,22 +65,40 @@ reTrack <- function(X,at=c("track","dfrm"),timestamp=timestamp,tsq=NULL){ # range.Track returns the timerange of an object of class Track range.Track <- function(X,...) { - Y <- cbind(as.data.frame(X)[c(coordnames(X), "time")]) - return(range(Y$time,...)) + out <- as.data.frame(X) + return(range(out$time,...)) } +range.Tracks <- function(X,...) { + out <- lapply(X@tracks,as.data.frame) + out <- do.call(rbind,out) + return(range(out$time,...)) +} + +range.TracksCollection <- function(X,...) { + outf <- list() + for (i in 1:length(X@tracksCollection)) { + out <- lapply(X@tracksCollection[[i]]@tracks,as.data.frame) + outf[[i]] <- do.call(rbind,out) + } + outf <- do.call(rbind,outf) + + return(range(outf$time,...)) +} # tsqtracks returns a sequance of time based on a list of tracks (or a single object of class Track) and an argument timestamp -tsqTracks <- function(X, timestamp){ +tsqTracks <- function(X, timestamp,from=NULL,to=NULL){ + + if(!(is.null(from) & is.null(to))) { + return(seq(from=as.POSIXct(strftime(from)),to=as.POSIXct(strftime(to)),by = timestamp)) + } + if(class(X)=="Track" | class(X)=="Tracks" | class(X)=="TracksCollection") timerange <- range(X) - timerange = if (is.list(X)) - lapply(X, range.Track) - else - range.Track(X) + if(class(X)=="list") timerange <- lapply(X, range) ; timerange <- range(timerange) - Trackrg <- range(timerange) - class(Trackrg) <- c('POSIXt','POSIXct') + class(timerange) <- c('POSIXct','POSIXt') # a seq from the range has been created every timestamp - timeseq <- seq(from=as.POSIXct(strftime(Trackrg[1])),to=as.POSIXct(strftime(Trackrg[2])),by = timestamp) + if (missing(timestamp)) stop("set timestamp") + timeseq <- seq(from=as.POSIXct(strftime(timerange[1])),to=as.POSIXct(strftime(timerange[2])),by = timestamp) return(timeseq) @@ -117,13 +135,13 @@ avedistTrack <- function(X,timestamp){ attr(avedist,"tsq") <- attr(Y,"tsq") return(avedist) } -print.distrack <- function(x, ...){ - print(as.vector(x), ...) +print.distrack <- function(x){ + print(as.vector(x)) } plot.distrack <- function(x,...){ x = unclass(x) - plot(attr(x,"tsq"), x, xlab="time",ylab="average distance",...) + plot(attr(x,"tsq"), x, xlab="time",ylab=expression(italic(bar(D))),...) } @@ -134,14 +152,14 @@ unique.Track <- function(x,...){ } -as.Track.ppp <- function(X,timestamp){ +as.Track.ppp <- function(X,timestamp,...){ stopifnot(class(X)=="list" | class(X)=="Tracks" | class(X)=="TracksCollection") if(class(X)=="Tracks") X <- as.list.Tracks(X) if (class(X)=="TracksCollection") X <- as.list.TracksCollection(X) stopifnot(length(X)>1 & is.list(X)) - + if (!requireNamespace("spatstat", quietly = TRUE)) stop("spatstat required: install first?") @@ -151,14 +169,21 @@ as.Track.ppp <- function(X,timestamp){ timeseq <- tsqTracks(X,timestamp = timestamp) # reconstruct tracks in sequance timeseq - Z <- lapply(X,reTrack,tsq = timeseq,at="dfrm") + Z <- lapply(X=1:length(X), function(j){ + i <- index(X[[j]]) + i1 <- max(i) + i2 <- min(i) + seq <- timeseq[timeseqi2] + cbind(as.data.frame(approxTrack(X[[j]],seq,...)@sp),t=seq) + }) + id <- rep(1:length(Z),sapply(Z, nrow)) Z <- do.call("rbind",Z) Z <- cbind(Z,id) allZ <- split(Z,Z[,3]) - dx <- (max(Z$xcoor)-min(Z$xcoor))/1000 - dy <- (max(Z$ycoor)-min(Z$ycoor))/1000 - w <- spatstat::owin(c(min(Z$xcoor)-dx,max(Z$xcoor)+dx),c(min(Z$ycoor)-dy,max(Z$ycoor)+dy)) + dx <- (max(Z$x)-min(Z$x))/1000 + dy <- (max(Z$y)-min(Z$y))/1000 + w <- spatstat::owin(c(min(Z$x)-dx,max(Z$x)+dx),c(min(Z$y)-dy,max(Z$y)+dy)) Tppp <- lapply(X=1:length(allZ), function(i){ p <- spatstat::as.ppp(allZ[[i]][,-c(3,4)],W=w) @@ -170,12 +195,12 @@ as.Track.ppp <- function(X,timestamp){ return(Tppp) } -print.ppplist <- function(x,...){ +print.ppplist <- function(x){ attributes(x) <- NULL - print(x, ...) + print(x) } -density.list <- function(x, timestamp, ...) { +density.list <- function(x, timestamp, method=c("kernel","Voronoi"), Fun=mean, ...) { stopifnot(class(x)=="list" | class(x)=="Tracks" | class(x)=="TracksCollection") if(class(x)=="Tracks") x <- as.list.Tracks(x) @@ -185,18 +210,28 @@ density.list <- function(x, timestamp, ...) { if (!requireNamespace("spatstat", quietly = TRUE)) stop("spatstat required: install first?") - if (missing(timestamp)) stop("set timestamp") + if (missing(timestamp)) stop("set timestamp") + if(missing(method)) method <- "kernel" p <- as.Track.ppp(x, timestamp) p <- p[!sapply(p, is.null)] - imlist <- lapply(p, spatstat::density.ppp, ...) - out <- Reduce("+", imlist) / length(imlist) + if(any(method == "kernel")){ + imlist <- lapply(p, spatstat::density.ppp, ...) + } + else{ + imlist <- lapply(p, spatstat::densityVoronoi, ...) + } + out <- sapply(imlist,"[") + out <- apply(out,1,Fun) + out <- spatstat::as.im(matrix(out,nrow=nrow(imlist[[1]]),ncol(imlist[[1]]))) + + # out <- Reduce("+", imlist) / length(imlist) attr(out, "Tracksim") <- imlist attr(out, "ppps") <- p return(out) } -as.Track.arrow <- function(X,timestamp,epsilon=epsilon){ +as.Track.arrow <- function(X,timestamp,epsilon=0){ stopifnot(class(X)=="list" | class(X)=="Tracks" | class(X)=="TracksCollection") if(class(X)=="Tracks") X <- as.list.Tracks(X) @@ -237,12 +272,12 @@ as.Track.arrow <- function(X,timestamp,epsilon=epsilon){ return(Y) } -print.Trrow <- function(x, ...) { +print.Trrow <- function(x) { attributes(x) <- NULL - print(x, ...) + print(x) } -Track.idw <- function(X,timestamp,epsilon=epsilon,...){ +idw.Track <- function(X,timestamp,epsilon=0,Fun=mean,...){ stopifnot(class(X)=="list" | class(X)=="Tracks" | class(X)=="TracksCollection") if(class(X)=="Tracks") X <- as.list.Tracks(X) @@ -254,11 +289,18 @@ Track.idw <- function(X,timestamp,epsilon=epsilon,...){ Y <- as.Track.arrow(X,timestamp,epsilon=epsilon) Z <- lapply(Y, spatstat::idw, ...) - meanIDW <- Reduce("+",Z)/length(Z) - return(meanIDW) + + out <- sapply(Z,"[") + out <- apply(out,1,Fun) + out <- spatstat::as.im(matrix(out,nrow=nrow(Z[[1]]),ncol(Z[[1]]))) + + attr(out, "idws") <- Z + + # meanIDW <- Reduce("+",Z)/length(Z) + return(out) } -avemove <- function(X,timestamp,epsilon=epsilon){ +avemove <- function(X,timestamp,epsilon=0){ stopifnot(class(X)=="list" | class(X)=="Tracks" | class(X)=="TracksCollection") if(class(X)=="Tracks") X <- as.list.Tracks(X) @@ -281,8 +323,8 @@ avemove <- function(X,timestamp,epsilon=epsilon){ return(out) } -print.arwlen <- function(x, ...){ - print(as.vector(x), ...) +print.arwlen <- function(x){ + print(as.vector(x)) } plot.arwlen <- function(x,...){ @@ -325,8 +367,8 @@ chimaps <- function(X,timestamp,rank,...){ } Kinhom.Track <- function(X,timestamp, - correction=c("border", "bord.modif", "isotropic", "translate"),q, - sigma=c("default","bw.diggle","bw.ppl"," bw.scott"),...){ + correction=c("border", "bord.modif", "isotropic", "translate"),q=0, + sigma=c("default","bw.diggle","bw.ppl"," bw.scott"),...){ stopifnot(class(X)=="list" | class(X)=="Tracks" | class(X)=="TracksCollection") @@ -392,8 +434,8 @@ Kinhom.Track <- function(X,timestamp, attr(out,"out") <- out return(out) } -print.KTrack <- function(x, ...){ - print("variability area of K-function", ...) +print.KTrack <- function(x){ + print("variability area of K-function") } plot.KTrack <- function(x,type="l",col= "grey70",cex=1,line=2.2,...){ @@ -401,15 +443,19 @@ plot.KTrack <- function(x,type="l",col= "grey70",cex=1,line=2.2,...){ stop("spatstat required: install first?") ylim <- c(min(c(x$lowk,x$theo)),max(c(x$upk,x$theo))) plot(x$r,x$lowk,ylim=ylim,type=type,ylab="",xlab="r",...) - title(ylab=expression(K[inhom](r)),line = line,...) + title(ylab=expression(italic(K[inhom](r))),line = line,...) points(x$r,x$upk,type=type) polygon(c(x$r, rev(x$r)), c(x$upk, rev(x$lowk)), col = col, border = NA) points(x$r,x$theo,type=type,col=2) points(x$r,x$avek,type=type) - legend(0,max(c(x$upk,x$theo)),col = c(2,0,1), - legend=c(expression(K[inhom]^{pois}),"",expression(bar(K)[inhom])), - lty=c(1,1),cex = cex) + legend(0,max(c(x$upk,x$theo)),col = c(2,1,"grey70","grey70"), + legend=c(expression(italic(K[inhom]^{pois})), + expression(italic(bar(K)[inhom])), + expression(italic({hat(K)[inhom]^{high}}(r))), + expression(italic({hat(K)[inhom]^{low}}(r))) + ), + lty=c(1,1,1,1),cex = cex) } pcfinhom.Track <- function(X,timestamp, @@ -454,7 +500,7 @@ pcfinhom.Track <- function(X,timestamp, Z <- attr(ZZ,"Tracksim") Y <- attr(ZZ,"ppps") - + g <- lapply(X=1:length(Y), function(i){ gg <- spatstat::pcfinhom(Y[[i]],lambda = Z[[i]],correction=cor,...) return(as.data.frame(gg)) @@ -482,8 +528,8 @@ pcfinhom.Track <- function(X,timestamp, } -print.gTrack <- function(x, ...){ - print("variability area of pair correlatio function", ...) +print.gTrack <- function(x){ + print("variability area of pair correlatio function") } plot.gTrack <- function(x,type="l",col= "grey70",cex=1,line=2.2,...){ @@ -491,25 +537,28 @@ plot.gTrack <- function(x,type="l",col= "grey70",cex=1,line=2.2,...){ stop("spatstat required: install first?") ylim <- c(min(x$lowg),max(x$upg)) plot(x$r,x$lowg,ylim=ylim,xlab="r",ylab="",type=type,...) - title(ylab=expression(g[inhom](r)),line = line,...) + title(ylab=expression(italic(g[inhom](r))),line = line,...) points(x$r,x$upg,type=type) polygon(c(x$r, rev(x$r)), c(x$upg, rev(x$lowg)), col = col, border = NA) points(x$r,x$theo,type=type,col=2) points(x$r,x$aveg,type=type) - legend(0.01*max(x$r),max(x$upg),col = c(2,0,1), - legend=c(expression(g[inhom]^{pois}),"", - expression(bar(g)[inhom])), - lty=c(1,1),cex=cex) + legend(0.01*max(x$r),max(x$upg),col = c(2,1,"grey70","grey70"), + legend=c(expression(italic(g[inhom]^{pois})), + expression(italic(bar(g)[inhom])), + expression(italic({hat(g)[inhom]^{high}}(r))), + expression(italic({hat(g)[inhom]^{low}}(r))) + ), + lty=c(1,1,1,1),cex=cex) } -auto.arima.Track <- function(X,...){ +auto.arima.Track <- function(track,...){ if (! requireNamespace("forecast", quietly = TRUE)) stop("package forecast required, please install it first") - - stopifnot(class(X)=="Track") - xseries <- coordinates(X)[,1] - yseries <- coordinates(X)[,2] + + stopifnot(class(track)=="Track") + xseries <- coordinates(track)[,1] + yseries <- coordinates(track)[,2] xfit <- forecast::auto.arima(xseries,...) yfit <- forecast::auto.arima(yseries,...) @@ -520,7 +569,7 @@ auto.arima.Track <- function(X,...){ return(out) } -print.ArimaTrack <- function(x, ...){ +print.ArimaTrack <- function(x){ attributes(x) <- NULL cat("Arima model fitted to x-coordinate: "); cat(paste0(x[[1]]),"\n") diff --git a/R/compare-methods.R b/R/compare-methods.R index ee0f6b1..5b80da3 100644 --- a/R/compare-methods.R +++ b/R/compare-methods.R @@ -119,6 +119,7 @@ frechetDist <- function(track1, track2) { if (!identicalCRS(track1, track2)) stop("CRS are not identical!") dists <- spDists(track1@sp, track2@sp) #dists between all points + if(all(diag(dists)==0)){return(0)} dists[,1] <- cummax(dists[,1]) # cases where one of the trajectories is a point dists[1,] <- cummax(dists[1,]) for (i in 2:nrow(dists)) { # build rest of frechet distance matrix @@ -126,7 +127,8 @@ frechetDist <- function(track1, track2) { dists[i,j] <- max(dists[i,j], min(dists[i-1,j], dists[i-1,j-1], dists[i,j-1])) } } - max(xts::last(xts::last(dists))) + min(max(xts::last(xts::last(dists))),max(xts::last(xts::last(t(dists))))) + # max(xts::last(xts::last(dists))) } diff --git a/R/generalize.R b/R/generalize.R index df2f4cd..aae7d3c 100644 --- a/R/generalize.R +++ b/R/generalize.R @@ -78,8 +78,9 @@ generalize.Track <- function(t, FUN = mean, ..., timeInterval, distance, n, tol, # in the "endTime" slot of STIDF objects does not work properly. attr(endTime, "tzone") = tz stidf@endTime = endTime + warning(paste("connections are only calculated for SpatialPoints")) Track(stidf) -} + } if(!isGeneric("generalize")) setGeneric("generalize", function(t, FUN = mean, ...) diff --git a/R/rtracks.R b/R/rtracks.R index 2c6a553..a354621 100644 --- a/R/rtracks.R +++ b/R/rtracks.R @@ -1,5 +1,5 @@ rTrack <- function (n = 100, origin = c(0, 0), start = as.POSIXct("1970-01-01"), - ar = 0.8, step = 60, sd0 = 1,bbox=bbox, transform=FALSE,nrandom=FALSE, ...){ + ar = 0.8, step = 60, sd0 = 1,bbox=bbox, transform=FALSE,nrandom=FALSE,...){ if(nrandom) repeat{n <- rpois(1,n);if(!n==0) break()} if (missing(bbox) & transform) { @@ -14,12 +14,12 @@ rTrack <- function (n = 100, origin = c(0, 0), start = as.POSIXct("1970-01-01"), } if (length(ar) == 1 && ar == 0) xy = cbind(x=cumsum(rnorm(n, sd = sd0)) + origin[1], y=cumsum(rnorm(n, - sd = sd0)) + origin[2]) + sd = sd0)) + origin[2]) else {xy = cbind(x=origin[1] + cumsum(as.vector(arima.sim(list(ar = ar), - n, sd = sd0, ...))), + n, sd = sd0, ...))), y=origin[2] + cumsum(as.vector(arima.sim(list(ar = ar), - - n, sd = sd0, ...))))} + + n, sd = sd0, ...))))} if(transform) { if(missing(bbox)) bbox <- matrix(c(0,1,0,1),nrow = 2,byrow = T); colnames(bbox) <- c("min","max");rownames(bbox) <- c("x","y") @@ -52,28 +52,28 @@ rTracksCollection <- function (p = 10, sd2 = 0, ...) sd = sd2), ...))) -print.Track <- function(x,...){ +print.Track <- function(x){ X = x if (class(X@sp)=="SpatialPoints") { cat("An object of class Track \n"); cat(paste0(nrow(as.data.frame(X@sp)), "points"),"\n"); - } + } if (class(X@sp)=="SpatialLines") { cat("A generalized object of class Track \n"); cat(paste0(length(X@sp@lines), "lines"),"\n"); } cat(paste0("bbox:"),"\n"); print(X@sp@bbox); - cat(paste0("Time period: [",range(X@endTime)[1],", ", range(X@endTime)[2],"]")) + cat(paste0("Time period: [",range(X@endTime)[1],", ", range(X@endTime)[2],"]"),"\n") } print.Tracks <- function(X){ cat("An object of class Tracks" ,"\n"); - cat(paste0(length(X@tracks)), "tracks followed by a single object") + cat(paste0(length(X@tracks)), "tracks followed by a single object","\n") } print.TracksCollection <- function(X){ cat("An object of class TracksCollection" ,"\n"); cat(paste0(length(X@tracksCollection)) - , "collection of tracks followed by", paste0(length(X@tracksCollection)), " object") + , "collection of tracks followed by", paste0(length(X@tracksCollection)), " object","\n") } diff --git a/inst/doc/article.pdf b/inst/doc/article.pdf deleted file mode 100644 index 2050a36..0000000 Binary files a/inst/doc/article.pdf and /dev/null differ diff --git a/man/A3.Rd b/man/A3.Rd index 4609855..05b3d69 100644 --- a/man/A3.Rd +++ b/man/A3.Rd @@ -1,14 +1,13 @@ \name{A3} \alias{A3} -\title{Trajectory} -\description{Trajectory, locally stored, from envirocar.org, see example below how it was imported} +\title{Trajectory data} +\description{Trajectory, locally stored, from envirocar.org.} \usage{ data(A3) } \keyword{datasets} \examples{ -library(spacetime) data(A3) dim(A3) -# see demo(A3) to see how A3 was fetched, and created from the web service +plot(A3) } diff --git a/man/Kinhom.Track.Rd b/man/Kinhom.Track.Rd index 3667ef8..8bc6015 100644 --- a/man/Kinhom.Track.Rd +++ b/man/Kinhom.Track.Rd @@ -1,41 +1,63 @@ \name{Kinhom.Track} \alias{Kinhom.Track} -%- Also NEED an '\alias' for EACH other topic documented here. +\alias{Kinhom.Tracks} +\alias{Kinhom.TracksCollection} + \title{ -Inhomogeneous K-function for trajectory pattern +Inhomogeneous K-function for a trajectory pattern } + \description{ -Estimate the variability area of K-function of a list of tracks.} +Estimate the variability area of the K-function for an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects over time.} + \usage{ Kinhom.Track(X,timestamp, - correction=c("border", "bord.modif", "isotropic", "translate"),q, + correction=c("border", "bord.modif", "isotropic", "translate"),q=0, sigma=c("default","bw.diggle","bw.ppl"," bw.scott"),...) } -%- maybe also 'usage' for other objects documented here. + \arguments{ - \item{X}{ -A list of Track objects +\item{X}{ +an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects. +} +\item{timestamp}{ +based on secs,mins,... . } -\item{timestamp}{based on secs,mins,...} -\item{correction}{the type of correction to be used in computing K-function} -\item{q}{(optional) a numeric value between 0 and 1. quantile to be applied to calculate the variability area} -\item{sigma}{method to be used in computing intensity function} -\item{...}{passed to the arguments of Kinhom} +\item{correction}{ +the type of correction to be used when computing K-function. } +\item{q}{optional. a numeric value between 0 and 1. quantile to be applied to calculate the variability area. +} +\item{sigma}{ +method to be considered for bandwidth selection in computing intensity function. +} +\item{...}{ +arguments passed to the \link[spatstat]{Kinhom}. +} +} + \details{ -This calculates the variability area of K-function over time. If sigma=default, it calculates the variability area using the defaults of Kinhom, otherwise it first estimate the intensity function using the given sigma as bandwidth selection method and then using the estimated intensity function, it estimates the variability area. +The type of interaction (clustering, repulsion, randomness) between tracks in X might vary over time. The function \link[trajectories]{Kinhom.Track} calculates the variability area of \link[spatstat]{Kinhom} over time. The variability area is calculated based on the K-functions of all obtained point patterns when converting a trajectory pattern to a list of point patterns. + +If sigma=default, it calculates the variability area using the defaults of \link[spatstat]{Kinhom}, otherwise it first estimates the intensity function using the given bandwidth selection method and then using the estimated intensity function it estimates the variability area. + +The lower and upper border of the variability area is calculated based on the \link[stats]{quantile} of values of all obtained K-functions. q=0 means considering maximum and minimum. + +Note that, tracks in X should overlap in time. } + \value{ -an object of class "KTrack". +an object of class KTrack. } + \author{ -Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } -%% ~Make other sections like Warning with \section{Warning }{....} ~ - \seealso{ -\link[trajectories]{rTrack}, \link[trajectories]{as.Track.ppp}, \link[spatstat]{Kinhom}} +\link[trajectories]{rTrack}, \link[trajectories]{as.Track.ppp}, \link[spatstat]{Kinhom} +} + \examples{ library(spatstat) X <- list() @@ -43,6 +65,7 @@ for(i in 1:100){ m <- matrix(c(0,10,0,10),nrow=2,byrow = TRUE) X[[i]] <- rTrack(bbox = m,transform = TRUE) } +k <- Kinhom.Track(X,timestamp = "180 secs") +plot(k) Kinhom.Track(X,timestamp = "180 secs") - -} +} \ No newline at end of file diff --git a/man/Track-Method.Rd b/man/Track-Method.Rd new file mode 100644 index 0000000..48d72f0 --- /dev/null +++ b/man/Track-Method.Rd @@ -0,0 +1,173 @@ +\name{Track-Method} +\alias{Track-Method} +\alias{[,Track-method} +\alias{[,Tracks-method} +\alias{[,TracksCollection-method} +\alias{[,Track,ANY,ANY,ANY-method} +\alias{[,Tracks,ANY,ANY,ANY-method} +\alias{[,TracksCollection,ANY,ANY,ANY-method} +\alias{[[,Track,ANY,missing-method} +\alias{[[,Tracks,ANY,missing-method} +\alias{[[,TracksCollection,ANY,missing-method} +\alias{[[<-,Track,ANY,missing-method} +\alias{[[<-,Tracks,ANY,missing-method} +\alias{[[<-,TracksCollection,ANY,missing-method} +\alias{$,Track-method} +\alias{$,Tracks-method} +\alias{$,TracksCollection-method} +\alias{$<-,Track-method} +\alias{$<-,Tracks-method} +\alias{$<-,TracksCollection-method} +\alias{coordnames,Track-method} +\alias{coordnames,Tracks-method} +\alias{coordnames,TracksCollection-method} +\alias{aggregate,Track-method} +\alias{aggregate,Tracks-method} +\alias{aggregate,TracksCollection-method} +\alias{plot,TracksCollection,ANY-method} +\alias{plot,Track,missing-method} +\alias{plot,Tracks,ANY-method} +\alias{stplot,TracksCollection-method} +\alias{spTransform,Track,CRS-method} +\alias{spTransform,Tracks,CRS-method} +\alias{spTransform,TracksCollection,CRS-method} +\alias{segPanel} +\alias{tracksPanel} + +\title{ +Methods for classes \link[trajectories]{Track}, \link[trajectories]{Tracks} or \link[trajectories]{TracksCollection}. +} +\description{ +Methods for classes \link[trajectories]{Track}, \link[trajectories]{Tracks} and \link[trajectories]{TracksCollection} +} +\usage{ +\method{as}{Track, Tracks, TracksCollection}(X,"segments") +\method{as}{Track, Tracks, TracksCollection}(X,"data.frame") +\method{as}{Track}(X,"Line") +\method{as}{Track, Tracks}(X,"Lines") +\method{as}{Track, Tracks, TracksCollection}(X,"SpatialLines") +\method{as}{Tracks, TracksCollection}(X,"SpatialLinesDataFrame") +\method{as}{Track, Tracks, TracksCollection}(X,"xts") +\method{as}{Track, Tracks, TracksCollection}(X,"STIDF") +\method{as}{Track, Tracks, TracksCollection}(X,"Spatial") +\method{as}{Track, Tracks, TracksCollection}(X,"SpatialPointsDataFrame") +\method{coordinates}{Track, Tracks, TracksCollection}(X) +\method{proj4string}{Track, Tracks, TracksCollection}(X) +\method{coordnames}{Track, Tracks, TracksCollection}(X) +\method{stbox}{Track, Tracks, TracksCollection}(X) +\method{bbox}{Track, Tracks, TracksCollection}(X) +\method{dim}{Track, Tracks, TracksCollection}(X) +\method{summary}{Track, Tracks, TracksCollection}(X) +\method{show}{Track, Tracks, TracksCollection}(X) +\method{over}{Track, Tracks, TracksCollection}(X) +\method{aggregate}{Track, Tracks, TracksCollection}(X) +\method{stack}{TracksCollection}(X) +\method{unstack}{TracksCollection}(X) + +\S4method{[}{Track, Tracks, TracksCollection}(X, i, ..., drop = TRUE) +\S4method{[[}{Track, Tracks, TracksCollection}(X, i, ..., drop = TRUE) + + +} + +\arguments{ +\item{X}{ +an object of class +\link[trajectories]{Track}, \link[trajectories]{Tracks} or \link[trajectories]{TracksCollection}. +} +\item{i}{ +selection of spatial entities. +} +\item{...}{ +selection of attribute(s). +} +\item{drop}{ +logical. +} +} + +\details{ +methods for classes \link[trajectories]{Track}, \link[trajectories]{Tracks} or \link[trajectories]{TracksCollection}. see examples below. +} +\value{ + +} +\author{ +Edzer Pebesma, \email{edzer.pebesma@uni-muenster.de} + +Mohammad Mehdi Moradi, \email{m2.moradi@yahoo.com} +} + + +\seealso{ +\link[trajectories]{rTrack}, \link[trajectories]{rTracks} or \link[trajectories]{rTracksCollection} +} + +\examples{ +library(sp) +x <- rTrack(n=10) +as(x,"segments") +as(x,"data.frame") +as(x,"Line") +as(x,"Lines") +as(x,"SpatialLines") +as(x,"xts") +as(x,"STIDF") +as(x,"Spatial") +as(x,"SpatialPointsDataFrame") +coordinates(x) +proj4string(x) +plot(x) +coordnames(x) +dim(x) +bbox(x) +stbox(x) +y <- rTrack(n=10) +y <- as(y,"Spatial") +over(x,y) +y <- rTrack(n=10) +y <- as(y,"xts") +over(x,y) +summary(x) +x[1:4] +names(x@connections) +x[["distance"]] +x[[1]] +x$distance +stack(x) +y <- as(x,"STIDF") +proj4string(y) <- CRS("+proj=longlat") +# transform to UTM 50N +# x.utm <- spTransform(y, CRS("+proj=utm +zone=50 +ellps=WGS84 +datum=WGS84 +# +units=m +no_defs ")) +# x.utm <- Track(x.utm) + +x.Tr <- TracksCollection(list(Tracks(list(x)))) +stplot(x.Tr,attr = "direction", arrows=TRUE, lwd = 3, by = "IDs") + + + +x.Tracks <- rTracks(n=100,m=4) +c(x.Tracks@tracks$Track1,x.Tracks@tracks$Track2) +c(x.Tracks[1:2],x.Tracks[3:4]) + +x.Tracks.Tr <- TracksCollection(list(x.Tracks)) +stplot(x.Tracks.Tr,attr = "direction", arrows=TRUE, lwd = 3, by = "IDs") + + +x.TracksCollection <- rTracksCollection(n=10,m=4,p=4) +c(x.TracksCollection[1:2],x.TracksCollection[3:4]) +dim(x.TracksCollection) +dim(x.TracksCollection[2]) +dim(x.TracksCollection[2][1]) + +stplot(x.TracksCollection,attr = "direction", arrows=TRUE, lwd = 3, by = "IDs") +plot(x.TracksCollection, col=2, axes=TRUE) + + +u = stack(x.TracksCollection) # four IDs +dim(u) +dim(unstack(u, c(rep(1,4),rep(2,4),rep(3,4),rep(4,4)))) # regroups to original +dim(unstack(u, c(rep(1,4),rep(2,4),rep(3,4),rep(4,2),rep(5,2)))) # regroups to five IDs + +} diff --git a/man/Track-class.Rd b/man/Track-class.Rd index 53a0117..9fbec8a 100644 --- a/man/Track-class.Rd +++ b/man/Track-class.Rd @@ -7,169 +7,117 @@ \alias{Track} \alias{Tracks} \alias{TracksCollection} -\alias{TrackStats} -\alias{TrackSummary} -\alias{TracksSummary} -\alias{[,Track-method} -\alias{[,Tracks-method} -\alias{[,TracksCollection-method} -\alias{[,Track,ANY,ANY,ANY-method} -\alias{[,Tracks,ANY,ANY,ANY-method} -\alias{[,TracksCollection,ANY,ANY,ANY-method} -\alias{[[,Track,ANY,missing-method} -\alias{[[,Tracks,ANY,missing-method} -\alias{[[,TracksCollection,ANY,missing-method} -\alias{[[<-,Track,ANY,missing-method} -\alias{[[<-,Tracks,ANY,missing-method} -\alias{[[<-,TracksCollection,ANY,missing-method} -\alias{$,Track-method} -\alias{$,Tracks-method} -\alias{$,TracksCollection-method} -\alias{$<-,Track-method} -\alias{$<-,Tracks-method} -\alias{$<-,TracksCollection-method} \alias{coerce,Track,data.frame-method} \alias{coerce,Tracks,data.frame-method} \alias{coerce,TracksCollection,data.frame-method} -\alias{coordnames,Track-method} -\alias{coordnames,Tracks-method} -\alias{coordnames,TracksCollection-method} -\alias{aggregate,Track-method} -\alias{aggregate,Tracks-method} -\alias{aggregate,TracksCollection-method} -\alias{plot,TracksCollection,ANY-method} -\alias{plot,Track,missing-method} -\alias{plot,Tracks,ANY-method} -\alias{stplot,TracksCollection-method} -\alias{spTransform,Track,CRS-method} -\alias{spTransform,Tracks,CRS-method} -\alias{spTransform,TracksCollection,CRS-method} -\alias{segPanel} -\alias{tracksPanel} -\alias{approxTrack} -\alias{approxTracks} -\alias{approxTracksCollection} -\title{Classes "Track", "Tracks", and "TracksCollection"} -\description{ Classes for representing sets of trajectory data, -with attributes, for different IDs (persons, objects, etc) } +\title{ +Classes Track, Tracks and TracksCollection +} + +\description{ +Classes for representing sets of trajectory data, +with attributes, for different IDs (persons, objects, etc). +} + \section{Objects from the Class}{ -Objects of class \code{Track} extend \link{STIDF-class} +objects of class \code{Track} extend \link{STIDF-class} and contain single trips or tracks, objects of class \code{Tracks} contain multiple \code{Track} objects for a single ID (person, object or tracking device), objects of class \code{TracksCollection} contain multiple \code{Tracks} objects for different IDs. } + \section{Slots of class "Track"}{ - \describe{ - \item{\code{sp}:}{spatial locations of the track points, with length n} - \item{\code{time}:}{time stamps of the track points} - \item{\code{endTime}:}{end time stamps of the track points} - \item{\code{data}:}{\code{data.frame} with n rows, containing - attributes of the track points} - \item{\code{connections}:}{\code{data.frame}, with n-1 rows, containing - attributes between the track points such as distance and speed } - } +\describe{ +\item{\code{sp}:}{ +spatial locations of the track points, with length n. +} +\item{\code{time}:}{ +time stamps of the track points. +} +\item{\code{endTime}:}{ +end time stamps of the track points. +} +\item{\code{data}:}{ +\code{data.frame} with n rows, containing attributes of the track points. } +\item{\code{connections}:}{ +\code{data.frame}, with n-1 rows, containing attributes between the track points such as distance and speed. +} +} +} + \section{Slots of class "Tracks"}{ - \describe{ - \item{\code{tracks}:}{\code{list} with \code{Track} objects, of length m} - \item{\code{tracksData}:}{\code{data.frame} with m rows, containing - summary data for each \code{Track} object} - } +\describe{ +\item{\code{tracks}:}{ +\code{list} with \code{Track} objects, of length m. +} +\item{\code{tracksData}:}{ +\code{data.frame} with m rows, containing summary data for each \code{Track} object. +} +} } + \section{Slots of class "TracksCollection"}{ - \describe{ - \item{\code{tracksCollection}:}{\code{list} \code{Tracks} objects, of - length p} - \item{\code{tracksCollectionData}:}{\code{data.frame} with p rows, - containing summary data for each \code{Tracks} object} - } +\describe{ +\item{\code{tracksCollection}:}{ +\code{list} \code{Tracks} objects, of length p. +} +\item{\code{tracksCollectionData}:}{ +\code{data.frame} with p rows, containing summary data for each \code{Tracks} object. } -\section{Methods}{ - \describe{ - \item{[[}{\code{signature(obj = "Track")}: retrieves the attribute element} - \item{[[}{\code{signature(obj = "Tracks")}: retrieves the attribute element} - \item{[[}{\code{signature(obj = "TracksCollection")}: retrieves the attribute element} - \item{[[<-}{\code{signature(obj = "Track")}: sets or replaces the attribute element} - \item{[[<-}{\code{signature(obj = "Tracks")}: sets or replaces the attribute element} - \item{[[<-}{\code{signature(obj = "TracksCollection")}: sets or replaces the attribute element} - \item{$}{\code{signature(obj = "Track")}: retrieves the attribute element} - \item{$}{\code{signature(obj = "Tracks")}: retrieves the attribute element} - \item{$}{\code{signature(obj = "TracksCollection")}: retrieves the attribute element} - \item{$<-}{\code{signature(obj = "Track")}: sets or replaces the attribute element} - \item{$<-}{\code{signature(obj = "Tracks")}: sets or replaces the attribute element} - \item{$<-}{\code{signature(obj = "TracksCollection")}: sets or replaces the attribute element} - \item{coerce}{Track,data.frame}{coerce to \code{data.frame}} - \item{coerce}{Tracks,data.frame}{coerce to \code{data.frame}} - \item{coerce}{TracksCollection,data.frame}{coerce to \code{data.frame}} - \item{plot}{\code{signature(x = "TracksCollection", y = "missing")}: - plots sets of sets of tracks} - \item{stplot}{\code{signature(obj = "TracksCollection")}: - plots sets of sets of tracks} - % for spatial objects; does nothing but setting up a plotting region choosing - % a suitable aspect if not given(see below), colouring the plot background using either a bg= argument or par("bg"), and possibly drawing axes. } - % \item{summary}{\code{signature(object = "Spatial")}: summarize object} - } } +} + \usage{ - Track(track, df = fn(track), fn = TrackStats) - Tracks(tracks, tracksData = data.frame(row.names=names(tracks)), - fn = TrackSummary) - TracksCollection(tracksCollection, tracksCollectionData, - fn = TracksSummary) - TrackStats(track) - TrackSummary(track) - TracksSummary(tracksCollection) - \S4method{[}{Track}(x, i, j, ..., drop = TRUE) - \S4method{[}{TracksCollection}(x, i, j, ..., drop = TRUE) - \S4method{coerce}{Track,data.frame}(from, to) - \S4method{coerce}{Tracks,data.frame}(from, to) - \S4method{coerce}{TracksCollection,data.frame}(from, to) +Track(track, df = fn(track), fn = TrackStats) +Tracks(tracks, tracksData = data.frame(row.names=names(tracks)), fn = TrackSummary) +TracksCollection(tracksCollection, tracksCollectionData, +fn = TracksSummary) +\S4method{coerce}{Track,data.frame}(from, to) +\S4method{coerce}{Tracks,data.frame}(from, to) +\S4method{coerce}{TracksCollection,data.frame}(from, to) % \S4method{over}{Tracks,Spatial}(x, y, returnList = FALSE, fn = NULL, ...) % \S4method{over}{TracksCollection,Spatial}(x, y, returnList = FALSE, } \arguments{ -\item{track}{object of class \link{STIDF-class}, representing a single trip} -\item{df}{optional \code{data.frame} with information between track points} -\item{tracks}{named list with \code{Track} objects} -\item{tracksData}{\code{data.frame} with summary data for each \code{Track}} -\item{tracksCollection}{list, with \code{Tracks} objects} -\item{tracksCollectionData}{data.frame, with summary data on - \code{tracksCollection}} -\item{fn}{function; } -\item{x}{object of class \code{Track} etc} -%\item{y}{object of class \code{Spatial}} -\item{i}{selection of spatial entities} -\item{j}{selection of temporal entities (see syntax in package xts) } -\item{...}{selection of attribute(s)} -\item{drop}{logical} -\item{from}{from} -\item{to}{target class} +\item{track}{ +object of class \link{STIDF-class}, representing a single trip. +} +\item{df}{ +optional \code{data.frame} with information between track points. +} +\item{fn}{ +function. +} +\item{tracks}{ +named list with \code{Track} objects. +} +\item{tracksData}{ +\code{data.frame} with summary data for each \code{Track}. +} +\item{tracksCollection}{ +list, with \code{Tracks} objects. +} +\item{tracksCollectionData}{ +data.frame, with summary data on \code{tracksCollection}. +} +\item{from}{from.} +\item{to}{target class.} } -\value{Functions \code{Track}, \code{Tracks} and +\value{ +functions \code{Track}, \code{Tracks} and \code{TracksCollection} are constructor functions that take the slots as arguments, check object validity, and compute summary statistics on the track and tracks sets. - -\code{TrackStats} returns a \code{data.frame} with for each track -segment the distance, duration, speed, and direction. In case data are -geographical coordinates (long/lat), distance is in m, and direction -is initial bearing. - -\code{TrackSummary} reports for each track xmin, xmax, ymin, ymax, -tmin, tmax, (number of points) n, (total) distance, and medspeed -(median speed). - -\code{TracksSummary} reports for each Tracks of a TracksCollection -(number of tracks) n, xmin, xmax, ymin, ymax, tmin, tmin, tmax. } -\author{ Edzer Pebesma, \email{edzer.pebesma@uni-muenster.de} } +\author{Edzer Pebesma, \email{edzer.pebesma@uni-muenster.de} } \references{ http://www.jstatsoft.org/v51/i07/ } \note{\code{segments} is a \code{data.frame} form in which track @@ -216,23 +164,7 @@ B2 = Track(stidf) # Tracks for person A: B = Tracks(list(B1=B1,B2=B2)) Tr = TracksCollection(list(A=A,B=B)) -stplot(Tr, scales = list(draw=TRUE)) -stplot(Tr, attr = "direction", arrows=TRUE, lwd = 3, by = "direction") -stplot(Tr, attr = "direction", arrows=TRUE, lwd = 3, by = "IDs") -plot(Tr, col=2, axes=TRUE) -dim(Tr) -dim(Tr[2]) -dim(Tr[2][1]) -u = stack(Tr) # four IDs -dim(u) -dim(unstack(u, c(1,1,2,2))) # regroups to original -dim(unstack(u, c(1,1,2,3))) # regroups to three IDs -dim(unstack(u, c(1,2,2,1))) # regroups differently -as(Tr, "data.frame")[1:10,] # tracks separated by NA rows -as(Tr, "segments")[1:10,] # track segments as records -Tr[["distance"]] = Tr[["distance"]] * 1000 -Tr$distance = Tr$distance / 1000 -Tr$distance + # work with custum TrackStats function: MyStats = function(track) { df = apply(coordinates(track@sp), 2, diff) # requires sp @@ -244,34 +176,6 @@ B2 = Track(stidf) # no longer longlat; B3 = Track(stidf, fn = MyStats) all.equal(B3$distance, B2$distance) -# approxTrack: -opar = par() -par(mfrow = c(1, 2)) -plot(B2, ylim = c(.5, 6)) -plot(B2, pch = 16, add = TRUE) -title("irregular time steps") -i = index(B2) -B3 = approxTrack(B2, seq(min(i), max(i), length.out = 50)) -plot(B3, col = 'red', type = 'p', add = TRUE) -B4 = approxTrack(B2, seq(min(i), max(i), length.out = 50), FUN = spline) -plot(B4, col = 'blue', type = 'b', add = TRUE) -# regular time steps: -t = max(t) + (1:n) * 60 # regular -B2 = Track(STIDF(SpatialPoints(cbind(x,y),crs), t, data.frame(co2 = rnorm(n)))) -plot(B2, ylim = c(.5, 6)) -plot(B2, pch = 16, add = TRUE) -title("constant time steps") -i = index(B2) -B3 = approxTrack(B2) -plot(B3, type = 'p', col = 'red', add = TRUE) -B4 = approxTrack(B2, FUN = spline) -plot(B4, type = 'p', col = 'blue', add = TRUE) -# par(opar) # good to do, but would generate warnings -smth = function(x,y,xout,...) predict(smooth.spline(as.numeric(x), y), as.numeric(xout)) -data(storms) -plot(storms, type = 'p') -storms.smooth = approxTracksCollection(storms, FUN = smth, n = 200) -plot(storms.smooth, add = TRUE, col = 'red') } \keyword{classes} diff --git a/man/Track.idw.Rd b/man/Track.idw.Rd deleted file mode 100644 index a0a0e7c..0000000 --- a/man/Track.idw.Rd +++ /dev/null @@ -1,45 +0,0 @@ -\name{Track.idw} -\alias{Track.idw} -%- Also NEED an '\alias' for EACH other topic documented here. -\title{ -Movement smoothing of trajectory pattern -} -\description{ -Movement smoothing of trajectory pattern -} -\usage{ -Track.idw(X,timestamp,epsilon=epsilon,...) -} -%- maybe also 'usage' for other objects documented here. -\arguments{ - \item{X}{ -a list of objects of class "Track" -} -\item{timestamp}{ -based on secs,mins, ... -} -\item{epsilon}{(optional) movements with length less than epsilon are not considered in the calculation} -\item{...}{passed to arguments of fucntion idw in spatstat} -} -\details{ -Performs spatial smoothing to the movements of a list of tracks. -} -\value{ -an image of class "im". -} -\author{ -Mohammad Mehdi Moradi -} - -%% ~Make other sections like Warning with \section{Warning }{....} ~ - -\seealso{ -\link[trajectories]{as.Track.arrow}, \link[spatstat]{idw}} -\examples{ -X <- list() -for(i in 1:10){ - m <- matrix(c(0,10,0,10),nrow=2,byrow = TRUE) - X[[i]] <- rTrack(bbox = m,transform = TRUE) -} -Track.idw(X,timestamp="180 secs") -} diff --git a/man/TrackStats.Rd b/man/TrackStats.Rd new file mode 100644 index 0000000..c8409d3 --- /dev/null +++ b/man/TrackStats.Rd @@ -0,0 +1,45 @@ +\name{TrackStats} +\alias{TrackStats} +\alias{TrackSummary} +\alias{TracksSummary} + +\title{ +Statistics for objects of classes \link[trajectories]{Track}, \link[trajectories]{Tracks} or \link[trajectories]{TracksCollection}. +} +\description{ +Some statistics for objects of class Track, Tracks and TracksCollection.} +\usage{ +TrackStats(X) +TrackSummary(X) +TracksSummary(X) +} +\arguments{ +\item{X}{an object of class \link[trajectories]{Track} or a list of \link[trajectories]{Tracks} objects. +} +} +\details{ +\link[trajectories]{TrackStats} returns a data.frame with the distance, duration, speed, and direction of each segment of X (an object of class Track). In case data are geographical coordinates (long/lat), distance is in m, and direction is initial bearing. Direction reperesents the turnning angle, two-argument arc-tangent, in Degree. + +\link[trajectories]{TrackSummary} returns a data.frame with minimum and maximum of x,y and time of X (an object of class Track) together with number of its spatial points, total distance traveled and median of speed. + + +\link[trajectories]{TracksSummary} returns a data.frame with minimum and maximum of x,y and time of X (a list of objects of class Tracks) +} + +\value{ +a data frame. +} +\author{ +Edzer Pebesma, \email{edzer.pebesma@uni-muenster.de} +} +\seealso{ +\link[trajectories]{Track}, \link[trajectories]{Tracks}, \link[trajectories]{rTrack} +} +\examples{ +X <- rTrack() +TrackStats(X) +TrackSummary(X) + +X <- list(rTracks(),rTracks()) +TracksSummary(X) +} diff --git a/man/approxTrack.Rd b/man/approxTrack.Rd new file mode 100644 index 0000000..a45d026 --- /dev/null +++ b/man/approxTrack.Rd @@ -0,0 +1,133 @@ +\name{approxTrack} +\alias{approxTrack} +\alias{approxTracks} +\alias{approxTracksCollection} + +\title{ +Interpolation for trajectories +} +\description{ +Interpolating objects of classes \link[trajectories]{Track}, \link[trajectories]{Tracks} or \link[trajectories]{TracksCollection}. +} +\usage{ +approxTrack(track, when, ..., n = 50, by, FUN = stats::approx, warn.if.outside = TRUE) +approxTracks(tr,...) +approxTracksCollection(tc,...) + +} +\arguments{ +\item{track,tr,tc}{ +an object of class +\link[trajectories]{Track}, \link[trajectories]{Tracks} or \link[trajectories]{TracksCollection}. +} +\item{when}{ +a time sequance specifying where interpolation is to take place. +} +\item{n}{ +if when is not specified, interpolation takes place at n equally spaced times spanning the interval [min(index(track)), max(index(track))]. +} +\item{by}{ +if when is not specified, by can be used to create a sequance of equally spaced times spanning the interval [min(index(track)), max(index(track))]. +} +\item{FUN}{ +a function to be used for interpolation. +} +\item{\dots}{ +passed to FUN. +} +\item{warn.if.outside}{ +warning if when has times outside the range of data. +} +} +\details{ +Interpolating Track, Tracks, and TracksCollection based on a desirable function. Default is to use \link[stats]{approx} for a linear interpolation. See exapmle below for the use of other functions. +} +\value{ +an object of class Track, Tracks or TracksCollection. +} +\author{ +Edzer Pebesma, \email{edzer.pebesma@uni-muenster.de} +} +\seealso{ +\link[stats]{approx}, \link[stats]{spline} +} +\examples{ +library(sp) +library(spacetime) + +t0 = as.POSIXct(as.Date("2013-09-30",tz="CET")) +# person A, track 1: +x = c(7,6,5,5,4,3,3) +y = c(7,7,6,5,5,6,7) +n = length(x) +set.seed(131) +t = t0 + cumsum(runif(n) * 60) +require(rgdal) +crs = CRS("+proj=longlat +ellps=WGS84") # longlat +stidf = STIDF(SpatialPoints(cbind(x,y),crs), t, data.frame(co2 = rnorm(n))) +A1 = Track(stidf) + +# person A, track 2: +x = c(7,6,6,7,7) +y = c(6,5,4,4,3) +n = length(x) +t = max(t) + cumsum(runif(n) * 60) +stidf = STIDF(SpatialPoints(cbind(x,y),crs), t, data.frame(co2 = rnorm(n))) +A2 = Track(stidf) + +# Tracks for person A: +A = Tracks(list(A1=A1,A2=A2)) + +# person B, track 1: +x = c(2,2,1,1,2,3) +y = c(5,4,3,2,2,3) +n = length(x) +t = max(t) + cumsum(runif(n) * 60) +stidf = STIDF(SpatialPoints(cbind(x,y),crs), t, data.frame(co2 = rnorm(n))) +B1 = Track(stidf) + +# person B, track 2: +x = c(3,3,4,3,3,4) +y = c(5,4,3,2,1,1) +n = length(x) +t = max(t) + cumsum(runif(n) * 60) +stidf = STIDF(SpatialPoints(cbind(x,y),crs), t, data.frame(co2 = rnorm(n))) +B2 = Track(stidf) + +# Tracks for person B: +B = Tracks(list(B1=B1,B2=B2)) + +Tr = TracksCollection(list(A=A,B=B)) + +# approxTrack: +opar = par() +par(mfrow = c(1, 2)) +plot(B2, ylim = c(.5, 6)) +plot(B2, pch = 16, add = TRUE) +title("irregular time steps") +i = index(B2) +B3 = approxTrack(B2, seq(min(i), max(i), length.out = 50)) +plot(B3, col = 'red', type = 'p', add = TRUE) + +B4 = approxTrack(B2, seq(min(i), max(i), length.out = 50), FUN = spline) +plot(B4, col = 'blue', type = 'b', add = TRUE) + +# regular time steps: +t = max(t) + (1:n) * 60 # regular +B2 = Track(STIDF(SpatialPoints(cbind(x,y),crs), t, data.frame(co2 = rnorm(n)))) +plot(B2, ylim = c(.5, 6)) +plot(B2, pch = 16, add = TRUE) +title("constant time steps") +i = index(B2) +B3 = approxTrack(B2) +plot(B3, type = 'p', col = 'red', add = TRUE) +B4 = approxTrack(B2, FUN = spline) +plot(B4, type = 'p', col = 'blue', add = TRUE) +# par(opar) # good to do, but would generate warnings +smth = function(x,y,xout,...) predict(smooth.spline(as.numeric(x), y), as.numeric(xout)) +data(storms) +plot(storms, type = 'p') +storms.smooth = approxTracksCollection(storms, FUN = smth, n = 200) +plot(storms.smooth, add = TRUE, col = 'red') + +} diff --git a/man/as.Track.Rd b/man/as.Track.Rd index 49e0b02..06d25f9 100644 --- a/man/as.Track.Rd +++ b/man/as.Track.Rd @@ -1,41 +1,38 @@ \name{as.Track} \alias{as.Track} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Converts data to an object of class "Track" +Converts data to an object of class Track } \description{ -Function as.Track accepts converts x,y coordinates and thier corresponding time/date to an object of class Track. It can also accepts covariates for the corresponding - locations, covariates must be a dataframe with some columns and length of each column is equal - to length of x,y,t. +This function accepts x,y coordinates and thier corresponding time/date, and converts them to an object of class \link[trajectories]{Track}. It can also accepts covariates for the corresponding locations. } \usage{ as.Track(x,y,t,covariate) } -%- maybe also 'usage' for other objects documented here. + \arguments{ - \item{x}{ x coordinate. -} -\item{y}{ y coordinate. -} -\item{t}{ corresponding time and date of x,y. -} -\item{covariate}{ additional information. -} +\item{x}{ x coordinate.} +\item{y}{ y coordinate.} +\item{t}{ corresponding time and date of x,y.} +\item{covariate}{ additional information.} } + \details{ -An object of class "Track" can be created by some geographical locations and corresponding time/dates. Function as.Track converts locations and dates/times to an object of class "Track". time/date should be from class "POSIXct" "POSIXt". See example below. +An object of class \link[trajectories]{Track} can be created by some geographical locations and corresponding time/dates. The function \link[trajectories]{as.Track} converts locations and dates/times to an object of class \link[trajectories]{Track}. time/date should be of classes \link[base]{POSIXct} or \link[base]{POSIXt}. + +The additional covariates must be a dataframe with some columns (each column is conisdered as a convariate), and the length of each column must be equal to length of x,y,t. } + \value{ -An object of class "Track".} -\author{ -Mohammad Mehdi Moradi +An object of class \link[trajectories]{Track}. } -%% ~Make other sections like Warning with \section{Warning }{....} ~ +\author{ +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} +} \seealso{ -\link[trajectories]{Track}, \link[base]{as.POSIXct} +\link[trajectories]{Track}, \link[base]{as.POSIXct}, \link[base]{as.POSIXlt} } \examples{ x <- runif(10,0,1) diff --git a/man/as.Track.arrow.Rd b/man/as.Track.arrow.Rd index ffaf400..e440e6b 100644 --- a/man/as.Track.arrow.Rd +++ b/man/as.Track.arrow.Rd @@ -1,36 +1,39 @@ \name{as.Track.arrow} \alias{as.Track.arrow} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Convert trajectory pattern to a list of marked point patterns +Convert a trajectory pattern to a list of marked point patterns } + \description{ -Converting a list of Track objects to a list of marked point patterns. Each mark shows the length of movement. +Convert objects of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects to a list of marked point patterns. } + \usage{ -as.Track.arrow(X,timestamp,epsilon=epsilon) +as.Track.arrow(X,timestamp,epsilon=0) } -%- maybe also 'usage' for other objects documented here. + \arguments{ - \item{X}{ -A list of Track objects -} +\item{X}{an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects.} \item{timestamp}{based on secs, mins,...} -\item{epsilon}{(optional) movements with length less than epsilon are not considered in the calculation} +\item{epsilon}{optional. movements with a length less than epsilon are not considered in the calculation.} } \details{ -Converting a list of Track objetcs to a list of marked point patterns. Marks show the length of movement with respect to the previous location. +This function converts an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects to a list of marked point patterns. +The function first converts X to a list of spatial point patterns based on a given timestamp and using the function \link[trajectories]{as.Track.ppp}. Then each two consecutive (according to their corresponding time) point patterns make a segment pattern of class \link[spatstat]{psp}. Finally, each segment pattern will be converted to a marked point pattern according to which points represent the midpoints of segments and marks are the length of segments. The segment patterns are kept as attributes. + +Dealing with real data, sometimes moving objects such as taxies and pedestrians are not moving while being recorded their location. In order to deal with such a situation, argument epsilon is implemented in \link[trajectories]{as.Track.arrow} to ignore the movements with a length less than epsilon. epsilon=0 does not ignore any movement. + +Note that, tracks in X should overlap in time. } \value{ a list of marked point patterns. } \author{ -Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } -%% ~Make other sections like Warning with \section{Warning }{....} ~ \seealso{ -\link[trajectories]{rTrack}, \link[trajectories]{as.Track.ppp} +\link[trajectories]{rTrack}, \link[trajectories]{as.Track.ppp}, \link[spatstat]{psp}, \link[spatstat]{midpoints.psp} } \examples{ X <- list() diff --git a/man/as.Track.ppp.Rd b/man/as.Track.ppp.Rd index f01bb95..82e68cc 100644 --- a/man/as.Track.ppp.Rd +++ b/man/as.Track.ppp.Rd @@ -1,34 +1,40 @@ \name{as.Track.ppp} \alias{as.Track.ppp} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Conver trajectory pattern to a list of objects of class ppp +Convert a trajectory pattern to a list of spatial point patterns } + \description{ -This function converts a list of Tracks to a list of point patterns (class "ppp")} +This function convert objects of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects to a list of spatial point patterns. +} + \usage{ as.Track.ppp(X,timestamp) } -%- maybe also 'usage' for other objects documented here. + \arguments{ - \item{X}{ -a list of Track objects -} -\item{timestamp}{based on secs, mins,...} +\item{X}{an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects.} +\item{timestamp}{based on secs, mins,... .} } + \details{ -as.Track.ppp converts a list of Track objetcs to a list of ppp objetcs.} +The function \link[trajectories]{as.Track.ppp} converts objects of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects to a list of spatial point patterns of class \link[spatstat]{ppp} according to a given timestamp. Each obtained spatial point pattern represents the location of all moving objects in a fixed time. Since usually the location of different tracks are not recorded according to a single time sequence, this function first interpolates all tracks according to a regular time sequence and then convert them to a list of spatial point patterns. Note that, if we do not interpolate the location of all tracks according to a regular time sequence, the final point patterns can not contain the location of all objects. + +Note that, tracks in X should overlap in time. +} + \value{ -A list of point patterns, objects of class "ppp". +A list of spatial point patterns of class \link[spatstat]{ppp}. } -\author{ -Mohammad Mehdi Moradi } -%% ~Make other sections like Warning with \section{Warning }{....} ~ +\author{ +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} +} \seealso{ \link[trajectories]{avedistTrack}, \link[spatstat]{as.ppp} } + \examples{ X <- list() for(i in 1:10){ @@ -36,4 +42,4 @@ for(i in 1:10){ X[[i]] <- rTrack(bbox = m,transform = TRUE) } Y <- as.Track.ppp(X,timestamp="120 secs") -} +} \ No newline at end of file diff --git a/man/as.list.Tracks.Rd b/man/as.list.Tracks.Rd index 7327025..8c4af30 100644 --- a/man/as.list.Tracks.Rd +++ b/man/as.list.Tracks.Rd @@ -1,36 +1,36 @@ \name{as.list.Tracks} \alias{as.list.Tracks} -%- Also NEED an '\alias' for EACH other topic documented here. +\alias{as.list.TracksCollection} \title{ -as.list.Tracks -%% ~~function to do ... ~~ +Tracks methods } \description{ -Convert a "Tracks" object to a list of tracks -%% ~~ A concise (1-5 lines) description of what the function does. ~~ +Convert an objects of classes \link[trajectories]{Tracks} and \link[trajectories]{TracksCollection} to a list of of objects of class \link[trajectories]{Track}. } + \usage{ -\method{as.list}{Tracks}(x,...) +\method{as.list}{Tracks}(tr,...) +\method{as.list}{TracksCollection}(tc,...) } -%- maybe also 'usage' for other objects documented here. + \arguments{ - \item{x}{ - an object of class "Tracks" -%% ~~Describe \code{X} here~~ +\item{tr,tc}{objects of classes \link[trajectories]{Tracks} and \link[trajectories]{TracksCollection}. } -\item{...}{passed to arguments of as.list} +\item{...}{optional. additional arguments passed on the \link[base]{as.list} fucntion.} } + \author{ -Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } -%% ~Make other sections like Warning with \section{Warning }{....} ~ \seealso{ \link[trajectories]{rTrack}, \link[trajectories]{rTracks}, \link[trajectories]{rTracksCollection}, \link[base]{as.list} -%% ~~objects to See Also as \code{\link{help}}, ~~~ } + \examples{ -x <- rTracks() -as.list(x) +tr <- rTracks(m=2,n=10) +as.list(tr) +tc <- rTracksCollection(p=2,m=2,n=10) +as.list(tc) } diff --git a/man/as.list.TracksCollection.Rd b/man/as.list.TracksCollection.Rd deleted file mode 100644 index e1d7a93..0000000 --- a/man/as.list.TracksCollection.Rd +++ /dev/null @@ -1,36 +0,0 @@ -\name{as.list.TracksCollection} -\alias{as.list.TracksCollection} -%- Also NEED an '\alias' for EACH other topic documented here. -\title{ -as.list.TracksCollection -%% ~~function to do ... ~~ -} -\description{ -Convert a "TracksCollection" object to a list of tracks -%% ~~ A concise (1-5 lines) description of what the function does. ~~ -} -\usage{ -\method{as.list}{TracksCollection}(x,...) -} -%- maybe also 'usage' for other objects documented here. -\arguments{ - \item{x}{ - an object of class "TracksCollection" -%% ~~Describe \code{Y} here~~ -} -\item{...}{passed to arguments of as.list} -} -\author{ -Mohammad Mehdi Moradi -} - -%% ~Make other sections like Warning with \section{Warning }{....} ~ - -\seealso{ -\link[trajectories]{rTrack}, \link[trajectories]{rTracks}, \link[trajectories]{rTracksCollection}, \link[base]{as.list} -%% ~~objects to See Also as \code{\link{help}}, ~~~ -} -\examples{ -x <- rTracksCollection() -as.list(x) -} diff --git a/man/auto.arima.Track.Rd b/man/auto.arima.Track.Rd index 85a9566..47e69c8 100644 --- a/man/auto.arima.Track.Rd +++ b/man/auto.arima.Track.Rd @@ -1,33 +1,37 @@ \name{auto.arima.Track} \alias{auto.arima.Track} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Fitting arima model to a track +Fitting arima model to an object of class Track } \description{ -Fit arima models to objects of class "Track".} +Fit arima models to objects of class \link[trajectories]{Track}. +} + \usage{ -auto.arima.Track(X, ...) +auto.arima.Track(track, ...) } -%- maybe also 'usage' for other objects documented here. + \arguments{ - \item{X}{ an object of class "Track"} - \item{...}{ passed to arguments of \link[forecast]{auto.arima}} + \item{track}{an object of class \link[trajectories]{Track}.} + \item{...}{arguments passed to the \link[forecast]{auto.arima}.} } + \details{ -This fita arima models to the x,y locations of objects of class "Track".} +This function considers objects of class \link[trajectories]{Track} as time series and returns arima models to their x,y locations separately. +} + \value{ -an object of class "ArimaTrack" +an object of class "ArimaTrack". Fitted arima models to coordinates x and y are kept as attribute. } + \author{ -Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } -%% ~Make other sections like Warning with \section{Warning }{....} ~ - \seealso{ \link[trajectories]{rTrack}, \link[forecast]{auto.arima} } + \examples{ X <- rTrack() auto.arima.Track(X) diff --git a/man/avedistTrack.Rd b/man/avedistTrack.Rd index c93ad31..841fc79 100644 --- a/man/avedistTrack.Rd +++ b/man/avedistTrack.Rd @@ -1,46 +1,49 @@ \name{avedistTrack} \alias{avedistTrack} -%- Also NEED an '\alias' for EACH other topic documented here. + \title{ -Average pairwise distance of trajectory pattern over time +Average pairwise distance of a trajectory pattern over time } + \description{ This measures the average of pairwise distances between tracks over time. } + \usage{ avedistTrack(X,timestamp) } -%- maybe also 'usage' for other objects documented here. + \arguments{ - \item{X}{a list of some objects of class "Track" -%% ~~Describe \code{x} here~~ -} -\item{timestamp}{timestamp to calculate the pairwise distances between tarcks} +\item{X}{an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects.} +\item{timestamp}{a timestamp to calculate the pairwise distances between tracks accordingly.} } + \details{ -This function calculates the average pairwise distance between a list of tracks according to a given timestamp. +This function calculates the average pairwise distance for an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects according to a given timestamp. + +The function first converts X to a list of spatial point patterns based on a given timestamp and using the function \link[trajectories]{as.Track.ppp}. For each obtained point pattern pairwise distances are calculated using \link[spatstat]{pairdist} and then their average is considered as "average pairwise distance" for their corresponding time. Distance from each point to itself is ignored. + +Note that, tracks in X should overlap in time. } + \value{ -An object of class "distrack". It can be plotted over time. +a numeric vector represents the average pairwise distances that can be plotted with respect to time. } + \author{ -Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } -%% ~Make other sections like Warning with \section{Warning }{....} ~ - \seealso{ -\link[trajectories]{as.Track.ppp} +\link[trajectories]{as.Track.ppp}, \link[spatstat]{pairdist} } + \examples{ X <- list() for(i in 1:10){ m <- matrix(c(0,10,0,10),nrow=2,byrow = TRUE) X[[i]] <- rTrack(bbox = m,transform = TRUE) } - -ave <- avedistTrack(X,timestamp = "120 secs") -plot(ave,type="l") - - -} +out <- avedistTrack(X,timestamp = "120 secs") +plot(out,type="l") +} \ No newline at end of file diff --git a/man/avemove.Rd b/man/avemove.Rd index 9ac294c..a4d305f 100644 --- a/man/avemove.Rd +++ b/man/avemove.Rd @@ -1,42 +1,52 @@ \name{avemove} \alias{avemove} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Average movement of trajectory pattern +Average length of movement of a trajectory pattern over time } + \description{ -This returns the average movements of a lits of objects of class "Track" over time. +This returns the average length of movements of an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects over time. } + \usage{ -avemove(X,timestamp,epsilon=epsilon) +avemove(X,timestamp,epsilon=0) } -%- maybe also 'usage' for other objects documented here. + \arguments{ - \item{X}{a list of some objects of class Track -%% ~~Describe \code{x} here~~ -} -\item{timestamp}{timestamp to calculate the pairwise distances between tarcks} -\item{epsilon}{(optional) movements with length less than epsilon are not considered in the calculation} +\item{X}{an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects.} +\item{timestamp}{a timestamp to calculate the length of movements accordingly.} +\item{epsilon}{optional. movements with a length less than epsilon are not considered in the calculation.} } + \details{ -when analysying a list of tracks, avemove calculate the average of movements based on given timestamp.} + +The function first converts X to a list of spatial point patterns based on a given timestamp and using the function \link[trajectories]{as.Track.ppp}. Then each two consecutive (according to their corresponding time) point patterns make a segment pattern of class \link[spatstat]{psp}. +Each segment shows the movement, connecting an origin point (the location at the previous time) to a destination point (the location at the current time). +Finally, for the obtained segment patterns, the length of each segment is calculated using \link[spatstat]{lengths.psp} and their average is considered as "average length of movement" at that time. + +Dealing with real data, sometimes moving objects such as taxies and pedestrians are not moving while being recorded their location. In order to deal with such a situation, argument epsilon is implemented in \link[trajectories]{avemove} to ignore the movements with a length less than epsilon. epsilon=0 does not ignore any movement. + +Note that, tracks in X should overlap in time. + +} + \value{ -an object of class "numeric" or "arwlen". +a numeric vector represents the average length of movements that can be plotted with respect to time. } \author{ -Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } -%% ~Make other sections like Warning with \section{Warning }{....} ~ - \seealso{ -\link[trajectories]{as.Track.arrow} +\link[trajectories]{as.Track.arrow}, \link[spatstat]{lengths.psp} } + \examples{ X <- list() for(i in 1:10){ m <- matrix(c(0,10,0,10),nrow=2,byrow = TRUE) X[[i]] <- rTrack(bbox = m,transform = TRUE) } -avemove(X,timestamp = "30 secs") -} +out <- avemove(X,timestamp = "30 secs") +plot(out,type="l") +} \ No newline at end of file diff --git a/man/chimaps.Rd b/man/chimaps.Rd index f1f4588..9626373 100644 --- a/man/chimaps.Rd +++ b/man/chimaps.Rd @@ -1,38 +1,45 @@ \name{chimaps} \alias{chimaps} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Chimaps of tarjectory pattern. +Chi-squared maps of a tarjectory pattern } \description{ -Computes the chimaps, corresponding to a list of objects of class "Track". chimaps are based on the discrepancy between computed and expected intensity in a given location.} +Chi-squared maps of a tarjectory pattern.} \usage{ -chimaps(X,timestamp,rank,...) +chimaps(X,timestamp,rank=1,...) } -%- maybe also 'usage' for other objects documented here. + \arguments{ - \item{X}{ -A list of Track objects -} -\item{timestamp}{based on secs,mins,...} -\item{rank}{a number between one and the length of corresponding time sequance which is created based on given timestamp.} -\item{...}{passed to arguments of density.Track} +\item{X}{an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects.} +\item{timestamp}{based on secs, mins, ... .} +\item{rank}{a number between one and the length of corresponding time sequance which is created based on a given timestamp.} +\item{...}{arguments passed to \link[trajectories]{density.list}.} } + \details{ -[estimated intensity - expected intensity] / sqrt(expected intensity). +This function converts a trajectory pattern to a list of spatial point patterns according to a given timestamp and calculates their intensities using \link[trajectories]{density.list}. Based on the estimated intensities, it calculates an expected intensity for a sequence of time which is already obtained based on a given timestamp. Having estimated and expected intensities, \link[trajectories]{chimaps} computes Chi-squared maps for a sequence of time as follows + +\eqn{\chi=[\lambda_o - \lambda_e]/\sqrt\lambda_e} + +where \eqn{\lambda_o} and \eqn{\lambda_e} are the estimated intensity and expected intensity respectively. + +According to a given timestamp, a time sequence will be created based on the range of times of tracks so that Chi-squared maps will be computed for this time sequence. Argument rank means which one to be represented as output, however, all Chi-squared maps are still stored as attributes. + +Note that, tracks in X should overlap in time. } + \value{ -an image of class "im". +an image of class \link[spatstat]{im}. } + \author{ -Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } -%% ~Make other sections like Warning with \section{Warning }{....} ~ - \seealso{ \link[trajectories]{density.list}, \link[spatstat]{density.ppp} } + \examples{ X <- list() for(i in 1:10){ diff --git a/man/compare.Rd b/man/compare.Rd index d36fd73..1e9afbe 100644 --- a/man/compare.Rd +++ b/man/compare.Rd @@ -1,11 +1,10 @@ \name{compare} - \docType{methods} \alias{compare} \alias{compare,Track-method} -\title{Compares objects of class \code{Track}} +\title{Compares objects of class Track} \description{ Calculates distances between two tracks for the overlapping time interval. @@ -16,8 +15,8 @@ Calculates distances between two tracks for the overlapping time interval. } \arguments{ -\item{tr1}{An object of class \code{Track}.} -\item{tr2}{An object of class \code{Track}.} +\item{tr1}{an object of class \code{Track}.} +\item{tr2}{an object of class \code{Track}.} } \value{A difftrack object. Includes both tracks extended with additional points diff --git a/man/cut.Rd b/man/cut.Rd index 4c17ca6..5b6bd80 100644 --- a/man/cut.Rd +++ b/man/cut.Rd @@ -4,21 +4,21 @@ \alias{cut.Tracks} \alias{cut.TracksCollection} -\title{ obtain ranges of space and time coordinates } +\title{obtain ranges of space and time coordinates} \description{ obtain ranges of space and time coordinates } \usage{ -\method{cut}{Track}(x, breaks, ..., include.lowest = TRUE, touch = TRUE) -\method{cut}{Tracks}(x, breaks, ...) -\method{cut}{TracksCollection}(x, breaks, ...) +\method{cut}{Track}(track, breaks, ..., include.lowest = TRUE, touch = TRUE) +\method{cut}{Tracks}(tr, breaks, ...) +\method{cut}{TracksCollection}(tc, breaks, ...) } \arguments{ - \item{x}{ object of class \code{Track}, \code{Tracks} or \code{TracksCollection}} - \item{breaks}{ define the breaks; see \link[base]{cut}} - \item{...}{ passed down to Tracks and Track methods, then to \link[base]{cut}} - \item{include.lowest}{ see \link[base]{cut}} - \item{touch}{ logical; if FALSE, Track objects will be formed from + \item{track, tr, tc}{object of class \code{Track}, \code{Tracks} or \code{TracksCollection}.} + \item{breaks}{define the breaks; see \link[base]{cut}.} + \item{...}{passed down to Tracks and Track methods, then to \link[base]{cut}.} + \item{include.lowest}{see \link[base]{cut}.} + \item{touch}{logical; if FALSE, Track objects will be formed from unique sets of points, meaning that gaps between two consecutive - Track objects will arise; if FALSE, the first point from each + Track objects will arise; if TRUE, the first point from each next track is copied, meaning that sets of Track are seamless.} } \value{ diff --git a/man/density.list.Rd b/man/density.list.Rd index 791758c..45b7b26 100644 --- a/man/density.list.Rd +++ b/man/density.list.Rd @@ -1,43 +1,72 @@ \name{density.list} \alias{density.list} -%- Also NEED an '\alias' for EACH other topic documented here. +\alias{density.Track} +\alias{density.Tracks} +\alias{density.TrackCollection} + \title{ -Kernel estimate of intensity of trajectory pattern +Density estimate of a trajectory pattern } + \description{ -Estimating the intensity of a list of tracks. +Estimating the intensity of an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects. } + \usage{ -\method{density}{list}(x, timestamp,...) +\method{density}{list}(x, timestamp, method=c("kernel","Voronoi"),Fun=mean,...) +\method{density}{Track}(x, timestamp, method=c("kernel","Voronoi"),Fun=mean,...) +\method{density}{Tracks}(x, timestamp, method=c("kernel","Voronoi"),Fun=mean,...) +\method{density}{TracksCollection}(x, timestamp, method=c("kernel","Voronoi"),Fun=mean,...) + } -%- maybe also 'usage' for other objects documented here. \arguments{ - \item{x}{ -a list of "Track" objects, an object of class "Tracks" or "TracksCollection" +\item{x}{an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects. +} +\item{timestamp}{based on secs, mins, ... . } -\item{timestamp}{based on secs, mins, ...} -\item{...}{passed to arguments of density.ppp} +\item{method}{method to be selected between kernel smoothing and Voronoi tessellation. } +\item{Fun}{a function to be applied to the values of each pixel, see details. +} +\item{...}{arguments passed to the \link[spatstat]{density.ppp} or \link[spatstat]{densityVoronoi}. +} +} + \details{ -This estimate the average intensity function of moving objects over time. Bandwidth selection methods such as bw.diggle, bw.scott and bw.ppl can be passed to this density.list. +This function converts a trajectory pattern to a list of spatial point patterns and then it calclulates the intensity of each obtained point pattern using \link[spatstat]{density.ppp} or \link[spatstat]{densityVoronoi}. This results in a list of images in which function FUN (default mean) will then be applied to the corresponding values of each pixel. Bandwidth selection methods such as \link[spatstat]{bw.diggle}, \link[spatstat]{bw.scott} and \link[spatstat]{bw.ppl} can be considered in \link[trajectories]{density.list}. + +Note that, tracks in X should overlap in time. } + \value{ -an image of class "im". +an image of class \link[spatstat]{im}. } + \author{ -Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } -%% ~Make other sections like Warning with \section{Warning }{....} ~ - \seealso{ -\link[trajectories]{rTrack}, \link[spatstat]{density.ppp} +\link[trajectories]{rTrack}, \link[spatstat]{density.ppp}, \link[spatstat]{bw.diggle}, \link[spatstat]{bw.scott}, \link[spatstat]{bw.ppl} } + \examples{ +library(trajectories) X <- list() for(i in 1:10){ m <- matrix(c(0,10,0,10),nrow=2,byrow = TRUE) X[[i]] <- rTrack(bbox = m,transform = TRUE) } -density(X, timestamp = "180 secs") +d1 <- density(X, timestamp = "180 secs") +plot(d1) + +d2 <- density(X, timestamp = "180 secs",method = "Voronoi") +plot(d2) + +# library(sp) +# Ims <- attr(d1, "Tracksim") +# Ims_raster <- lapply(Ims,raster::raster) +# Ims_raster_brick <- raster::brick(Ims_raster) +# spplot(Ims_raster_brick[[1:12]]) + } diff --git a/man/difftrack-class.Rd b/man/difftrack-class.Rd deleted file mode 100644 index 56705ce..0000000 --- a/man/difftrack-class.Rd +++ /dev/null @@ -1,57 +0,0 @@ -\name{difftrack-class} -\Rdversion{1.1} -\docType{class} -\alias{difftrack-class} -\alias{difftrack} -\alias{plot,difftrack,ANY-method} - -\title{Class "difftrack"} -\description{ -Class that represents differences between two \link{Track} objects. -} - -\section{Objects from the Class}{ -Objects can be created by calls of the form \code{new("difftrack", ...)}. -Objects of class \code{difftrack} contain 2 objects of class \link{Track} -extended with points for timestamps of the other track and 2 -\link{SpatialLinesDataFrame} conataining the the lines and distances between tracks. -} -\section{Slots}{ - \describe{ - \item{\code{track1}:}{Extended track1} - \item{\code{track2}:}{Extended track2} - \item{\code{conns1}:}{Lines between the original track1 and the new points on track2} - \item{\code{conns2}:}{Lines between the original track2 and the new points on track1} - } -} -\section{Methods}{ - \describe{ - \item{plot}{\code{signature(x = "difftrack", y = "missing")}: plot a difftrack} - } -} - -\author{ -Nikolai Gorte -} - - -\examples{ -showClass("difftrack") -## example tracks -library(sp) -library(xts) -data(A3) -track2 <- A3 -index(track2@time) <- index(track2@time) + 32 -track2@sp@coords <- track2@sp@coords + 0.003 - -## compare and plot -difftrack <- compare(A3, track2) -plot(difftrack) - -## space-time cube of the difftrack -\dontrun{ - stcube(difftrack) -} -} -\keyword{classes} diff --git a/man/dists.Rd b/man/dists.Rd index 0455af9..5240971 100644 --- a/man/dists.Rd +++ b/man/dists.Rd @@ -5,10 +5,10 @@ \alias{dists} \alias{dists,Tracks,Tracks-method} -\title{Calculate distances between two \code{Tracks} objects} +\title{Calculate matrix of distances} \description{ -Calculates a distance matrix with distances for each pair of tracks. +Calculates distances between two \link[trajectories]{Tracks} objects. } \usage{% @@ -16,21 +16,26 @@ Calculates a distance matrix with distances for each pair of tracks. } \arguments{ -\item{tr1}{An object of class \code{Tracks}.} -\item{tr2}{An object of class \code{Tracks}.} -\item{f}{A function to calculate distances. Default is \code{mean}.} -\item{...}{Additional parameters passed to \code{f}.} +\item{tr1}{an object of class \link[trajectories]{Tracks}.} +\item{tr2}{an object of class \link[trajectories]{Tracks}.} +\item{f}{a function to calculate distances. Default is \code{mean}.} +\item{...}{additional parameters passed to \code{f}.} } \value{A matrix with distances between each pair of tracks or \code{NA} if they don't overlap in time.} \details{ +This function makes use of fucntion \link[trajectories]{compare}, and \code{f} can be any function applicable to a numerical vector or \link{frechetDist}. } +\seealso{ +\link[trajectories]{compare}, \link[trajectories]{frechetDist}, \link[trajectories]{Tracks} +} + + \examples{ -## example tracks library(sp) library(xts) data(A3) @@ -43,12 +48,10 @@ tracks1 <- Tracks(list(A3, track2)) tracks2 <- Tracks(list(track2, A3)) ## calculate distances -\dontrun{ dists(tracks1, tracks2) dists(tracks1, tracks2, sum) dists(tracks1, tracks2, frechetDist) } -} \keyword{dists} diff --git a/man/downsample.Rd b/man/downsample.Rd index 9471d06..941abd4 100644 --- a/man/downsample.Rd +++ b/man/downsample.Rd @@ -1,13 +1,11 @@ \name{downsample} - \docType{methods} - \alias{downsample} \alias{downsample,Track-method} -\title{Downsample a \code{Track}} +\title{Downsample a Track} \description{ -Downsamples a \code{Track} to the size (amount of points) of another \code{Track}. +Downsamples a \link[trajectories]{Track} to the size (amount of points) of another Track. } \usage{% @@ -15,15 +13,24 @@ Downsamples a \code{Track} to the size (amount of points) of another \code{Track } \arguments{ -\item{track1}{\code{Track} that will be downsampled.} -\item{track2}{Reference \code{Track}.} +\item{track1}{Track that will be downsampled.} +\item{track2}{Reference Track.} } -\value{A \code{Track} object. The downsampled track1.} +\value{A Track object. The downsampled track1.} \author{ Nikolai Gorte } +\examples{ +x <- rTrack(15) +dim(x) +y <- rTrack(20) +dim(y) +z <- downsample(y,x) +dim(z) +} + \keyword{downsample} diff --git a/man/frechetDist.Rd b/man/frechetDist.Rd index 2fe7cd4..2167a62 100644 --- a/man/frechetDist.Rd +++ b/man/frechetDist.Rd @@ -4,7 +4,7 @@ \alias{frechetDist,Track-method} \title{Frechet distance} \description{ -Compute the discrete Frechet distance between two \code{Track} objects. +Compute the discrete Frechet distance between two \link[trajectories]{Track} objects. } \usage{% @@ -12,18 +12,26 @@ Compute the discrete Frechet distance between two \code{Track} objects. } \arguments{ -\item{track1}{An object of class \code{Track}.} -\item{track2}{An object of class \code{Track}.} +\item{track1}{an object of class Track.} +\item{track2}{an object of class Track.} } -\value{Discrete Frechet distance.} +\value{A numeric value representing the Frechet distance.} -\references{ http://en.wikipedia.org/wiki/Fr\'echet_distance } +\references{http://en.wikipedia.org/wiki/Fr\'echet_distance} \author{ Nikolai Gorte + +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} + } +\examples{ +x <- rTrack(10) +y <- rTrack(10) +frechetDist(x,y) +} \keyword{methods} diff --git a/man/generalize.Rd b/man/generalize.Rd index c6efbb4..159a71f 100644 --- a/man/generalize.Rd +++ b/man/generalize.Rd @@ -5,9 +5,9 @@ \alias{generalize,Tracks-method} \alias{generalize,TracksCollection-method} -\title{Generalize objects of class \code{Track}, \code{Tracks} and \code{TracksCollection}} +\title{Generalize trajectories} -\description{Generalize objects of class \code{Track}, \code{Tracks} and \code{TracksCollection}.} +\description{Generalize objects of class \link[trajectories]{Track}, \link[trajectories]{Tracks} or \link[trajectories]{TracksCollection}.} \usage{% \S4method{generalize}{Track}(t, FUN = mean, ..., timeInterval, distance, n, tol, toPoints) @@ -15,17 +15,41 @@ \S4method{generalize}{TracksCollection}(t, FUN = mean, ...)} \arguments{ -\item{t}{An object of class \code{Track}, \code{Tracks} or \code{TracksCollection}.} -\item{FUN}{The generalization method to be applied. Defaults to \code{mean} if none is passed.} -\item{timeInterval}{ (lower limit) time interval to split Track into segments } -\item{distance}{ (lower limit) distance to split Track into segments } -\item{n}{ number of points to form segments } -\item{tol}{ tolerance passed on to \link[rgeos]{gSimplify}, to generalize segments - using the Douglas-Peucker algorithm. } -\item{toPoints}{ keep mid point rather than forming \link[sp]{SpatialLines} segments } -\item{...}{Additional arguments passed to FUN} -} - -\value{An object of class \code{Track}, \code{Tracks} or \code{TracksCollection}.} +\item{t}{an object of class \link[trajectories]{Track}, \link[trajectories]{Tracks} or \link[trajectories]{TracksCollection}. +} +\item{FUN}{ +the generalization method to be applied. Defaults to mean if none is passed. +} +\item{timeInterval}{ +(lower limit) time interval to split Track into segments. +} +\item{distance}{ +(lower limit) distance to split Track into segments. +} +\item{n}{number of points to form segments. +} +\item{tol}{ +tolerance passed on to \link[rgeos]{gSimplify}, to generalize segments using the Douglas-Peucker algorithm. +} +\item{toPoints}{ +keep mid point rather than forming \link[sp]{SpatialLines} segments. +} +\item{...}{additional arguments passed to FUN. +} +} + +\value{A generalized object of class \link[trajectories]{Track}, \link[trajectories]{Tracks} or \link[trajectories]{TracksCollection}.} + + +\details{ +Generalize object of classes \link[trajectories]{Track}, \link[trajectories]{Traks} or \link[trajectories]{TracksCollection} to \link[sp]{SpatialLines} based on number of spatial points, time or distance passed. +} + +\examples{ +x <- rTrack() +generalize(x,n=15) +generalize(x,distance=40) +generalize(x,timeInterval=50) +} \keyword{generalize} diff --git a/man/idw.Track.Rd b/man/idw.Track.Rd new file mode 100644 index 0000000..1f7ab67 --- /dev/null +++ b/man/idw.Track.Rd @@ -0,0 +1,61 @@ +\name{idw.Track} +\alias{idw.Track} +\alias{idw.Tracks} +\alias{idw.TracksCollection} + +\title{ +Movement smoothing of a trajectory pattern +} +\description{ +Movement smoothing of an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects. +} +\usage{ +\method{idw}{Track}(X,timestamp,epsilon=0,Fun=mean,...) +\method{idw}{Tracks}(X,timestamp,epsilon=0,Fun=mean,...) +\method{idw}{TrackCollection}(X,timestamp,epsilon=0,Fun=mean,...) + +} + +\arguments{ +\item{X}{ +an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects. +} +\item{timestamp}{ +based on secs,mins, ... . +} +\item{epsilon}{ +optional. movements with a length less than epsilon are not considered in the calculation. +} +\item{Fun}{ +a function to be applied to the values of each pixel, see details. +} +\item{...}{ +arguments passed to \link[spatstat]{idw} function. +} +} +\details{ +Performs spatial smoothing to an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects. + +X will be converted to a list of marked point patterns using \link[trajectories]{as.Track.arrow} where marks are the length of movements at corresponding points, and then inverse-distance weighted smoothing will be applied to each obtained marked point pattern using \link[spatstat]{idw}. This results in a list of images in which function FUN (default mean) will then be applied to the corresponding values of each pixel. + +Note that, tracks in X should overlap in time. +} +\value{ +an image of class \link[spatstat]{im}. +} +\author{ +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} +} + +\seealso{ +\link[trajectories]{as.Track.arrow}, \link[spatstat]{idw} +} + +\examples{ +X <- list() +for(i in 1:10){ + m <- matrix(c(0,10,0,10),nrow=2,byrow = TRUE) + X[[i]] <- rTrack(bbox = m,transform = TRUE) +} +idw.Track(X,timestamp="180 secs") +} diff --git a/man/pcfinhom.Track.Rd b/man/pcfinhom.Track.Rd index 4503cea..a893212 100644 --- a/man/pcfinhom.Track.Rd +++ b/man/pcfinhom.Track.Rd @@ -1,41 +1,55 @@ \name{pcfinhom.Track} \alias{pcfinhom.Track} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Pair correlation funcrion of trajectory pattern +Pair correlation funcrion of a trajectory pattern } + \description{ -Pair correlation funcrion of trajectory pattern +Estimate the variability area of the pair correlation funcrion for an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects over time. } \usage{ -pcfinhom.Track(X,timestamp,correction = c("translate", "Ripley"),q, +pcfinhom.Track(X,timestamp,correction = c("translate", "Ripley"),q=0, sigma=c("default","bw.diggle","bw.ppl","bw.scott"),...) } -%- maybe also 'usage' for other objects documented here. \arguments{ \item{X}{ -A list of Track objects +an object of classes \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects. +} +\item{timestamp}{ +based on secs,mins,... . +} +\item{correction}{ +the type of correction to be used when computing pair correlation function. +} +\item{q}{ +optional. a numeric value between 0 and 1. quantile to be applied to calculate the variability area. +} +\item{sigma}{ +method to be considered for bandwidth selection in computing intensity function. +} +\item{...}{ +arguments passed to the \link[spatstat]{pcfinhom}. } -\item{timestamp}{based on secs,mins,...} -\item{correction}{the type of correction to be used in computing pair correlation function} -\item{q}{(optional) a numeric value between 0 and 1. quantile to be applied to calculate the variability area} -\item{sigma}{method to be used in computing intensity function} -\item{...}{passed to the arguments of pcfinhom} } \details{ -This calculates the variability area of pair correlation function over time. If sigma=default, it calculates the variability area using the defaults of pcfinhom, otherwise it first estimate the intensity function using the given sigma as bandwidth selection method and then using the estimated intensity function, it estimates the variability area. +The type of interaction (clustering, repulsion, randomness) between tracks in X might vary over time. The function \link[trajectories]{pcfinhom.Track} calculates the variability area of \link[spatstat]{pcfinhom} over time. The variability area is calculated based on the pair correlation functions of all obtained point patterns when converting a trajectory pattern to a list of point patterns. + +If sigma=default, it calculates the variability area using the defaults of \link[spatstat]{pcfinhom}, otherwise it first estimates the intensity function using the given bandwidth selection method and then using the estimated intensity function it estimates the variability area. + +The lower and upper border of the variability area is calculated based on the \link[stats]{quantile} of values of all obtained pair correlation functions. q=0 means considering maximum and minimum. + +Note that, tracks in X should overlap in time. } \value{ -an object of class "gTrack" +an object of class gTrack. } \author{ -Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } -%% ~Make other sections like Warning with \section{Warning }{....} ~ - \seealso{ -\link[trajectories]{rTrack}, \link[trajectories]{as.Track.ppp}, \link[spatstat]{pcfinhom}} +\link[trajectories]{rTrack}, \link[trajectories]{as.Track.ppp}, \link[spatstat]{pcfinhom} +} \examples{ X <- list() for(i in 1:100){ @@ -44,4 +58,4 @@ for(i in 1:100){ } g <- pcfinhom.Track(X,timestamp = "180 sec") plot(g) -} +} \ No newline at end of file diff --git a/man/plot.KTrack.Rd b/man/plot.KTrack.Rd index e4748ac..25e7b09 100644 --- a/man/plot.KTrack.Rd +++ b/man/plot.KTrack.Rd @@ -1,29 +1,23 @@ \name{plot.KTrack} \alias{plot.KTrack} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Methods for class "KTrack" +Plot Methods } \description{ -Methods for class "KTrack" +plot the K-function for a trajectory pattern. } \usage{ \method{plot}{KTrack}(x, type = "l", col = "grey70",cex=1,line=2.2, ...) } -%- maybe also 'usage' for other objects documented here. + \arguments{ - \item{x}{an object of class KTrack} - \item{type}{ line type} - \item{col}{ color} - \item{cex}{used for size of legend} - \item{line}{specifying a value for line overrides the default placement of labels, and places them this many lines outwards from the plot edge} - \item{...}{ passed on to plot} -} -\details{ -plotting the variability area of K-function of a list of tracks.} -\value{ -a plot. + \item{x}{an object of class KTrack.} + \item{type}{type.} + \item{col}{color.} + \item{cex}{used for size of legend.} + \item{line}{specifying a value for line overrides the default placement of labels, see \link[graphics]{title}.} + \item{...}{arguments passed to plot.} } \author{ -Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } diff --git a/man/plot.arwlen.Rd b/man/plot.arwlen.Rd index 1d2ccc4..f7da426 100644 --- a/man/plot.arwlen.Rd +++ b/man/plot.arwlen.Rd @@ -1,27 +1,24 @@ \name{plot.arwlen} \alias{plot.arwlen} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Methods for class "arwlen" +Plot Methods } \description{ -Methods for class "arwlen" +Methods for class arwlen. } \usage{ \method{plot}{arwlen}(x, ...) } -%- maybe also 'usage' for other objects documented here. \arguments{ - \item{x}{ an object of class "arwlen"} - \item{...}{ passed on to plot} + \item{x}{ an object of class arwlen.} + \item{...}{arguments passed to plot.} } \value{ a plot. } \author{ -Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } - -%% ~Make other sections like Warning with \section{Warning }{....} ~ - -\seealso{avemove} +\seealso{ +\link[trajectories]{avemove} +} \ No newline at end of file diff --git a/man/plot.distrack.Rd b/man/plot.distrack.Rd index d4b36bf..9a99e26 100644 --- a/man/plot.distrack.Rd +++ b/man/plot.distrack.Rd @@ -1,23 +1,22 @@ \name{plot.distrack} \alias{plot.distrack} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Methods for class "distrack" +Plot Methods } \description{ -The plot method for "distrack" objects. +The plot method for class distrack. } \usage{ \method{plot}{distrack}(x, ...) } -%- maybe also 'usage' for other objects documented here. \arguments{ - \item{x}{ an object of class "distrack" } - \item{...}{ ignored } -} -\details{ -This plots an object of class "distrack". +\item{x}{ an object of class distrack.} +\item{...}{arguments passed to plot.} } + \author{ -Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} +} +\seealso{ +\link[trajectories]{avedistTrack} } diff --git a/man/plot.gTrack.Rd b/man/plot.gTrack.Rd index 7ad3639..1bc3d2e 100644 --- a/man/plot.gTrack.Rd +++ b/man/plot.gTrack.Rd @@ -1,22 +1,24 @@ \name{plot.gTrack} \alias{plot.gTrack} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Methods for class "gTrack" +Plot Methods } \description{ -plot method} +plot the pair correlation function for a trajectory pattern. +} \usage{ \method{plot}{gTrack}(x, type = "l", col = "grey70",cex=1,line=2.2, ...) } -%- maybe also 'usage' for other objects documented here. \arguments{ - \item{x}{ an object of class "gTrack" } - \item{type}{ line type} - \item{col}{ line color} - \item{cex}{used for size of legend} - \item{line}{specifying a value for line overrides the default placement of labels, and places them this many lines outwards from the plot edge} - \item{...}{ passed on to plot} +\item{x}{ +an object of class gTrack.} +\item{type}{type.} +\item{col}{color.} +\item{cex}{used for size of legend.} +\item{line}{specifying a value for line overrides the default placement of labels, see \link[graphics]{title}. +} +\item{...}{arguments passed to plot.} } \author{ -Mohammad Mehdi Moradi } +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} +} diff --git a/man/print.ArimaTrack.Rd b/man/print.ArimaTrack.Rd index 0a43333..c4c8e66 100644 --- a/man/print.ArimaTrack.Rd +++ b/man/print.ArimaTrack.Rd @@ -1,22 +1,18 @@ \name{print.ArimaTrack} \alias{print.ArimaTrack} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Methods for class "ArimaTrack" +Print Methods } \description{ -print method.} +print method. +} \usage{ -\method{print}{ArimaTrack}(x, ...) +\method{print}{ArimaTrack}(x) } -%- maybe also 'usage' for other objects documented here. + \arguments{ - \item{x}{ an object of class "ArimaTrack" } - \item{...}{ignored} + \item{x}{an object of class ArimaTrack.} } \author{ -Mohammad Mehdi Moradi -} - -%% ~Make other sections like Warning with \section{Warning }{....} ~ - +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} +} \ No newline at end of file diff --git a/man/print.KTrack.Rd b/man/print.KTrack.Rd index 25d78fc..a164407 100644 --- a/man/print.KTrack.Rd +++ b/man/print.KTrack.Rd @@ -1,22 +1,19 @@ \name{print.KTrack} \alias{print.KTrack} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Methods for class "KTrack" +Print Methods } \description{ -Methods for class "KTrack" +Print method for class KTrack. } \usage{ -\method{print}{KTrack}(x,...) +\method{print}{KTrack}(x) } -%- maybe also 'usage' for other objects documented here. \arguments{ - \item{x}{ an object of class "KTrack" } - \item{...}{ ignored } + \item{x}{ an object of class KTrack.} } -\details{ to print an object of class "KTrack".} \author{ -Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } + diff --git a/man/print.Track.Rd b/man/print.Track.Rd index 1d150b3..2e9a6f4 100644 --- a/man/print.Track.Rd +++ b/man/print.Track.Rd @@ -1,22 +1,23 @@ \name{print.Track} \alias{print.Track} -%- Also NEED an '\alias' for EACH other topic documented here. +\alias{print.Tracks} +\alias{print.TracksCollection} + \title{ -Methods for class "Track" +Print Methods } \description{ -method to print an object of class "Track"} +Print method for classes \link[trajectories]{Track}, \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection}. +} \usage{ -\method{print}{Track}(x,...) +\method{print}{Track}(x) +\method{print}{Tracks}(x) +\method{print}{TracksCollection}(x) + } -%- maybe also 'usage' for other objects documented here. \arguments{ - \item{x}{ an object of class "Track" } - \item{...}{ ignored} + \item{x}{ an object of classes \link[trajectories]{Track}, \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection}} } \author{ -Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } - -%% ~Make other sections like Warning with \section{Warning }{....} ~ - diff --git a/man/print.Tracks.Rd b/man/print.Tracks.Rd deleted file mode 100644 index ef89489..0000000 --- a/man/print.Tracks.Rd +++ /dev/null @@ -1,22 +0,0 @@ -\name{print.Tracks} -\alias{print.Tracks} -%- Also NEED an '\alias' for EACH other topic documented here. -\title{ -Methods for class "Tracks" -} -\description{ -method to print an object of class "Tracks"} -\usage{ -print.Tracks(X) -} -%- maybe also 'usage' for other objects documented here. -\arguments{ - \item{X}{ -an object of class "Tracks" -} -} -\author{ -Mohammad Mehdi Moradi -} - - diff --git a/man/print.TracksCollection.Rd b/man/print.TracksCollection.Rd deleted file mode 100644 index db8dc48..0000000 --- a/man/print.TracksCollection.Rd +++ /dev/null @@ -1,20 +0,0 @@ -\name{print.TracksCollection} -\alias{print.TracksCollection} -%- Also NEED an '\alias' for EACH other topic documented here. -\title{ -Methods for class "TracksCollection" -} -\description{ -method to print an object of class "TracksCollection"} -\usage{ -print.TracksCollection(X) -} -%- maybe also 'usage' for other objects documented here. -\arguments{ - \item{X}{ -an object of class "TracksCollection" -} -} -\author{ -Mohammad Mehdi Moradi -} diff --git a/man/print.Trrow.Rd b/man/print.Trrow.Rd index e2bee57..41ebf0e 100644 --- a/man/print.Trrow.Rd +++ b/man/print.Trrow.Rd @@ -1,23 +1,17 @@ \name{print.Trrow} \alias{print.Trrow} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Methods for class "Trrow" +Print Methods } \description{ -Print objetcs of class "Trrow"} +Print method for class Trrow. +} \usage{ -\method{print}{Trrow}(x,...) +\method{print}{Trrow}(x) } -%- maybe also 'usage' for other objects documented here. \arguments{ - \item{x}{ an object of class "Trrow" } - \item{...}{ ignored } + \item{x}{an object of class Trrow.} } \author{ -Mohammad Mehdi Moradi -} - -\seealso{ -as.Track.arrow +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } diff --git a/man/print.arwlen.Rd b/man/print.arwlen.Rd index 2e9cb40..74c94bc 100644 --- a/man/print.arwlen.Rd +++ b/man/print.arwlen.Rd @@ -1,22 +1,18 @@ \name{print.arwlen} \alias{print.arwlen} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Methods for class "arwlen" +Print Methods } \description{ -to print an object of class "arwlen".} +print method. +} + \usage{ -\method{print}{arwlen}(x,...) +\method{print}{arwlen}(x) } -%- maybe also 'usage' for other objects documented here. \arguments{ - \item{x}{ an object of class "arqlen" } - \item{...}{ignored} + \item{x}{an object of class arwlen.} } \author{ -Mohammad Mehdi Moradi -} - -%% ~Make other sections like Warning with \section{Warning }{....} ~ - +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} +} \ No newline at end of file diff --git a/man/print.distrack.Rd b/man/print.distrack.Rd index 73889fa..b6e1983 100644 --- a/man/print.distrack.Rd +++ b/man/print.distrack.Rd @@ -1,39 +1,19 @@ \name{print.distrack} \alias{print.distrack} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Methods for class "distrack" +Print Methods } \description{ -This is a method for class "distrack". +Print method ffor class distrack. } + \usage{ -\method{print}{distrack}(x,...) +\method{print}{distrack}(x) } -%- maybe also 'usage' for other objects documented here. + \arguments{ - \item{x}{ an object of class "distrack"} - \item{...}{ignored} -} -\details{ -This is a method for class "distrack". -} -\value{ -See the documentation on the corresponding generic function. + \item{x}{ an object of class distrack.} } \author{ -Mohammad Mehdi Moradi -} - -%% ~Make other sections like Warning with \section{Warning }{....} ~ - -\examples{ -X <- list() -for(i in 1:10){ - m <- matrix(c(0,10,0,10),nrow=2,byrow = TRUE) - X[[i]] <- rTrack(bbox = m,transform = TRUE) -} - -ave <- avedistTrack(X,timestamp = "30 secs") -plot(ave,type="l") +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } diff --git a/man/print.gTrack.Rd b/man/print.gTrack.Rd index 2db0b1a..e716cf5 100644 --- a/man/print.gTrack.Rd +++ b/man/print.gTrack.Rd @@ -1,19 +1,19 @@ \name{print.gTrack} \alias{print.gTrack} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Methods for class "gTrack" +Print Methods } \description{ -print method.} +Print method for class gTrack. +} \usage{ -\method{print}{gTrack}(x,...) +\method{print}{gTrack}(x) } -%- maybe also 'usage' for other objects documented here. \arguments{ - \item{x}{ an object of class "gTrack"} - \item{...}{ignored} + \item{x}{ an object of class gTrack.} +} +\author{ +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } -\author{ Mohammad Mehdi Moradi } diff --git a/man/print.ppplist.Rd b/man/print.ppplist.Rd index eff73a7..0c78b5c 100644 --- a/man/print.ppplist.Rd +++ b/man/print.ppplist.Rd @@ -1,23 +1,19 @@ \name{print.ppplist} \alias{print.ppplist} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ - Methods for class "Track" +Print Methods } \description{ - method to print an object of class "ppplist"} + method to print an object of class ppplist} \usage{ \method{print}{ppplist}(x,...) } -%- maybe also 'usage' for other objects documented here. \arguments{ - \item{x}{ an object of class "ppplist" } - \item{...}{ ignored} + \item{x}{an object of class ppplist.} + \item{...}{ignored} } \author{ - Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } -%% ~Make other sections like Warning with \section{Warning }{....} ~ - \ No newline at end of file diff --git a/man/range.Track.Rd b/man/range.Track.Rd index b646794..0033121 100644 --- a/man/range.Track.Rd +++ b/man/range.Track.Rd @@ -1,30 +1,26 @@ \name{range.Track} \alias{range.Track} -%- Also NEED an '\alias' for EACH other topic documented here. +\alias{range.Tracks} +\alias{range.TracksCollection} \title{ -range.Track -%% ~~function to do ... ~~ +range } \description{ -Retrieves the range of a "Track" object -%% ~~ A concise (1-5 lines) description of what the function does. ~~ +Retrieves the range of objects of classes \link[trajectories]{Track},\link[trajectories]{Tracks} and \link[trajectories]{TracksCollection}. } \usage{ \method{range}{Track}(X,...) +\method{range}{Tracks}(X,...) +\method{range}{TracksCollection}(X,...) } -%- maybe also 'usage' for other objects documented here. \arguments{ - \item{X}{ - an object of class "Track" -%% ~~Describe \code{X} here~~ -} -\item{...}{passed to arguments of range} +\item{X}{an object of class \link[trajectories]{Track},\link[trajectories]{Tracks} or \link[trajectories]{TracksCollection}.} +\item{...}{arguments passed to the \link[base]{range} function.} } \author{ -Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } -%% ~Make other sections like Warning with \section{Warning }{....} ~ \seealso{ \link[trajectories]{rTrack}, \link[trajectories]{rTracks}, \link[trajectories]{rTracksCollection}, \link[base]{range} diff --git a/man/reTrack.Rd b/man/reTrack.Rd index 7a524a6..11398d5 100644 --- a/man/reTrack.Rd +++ b/man/reTrack.Rd @@ -1,40 +1,33 @@ \name{reTrack} \alias{reTrack} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -Reconstruct objects of class "Track" +Reconstruct objects of class Track. } \description{ -Function reTrack accepts X as an object of class "Track". Output is a reconstructed Track (again an object of class Track), based on a regular "timestamp". It only returns the interpolated points. +Reconstruct objects of class \link[trajectories]{Track} according to a given timestamp. } \usage{ reTrack(X,at=c("track","dfrm"),timestamp=timestamp,tsq=NULL) } -%- maybe also 'usage' for other objects documented here. \arguments{ - \item{X}{ -an object of class Track -} -\item{at}{ -to set the type of output as either an object of class "Track" or data.frame -} -\item{timestamp}{ -timestamp which Track be reconstructed based on -} -\item{tsq}{ -a time sequence to reconstruct Track X based on it. This is optional. If this is not given, the function creates the time sequance based on timestamp. -} +\item{X}{an object of class \link[trajectories]{Track}.} +\item{at}{to set the type of output as either an object of class \link[trajectories]{Track} or \link[base]{data.frame}.} +\item{timestamp}{a timestamp which \link[trajectories]{Track} be reconstructed based on.} +\item{tsq}{optional. a time sequence to reconstruct X based on it. If this is not given, the function creates the time sequance based on timestamp.} } + \details{ -Sometimes tracks data are not collected according to a regular timestamp. In order to compare different tracks which share some time intervals, we might need to be aware of the locations in a regular timestamp. Function reTrack unables us to reconstruct an object of class "Track" based on a regular timestamp. Time sequance can be given by user, if not reTrack creates a regulare time sequance based on the given timestamp. +Sometimes tracks data are not collected according to a regular timestamp. In order to compare different tracks which share some time intervals, we might need to be aware of the locations in a regular timestamp. The function \link[trajectories]{reTrack} unables us to reconstruct an object of class \link[trajectories]{Track} based on a regular timestamp. + +Time sequance can be given by user through argument tsq, if not \link[trajectories]{reTrack} first creates a regulare time sequance based on the given timestamp. } \value{ -Either an object of class "Track" or a data.frame +an object of class \link[trajectories]{Track} or \link[base]{data.frame}. } \author{ -Mohammad Mehdi Moradi } +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} +} -%% ~Make other sections like Warning with \section{Warning }{....} ~ \seealso{ \link[trajectories]{rTrack}, \link[trajectories]{as.Track}, diff --git a/man/rtrack.Rd b/man/rtrack.Rd index cfdee28..9df1547 100644 --- a/man/rtrack.Rd +++ b/man/rtrack.Rd @@ -1,11 +1,14 @@ \name{rTrack} - \alias{rTrack} \alias{rTracks} \alias{rTracksCollection} -\title{Generate random \code{Track}, \code{Tracks} or \code{TracksCollection} objects} -\description{Generate random \code{Track}, \code{Tracks} or \code{TracksCollection} objects} +\title{ +Generate random Track, Tracks or TracksCollection objects +} +\description{ +Generate random \link[trajectories]{Track}, \link[trajectories]{Tracks} or \link[trajectories]{TracksCollection} objects. +} \usage{ rTrack(n = 100, origin = c(0,0), start = as.POSIXct("1970-01-01"), ar = .8, step = 60, sd0 = 1, bbox = bbox, transform = FALSE, nrandom = FALSE, ...) @@ -14,43 +17,77 @@ rTracks(m = 20, start = as.POSIXct("1970-01-01"), delta = 7200, sd1 = 0, rTracksCollection(p = 10, sd2 = 0, ...) } \arguments{ -\item{n}{number of points per Track} -\item{origin}{numeric, length two, indicating the origin of the Track} -\item{start}{POSIXct, indicating the start time of the Track} -\item{ar}{numeric vector, indicating the amound of correlation in the Track} -\item{step}{ numeric; time step(s) in seconds between Track fixes } -\item{sd0}{standard deviation of the random steps in a Track} -\item{sd1}{standard deviation of the consecutive Track origin values (using rnorm)} -\item{sd2}{standard deviation of the consecutive Tracks origin values (using rnorm)} -\item{bbox}{bbox object FIXME:fill in} -\item{transform}{logical; FIXME:fill in } -\item{nrandom}{logical; if \code{TRUE}, draw \code{n} from \code{rpois(n)}} -\item{...}{rTrack: arguments passed on to \link[stats]{arima.sim}, rTracks: arguments -passed on to rTrack; rTracksCollection: arguments passed on to rTracks} -\item{m}{ number of Track objects to simulate} -\item{delta}{ time difference between consecutive Track start times} -\item{p}{ number of IDs with Tracks to generate} -} -\details{\code{ar} is passed on to \link[stats]{arima.sim} as \code{ar} +\item{n}{ +number of points per Track. +} +\item{origin}{ +numeric, length two, indicating the origin of the Track. +} +\item{start}{ +POSIXct, indicating the start time of the Track. +} +\item{ar}{ +numeric vector, indicating the amound of correlation in the Track. +} +\item{step}{ +numeric; time step(s) in seconds between Track fixes. +} +\item{sd0}{ +standard deviation of the random steps in a Track. +} +\item{sd1}{ +standard deviation of the consecutive Track origin values (using rnorm). +} +\item{sd2}{ +standard deviation of the consecutive Tracks origin values (using rnorm). +} +\item{bbox}{ +bbox object FIXME:fill in. +} +\item{transform}{ +logical; FIXME:fill in. +} +\item{nrandom}{ +logical; if \code{TRUE}, draw \code{n} from \code{rpois(n)}. +} +\item{...}{ +rTrack: arguments passed on to \link[stats]{arima.sim}, rTracks: arguments passed on to rTrack; rTracksCollection: arguments passed on to rTracks. +} +\item{m}{ +number of Track objects to simulate. +} +\item{delta}{ +time difference between consecutive Track start times. +} +\item{p}{ +number of IDs with Tracks to generate. +} +} +\details{ +\code{ar} is passed on to \link[stats]{arima.sim} as \code{ar} element, and may contain multiple AR coefficients. The generated track is a \link[base]{cumsum} over the simulated AR values, for each dimension. -In case it has length 1 and value 0, random walk is created using \link[stats]{rnorm}. If bbox is given, the generated track will be transformed to bbox. If transform is TRUE and no bbox is given, it transforms the track to a unit box. If nrandom is TRUE, it generates a random number using \link[stats]{rpois} with parameter n as the number of locations per track.} -\value{An object of class \code{Track}, \code{Tracks} or \code{TracksCollection}.} +In case it has length 1 and value 0, random walk is created using \link[stats]{rnorm}. If bbox is given, the generated track will be transformed to bbox. If transform is TRUE and no bbox is given, it transforms the track to a unit box. If nrandom is TRUE, it generates a random number using \link[stats]{rpois} with parameter n as the number of locations per track. +} + +\value{ +An object of class \link[trajectories]{Track}, \link[trajectories]{Tracks} or \link[trajectories]{TracksCollection}. +} \author{ -Edzer Pebesma , -Mohammad Mehdi Moradi +Edzer Pebesma, \email{edzer.pebesma@uni-muenster.de} , +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } \examples{ -x = rTrack() +x <- rTrack(n=10) dim(x) plot(x) -# x = rTracks(sd1 = 120) -# dim(x) -# plot(as(x, "SpatialLines"), col = 1:dim(x)[1], axes=TRUE) -# x = rTracksCollection() # star -# dim(x) -# plot(x) -x = rTracksCollection(sd2 = 200,p=4,m=10) -plot(x, col=1:dim(x)[1]) +y <- rTracks(n=10,m=5) +dim(y) +plot(as(y, "SpatialLines"), col = 1:dim(x)[1], axes=TRUE) +z <- rTracksCollection(n=10,m=5,p=2) # star +dim(z) +plot(z) +plot(z, col=1:dim(x)[1]) +stplot(z,attr = "direction", arrows=FALSE, lwd = 3, by = "IDs") } \keyword{random} diff --git a/man/stbox.Rd b/man/stbox.Rd index e46d26d..c9cbc3c 100644 --- a/man/stbox.Rd +++ b/man/stbox.Rd @@ -2,23 +2,31 @@ \alias{stbox} \alias{stbox,Tracks-method} \alias{stbox,TracksCollection-method} -\title{ obtain ranges of space and time coordinates } -\description{ obtain ranges of space and time coordinates } -\section{Methods}{ - \describe{ - \item{stbox}{\code{signature(x = "Tracks")}: obtain st range from object} - \item{stbox}{\code{signature(x = "TracksCollection")}: obtain st range from object} - } +\title{ +obtain ranges of space and time coordinates } +\description{ +obtain ranges of space and time coordinates of objects of classes \link[trajectories]{Track}, \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection}. +} + + \usage{ stbox(obj) } \arguments{ -\item{obj}{ object of a class deriving from \code{Tracks} or \code{TracksCollection}.} +\item{obj}{ +object of a class deriving from \link[trajectories]{Track}, \link[trajectories]{Tracks} and \link[trajectories]{TracksCollection}. +} } -\value{ \code{stbox} returns a \code{data.frame}, with three columns +\value{ +\code{stbox} returns a \code{data.frame}, with three columns representing x-, y- and time-coordinates, and two rows containing min and max values. \code{bbox} gives a matrix with coordinate min/max values, -compatible to \link[sp]{bbox}} +compatible to \link[sp]{bbox}. +} +\examples{ +x <- rTrack() +stbox(x) +} \keyword{dplot} diff --git a/man/stcube.Rd b/man/stcube.Rd index dcb91c4..7ff2f68 100644 --- a/man/stcube.Rd +++ b/man/stcube.Rd @@ -10,7 +10,7 @@ \title{Draw a space-time cube.} -\description{Draw a space-time cube for a Track, TRacks, TracksCollection, difftrack or STI(DF) class.} +\description{Draw a space-time cube for a Track, Tracks, TracksCollection, difftrack or STI(DF) class.} \usage{% \S4method{stcube}{Track}(x, xlab = "x", ylab = "y", zlab = "t", type = "l", @@ -37,18 +37,37 @@ showMap = FALSE, mapType = "osm", mapZoom = NULL, col, ..., y, z)} \arguments{ -\item{x}{An object of class \code{Track}, \code{Tracks}, or \code{TracksCollection} or \code{difftrack}.} -\item{xlab, ylab, zlab, type, aspect, xlim, ylim, zlim}{Arguments passed to plot3d() of package \code{rgl}.} -\item{showMap}{Flag if a basemap is to be shown on the xy plane; for this to function, you may need to load library \code{raster} first, see also the \code{stcube} demo script.} -\item{mapType}{The tile server from which to get the map. Passed as \code{type} to openmap() of package \code{OpenStreetMap}.} -\item{normalizeBy}{An abstract time period (either \code{week} or \code{day}) to be normalized by.} -\item{mapZoom}{Set a zoom level for the map used as background. Null will use the osm package default strategie.} -\item{y, z, col}{Ignored, but included in the method signature for implementation reasons.} -\item{...}{Additional arguments passed to plot3d() of package \code{rgl}.}} +\item{x}{ +an object of class \link[trajectories]{Track}, \link[trajectories]{Tracks} and \link[trajectories]{TracksCollection} or \link[trajectories]{difftrack}. +} +\item{ +xlab, ylab, zlab, type, aspect, xlim, ylim, zlim}{ +arguments passed to \link[rgl]{plot3d}. +} +\item{showMap}{ +flag if a basemap is to be shown on the xy plane; for this to function, you may need to load library \code{raster} first, see also the \code{stcube} demo script. +} +\item{mapType}{ +the tile server from which to get the map. Passed as \code{type} to openmap() of package \code{OpenStreetMap}. +} +\item{normalizeBy}{ +an abstract time period (either \code{week} or \code{day}) to be normalized by. +} +\item{mapZoom}{ +set a zoom level for the map used as background. Null will use the osm package default strategie. +} +\item{y, z, col}{ +ignored, but included in the method signature for implementation reasons.} +\item{...}{ +additional arguments passed to \link[rgl]{plot3d}. +} +} \value{A space-time cube.} + \examples{ -\dontrun{demo(stcube)} +x <- rTrack() +stcube(x) } \keyword{space-time cube} diff --git a/man/storms.Rd b/man/storms.Rd index 803f528..aaaaeda 100644 --- a/man/storms.Rd +++ b/man/storms.Rd @@ -10,9 +10,4 @@ data(storms) data(storms) dim(storms) plot(storms) -x = approxTracksCollection(storms, by = "30 min", FUN = spline) -plot(x, col = 'red', add = TRUE) -\dontrun{ -demo(storms) # regenerates these data from their source -} } diff --git a/man/tsqTracks.Rd b/man/tsqTracks.Rd index 6e2cf47..55d93ca 100644 --- a/man/tsqTracks.Rd +++ b/man/tsqTracks.Rd @@ -1,51 +1,39 @@ \name{tsqTracks} \alias{tsqTracks} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -tsqTracks +sequance generation of time of a trajectory pattern } \description{ -tsqtracks returns a sequance of time based on a list of tracks (or a single object of class "Track"") and an argument timestamp. - +sequance generation of time of a trajectory pattern based on a given timestamp. } \usage{ tsqTracks(X,timestamp) } -%- maybe also 'usage' for other objects documented here. + \arguments{ - \item{X}{either an object of class "Track"" or a list of some objects of class "Track" -%% ~~Describe \code{x} here~~ +\item{X}{ +an object of classes \link[trajectories]{Track}, \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects. +} +\item{timestamp}{ +a given timestamp based on secs,mins, etc to generate the time sequence based on it. } -\item{timestamp}{a timestamp to create the time sequence based on it} } \details{ -This creates a sequence of time based on a track or a list of tracks. -%% ~~ If necessary, more details than the description above ~~ +this function generates a regular sequence of time based on a given timestamp for an object of classes \link[trajectories]{Track}, \link[trajectories]{Tracks}, \link[trajectories]{TracksCollection} or any list of \link[trajectories]{Track} objects. } + \value{ -An object of class "POSIXct" or "POSIXt". +an object of class \link[base]{POSIXct} or \link[base]{POSIXt}. } -\author{ -Mohammad Mehdi Moradi } - -%% ~Make other sections like Warning with \section{Warning }{....} ~ +\author{ +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} +} \seealso{ -rTrack +\link[trajectories]{rTrack}, \link[base]{seq} } + \examples{ -library(sp) -library(spacetime) -t0 = as.POSIXct(as.Date("2013-09-30",tz="CET")) -# person A, track 1: -x = c(7,6,5,5,4,3,3) -y = c(7,7,6,5,5,6,7) -n = length(x) -set.seed(131) -t = t0 + cumsum(runif(n) * 60) -require(rgdal) -crs = CRS("+proj=longlat +datum=WGS84") # longlat -stidf = STIDF(SpatialPoints(cbind(x,y),crs), t, data.frame(co2 = rnorm(n))) -A1 = Track(stidf) -tsqTracks(A1,timestamp = "1 sec") -} +X <- rTrack() +tsqTracks(X,timestamp = "120 sec") +} \ No newline at end of file diff --git a/man/unique.Track.Rd b/man/unique.Track.Rd index 668650a..96715fc 100644 --- a/man/unique.Track.Rd +++ b/man/unique.Track.Rd @@ -1,30 +1,33 @@ \name{unique.Track} \alias{unique.Track} -%- Also NEED an '\alias' for EACH other topic documented here. \title{ -unique.Track +extract unique points from a trajectory pattern } \description{ -Removing duplicated points in a track} +Removing duplicated points in a \link[trajectories]{Track}.} \usage{ \method{unique}{Track}(x,...) } -%- maybe also 'usage' for other objects documented here. + \arguments{ - \item{x}{ -an object of class "Track" +\item{x}{ +an object of class \link[trajectories]{Track}. +} +\item{...}{ +arguments passed to \link[base]{unique}. } -\item{...}{passed to arguments of unique} } + \details{ -This function removes duplicated points in an object of class "Track".} +this function removes duplicated points in an object of class \link[trajectories]{Track}. +} \value{ -An object of class Track with no duplicated point.} +an object of class \link[trajectories]{Track} with no duplicated point. +} \author{ -Mohammad Mehdi Moradi +Mohammad Mehdi Moradi \email{m2.moradi@yahoo.com} } -%% ~Make other sections like Warning with \section{Warning }{....} ~ \seealso{ \link[trajectories]{rTrack}, \link[trajectories]{rTracks}, \link[trajectories]{rTracksCollection}, \link[base]{unique} diff --git a/tests/tracks.R b/tests/tracks.R index 411bdd2..ea2bc69 100644 --- a/tests/tracks.R +++ b/tests/tracks.R @@ -103,7 +103,7 @@ checkDim(res, dim) res = lapply(all, function(x) as(x, "data.frame")) checkClass(res, "data.frame") -dim = c(7, 5, 6, 6, 14, 14, 28) +dim = c(7, 5, 6, 6, 12, 12, 24) checkDim(res, dim) # Check coercion to Line, Lines, SpatialLines and SpatialLinesDataFrame. @@ -163,11 +163,11 @@ lapply(all, function(x) stbox(x)) # Check generalize methods. -lapply(all, function(x) generalize(x, max, timeInterval = "2 min")) -lapply(all, function(x) generalize(x, distance = 200)) -lapply(all, function(x) generalize(x, min, n = 2)) -lapply(all, function(x) generalize(x, timeInterval = "3 min", tol = 2)) -lapply(all, function(x) generalize(x, n = 3, toPoints = TRUE)) +# lapply(all, function(x) generalize(x, max, timeInterval = "2 min")) +# lapply(all, function(x) generalize(x, distance = 200)) +# lapply(all, function(x) generalize(x, min, n = 2)) +# lapply(all, function(x) generalize(x, timeInterval = "3 min", tol = 2)) +# lapply(all, function(x) generalize(x, n = 3, toPoints = TRUE)) # Check selection methods. @@ -182,7 +182,7 @@ stopifnot(class(Tr[list(integer(0), 2:3), drop = FALSE])[1] == "TracksCollection stopifnot(class(Tr[list(integer(0), 2), drop = FALSE])[1] == "TracksCollection") stopifnot(class(Tr[, "distance"]) == "TracksCollection") -lapply(all, function(x) x[["co2"]]) -lapply(all, function(x) x[["co2"]] = x[["co2"]] / 1000) -lapply(all, function(x) x$distance) -lapply(all, function(x) x$distance = x$distance * 1000) +# lapply(all, function(x) x[["co2"]]) +# lapply(all, function(x) x[["co2"]] = x[["co2"]]/1000) +# lapply(all, function(x) x$distance) +# lapply(all, function(x) x$distance = x$distance * 1000) diff --git a/vignettes/article.pdf b/vignettes/article.pdf index d3d3523..ec3c0e5 100644 Binary files a/vignettes/article.pdf and b/vignettes/article.pdf differ diff --git a/vignettes/article.tex b/vignettes/article.tex index 57dd7ae..cad85a8 100644 --- a/vignettes/article.tex +++ b/vignettes/article.tex @@ -40,9 +40,9 @@ %% - \title{} in title case %% - \Plaintitle{} without LaTeX markup (if any) %% - \Shorttitle{} with LaTeX markup (if any), used as running title -\title{trajectories: Classes and Methods for Trajectory Data} - \Plaintitle{trajectories: Classes and Methods for Trajectory Data} -\Shorttitle{trajectories: analysing movement data} +\title{\pkg{trajectories}: Classes and Methods for Trajectory Data} + \Plaintitle{\pkg{trajectories}: Classes and Methods for Trajectory Data} +\Shorttitle{\pkg{trajectories}: analysing movement data} %% - \Abstract{} almost as usual \Abstract{ @@ -52,7 +52,7 @@ %% - \Keywords{} with LaTeX markup, at least one required %% - \Plainkeywords{} without LaTeX markup (if necessary) %% - Should be comma-separated and in sentence case. -\Keywords{Chi-map, Distance, Intensity, \proglang{R}, Second-order characteristics, Spatio-Temporal, Taxi Movements, Trajectory} +\Keywords{Chi-map, Distance, Intensity, \proglang{R}, Second-order characteristics, Spatio-temporal, Taxi Movements, Trajectory} \Plainkeywords{JSS, style guide, comma-separated, not capitalized, R} %% - \Address{} of at least one author @@ -99,11 +99,9 @@ %% -- Introduction ------------------------------------------------------------- \section[Introduction]{Introduction}\label{sec:intro} -Modern data collection techniques allow tracking objects continuously. This means that we do not only know the current location of a moving object, but we also track the objects over time. A set of some tracks from different moving objects may be considered a trajectory pattern. Another example is that in which we record the location of a group of moving objects (e.g., cars, pedestrians, animals) within a regular/irregular time sequence. \cite{guting05} focused on moving objects databases and extended database technology to deal with moving objects. \cite{challa2011} presented an introduction to the field of object tracking and provided solid foundation to the collection of diverse algorithms developed by academics, scientific researchers and engineers. \cite{hanks15} proposed a continuous-time, discrete-space (CTDS) model for animal movement. \cite{niu2016modeling} considered a multivariate Ornstein Uhlenbeck diffusion process to model the movement of animals in continuous time. \cite{russell16} introduced an approach that models dependent movement by augmenting a dynamic marginal movement model with a spatial point process interaction function within a weighted distribution framework. \cite{hooten17} presented a natural basis function approach to constructing appropriate covariance models for movement processes. There are already some \proglang{R} packages available in \href{https://cran.r-project.org}{CRAN Task View: Handling and Analyzing Spatio-Temporal Data} to handle moving objects. Most of them are focused on handling and analysing animal movements such as \pkg{adehabitatLT} \citep{calenge06}, \pkg{tripEstimation} \citep{sumner2009}, \pkg{argosfilter} \citep{argosf}, \pkg{V-Track} \citep{V-Track}, \pkg{animalTrack} \citep{animalTrack}, \pkg{BBMM} \citep{BBMM}, \pkg{bcpa} \citep{bcpa}, \pkg{BayesianAnimalTracker} \citep{BayesianAnimalTracker}, \pkg{TrackReconstruction} \citep{TrackReconstruction}, \pkg{mkde} \citep{mkde}, \pkg{SimilarityMeasures} \citep{SimilarityMeasures}, \pkg{smam} \citep{smam}, \pkg{trip}\citep{trip}, \pkg{moveHMM} \citep{moveHMM}, \pkg{FLightR} \citep{FLightR}. In particular, the package \pkg{adehabitatLT} \citep{calenge06} provides tools to simulate trajectories using a Brownian motion, correlated Random walks and Levy walks. \cite{SimilarityMeasures} presented four different similarity measures in \pkg{SimilarityMeasures}. \cite{moveHMM} in \pkg{moveHMM} provided animal movement modelling using hidden Markov models. Using multiple regression, \pkg{fishmove} \citep{fishmove} provides functions to predict fish movement parameters. The \proglang{R} package \pkg{trackeR} \citep{frick} provides infrastructure for running and cycling Data. +Modern data collection techniques allow tracking objects continuously. This means that we do not only know the current location of a moving object, but we also track the objects over time. A set of some tracks from different moving objects may be considered a trajectory pattern. Another example is that in which we record the location of a group of moving objects (e.g., cars, pedestrians, animals) within a regular/irregular time sequence. \cite{guting05} focused on moving objects databases and extended database technology to deal with moving objects. \cite{challa2011} presented an introduction to the field of object tracking and provided solid foundation to the collection of diverse algorithms developed by academics, scientific researchers and engineers. \cite{hanks15} proposed a continuous-time discrete-space (CTDS) model for animal movement. \cite{niu2016modeling} considered a multivariate Ornstein Uhlenbeck diffusion process to model the movement of animals in continuous time. \cite{russell16} introduced an approach that models dependent movement by augmenting a dynamic marginal movement model with a spatial point process interaction function within a weighted distribution framework. \cite{hooten17} presented a natural basis function approach to constructing appropriate covariance models for movement processes. There are already some \proglang{R} packages available in \href{https://cran.r-project.org}{CRAN Task View: Handling and Analyzing Spatio-Temporal Data} to handle moving objects. Most of them are focused on handling and analysing animal movements such as \pkg{adehabitatLT} \citep{calenge06}, \pkg{tripEstimation} \citep{sumner2009}, \pkg{argosfilter} \citep{argosf}, \pkg{V-Track} \citep{V-Track}, \pkg{animalTrack} \citep{animalTrack}, \pkg{BBMM} \citep{BBMM}, \pkg{bcpa} \citep{bcpa}, \pkg{BayesianAnimalTracker} \citep{BayesianAnimalTracker}, \pkg{TrackReconstruction} \citep{TrackReconstruction}, \pkg{mkde} \citep{mkde}, \pkg{SimilarityMeasures} \citep{SimilarityMeasures}, \pkg{smam} \citep{smam}, \pkg{trip}\citep{trip}, \pkg{moveHMM} \citep{moveHMM}, \pkg{FLightR} \citep{FLightR}. In particular, the package \pkg{adehabitatLT} \citep{calenge06} provides tools to simulate trajectories using a Brownian motion, correlated Random walks and Levy walks. \cite{SimilarityMeasures} presented four different similarity measures in \pkg{SimilarityMeasures}. \cite{moveHMM} in \pkg{moveHMM} provided animal movement modelling using hidden Markov models. Using multiple regression, \pkg{fishmove} \citep{fishmove} provides functions to predict fish movement parameters. The \proglang{R} package \pkg{trackeR} \citep{frick} provides infrastructure for running and cycling Data. -However, to the best of our knowledge, \proglang{R} is still missing a complete set of generic data structures and methods to effectively analyse trajectories without being limited to a particular domain. Figure~\ref{taxitracks} shows routes passed by 5 different taxis on the 4th of Feb 2008 in Beijing, China. Each taxi has a different start/end time. To avoid having a complicated plot, we have only displayed 5 tracks; the entire dataset will be analysed in Section \ref{sec:explo}. - -The entire dataset is stored in the \proglang{R} package \pkg{taxidata} and can be installed through the following code. +However, to the best of our knowledge, \proglang{R} is still missing a complete set of generic data structures and methods to effectively analyse trajectories without being limited to a particular domain. Figure~\ref{taxitracks} shows the routes passed by 5 different taxis on the 4th of Feb 2008 in Beijing, China. Each taxi has a different start/end time. To avoid having a complicated plot, we have only displayed 5 tracks. The entire dataset is stored in the \proglang{R} package \pkg{taxidata} that can be installed through the following code %\begin{Schunk} \begin{Sinput} R> install.packages("taxidata", @@ -113,8 +111,7 @@ Figure~\ref{taxitracks} is generated using the following lines of code. -\begin{figure}[!h] -\begin{center} + %\begin{Schunk} \begin{Sinput} R> library("trajectories") @@ -132,6 +129,8 @@ R> plot(Z[[15]],add=T,col=4,lwd=2) \end{Sinput} %\end{Schunk} +\begin{figure}[!h] +\begin{center} \includegraphics{article-003} \end{center} \caption{Trajectory pattern containing tracks of five taxis on the 4th of Feb 2008 in Beijing, China. Each color represents a different taxi track.} @@ -144,9 +143,9 @@ % \label{taxitracks} % \end{figure} -Studying the behaviour of moving objects over time and their interaction, either between objects or with environment, plays a crucial role in understanding how they use space and more importantly how they interact each other. Moving objects are moving within a particular area over time, thus a snapshot of a trajectory pattern might be seen as a spatial point pattern. This aspect then empowers us to study the behaviour of moving objects within space and over time. A set of locations, usually non-uniformly distributed within a certain region, can be considered as a realisation of a spatial point process. Analysis of spatial point processes has been widely discussed in the literature \citep{MW03,IPSS08,D13,BRT15}. The \proglang{R} package \pkg{spatstat} \citep{baddeley05,BRT15} provides different tools for statistical analysis, model-fitting, simulation and tests on spatial point patterns. \cite{D13} has broadly considered the details of spatio-temporal point processes. Application of such processes can be found in traffic management, geography, forestry, ecology, epidemiology, seismology, astronomy and criminology. +Studying the behaviour of moving objects over time and their interaction, either between objects or with environment, plays a crucial role in understanding how they use space and more importantly how they interact each other. Moving objects are moving within a particular area over time, thus a snapshot of a trajectory pattern might be seen as a spatial point pattern. This aspect then allows to study the behaviour of moving objects within space and over time. A set of locations, usually non-uniformly distributed within a certain region, can be considered as a realisation of a spatial point process. Analysis of spatial point processes has been widely discussed in the literature \citep{MW03,IPSS08,D13,BRT15}. The \proglang{R} package \pkg{spatstat} \citep{baddeley05,BRT15} provides different tools for statistical analysis, model-fitting, simulation and tests on spatial point patterns. \cite{D13} has broadly considered the details of spatio-temporal point processes. Application of such processes can be found in traffic management, geography, forestry, ecology, epidemiology, seismology, astronomy and criminology. -This paper describes a collection of tools provided by the \proglang{R} package \pkg{trajectories} to handle, simulate and statistically analyse movement data regardless of the domain, converting a trajectory pattern into a list of point patterns based on regular timestamps. We here propose different functions to analyse the behaviour of objects over time and how they use space and also how they interact with each other. The type of interaction between objects may vary over time. The effect of the environment on the type of interaction might also be of interest. Therefore, using the literature of spatial point processes, the \proglang{R} package \pkg{trajectories} opens up a new way of thinking about trajectory datasets. We define different classes to handle trajectories, and different functions for simulating and performing exploratory data analysis. We also borrow first and second-order characteristics from the literature of spatial point processes and, by adapting them to trajectory patterns, we aim at highlighting the most frequently used routes within the studied area together with disclosing the type of interaction between the objects over time. Moreover, the \pkg{trajectories} package fits time series models to the spatial coordinates of a trajectory dataset. +This paper describes a collection of tools provided by the \proglang{R} package \pkg{trajectories} to handle, simulate and statistically analyse movement data regardless of the domain, converting a trajectory pattern into a list of point patterns based on regular timestamps. We here propose different functions to analyse the behaviour of objects over time, the way they use space and also how they interact with each other. The type of interaction between objects may vary over time. The effect of the environment on the type of interaction might also be of interest. Therefore, using the literature of spatial point processes, the \proglang{R} package \pkg{trajectories} opens up a new way of thinking about trajectory datasets. We define different classes to handle trajectories, and different functions for simulating and performing exploratory data analysis. We also borrow the first- and second-order characteristics from the literature of spatial point processes and, by adapting them to trajectory patterns, we aim at highlighting the most frequently used routes within the studied area together with disclosing the type of interaction between the objects over time. We further, and based on $\chi^2$ statistics, introduce Chi maps which show the discrepancy between the estimated intensity and expected intensity over the studied area. Moreover, the \pkg{trajectories} package fits time series models to the spatial coordinates of a trajectory dataset. The plan of the paper is the following. Section \ref{sec:setdef} presents some background and definitions. @@ -157,16 +156,16 @@ \section{Setup and definition}\label{sec:setdef} \begin{eqnarray}\label{campbell} \ee \left[\sum\limits_{x \in X} f(x)\right]=\int_{\R^2} f(u)\lambda(u) \de u, \hspace{1cm} u \in \R^2. \end{eqnarray} -Equation~\ref{campbell} has been broadly used in the literature of spatial point processes and it is called \textit{Campbell's formula}. Generally speaking, $\lambda(\cdot) $ is the expected number of points per unit area. Recall that if $\lambda(\cdot)$ is constant then $X$ is homogeneous, otherwise $X$ is called an inhomogeneous point process. One of the first and an important step in studying point processes is to investigate the intensity function. Estimating the intensity function of spatial point processes has been largely discussed \citep{D85,jones93,CSKWM13}. We denote a realisation of the point process $X$ with $n$ points as $\mathbf{x}=\{x_1,x_2,\ldots,x_n \}$; note that $n$ is not fixed in advance. -In point process analysis, we only consider a single realisation of the underlying point process, and then analyse the behaviour of that realisation. However, we might be able to collect the location of spatial events according to regular or irregular timestamps over time. We then have a series of points over time per single object which can be considered as a single track. For instance, recording the location of a taxi over particular times results in the route passed by that taxi. We here consider a {\em trajectory pattern} as a point pattern which lives in $\R^2$ but moves over time. This allows us to adapt the point process statistical methodology into the literature of trajectory patterns. +Equation~\ref{campbell} has been broadly used in the literature of spatial point processes and it is called Campbell's formula. Generally speaking, $\lambda(\cdot) $ is the expected number of points per unit area. Recall that if $\lambda(\cdot)$ is constant then $X$ is homogeneous, otherwise $X$ is called an inhomogeneous point process. One of the first and an important step in studying point processes is to investigate the intensity function. Estimating the intensity function of spatial point processes has been largely discussed \citep{D85,jones93,CSKWM13}. We denote a realisation of the point process $X$ with $n$ points as $\mathbf{x}=\{x_1,x_2,\ldots,x_n \}$; note that $n$ is not fixed in advance. +In point process analysis, we only consider a single realisation of the underlying point process, and then analyse the behaviour of that realisation. However, we might be able to collect the location of spatial events according to regular or irregular timestamps over time. We then have a series of points over time per single object which can be considered as a single track. For instance, recording the location of a taxi over particular times results in the route passed by that taxi. We here consider a trajectory pattern as a point pattern which lives in $\R^2$ but moves over time. This allows us to adapt the point process statistical methodology into the literature of trajectory patterns. \begin{definition} A \textit{trajectory pattern} is a dataset which provides observed -tracks $(s_i)$ of a set of moving objects such as cars, humans, etc over a finite time period $T$. We denote a trajectory pattern consisted by $n>0$ single tracks as $S=\{s_i: s_i \subset \R^2, \hspace{1mm} i=1,\ldots,n \}$, that is a countable set of tracks. Each $s_i$ is itself a countable set of points, e.g., $s_i=\{x_1^{s_i},x_2^{s_i}.\cdots, x_{m_i}^{s_i} \}$ with $i=1,\cdots,n$ where each $s_i$ consists of $m_i<\infty$ points that are associated with an increasing set of time stamps $t_1,...,t_{m_i}$, $t_j > t_{j+1} \forall j$. +tracks $(s_i)$ of a set of moving objects such as cars, humans, etc over a finite time period $T$. We denote a trajectory pattern consisting of $n>0$ single tracks as $S=\{s_i: s_i \subset \R^2, \hspace{1mm} i=1,\ldots,n \}$, that is a countable set of tracks. Each $s_i$ is itself a countable set of points, e.g., $s_i=\{x_1^{s_i},x_2^{s_i}.\cdots, x_{m_i}^{s_i} \}$ with $i=1,\cdots,n$ where each $s_i$ consists of $m_i<\infty$ points that are associated with an increasing set of time stamps $t_1,...,t_{m_i}$, $t_j > t_{j+1} \forall j$. \end{definition} We point out that the length of each of the tracks $s_i$ is not necessarily the same for all tracks. In other words, they might have different start/end times. Each single track $s_i$ represents the movement of a moving object within a finite time/area. It is usually supposed that locations of a moving object are recorded in regular timestamps. However, if timestamps are not regular, one can still interpolate the locations in regular timestamps. Therefore, each single track in $S$ might be seen as a set of points corresponding to the considered timestamps. Discretising all tracks of $S$ according to regular timestamps results in a list of point patterns (one per each time) which enables us to consider a trajectory pattern as a point pattern which is changing over time. Therefore, using point pattern methodology, one can study the behaviour of moving objects over time. For instance, the spatially varying distribution of objects and the type of interaction between them over time can be of interest. Assume that the trajectory pattern $S$ is observed within the time period $T$, thus discretising $T$ into a time sequence $\{t_i: t_i \subset T, i=1,\ldots,k \quad \text{where} \quad t_i < t_j \quad \text{if} \quad i< j \}$ generates a collection of spatial point patterns, say, $\textbf{x}_1,\textbf{x}_2, \ldots, \textbf{x}_k$ $(k>1)$. Details are provided in Section \ref{sec:explo}. Nevertheless, one may still consider $S$ as a point process on $\R^{2\otimes k}$, where $\R^{2\otimes k}$ means $\R^2 \times \cdots \times \R^2$ for $k$ times when the length of timestamps is $k$. We do not discuss this other approach here. \section{Classes and methods} \label{sec:classes} -In this section, we review different classes of trajectories to handle movement data in \proglang{R}. These classes were initially defined in the \proglang{R} package \pkg{spacetime} \citep{spacetime}. Before moving into the details and start analysing trajectory patterns, we load the package with: +In this section, we review different classes of trajectories to handle movement data in \proglang{R}. These classes were initially defined in the \proglang{R} package \pkg{spacetime} \citep{spacetime}. Before moving into the details and start analysing trajectory patterns, we load the package with %\begin{Schunk} \begin{Sinput} @@ -239,7 +238,7 @@ \subsection{Track} %\end{Schunk} \subsection{Tracks} - The class \class{Tracks} embodies a collection of tracks followed by a single person, animal or object. The class contains two slots: @tracks to store the tracks as objects of class \class{Track} and @tracksData to hold a summary record for each particular track (e.g., minimum and maximum time, total distance and average speed). An object of class \class{Tracks} can be created by: + The class \class{Tracks} embodies a collection of tracks followed by a single person, animal or object. The class contains two slots: @tracks to store the tracks as objects of class \class{Track} and @tracksData to hold a summary record for each particular track (e.g., minimum and maximum time, total distance and average speed). An object of class \class{Tracks} can be created by %\begin{Schunk} \begin{Sinput} @@ -262,7 +261,7 @@ \subsection{Tracks} where \code{A1} and \code{A2} are of class \class{Track}. By default, the minimum and maximum coordinates and time, the total number of geometries, the total distance as well as the average speed are computed as the summary information data. As for the \class{Track} method, a data frame and/or a custom function can be passed to expand the default data. \subsection{TracksCollection} -The class \class{TracksCollection} represents a collection of tracks followed by many persons, animals or objects. The class contains two slots: @tracksCollection to store the tracks as objects of class \class{Tracks} and @tracksCollectionData to hold summary information about each particular person, animal or object (e.g., the total number of tracks per each object). A \class{TracksCollection} object can be created by: +The class \class{TracksCollection} represents a collection of tracks followed by many persons, animals or objects. The class contains two slots: @tracksCollection to store the tracks as objects of class \class{Tracks} and @tracksCollectionData to hold summary information about each particular person, animal or object (e.g., the total number of tracks per each object). A \class{TracksCollection} object can be created by %\begin{Schunk} \begin{Sinput} R> # person B, track 1: @@ -304,8 +303,9 @@ \subsection{segments} \label{classes} \end{figure} -Figure~\ref{classes} shows the classes and their connection. We point out that classes \class{STIDF},\class{STI} and \class{ST} belong to the package \pkg{spacetime} inherently . - % \section{Methods} \label{sec:methods} +Figure~\ref{classes} shows the classes and their connection. We point out that classes \class{STIDF},\class{STI} and \class{ST} belong to the package \pkg{spacetime} inherently. + + \subsection{Methods} \label{sec:methods} A wealth of methods have been implemented to cover the most frequently used use cases. Table~\ref{Tablemethod} lists some of the methods applied to the objects of classes \code{Track}, \code{Tracks} and \code{TracksCollection}. Apart from those listed in Table~\ref{Tablemethod}, attribute data can be obtained or replaced by using \code{[]}, \code{[[]]}, \code{@} and \code{$}. \begin{table}[!h] @@ -323,7 +323,7 @@ \subsection{segments} \code{stbox}& The spatio-temporal box (window) which contains the objects\\ \code{aggregate}& Spatially aggregate track properties (coercing fixes to points)\\ \code{compare}& Compares two \class{Track} objects: for the common time period\\ - \code{dists}& Compares two \class{Tracks} using the mean distance, the Frechet distance,etc\\ + \code{dists}& Compares two \class{Tracks} using the mean distance, the Frechet distance, etc\\ \code{downsample}& Remove fixes from a \class{Track}, starting with the most densely sampled ones\\ \code{frechetDist}& Compute Frechet distance between two \class{Track} objects\\ \code{stcube} & Draw a space-time cube\\ @@ -389,7 +389,7 @@ \subsection{segments} \section{Simulation and model fitting}\label{simandfitt} \subsection{Trajectory simulation} - Simulating trajectory patterns can be a useful tool to imitate true models and understand their behaviour. The package \pkg{trajectories} allows simulating tracks using \code{rTrack}, \code{rTracks}, \code{rTracksCollection} where \code{rTrack()} generates a single track, \code{rTracks()} simulates a collection of tracks assumed to be passed by a single object and \code{rTracksCollection} is used to simulate a set of tracks passed by different objects. By default, these functions do not consider any box (or window) for the track to be simulated in and consider \code{origin=c(0,0)} as the origin of the track. However, one can still restrict the track to a desirable closed box using the argument \code{bbox}. If \code{transform=TRUE} and no \code{bbox} is given, then \code{rTrack} transforms the track to the default box $[0,1]\times [0,1]$, where in this case the origin is a random point in the default box. If a default box \code{bbox} (e.g., \code{m} in the following example) is given and \code{transform=TRUE}, then \code{origin} is a random point in \code{bbox} and the final track is also transformed into \code{bbox}. The function \code{rTrack} simulates tracks with a predefined number of points per track (indicated as \code{n} in the code with default $100$). However if \code{nrandom=TRUE} then it simulates a track with a random number of points based on a Poisson distribution with parameter \code{n}. An example of these functions is the following: + Simulating trajectory patterns can be a useful tool to imitate true models and understand their behaviour. The package \pkg{trajectories} allows simulating tracks using \code{rTrack}, \code{rTracks}, \code{rTracksCollection} where \code{rTrack()} generates a single track, \code{rTracks()} simulates a collection of tracks assumed to be passed by a single object and \code{rTracksCollection} is used to simulate a set of tracks passed by different objects. By default, these functions do not consider any box (or window) for the track to be simulated in and consider \code{origin=c(0,0)} as the origin of the track. However, one can still restrict the track to a desirable closed box using the argument \code{bbox}. If \code{transform=TRUE} and no \code{bbox} is given, then \code{rTrack} transforms the track to the default box $[0,1]\times [0,1]$, where in this case the origin is a random point in the default box. If a default box \code{bbox} (e.g., \code{m} in the following example) is given and \code{transform=TRUE}, then \code{origin} is a random point in \code{bbox} and the final track is also transformed into \code{bbox}. The function \code{rTrack} simulates tracks with a predefined number of points per track (indicated as \code{n} in the code with default $100$). However if \code{nrandom=TRUE} then it simulates a track with a random number of points based on a Poisson distribution with parameter \code{n}. An example of these functions is the following %\begin{Schunk} \begin{Sinput} R> set.seed(10) @@ -494,7 +494,8 @@ \subsection{Data} \item Regardless of taxis with no information, there are $4694$ taxis with less than $10$ recorded locations in at least one day. \item There are tracks with some jumps to the outside of the studied area and it may be caused by lack of GPS accuracy so that wrong locations have been removed. These locations might later be recovered by interpolation. \end{itemize} - We thus analyse the cleaned dataset which is based on moving data of $5642$ taxis. The map of the studied area is displayed in Figure~\ref{Beijingmapgoogle}. It is seen that the metropolitan area of Beijing is almost located in the centre of the map while there are some other townships, airports in the countryside of Beijing. + +The cleaned dataset contains the movements of $5642$ taxis, but here we only analyse the movements of 2000 taxis to speed up calculations. The map of the studied area is displayed in Figure~\ref{Beijingmapgoogle}. It is seen that the metropolitan area of Beijing is almost located in the centre of the map while there are some other townships, airports in the countryside of Beijing. \begin{figure}[!h] \centering \includegraphics[width = 4in]{Beijingmap} @@ -504,7 +505,7 @@ \subsection{Data} In the following, we present the implemented methods in \pkg{trajectories} by applying them to the taxi movement dataset in Beijing, China. \subsection{Distance analysis}\label{distanal} - A simple way to get into the nature of movement data is to study the distance between objects. The function \code{dists} provides users with calculating the distance between a pair of objects of class \class{Tracks}. This considers the distance between tracks when they overlap in time. The output is a matrix with distances between each pair of tracks or 'NA', if they do not overlap in time. A function to calculate distances can be passed to \code{dists}, such as \code{mean}, \code{sum}, \code{frechetDist}, etc. + A simple way to get into the nature of movement data is to study the distance between objects. The function \code{dists} provides users with calculating the distance between a pair of objects of class \class{Tracks}. This considers the distance between tracks when they overlap in time. The output is a matrix with distances between each pair of tracks or `NA', if they do not overlap in time. A function to calculate distances can be passed to \code{dists}, such as \code{mean}, \code{sum}, \code{frechetDist}, etc. %\begin{Schunk} \begin{Sinput} @@ -548,7 +549,7 @@ \subsubsection{Average distance over time} %\end{Schunk} \includegraphics{article-016} \end{center} -\caption{Average pairwise distances between taxis in Beijing, China. \emph{Left}: Within the period $2-8$, Feb $2008$. \emph{Right}: During $3$-rd of Feb $2008$.} +\caption{Average pairwise distances between taxis in Beijing, China. \emph{Left}: Within the period $2\text{-}8$, Feb $2008$. \emph{Right}: During $3$-{\it rd} of Feb $2008$.} \label{distbijing} \end{figure} @@ -559,7 +560,7 @@ \subsubsection{Average distance over time} % \caption{Average pairwise distance between taxis in Beijing, China. \emph{Left}: Within the period $2-8$, Feb $2008$. \emph{Right}: During $3$-rd of Feb $2008$.} % \label{distbijing} % \end{figure} -Figure~\ref{distbijing} shows the average distance between taxis in Beijing. The left plot shows the average pairwise distance between taxis for all the week and it is easily seen that there is a daily trend. In order to see the more crowded hours within a day, we show the average pairwise distances during the $3$-rd of Feb $2008$ in the right plot in Figure~\ref{distbijing}. It can be seen that the crowded time comes between midday and $17:00$. Also, it shows how taxis are getting far from each other during night. Note that small average distances between taxis might be a sign of traffic during the corresponding hours. We point out that the reason of having larger average distance in the last two days might be the Chinese new year holidays. +Figure~\ref{distbijing} shows the average distance between taxis in Beijing. The left plot shows the average pairwise distance between taxis for all the week and it is easily seen that there is a daily trend. In order to see the more crowded hours within a day, we show the average pairwise distances during the $3$-{\it rd} of Feb $2008$ in the right plot in Figure~\ref{distbijing}. It can be seen that the crowded time comes between midday and $17$. Also, it shows how taxis are getting far from each other during night. Note that small average distances between taxis might be a sign of traffic during the corresponding hours. We point out that the reason of having larger average distance in the last two days might be the Chinese new year holidays. As an alternative, one can use nearest neighbour distances instead of pairwise distances. But that might not distinguish patterns with different clusters, i.e., patterns with different sets of tracks concentrated in some particular subregions. \subsection{Movement smoothing} @@ -608,7 +609,7 @@ \subsubsection{Average distance over time} % \end{figure} Figure~\ref{idwBeijing} shows the movement smoothing for taxi data in Beijing according to the \code{timestamp= "20 mins"}. Here, we have not considered movements with length less than $1000$ meters. In other words, we assume taxis with the length of movements less than $1000$ meters per $20$ minutes as stopped. This confirms that moving in the centre is slower than countryside/highways in Beijing, and in particular, it reveals some highways/freeways in which taxis are moving faster. - After smoothing the length of movements over space, we now turn to see the changes in the average of the length of movements over time. The function \code{avemove} measures the average length of movements passed by a collection of tracks based on a desirable timestamps. Now, we apply this to the taxi data in Beijing as follows + After smoothing the length of movements over space, we now turn to see the changes in the average of the length of movements over time. The function \code{avemove} measures the average length of movements passed by a collection of tracks based on a desirable timestamps. Now, we apply this to the taxi data in Beijing. \begin{figure}[!h] \begin{center} %\begin{Schunk} @@ -625,7 +626,7 @@ \subsubsection{Average distance over time} %\end{Schunk} \includegraphics{article-018} \end{center} -\caption{Average length of movements by taxis in Beijing, China versus time based on \code{timestamp = "20 mins"}, and movements with length longer than $1000$ meters. \emph{Left}: Within the period $2-8$ Feb $2008$. \emph{Right}: During the $3$-rd of Feb $2008$.} +\caption{Average length of movements by taxis in Beijing, China versus time based on \code{timestamp = "20 mins"}, and movements with length longer than $1000$ meters. \emph{Left}: Within the period $2\text{-}8$ Feb $2008$. \emph{Right}: During the $3$-{\it rd} of Feb $2008$.} \label{avemovebijing} \end{figure} % \begin{figure}[!h] @@ -717,7 +718,7 @@ \subsection{Intensity function}\label{sec:intensity} \end{eqnarray*} is the expected intensity at time $t=t_1$ and location $u \in W$. Doing so for all $u \in W$ enables us to draw a map of $\chi^2$ values in a fixed time. The resulting map discloses the areas where the estimated intensity differs from the expected intensity. The function \code{chimaps} generates a map based on a given timestamp and rank. The argument rank is a number between one and the length of the generated time sequence based on the given timestamp, and with default one. - The chi maps of the $3$-rd of Feb based on three different ranks are displayed in Figure~\ref{bijingchi}. Values of each pixel is calculated by equation~\ref{chistat}. We show the chi maps for three different times during the day in which changes over time can be seen. The left plot of Figure~\ref{bijingchi} shows the chi map at \code{06:10:44} so that the estimated intensity is higher than the expected intensity in the countryside. The reason for this might be the movements from countryside to the city center in the early morning. The middle plot of Figure~\ref{bijingchi} shows that the estimated intensity in the city is higher than the expected intensity. This may be caused by heavier traffic in the city during the day than in the countryside. In the right plot of Figure~\ref{bijingchi}, although the estimated intensity is still slightly higher than the expected one in the city, we can see that the $\chi^2$ statistic~\ref{chistat} takes values around $0$ almost everywhere at night. These three plots together confirm the changes in the values of the $\chi^2$ statistic~\ref{chistat} over time so that the mass is moving to the city in the morning and goes away in the evening. This behaviour may be explained by the movements to the city in the morning and moving back to the countryside in the evening. + The chi maps of the $3$-{\it rd} of Feb based on three different ranks are displayed in Figure~\ref{bijingchi}. Value of each pixel is calculated by equation~\ref{chistat}. We show the chi maps for three different times during the day in which changes over time can be seen. The left plot of Figure~\ref{bijingchi} shows the chi map at \code{06:10:44} so that the estimated intensity is higher than the expected intensity in the countryside. The reason for this might be the movements from countryside to the city center in the early morning. The middle plot of Figure~\ref{bijingchi} shows that the estimated intensity in the city is higher than the expected intensity. This may be caused by heavier traffic in the city during the day than in the countryside. In the right plot of Figure~\ref{bijingchi}, although the estimated intensity is still slightly higher than the expected one in the city, we can see that the $\chi^2$ statistic~\ref{chistat} takes values around $0$ almost everywhere at night. These three plots together confirm the changes in the values of the $\chi^2$ statistic~\ref{chistat} over time so that the mass is moving to the city in the morning and goes away in the evening. This behaviour may be explained by the movements to the city in the morning and moving back to the countryside in the evening. \begin{figure}[!h] \begin{center} @@ -796,12 +797,12 @@ \subsection{Second-order summary statistics} \end{enumerate} \end{leftbar} -Note that, steps above can be applied to the pair correlation function as well. +Note that steps above can be applied to the pair correlation function as well. In both functions above, users can take advantage of the bandwidth selection to first estimate the intensity function and then pass estimated intensities to the function \code{Kinhom} or \code{pcfinhom}. Default is to not pass any estimated intensity function to \code{Kinhom} or \code{pcfinhom} in which the intensity will be estimated using the `leave-one-out' kernel smoother \citep{baddeley00,BRT15}. Different edge corrections can be also passed to \code{Kinhom.Track} and \code{pcfinhom.Track}. - Finally and taking into account that estimated intensity in Figure~\ref{bijingint} represent a non-unifrom distribution and/or clustering behaviour, we show the variability area of $K$-function and pair correlation function over time in Figure~\ref{Kgvariation} (considering the ``translate'' correction, see \cite{gabriel2014}). The left plot displays the variation of $K$-function, showing that for small distances taxis tend to have a clustering behaviour while for larger distances they favour inhibition. The right plot of the variation of the pair correlation function also confirms the same behaviour. Due to the preference of moving within particular zones, $K$-function and pair correlation function might result as what is displayed in Figure~\ref{Kgvariation}. In other words, taxis might prefer to take passengers to close destinations within particular zones rather than further destinations. Argument \code{q} is to use quantiles of the values of $K$-function (or pair correlation function) rather than using maximum and minimum. Default \code{q=0} uses maximum and minimum. + Finally and taking into account that estimated intensity in Figure~\ref{bijingint} represents a non-uniform distribution and/or clustering behaviour, we show the variability area of $K$-function and pair correlation function over time in Figure~\ref{Kgvariation} (considering the ``translate'' correction, see \cite{gabriel2014}). The left plot displays the variation of $K$-function, showing that for small distances taxis tend to have a clustering behaviour while for larger distances they favour inhibition. The right plot of the variation of the pair correlation function also confirms the same behaviour. Due to the preference of moving within particular zones, $K$-function and pair correlation function might result as what is displayed in Figure~\ref{Kgvariation}. In other words, taxis might prefer to take passengers to close destinations within particular zones rather than further destinations. Argument \code{q} is to use quantiles of the values of $K$-function (or pair correlation function) rather than using maximum and minimum. Default \code{q=0} uses maximum and minimum. \begin{figure}[!h] \begin{center} %\begin{Schunk} @@ -828,14 +829,14 @@ \subsection{Second-order summary statistics} % \label{Kgvariation} % \end{figure} - We point out that as this kind of discretising trajectory patterns results in a set of spatial point patterns, it may also drives us to consider them as replicated spatial point patterns. Therefore, one may be able to introduce a single $K$-function or pair correlation function for all patterns. Note that in this case, point patterns are not independent. For more details, see \citet[Section 5.4]{D13}. + We point out that as this kind of discretising trajectory patterns results in a set of spatial point patterns, it may also drive us to consider them as replicated spatial point patterns. Therefore, one may be able to introduce a single $K$-function or pair correlation function for all patterns. Note that in this case, point patterns are not independent. For more details, see \citet[Section 5.4]{D13}. \section{Summary and discussion} \label{sec:summary} Analysing trajectory data is often a challenge as moving objects are living in space while moving in time. Such data might be analysed in space or time separately. However, one may look at trajectory patterns with a different perspective. In this paper, we introduced a set of classes to handle trajectory data and defined a set of methods to summarise trajectory patterns. We have considered different classes to handle tracks passed by one object or a group of objects. We also aimed at statistically analysing trajectory data in space and see the changes in the behaviour of data over time. To do so, the literature of spatial point processes has been adapted to trajectory patterns. An average intensity function is defined for a trajectory pattern with tracks that overlap in time and it nicely reveals the more visited spots, streets, highways, etc. Pairwise distances between different objects have been also considered in \pkg{trajectories} showing how moving objects interact over time. Moreover, we have implemented methods to smooth the length of movements over time which highlights where objects move faster/slower. In addition, the discrepancy between the estimated intensity and the expected intensity per location per time can be studied in \pkg{trajectories} which shows how the mass is moving within the studied area over time. We finally presented a variability area for second-order summary statistics such as $K$-function and pair correlation function which displays the type of interaction between objects over time, highlighting possible clustering or inhibition. - To perform an exploratory data analysis, we finally applied the developed methodologies to a taxi data from Beijing, China. The results nicely highlight the behaviour of taxis over time. We have recognized where the more visited spots are and also at what time data pattern is denser or objects get closer to each other. We smoothed the movements of taxis and discovered where and at what time they move faster. Not surprisingly, results confirm that moving within the city is slower than countryside or highways. Also, in the afternoon there is a decrease in the length of movements which might be affected by traffic. Chi maps have been studied showing how the mass is moving within the studied area. They display that objects are moving from countryside to the city in the morning making a heavy traffic in the city in the afternoon, as the estimated intensity is higher than the expected one. Chi maps also confirm that the discrepancy between the estimated intensity and the expected one is less during the evening than any other time. The variability area of $K$-function and pair correlation function show that for small distances, taxis tend to show a clustering behaviour while for longer distances they show repulsion. + To perform an exploratory data analysis, we finally applied the developed methodologies to a taxi data from Beijing, China. The results nicely highlight the behaviour of taxis over time. We have recognised where the more visited spots are and also at what time data pattern is denser or objects get closer to each other. We smoothed the movements of taxis and discovered where and at what time they move faster. Not surprisingly, results confirm that moving within the city is slower than countryside or highways. Also, in the afternoon there is a decrease in the length of movements which might be affected by traffic. Chi maps have been studied showing how the mass is moving within the studied area. They display that objects are moving from countryside to the city in the morning making a heavy traffic in the city in the afternoon, as the estimated intensity is higher than the expected one. Chi maps also confirm that the discrepancy between the estimated intensity and the expected one is less during the evening than any other time. The variability area of $K$-function and pair correlation function show that for small distances, taxis tend to show a clustering behaviour while for longer distances they show repulsion. We leave open the analysis of the effect of the environment on moving objects and the corresponding parametric analysis for future works. diff --git a/vignettes/jss.bst b/vignettes/jss.bst new file mode 100644 index 0000000..ae75415 --- /dev/null +++ b/vignettes/jss.bst @@ -0,0 +1,1653 @@ +%% +%% This is file `jss.bst', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% merlin.mbs (with options: `ay,nat,nm-rvx,keyxyr,dt-beg,yr-par,note-yr,tit-qq,atit-u,trnum-it,vol-bf,volp-com,num-xser,pre-edn,isbn,issn,edpar,pp,ed,xedn,xand,etal-it,revdata,eprint,url,url-blk,doi,nfss') +%% +%% ** BibTeX style file for JSS publications (http://www.jstatsoft.org/) +%% +%% License: GPL-2 | GPL-3 + % =============================================================== + % IMPORTANT NOTICE: + % This bibliographic style (bst) file has been generated from one or + % more master bibliographic style (mbs) files, listed above, provided + % with kind permission of Patrick W Daly. + % + % This generated file can be redistributed and/or modified under the terms + % of the General Public License (Version 2 or 3). + % =============================================================== + % Name and version information of the main mbs file: + % \ProvidesFile{merlin.mbs}[2011/11/18 4.33 (PWD, AO, DPC)] + % For use with BibTeX version 0.99a or later + %------------------------------------------------------------------- + % This bibliography style file is intended for texts in ENGLISH + % This is an author-year citation style bibliography. As such, it is + % non-standard LaTeX, and requires a special package file to function properly. + % Such a package is natbib.sty by Patrick W. Daly + % The form of the \bibitem entries is + % \bibitem[Jones et al.(1990)]{key}... + % \bibitem[Jones et al.(1990)Jones, Baker, and Smith]{key}... + % The essential feature is that the label (the part in brackets) consists + % of the author names, as they should appear in the citation, with the year + % in parentheses following. There must be no space before the opening + % parenthesis! + % With natbib v5.3, a full list of authors may also follow the year. + % In natbib.sty, it is possible to define the type of enclosures that is + % really wanted (brackets or parentheses), but in either case, there must + % be parentheses in the label. + % The \cite command functions as follows: + % \citet{key} ==>> Jones et al. (1990) + % \citet*{key} ==>> Jones, Baker, and Smith (1990) + % \citep{key} ==>> (Jones et al., 1990) + % \citep*{key} ==>> (Jones, Baker, and Smith, 1990) + % \citep[chap. 2]{key} ==>> (Jones et al., 1990, chap. 2) + % \citep[e.g.][]{key} ==>> (e.g. Jones et al., 1990) + % \citep[e.g.][p. 32]{key} ==>> (e.g. Jones et al., 1990, p. 32) + % \citeauthor{key} ==>> Jones et al. + % \citeauthor*{key} ==>> Jones, Baker, and Smith + % \citeyear{key} ==>> 1990 + %--------------------------------------------------------------------- + +ENTRY + { address + archive + author + booktitle + chapter + collaboration + doi + edition + editor + eid + eprint + howpublished + institution + isbn + issn + journal + key + month + note + number + numpages + organization + pages + publisher + school + series + title + type + url + volume + year + } + {} + { label extra.label sort.label short.list } +INTEGERS { output.state before.all mid.sentence after.sentence after.block } +FUNCTION {init.state.consts} +{ #0 'before.all := + #1 'mid.sentence := + #2 'after.sentence := + #3 'after.block := +} +STRINGS { s t} +FUNCTION {output.nonnull} +{ 's := + output.state mid.sentence = + { ", " * write$ } + { output.state after.block = + { add.period$ write$ + newline$ + "\newblock " write$ + } + { output.state before.all = + 'write$ + { add.period$ " " * write$ } + if$ + } + if$ + mid.sentence 'output.state := + } + if$ + s +} +FUNCTION {output} +{ duplicate$ empty$ + 'pop$ + 'output.nonnull + if$ +} +FUNCTION {output.check} +{ 't := + duplicate$ empty$ + { pop$ "empty " t * " in " * cite$ * warning$ } + 'output.nonnull + if$ +} +FUNCTION {fin.entry} +{ add.period$ + write$ + newline$ +} + +FUNCTION {new.block} +{ output.state before.all = + 'skip$ + { after.block 'output.state := } + if$ +} +FUNCTION {new.sentence} +{ output.state after.block = + 'skip$ + { output.state before.all = + 'skip$ + { after.sentence 'output.state := } + if$ + } + if$ +} +FUNCTION {add.blank} +{ " " * before.all 'output.state := +} + +FUNCTION {date.block} +{ + new.block +} + +FUNCTION {not} +{ { #0 } + { #1 } + if$ +} +FUNCTION {and} +{ 'skip$ + { pop$ #0 } + if$ +} +FUNCTION {or} +{ { pop$ #1 } + 'skip$ + if$ +} +FUNCTION {non.stop} +{ duplicate$ + "}" * add.period$ + #-1 #1 substring$ "." = +} + +STRINGS {z} + +FUNCTION {remove.dots} +{ 'z := + "" + { z empty$ not } + { z #1 #2 substring$ + duplicate$ "\." = + { z #3 global.max$ substring$ 'z := * } + { pop$ + z #1 #1 substring$ + z #2 global.max$ substring$ 'z := + duplicate$ "." = 'pop$ + { * } + if$ + } + if$ + } + while$ +} +FUNCTION {new.block.checkb} +{ empty$ + swap$ empty$ + and + 'skip$ + 'new.block + if$ +} +FUNCTION {field.or.null} +{ duplicate$ empty$ + { pop$ "" } + 'skip$ + if$ +} +FUNCTION {emphasize} +{ duplicate$ empty$ + { pop$ "" } + { "\emph{" swap$ * "}" * } + if$ +} +FUNCTION {bolden} +{ duplicate$ empty$ + { pop$ "" } + { "\textbf{" swap$ * "}" * } + if$ +} +FUNCTION {tie.or.space.prefix} +{ duplicate$ text.length$ #3 < + { "~" } + { " " } + if$ + swap$ +} + +FUNCTION {capitalize} +{ "u" change.case$ "t" change.case$ } + +FUNCTION {space.word} +{ " " swap$ * " " * } + % Here are the language-specific definitions for explicit words. + % Each function has a name bbl.xxx where xxx is the English word. + % The language selected here is ENGLISH +FUNCTION {bbl.and} +{ "and"} + +FUNCTION {bbl.etal} +{ "et~al." } + +FUNCTION {bbl.editors} +{ "eds." } + +FUNCTION {bbl.editor} +{ "ed." } + +FUNCTION {bbl.edby} +{ "edited by" } + +FUNCTION {bbl.edition} +{ "edition" } + +FUNCTION {bbl.volume} +{ "volume" } + +FUNCTION {bbl.of} +{ "of" } + +FUNCTION {bbl.number} +{ "number" } + +FUNCTION {bbl.nr} +{ "no." } + +FUNCTION {bbl.in} +{ "in" } + +FUNCTION {bbl.pages} +{ "pp." } + +FUNCTION {bbl.page} +{ "p." } + +FUNCTION {bbl.eidpp} +{ "pages" } + +FUNCTION {bbl.chapter} +{ "chapter" } + +FUNCTION {bbl.techrep} +{ "Technical Report" } + +FUNCTION {bbl.mthesis} +{ "Master's thesis" } + +FUNCTION {bbl.phdthesis} +{ "Ph.D. thesis" } + +MACRO {jan} {"January"} + +MACRO {feb} {"February"} + +MACRO {mar} {"March"} + +MACRO {apr} {"April"} + +MACRO {may} {"May"} + +MACRO {jun} {"June"} + +MACRO {jul} {"July"} + +MACRO {aug} {"August"} + +MACRO {sep} {"September"} + +MACRO {oct} {"October"} + +MACRO {nov} {"November"} + +MACRO {dec} {"December"} + +MACRO {acmcs} {"ACM Computing Surveys"} + +MACRO {acta} {"Acta Informatica"} + +MACRO {cacm} {"Communications of the ACM"} + +MACRO {ibmjrd} {"IBM Journal of Research and Development"} + +MACRO {ibmsj} {"IBM Systems Journal"} + +MACRO {ieeese} {"IEEE Transactions on Software Engineering"} + +MACRO {ieeetc} {"IEEE Transactions on Computers"} + +MACRO {ieeetcad} + {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"} + +MACRO {ipl} {"Information Processing Letters"} + +MACRO {jacm} {"Journal of the ACM"} + +MACRO {jcss} {"Journal of Computer and System Sciences"} + +MACRO {scp} {"Science of Computer Programming"} + +MACRO {sicomp} {"SIAM Journal on Computing"} + +MACRO {tocs} {"ACM Transactions on Computer Systems"} + +MACRO {tods} {"ACM Transactions on Database Systems"} + +MACRO {tog} {"ACM Transactions on Graphics"} + +MACRO {toms} {"ACM Transactions on Mathematical Software"} + +MACRO {toois} {"ACM Transactions on Office Information Systems"} + +MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"} + +MACRO {tcs} {"Theoretical Computer Science"} +FUNCTION {bibinfo.check} +{ swap$ + duplicate$ missing$ + { + pop$ pop$ + "" + } + { duplicate$ empty$ + { + swap$ pop$ + } + { swap$ + pop$ + } + if$ + } + if$ +} +FUNCTION {bibinfo.warn} +{ swap$ + duplicate$ missing$ + { + swap$ "missing " swap$ * " in " * cite$ * warning$ pop$ + "" + } + { duplicate$ empty$ + { + swap$ "empty " swap$ * " in " * cite$ * warning$ + } + { swap$ + pop$ + } + if$ + } + if$ +} +FUNCTION {format.eprint} +{ eprint duplicate$ empty$ + 'skip$ + { "\eprint" + archive empty$ + 'skip$ + { "[" * archive * "]" * } + if$ + "{" * swap$ * "}" * + } + if$ +} +FUNCTION {format.url} +{ + url + duplicate$ empty$ + { pop$ "" } + { "\urlprefix\url{" swap$ * "}" * } + if$ +} + +INTEGERS { nameptr namesleft numnames } + + +STRINGS { bibinfo} + +FUNCTION {format.names} +{ 'bibinfo := + duplicate$ empty$ 'skip$ { + 's := + "" 't := + #1 'nameptr := + s num.names$ 'numnames := + numnames 'namesleft := + { namesleft #0 > } + { s nameptr + "{vv~}{ll}{ jj}{ f{}}" + format.name$ + remove.dots + bibinfo bibinfo.check + 't := + nameptr #1 > + { + namesleft #1 > + { ", " * t * } + { + s nameptr "{ll}" format.name$ duplicate$ "others" = + { 't := } + { pop$ } + if$ + "," * + t "others" = + { + " " * bbl.etal emphasize * + } + { " " * t * } + if$ + } + if$ + } + 't + if$ + nameptr #1 + 'nameptr := + namesleft #1 - 'namesleft := + } + while$ + } if$ +} +FUNCTION {format.names.ed} +{ + 'bibinfo := + duplicate$ empty$ 'skip$ { + 's := + "" 't := + #1 'nameptr := + s num.names$ 'numnames := + numnames 'namesleft := + { namesleft #0 > } + { s nameptr + "{f{}~}{vv~}{ll}{ jj}" + format.name$ + remove.dots + bibinfo bibinfo.check + 't := + nameptr #1 > + { + namesleft #1 > + { ", " * t * } + { + s nameptr "{ll}" format.name$ duplicate$ "others" = + { 't := } + { pop$ } + if$ + "," * + t "others" = + { + + " " * bbl.etal emphasize * + } + { " " * t * } + if$ + } + if$ + } + 't + if$ + nameptr #1 + 'nameptr := + namesleft #1 - 'namesleft := + } + while$ + } if$ +} +FUNCTION {format.key} +{ empty$ + { key field.or.null } + { "" } + if$ +} + +FUNCTION {format.authors} +{ author "author" format.names + duplicate$ empty$ 'skip$ + { collaboration "collaboration" bibinfo.check + duplicate$ empty$ 'skip$ + { " (" swap$ * ")" * } + if$ + * + } + if$ +} +FUNCTION {get.bbl.editor} +{ editor num.names$ #1 > 'bbl.editors 'bbl.editor if$ } + +FUNCTION {format.editors} +{ editor "editor" format.names duplicate$ empty$ 'skip$ + { + " " * + get.bbl.editor + "(" swap$ * ")" * + * + } + if$ +} +FUNCTION {format.isbn} +{ isbn "isbn" bibinfo.check + duplicate$ empty$ 'skip$ + { + new.block + "ISBN " swap$ * + } + if$ +} + +FUNCTION {format.issn} +{ issn "issn" bibinfo.check + duplicate$ empty$ 'skip$ + { + new.block + "ISSN " swap$ * + } + if$ +} + +FUNCTION {format.doi} +{ doi empty$ + { "" } + { + new.block + "\doi{" doi * "}" * + } + if$ +} +FUNCTION {format.note} +{ + note empty$ + { "" } + { note #1 #1 substring$ + duplicate$ "{" = + 'skip$ + { output.state mid.sentence = + { "l" } + { "u" } + if$ + change.case$ + } + if$ + note #2 global.max$ substring$ * "note" bibinfo.check + } + if$ +} + +FUNCTION {format.title} +{ title + "title" bibinfo.check + duplicate$ empty$ 'skip$ + { + "\enquote{" swap$ * + add.period$ "}" * + } + if$ +} +FUNCTION {format.full.names} +{'s := + "" 't := + #1 'nameptr := + s num.names$ 'numnames := + numnames 'namesleft := + { namesleft #0 > } + { s nameptr + "{vv~}{ll}" format.name$ + 't := + nameptr #1 > + { + namesleft #1 > + { ", " * t * } + { + s nameptr "{ll}" format.name$ duplicate$ "others" = + { 't := } + { pop$ } + if$ + t "others" = + { + " " * bbl.etal emphasize * + } + { + numnames #2 > + { "," * } + 'skip$ + if$ + bbl.and + space.word * t * + } + if$ + } + if$ + } + 't + if$ + nameptr #1 + 'nameptr := + namesleft #1 - 'namesleft := + } + while$ +} + +FUNCTION {author.editor.key.full} +{ author empty$ + { editor empty$ + { key empty$ + { cite$ #1 #3 substring$ } + 'key + if$ + } + { editor format.full.names } + if$ + } + { author format.full.names } + if$ +} + +FUNCTION {author.key.full} +{ author empty$ + { key empty$ + { cite$ #1 #3 substring$ } + 'key + if$ + } + { author format.full.names } + if$ +} + +FUNCTION {editor.key.full} +{ editor empty$ + { key empty$ + { cite$ #1 #3 substring$ } + 'key + if$ + } + { editor format.full.names } + if$ +} + +FUNCTION {make.full.names} +{ type$ "book" = + type$ "inbook" = + or + 'author.editor.key.full + { type$ "proceedings" = + 'editor.key.full + 'author.key.full + if$ + } + if$ +} + +FUNCTION {output.bibitem} +{ newline$ + "\bibitem[{" write$ + label write$ + ")" make.full.names duplicate$ short.list = + { pop$ } + { * } + if$ + "}]{" * write$ + cite$ write$ + "}" write$ + newline$ + "" + before.all 'output.state := +} + +FUNCTION {n.dashify} +{ + 't := + "" + { t empty$ not } + { t #1 #1 substring$ "-" = + { t #1 #2 substring$ "--" = not + { "--" * + t #2 global.max$ substring$ 't := + } + { { t #1 #1 substring$ "-" = } + { "-" * + t #2 global.max$ substring$ 't := + } + while$ + } + if$ + } + { t #1 #1 substring$ * + t #2 global.max$ substring$ 't := + } + if$ + } + while$ +} + +FUNCTION {word.in} +{ bbl.in capitalize + " " * } + +FUNCTION {format.date} +{ year "year" bibinfo.check duplicate$ empty$ + { + "empty year in " cite$ * "; set to ????" * warning$ + pop$ "????" + } + 'skip$ + if$ + extra.label * + before.all 'output.state := + " (" swap$ * ")" * +} +FUNCTION {format.btitle} +{ title "title" bibinfo.check + duplicate$ empty$ 'skip$ + { + emphasize + } + if$ +} +FUNCTION {either.or.check} +{ empty$ + 'pop$ + { "can't use both " swap$ * " fields in " * cite$ * warning$ } + if$ +} +FUNCTION {format.bvolume} +{ volume empty$ + { "" } + { bbl.volume volume tie.or.space.prefix + "volume" bibinfo.check * * + series "series" bibinfo.check + duplicate$ empty$ 'pop$ + { swap$ bbl.of space.word * swap$ + emphasize * } + if$ + "volume and number" number either.or.check + } + if$ +} +FUNCTION {format.number.series} +{ volume empty$ + { number empty$ + { series field.or.null } + { series empty$ + { number "number" bibinfo.check } + { output.state mid.sentence = + { bbl.number } + { bbl.number capitalize } + if$ + number tie.or.space.prefix "number" bibinfo.check * * + bbl.in space.word * + series "series" bibinfo.check * + } + if$ + } + if$ + } + { "" } + if$ +} + +FUNCTION {format.edition} +{ edition duplicate$ empty$ 'skip$ + { + output.state mid.sentence = + { "l" } + { "t" } + if$ change.case$ + "edition" bibinfo.check + " " * bbl.edition * + } + if$ +} +INTEGERS { multiresult } +FUNCTION {multi.page.check} +{ 't := + #0 'multiresult := + { multiresult not + t empty$ not + and + } + { t #1 #1 substring$ + duplicate$ "-" = + swap$ duplicate$ "," = + swap$ "+" = + or or + { #1 'multiresult := } + { t #2 global.max$ substring$ 't := } + if$ + } + while$ + multiresult +} +FUNCTION {format.pages} +{ pages duplicate$ empty$ 'skip$ + { duplicate$ multi.page.check + { + bbl.pages swap$ + n.dashify + } + { + bbl.page swap$ + } + if$ + tie.or.space.prefix + "pages" bibinfo.check + * * + } + if$ +} +FUNCTION {format.journal.pages} +{ pages duplicate$ empty$ 'pop$ + { swap$ duplicate$ empty$ + { pop$ pop$ format.pages } + { + ", " * + swap$ + n.dashify + "pages" bibinfo.check + * + } + if$ + } + if$ +} +FUNCTION {format.journal.eid} +{ eid "eid" bibinfo.check + duplicate$ empty$ 'pop$ + { swap$ duplicate$ empty$ 'skip$ + { + ", " * + } + if$ + swap$ * + numpages empty$ 'skip$ + { bbl.eidpp numpages tie.or.space.prefix + "numpages" bibinfo.check * * + " (" swap$ * ")" * * + } + if$ + } + if$ +} +FUNCTION {format.vol.num.pages} +{ volume field.or.null + duplicate$ empty$ 'skip$ + { + "volume" bibinfo.check + } + if$ + bolden + number "number" bibinfo.check duplicate$ empty$ 'skip$ + { + swap$ duplicate$ empty$ + { "there's a number but no volume in " cite$ * warning$ } + 'skip$ + if$ + swap$ + "(" swap$ * ")" * + } + if$ * + eid empty$ + { format.journal.pages } + { format.journal.eid } + if$ +} + +FUNCTION {format.chapter.pages} +{ chapter empty$ + 'format.pages + { type empty$ + { bbl.chapter } + { type "l" change.case$ + "type" bibinfo.check + } + if$ + chapter tie.or.space.prefix + "chapter" bibinfo.check + * * + pages empty$ + 'skip$ + { ", " * format.pages * } + if$ + } + if$ +} + +FUNCTION {format.booktitle} +{ + booktitle "booktitle" bibinfo.check + emphasize +} +FUNCTION {format.in.ed.booktitle} +{ format.booktitle duplicate$ empty$ 'skip$ + { + editor "editor" format.names.ed duplicate$ empty$ 'pop$ + { + " " * + get.bbl.editor + "(" swap$ * "), " * + * swap$ + * } + if$ + word.in swap$ * + } + if$ +} +FUNCTION {format.thesis.type} +{ type duplicate$ empty$ + 'pop$ + { swap$ pop$ + "t" change.case$ "type" bibinfo.check + } + if$ +} +FUNCTION {format.tr.number} +{ number "number" bibinfo.check + type duplicate$ empty$ + { pop$ bbl.techrep } + 'skip$ + if$ + "type" bibinfo.check + swap$ duplicate$ empty$ + { pop$ "t" change.case$ } + { tie.or.space.prefix * * } + if$ +} +FUNCTION {format.article.crossref} +{ + word.in + " \cite{" * crossref * "}" * +} +FUNCTION {format.book.crossref} +{ volume duplicate$ empty$ + { "empty volume in " cite$ * "'s crossref of " * crossref * warning$ + pop$ word.in + } + { bbl.volume + capitalize + swap$ tie.or.space.prefix "volume" bibinfo.check * * bbl.of space.word * + } + if$ + " \cite{" * crossref * "}" * +} +FUNCTION {format.incoll.inproc.crossref} +{ + word.in + " \cite{" * crossref * "}" * +} +FUNCTION {format.org.or.pub} +{ 't := + "" + address empty$ t empty$ and + 'skip$ + { + t empty$ + { address "address" bibinfo.check * + } + { t * + address empty$ + 'skip$ + { ", " * address "address" bibinfo.check * } + if$ + } + if$ + } + if$ +} +FUNCTION {format.publisher.address} +{ publisher "publisher" bibinfo.warn format.org.or.pub +} + +FUNCTION {format.organization.address} +{ organization "organization" bibinfo.check format.org.or.pub +} + +FUNCTION {article} +{ output.bibitem + format.authors "author" output.check + author format.key output + format.date "year" output.check + date.block + format.title "title" output.check + new.block + crossref missing$ + { + journal + "journal" bibinfo.check + emphasize + "journal" output.check + format.vol.num.pages output + } + { format.article.crossref output.nonnull + format.pages output + } + if$ + format.issn output + format.doi output + new.block + format.note output + format.eprint output + format.url output + fin.entry +} +FUNCTION {book} +{ output.bibitem + author empty$ + { format.editors "author and editor" output.check + editor format.key output + } + { format.authors output.nonnull + crossref missing$ + { "author and editor" editor either.or.check } + 'skip$ + if$ + } + if$ + format.date "year" output.check + date.block + format.btitle "title" output.check + crossref missing$ + { format.bvolume output + new.block + format.number.series output + format.edition output + new.sentence + format.publisher.address output + } + { + new.block + format.book.crossref output.nonnull + } + if$ + format.isbn output + format.doi output + new.block + format.note output + format.eprint output + format.url output + fin.entry +} +FUNCTION {booklet} +{ output.bibitem + format.authors output + author format.key output + format.date "year" output.check + date.block + format.title "title" output.check + new.block + howpublished "howpublished" bibinfo.check output + address "address" bibinfo.check output + format.isbn output + format.doi output + new.block + format.note output + format.eprint output + format.url output + fin.entry +} + +FUNCTION {inbook} +{ output.bibitem + author empty$ + { format.editors "author and editor" output.check + editor format.key output + } + { format.authors output.nonnull + crossref missing$ + { "author and editor" editor either.or.check } + 'skip$ + if$ + } + if$ + format.date "year" output.check + date.block + format.btitle "title" output.check + crossref missing$ + { + format.bvolume output + format.chapter.pages "chapter and pages" output.check + new.block + format.number.series output + format.edition output + new.sentence + format.publisher.address output + } + { + format.chapter.pages "chapter and pages" output.check + new.block + format.book.crossref output.nonnull + } + if$ + crossref missing$ + { format.isbn output } + 'skip$ + if$ + format.doi output + new.block + format.note output + format.eprint output + format.url output + fin.entry +} + +FUNCTION {incollection} +{ output.bibitem + format.authors "author" output.check + author format.key output + format.date "year" output.check + date.block + format.title "title" output.check + new.block + crossref missing$ + { format.in.ed.booktitle "booktitle" output.check + format.bvolume output + format.number.series output + format.edition output + format.chapter.pages output + new.sentence + format.publisher.address output + format.isbn output + } + { format.incoll.inproc.crossref output.nonnull + format.chapter.pages output + } + if$ + format.doi output + new.block + format.note output + format.eprint output + format.url output + fin.entry +} +FUNCTION {inproceedings} +{ output.bibitem + format.authors "author" output.check + author format.key output + format.date "year" output.check + date.block + format.title "title" output.check + new.block + crossref missing$ + { format.in.ed.booktitle "booktitle" output.check + format.bvolume output + format.number.series output + format.pages output + new.sentence + publisher empty$ + { format.organization.address output } + { organization "organization" bibinfo.check output + format.publisher.address output + } + if$ + format.isbn output + format.issn output + } + { format.incoll.inproc.crossref output.nonnull + format.pages output + } + if$ + format.doi output + new.block + format.note output + format.eprint output + format.url output + fin.entry +} +FUNCTION {conference} { inproceedings } +FUNCTION {manual} +{ output.bibitem + format.authors output + author format.key output + format.date "year" output.check + date.block + format.btitle "title" output.check + organization address new.block.checkb + organization "organization" bibinfo.check output + address "address" bibinfo.check output + format.edition output + format.doi output + new.block + format.note output + format.eprint output + format.url output + fin.entry +} + +FUNCTION {mastersthesis} +{ output.bibitem + format.authors "author" output.check + author format.key output + format.date "year" output.check + date.block + format.btitle + "title" output.check + new.block + bbl.mthesis format.thesis.type output.nonnull + school "school" bibinfo.warn output + address "address" bibinfo.check output + format.doi output + new.block + format.note output + format.eprint output + format.url output + fin.entry +} + +FUNCTION {misc} +{ output.bibitem + format.authors output + author format.key output + format.date "year" output.check + date.block + format.title output + new.block + howpublished "howpublished" bibinfo.check output + format.doi output + new.block + format.note output + format.eprint output + format.url output + fin.entry +} +FUNCTION {phdthesis} +{ output.bibitem + format.authors "author" output.check + author format.key output + format.date "year" output.check + date.block + format.btitle + "title" output.check + new.block + bbl.phdthesis format.thesis.type output.nonnull + school "school" bibinfo.warn output + address "address" bibinfo.check output + format.doi output + new.block + format.note output + format.eprint output + format.url output + fin.entry +} + +FUNCTION {proceedings} +{ output.bibitem + format.editors output + editor format.key output + format.date "year" output.check + date.block + format.btitle "title" output.check + format.bvolume output + format.number.series output + new.sentence + publisher empty$ + { format.organization.address output } + { organization "organization" bibinfo.check output + format.publisher.address output + } + if$ + format.isbn output + format.issn output + format.doi output + new.block + format.note output + format.eprint output + format.url output + fin.entry +} + +FUNCTION {techreport} +{ output.bibitem + format.authors "author" output.check + author format.key output + format.date "year" output.check + date.block + format.title + "title" output.check + new.block + format.tr.number emphasize output.nonnull + institution "institution" bibinfo.warn output + address "address" bibinfo.check output + format.doi output + new.block + format.note output + format.eprint output + format.url output + fin.entry +} + +FUNCTION {unpublished} +{ output.bibitem + format.authors "author" output.check + author format.key output + format.date "year" output.check + date.block + format.title "title" output.check + format.doi output + new.block + format.note "note" output.check + format.eprint output + format.url output + fin.entry +} + +FUNCTION {default.type} { misc } +READ +FUNCTION {sortify} +{ purify$ + "l" change.case$ +} +INTEGERS { len } +FUNCTION {chop.word} +{ 's := + 'len := + s #1 len substring$ = + { s len #1 + global.max$ substring$ } + 's + if$ +} +FUNCTION {format.lab.names} +{ 's := + "" 't := + s #1 "{vv~}{ll}" format.name$ + s num.names$ duplicate$ + #2 > + { pop$ + " " * bbl.etal emphasize * + } + { #2 < + 'skip$ + { s #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" = + { + " " * bbl.etal emphasize * + } + { bbl.and space.word * s #2 "{vv~}{ll}" format.name$ + * } + if$ + } + if$ + } + if$ +} + +FUNCTION {author.key.label} +{ author empty$ + { key empty$ + { cite$ #1 #3 substring$ } + 'key + if$ + } + { author format.lab.names } + if$ +} + +FUNCTION {author.editor.key.label} +{ author empty$ + { editor empty$ + { key empty$ + { cite$ #1 #3 substring$ } + 'key + if$ + } + { editor format.lab.names } + if$ + } + { author format.lab.names } + if$ +} + +FUNCTION {editor.key.label} +{ editor empty$ + { key empty$ + { cite$ #1 #3 substring$ } + 'key + if$ + } + { editor format.lab.names } + if$ +} + +FUNCTION {calc.short.authors} +{ type$ "book" = + type$ "inbook" = + or + 'author.editor.key.label + { type$ "proceedings" = + 'editor.key.label + 'author.key.label + if$ + } + if$ + 'short.list := +} + +FUNCTION {calc.label} +{ calc.short.authors + short.list + "(" + * + year duplicate$ empty$ + short.list key field.or.null = or + { pop$ "" } + 'skip$ + if$ + * + 'label := +} + +FUNCTION {sort.format.names} +{ 's := + #1 'nameptr := + "" + s num.names$ 'numnames := + numnames 'namesleft := + { namesleft #0 > } + { s nameptr + "{vv{ } }{ll{ }}{ f{ }}{ jj{ }}" + format.name$ 't := + nameptr #1 > + { + " " * + namesleft #1 = t "others" = and + { "zzzzz" 't := } + 'skip$ + if$ + t sortify * + } + { t sortify * } + if$ + nameptr #1 + 'nameptr := + namesleft #1 - 'namesleft := + } + while$ +} + +FUNCTION {sort.format.title} +{ 't := + "A " #2 + "An " #3 + "The " #4 t chop.word + chop.word + chop.word + sortify + #1 global.max$ substring$ +} +FUNCTION {author.sort} +{ author empty$ + { key empty$ + { "to sort, need author or key in " cite$ * warning$ + "" + } + { key sortify } + if$ + } + { author sort.format.names } + if$ +} +FUNCTION {author.editor.sort} +{ author empty$ + { editor empty$ + { key empty$ + { "to sort, need author, editor, or key in " cite$ * warning$ + "" + } + { key sortify } + if$ + } + { editor sort.format.names } + if$ + } + { author sort.format.names } + if$ +} +FUNCTION {editor.sort} +{ editor empty$ + { key empty$ + { "to sort, need editor or key in " cite$ * warning$ + "" + } + { key sortify } + if$ + } + { editor sort.format.names } + if$ +} +FUNCTION {presort} +{ calc.label + label sortify + " " + * + type$ "book" = + type$ "inbook" = + or + 'author.editor.sort + { type$ "proceedings" = + 'editor.sort + 'author.sort + if$ + } + if$ + #1 entry.max$ substring$ + 'sort.label := + sort.label + * + " " + * + title field.or.null + sort.format.title + * + #1 entry.max$ substring$ + 'sort.key$ := +} + +ITERATE {presort} +SORT +STRINGS { last.label next.extra } +INTEGERS { last.extra.num last.extra.num.extended last.extra.num.blank number.label } +FUNCTION {initialize.extra.label.stuff} +{ #0 int.to.chr$ 'last.label := + "" 'next.extra := + #0 'last.extra.num := + "a" chr.to.int$ #1 - 'last.extra.num.blank := + last.extra.num.blank 'last.extra.num.extended := + #0 'number.label := +} +FUNCTION {forward.pass} +{ last.label label = + { last.extra.num #1 + 'last.extra.num := + last.extra.num "z" chr.to.int$ > + { "a" chr.to.int$ 'last.extra.num := + last.extra.num.extended #1 + 'last.extra.num.extended := + } + 'skip$ + if$ + last.extra.num.extended last.extra.num.blank > + { last.extra.num.extended int.to.chr$ + last.extra.num int.to.chr$ + * 'extra.label := } + { last.extra.num int.to.chr$ 'extra.label := } + if$ + } + { "a" chr.to.int$ 'last.extra.num := + "" 'extra.label := + label 'last.label := + } + if$ + number.label #1 + 'number.label := +} +FUNCTION {reverse.pass} +{ next.extra "b" = + { "a" 'extra.label := } + 'skip$ + if$ + extra.label 'next.extra := + extra.label + duplicate$ empty$ + 'skip$ + { "{\natexlab{" swap$ * "}}" * } + if$ + 'extra.label := + label extra.label * 'label := +} +EXECUTE {initialize.extra.label.stuff} +ITERATE {forward.pass} +REVERSE {reverse.pass} +FUNCTION {bib.sort.order} +{ sort.label + " " + * + year field.or.null sortify + * + " " + * + title field.or.null + sort.format.title + * + #1 entry.max$ substring$ + 'sort.key$ := +} +ITERATE {bib.sort.order} +SORT +FUNCTION {begin.bib} +{ preamble$ empty$ + 'skip$ + { preamble$ write$ newline$ } + if$ + "\begin{thebibliography}{" number.label int.to.str$ * "}" * + write$ newline$ + "\newcommand{\enquote}[1]{``#1''}" + write$ newline$ + "\providecommand{\natexlab}[1]{#1}" + write$ newline$ + "\providecommand{\url}[1]{\texttt{#1}}" + write$ newline$ + "\providecommand{\urlprefix}{URL }" + write$ newline$ + "\expandafter\ifx\csname urlstyle\endcsname\relax" + write$ newline$ + " \providecommand{\doi}[1]{doi:\discretionary{}{}{}#1}\else" + write$ newline$ + " \providecommand{\doi}{doi:\discretionary{}{}{}\begingroup \urlstyle{rm}\Url}\fi" + write$ newline$ + "\providecommand{\eprint}[2][]{\url{#2}}" + write$ newline$ +} +EXECUTE {begin.bib} +EXECUTE {init.state.consts} +ITERATE {call.type$} +FUNCTION {end.bib} +{ newline$ + "\end{thebibliography}" write$ newline$ +} +EXECUTE {end.bib} +%% End of customized bst file +%% +%% End of file `jss.bst'. diff --git a/vignettes/jss.cls b/vignettes/jss.cls new file mode 100644 index 0000000..c38b8f6 --- /dev/null +++ b/vignettes/jss.cls @@ -0,0 +1,509 @@ +%% +%% This is file `jss.cls', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% jss.dtx (with options: `class') +%% +%% IMPORTANT NOTICE: +%% +%% For the copyright see the source file. +%% +%% Any modified versions of this file must be renamed +%% with new filenames distinct from jss.cls. +%% +%% For distribution of the original source see the terms +%% for copying and modification in the file jss.dtx. +%% +%% This generated file may be distributed as long as the +%% original source files, as listed above, are part of the +%% same distribution. (The sources need not necessarily be +%% in the same archive or directory.) +\def\fileversion{3.0} +\def\filename{jss} +\def\filedate{2015/09/01} +%% +%% Package `jss' to use with LaTeX2e for JSS publications (http://www.jstatsoft.org/) +%% License: GPL-2 | GPL-3 +%% Copyright: (C) Achim Zeileis +%% Please report errors to Achim.Zeileis@R-project.org +%% +\NeedsTeXFormat{LaTeX2e} +\ProvidesClass{jss}[\filedate\space\fileversion\space jss class by Achim Zeileis] +%% options +\newif\if@article +\newif\if@codesnippet +\newif\if@bookreview +\newif\if@softwarereview +\newif\if@review +\newif\if@shortnames +\newif\if@nojss +\newif\if@notitle +\newif\if@noheadings +\newif\if@nofooter + +\@articletrue +\@codesnippetfalse +\@bookreviewfalse +\@softwarereviewfalse +\@reviewfalse +\@shortnamesfalse +\@nojssfalse +\@notitlefalse +\@noheadingsfalse +\@nofooterfalse + +\DeclareOption{article}{\@articletrue% + \@codesnippetfalse \@bookreviewfalse \@softwarereviewfalse} +\DeclareOption{codesnippet}{\@articlefalse% + \@codesnippettrue \@bookreviewfalse \@softwarereviewfalse} +\DeclareOption{bookreview}{\@articlefalse% + \@codesnippetfalse \@bookreviewtrue \@softwarereviewfalse} +\DeclareOption{softwarereview}{\@articlefalse% + \@codesnippetfalse \@bookreviewfalse \@softwarereviewtrue} +\DeclareOption{shortnames}{\@shortnamestrue} +\DeclareOption{nojss}{\@nojsstrue} +\DeclareOption{notitle}{\@notitletrue} +\DeclareOption{noheadings}{\@noheadingstrue} +\DeclareOption{nofooter}{\@nofootertrue} + +\ProcessOptions +\LoadClass[11pt,a4paper,twoside]{article} +%% required packages +\RequirePackage{graphicx,color,ae,fancyvrb} +\RequirePackage[T1]{fontenc} +\IfFileExists{upquote.sty}{\RequirePackage{upquote}}{} +%% bibliography +\if@shortnames + \usepackage[authoryear,round]{natbib} +\else + \usepackage[authoryear,round,longnamesfirst]{natbib} +\fi +\bibpunct{(}{)}{;}{a}{}{,} +\bibliographystyle{jss} +%% page layout +\topmargin 0pt +\textheight 46\baselineskip +\advance\textheight by \topskip +\oddsidemargin 0.1in +\evensidemargin 0.15in +\marginparwidth 1in +\oddsidemargin 0.125in +\evensidemargin 0.125in +\marginparwidth 0.75in +\textwidth 6.125in +%% paragraphs +\setlength{\parskip}{0.7ex plus0.1ex minus0.1ex} +\setlength{\parindent}{0em} +%% for all publications +\newcommand{\Address}[1]{\def\@Address{#1}} +\newcommand{\Plaintitle}[1]{\def\@Plaintitle{#1}} +\newcommand{\Shorttitle}[1]{\def\@Shorttitle{#1}} +\newcommand{\Plainauthor}[1]{\def\@Plainauthor{#1}} +\newcommand{\Volume}[1]{\def\@Volume{#1}} +\newcommand{\Year}[1]{\def\@Year{#1}} +\newcommand{\Month}[1]{\def\@Month{#1}} +\newcommand{\Issue}[1]{\def\@Issue{#1}} +\newcommand{\Submitdate}[1]{\def\@Submitdate{#1}} +%% for articles and code snippets +\newcommand{\Acceptdate}[1]{\def\@Acceptdate{#1}} +\newcommand{\Abstract}[1]{\def\@Abstract{#1}} +\newcommand{\Keywords}[1]{\def\@Keywords{#1}} +\newcommand{\Plainkeywords}[1]{\def\@Plainkeywords{#1}} +%% for book and software reviews +\newcommand{\Reviewer}[1]{\def\@Reviewer{#1}} +\newcommand{\Booktitle}[1]{\def\@Booktitle{#1}} +\newcommand{\Bookauthor}[1]{\def\@Bookauthor{#1}} +\newcommand{\Publisher}[1]{\def\@Publisher{#1}} +\newcommand{\Pubaddress}[1]{\def\@Pubaddress{#1}} +\newcommand{\Pubyear}[1]{\def\@Pubyear{#1}} +\newcommand{\ISBN}[1]{\def\@ISBN{#1}} +\newcommand{\Pages}[1]{\def\@Pages{#1}} +\newcommand{\Price}[1]{\def\@Price{#1}} +\newcommand{\Plainreviewer}[1]{\def\@Plainreviewer{#1}} +\newcommand{\Softwaretitle}[1]{\def\@Softwaretitle{#1}} +\newcommand{\URL}[1]{\def\@URL{#1}} +\newcommand{\DOI}[1]{\def\@DOI{#1}} +%% for internal use +\newcommand{\Seriesname}[1]{\def\@Seriesname{#1}} +\newcommand{\Hypersubject}[1]{\def\@Hypersubject{#1}} +\newcommand{\Hyperauthor}[1]{\def\@Hyperauthor{#1}} +\newcommand{\Footername}[1]{\def\@Footername{#1}} +\newcommand{\Firstdate}[1]{\def\@Firstdate{#1}} +\newcommand{\Seconddate}[1]{\def\@Seconddate{#1}} +\newcommand{\Reviewauthor}[1]{\def\@Reviewauthor{#1}} +%% defaults +\author{Firstname Lastname\\Affiliation} +\title{Title} +\Abstract{---!!!---an abstract is required---!!!---} +\Plainauthor{\@author} +\Volume{VV} +\Year{YYYY} +\Month{MMMMMM} +\Issue{II} +\Submitdate{yyyy-mm-dd} +\Acceptdate{yyyy-mm-dd} +\Address{ + Firstname Lastname\\ + Affiliation\\ + Address, Country\\ + E-mail: \email{name@address}\\ + URL: \url{http://link/to/webpage/} +} + +\Reviewer{Firstname Lastname\\Affiliation} +\Plainreviewer{Firstname Lastname} +\Booktitle{Book Title} +\Bookauthor{Book Author} +\Publisher{Publisher} +\Pubaddress{Publisher's Address} +\Pubyear{YYY} +\ISBN{x-xxxxx-xxx-x} +\Pages{xv + 123} +\Price{USD 69.95 (P)} +\URL{http://link/to/webpage/} +\DOI{10.18637/jss.v000.i00} +\if@article + \Seriesname{Issue} + \Hypersubject{Journal of Statistical Software} + \Plaintitle{\@title} + \Shorttitle{\@title} + \Plainkeywords{\@Keywords} +\fi + +\if@codesnippet + \Seriesname{Code Snippet} + \Hypersubject{Journal of Statistical Software -- Code Snippets} + \Plaintitle{\@title} + \Shorttitle{\@title} + \Plainkeywords{\@Keywords} +\fi + +\if@bookreview + \Seriesname{Book Review} + \Hypersubject{Journal of Statistical Software -- Book Reviews} + \Plaintitle{\@Booktitle} + \Shorttitle{\@Booktitle} + \Reviewauthor{\@Bookauthor\\ + \@Publisher, \@Pubaddress, \@Pubyear.\\ + ISBN~\@ISBN. \@Pages~pp. \@Price.\\ + \url{\@URL}} + \Plainkeywords{} + \@reviewtrue +\fi + +\if@softwarereview + \Seriesname{Software Review} + \Hypersubject{Journal of Statistical Software -- Software Reviews} + \Plaintitle{\@Softwaretitle} + \Shorttitle{\@Softwaretitle} + \Booktitle{\@Softwaretitle} + \Reviewauthor{\@Publisher, \@Pubaddress. \@Price.\\ + \url{\@URL}} + \Plainkeywords{} + \@reviewtrue +\fi + +\if@review + \Hyperauthor{\@Plainreviewer} + \Keywords{} + \Footername{Reviewer} + \Firstdate{\textit{Published:} \@Submitdate} + \Seconddate{} +\else + \Hyperauthor{\@Plainauthor} + \Keywords{---!!!---at least one keyword is required---!!!---} + \Footername{Affiliation} + \Firstdate{\textit{Submitted:} \@Submitdate} + \Seconddate{\textit{Accepted:} \@Acceptdate} +\fi +%% Sweave(-like) +\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl} +\DefineVerbatimEnvironment{Soutput}{Verbatim}{} +\DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl} +\newenvironment{Schunk}{}{} +\DefineVerbatimEnvironment{Code}{Verbatim}{} +\DefineVerbatimEnvironment{CodeInput}{Verbatim}{fontshape=sl} +\DefineVerbatimEnvironment{CodeOutput}{Verbatim}{} +\newenvironment{CodeChunk}{}{} +\setkeys{Gin}{width=0.8\textwidth} +%% footer +\newlength{\footerskip} +\setlength{\footerskip}{2.5\baselineskip plus 2ex minus 0.5ex} + +\newcommand{\makefooter}{% + \vspace{\footerskip} + + \if@nojss + \begin{samepage} + \textbf{\large \@Footername: \nopagebreak}\\[.3\baselineskip] \nopagebreak + \@Address \nopagebreak + \end{samepage} + \else + \begin{samepage} + \textbf{\large \@Footername: \nopagebreak}\\[.3\baselineskip] \nopagebreak + \@Address \nopagebreak + \vfill + \hrule \nopagebreak + \vspace{.1\baselineskip} + {\fontfamily{pzc} \fontsize{13}{15} \selectfont Journal of Statistical Software} + \hfill + \url{http://www.jstatsoft.org/}\\ \nopagebreak + published by the Foundation for Open Access Statistics + \hfill + \url{http://www.foastat.org/}\\[.3\baselineskip] \nopagebreak + {\@Month{} \@Year, Volume~\@Volume, \@Seriesname~\@Issue} + \hfill + \@Firstdate\\ \nopagebreak + {\href{http://dx.doi.org/\@DOI}{\tt doi:\@DOI}} + \hfill + \@Seconddate \nopagebreak + \vspace{.3\baselineskip} + \hrule + \end{samepage} + \fi +} +\if@nofooter + %% \AtEndDocument{\makefooter} +\else + \AtEndDocument{\makefooter} +\fi +%% required packages +\RequirePackage{hyperref} +%% new \maketitle +\def\@myoddhead{ + {\color{white} JSS}\\[-1.42cm] + \hspace{-2em} \includegraphics[height=23mm,keepaspectratio]{jsslogo} \hfill + \parbox[b][23mm]{118mm}{\hrule height 3pt + \center{ + {\fontfamily{pzc} \fontsize{28}{32} \selectfont Journal of Statistical Software} + \vfill + {\it \small \@Month{} \@Year, Volume~\@Volume, \@Seriesname~\@Issue.% + \hfill \href{http://dx.doi.org/\@DOI}{doi:\,\@DOI}}}\\[0.1cm] + \hrule height 3pt}} +\if@review + \renewcommand{\maketitle}{ + \if@nojss + %% \@oddhead{\@myoddhead}\\[3\baselineskip] + \else + \@oddhead{\@myoddhead}\\[3\baselineskip] + \fi + {\large + \noindent + Reviewer: \@Reviewer + \vspace{\baselineskip} + \hrule + \vspace{\baselineskip} + \textbf{\@Booktitle} + \begin{quotation} \noindent + \@Reviewauthor + \end{quotation} + \vspace{0.7\baselineskip} + \hrule + \vspace{1.3\baselineskip} + } + + \thispagestyle{empty} + \if@nojss + \markboth{\centerline{\@Shorttitle}}{\centerline{\@Hyperauthor}} + \else + \markboth{\centerline{\@Shorttitle}}{\centerline{\@Hypersubject}} + \fi + \pagestyle{myheadings} + } +\else + \def\maketitle{ + \if@nojss + %% \@oddhead{\@myoddhead} \par + \else + \@oddhead{\@myoddhead} \par + \fi + \begingroup + \def\thefootnote{\fnsymbol{footnote}} + \def\@makefnmark{\hbox to 0pt{$^{\@thefnmark}$\hss}} + \long\def\@makefntext##1{\parindent 1em\noindent + \hbox to1.8em{\hss $\m@th ^{\@thefnmark}$}##1} + \@maketitle \@thanks + \endgroup + \setcounter{footnote}{0} + + \if@noheadings + %% \markboth{\centerline{\@Shorttitle}}{\centerline{\@Hypersubject}} + \else + \thispagestyle{empty} + \if@nojss + \markboth{\centerline{\@Shorttitle}}{\centerline{\@Hyperauthor}} + \else + \markboth{\centerline{\@Shorttitle}}{\centerline{\@Hypersubject}} + \fi + \pagestyle{myheadings} + \fi + + \let\maketitle\relax \let\@maketitle\relax + \gdef\@thanks{}\gdef\@author{}\gdef\@title{}\let\thanks\relax + } + + \def\@maketitle{\vbox{\hsize\textwidth \linewidth\hsize + \if@nojss + %% \vskip 1in + \else + \vskip 1in + \fi + {\centering + {\LARGE\bf \@title\par} + \vskip 0.2in plus 1fil minus 0.1in + { + \def\and{\unskip\enspace{\rm and}\enspace}% + \def\And{\end{tabular}\hss \egroup \hskip 1in plus 2fil + \hbox to 0pt\bgroup\hss \begin{tabular}[t]{c}\large\bf\rule{\z@}{24pt}\ignorespaces}% + \def\AND{\end{tabular}\hss\egroup \hfil\hfil\egroup + \vskip 0.1in plus 1fil minus 0.05in + \hbox to \linewidth\bgroup\rule{\z@}{10pt} \hfil\hfil + \hbox to 0pt\bgroup\hss \begin{tabular}[t]{c}\large\bf\rule{\z@}{24pt}\ignorespaces} + \hbox to \linewidth\bgroup\rule{\z@}{10pt} \hfil\hfil + \hbox to 0pt\bgroup\hss \begin{tabular}[t]{c}\large\bf\rule{\z@}{24pt}\@author + \end{tabular}\hss\egroup + \hfil\hfil\egroup} + \vskip 0.3in minus 0.1in + \hrule + \begin{abstract} + \@Abstract + \end{abstract}} + \textit{Keywords}:~\@Keywords. + \vskip 0.1in minus 0.05in + \hrule + \vskip 0.2in minus 0.1in + }} +\fi +%% sections, subsections, and subsubsections +\newlength{\preXLskip} +\newlength{\preLskip} +\newlength{\preMskip} +\newlength{\preSskip} +\newlength{\postMskip} +\newlength{\postSskip} +\setlength{\preXLskip}{1.8\baselineskip plus 0.5ex minus 0ex} +\setlength{\preLskip}{1.5\baselineskip plus 0.3ex minus 0ex} +\setlength{\preMskip}{1\baselineskip plus 0.2ex minus 0ex} +\setlength{\preSskip}{.8\baselineskip plus 0.2ex minus 0ex} +\setlength{\postMskip}{.5\baselineskip plus 0ex minus 0.1ex} +\setlength{\postSskip}{.3\baselineskip plus 0ex minus 0.1ex} + +\newcommand{\jsssec}[2][default]{\vskip \preXLskip% + \pdfbookmark[1]{#1}{Section.\thesection.#1}% + \refstepcounter{section}% + \centerline{\textbf{\Large \thesection. #2}} \nopagebreak + \vskip \postMskip \nopagebreak} +\newcommand{\jsssecnn}[1]{\vskip \preXLskip% + \centerline{\textbf{\Large #1}} \nopagebreak + \vskip \postMskip \nopagebreak} + +\newcommand{\jsssubsec}[2][default]{\vskip \preMskip% + \pdfbookmark[2]{#1}{Subsection.\thesubsection.#1}% + \refstepcounter{subsection}% + \textbf{\large \thesubsection. #2} \nopagebreak + \vskip \postSskip \nopagebreak} +\newcommand{\jsssubsecnn}[1]{\vskip \preMskip% + \textbf{\large #1} \nopagebreak + \vskip \postSskip \nopagebreak} + +\newcommand{\jsssubsubsec}[2][default]{\vskip \preSskip% + \pdfbookmark[3]{#1}{Subsubsection.\thesubsubsection.#1}% + \refstepcounter{subsubsection}% + {\large \textit{#2}} \nopagebreak + \vskip \postSskip \nopagebreak} +\newcommand{\jsssubsubsecnn}[1]{\vskip \preSskip% + {\textit{\large #1}} \nopagebreak + \vskip \postSskip \nopagebreak} + +\newcommand{\jsssimplesec}[2][default]{\vskip \preLskip% +%% \pdfbookmark[1]{#1}{Section.\thesection.#1}% + \refstepcounter{section}% + \textbf{\large #1} \nopagebreak + \vskip \postSskip \nopagebreak} +\newcommand{\jsssimplesecnn}[1]{\vskip \preLskip% + \textbf{\large #1} \nopagebreak + \vskip \postSskip \nopagebreak} + +\if@review + \renewcommand{\section}{\secdef \jsssimplesec \jsssimplesecnn} + \renewcommand{\subsection}{\secdef \jsssimplesec \jsssimplesecnn} + \renewcommand{\subsubsection}{\secdef \jsssimplesec \jsssimplesecnn} +\else + \renewcommand{\section}{\secdef \jsssec \jsssecnn} + \renewcommand{\subsection}{\secdef \jsssubsec \jsssubsecnn} + \renewcommand{\subsubsection}{\secdef \jsssubsubsec \jsssubsubsecnn} +\fi +%% colors +\definecolor{Red}{rgb}{0.5,0,0} +\definecolor{Blue}{rgb}{0,0,0.5} +\if@review + \hypersetup{% + hyperindex = {true}, + colorlinks = {true}, + linktocpage = {true}, + plainpages = {false}, + linkcolor = {Blue}, + citecolor = {Blue}, + urlcolor = {Red}, + pdfstartview = {Fit}, + pdfpagemode = {None}, + pdfview = {XYZ null null null} + } +\else + \hypersetup{% + hyperindex = {true}, + colorlinks = {true}, + linktocpage = {true}, + plainpages = {false}, + linkcolor = {Blue}, + citecolor = {Blue}, + urlcolor = {Red}, + pdfstartview = {Fit}, + pdfpagemode = {UseOutlines}, + pdfview = {XYZ null null null} + } +\fi +\if@nojss + \AtBeginDocument{ + \hypersetup{% + pdfauthor = {\@Hyperauthor}, + pdftitle = {\@Plaintitle}, + pdfkeywords = {\@Plainkeywords} + } + } +\else + \AtBeginDocument{ + \hypersetup{% + pdfauthor = {\@Hyperauthor}, + pdftitle = {\@Plaintitle}, + pdfsubject = {\@Hypersubject}, + pdfkeywords = {\@Plainkeywords} + } + } +\fi +\if@notitle + %% \AtBeginDocument{\maketitle} +\else + \AtBeginDocument{\maketitle} +\fi +%% commands +\newcommand\code{\bgroup\@makeother\_\@makeother\~\@makeother\$\@codex} +\def\@codex#1{{\normalfont\ttfamily\hyphenchar\font=-1 #1}\egroup} +%%\let\code=\texttt +\let\proglang=\textsf +\newcommand{\pkg}[1]{{\fontseries{b}\selectfont #1}} +\newcommand{\email}[1]{\href{mailto:#1}{\normalfont\texttt{#1}}} +\ifx\csname urlstyle\endcsname\relax + \newcommand\@doi[1]{doi:\discretionary{}{}{}#1}\else + \newcommand\@doi{doi:\discretionary{}{}{}\begingroup +\urlstyle{tt}\Url}\fi +\newcommand{\doi}[1]{\href{http://dx.doi.org/#1}{\normalfont\texttt{\@doi{#1}}}} +\newcommand{\E}{\mathsf{E}} +\newcommand{\VAR}{\mathsf{VAR}} +\newcommand{\COV}{\mathsf{COV}} +\newcommand{\Prob}{\mathsf{P}} +\endinput +%% +%% End of file `jss.cls'. diff --git a/vignettes/refs.bib b/vignettes/refs.bib index 6da6794..4cf3772 100644 --- a/vignettes/refs.bib +++ b/vignettes/refs.bib @@ -10,7 +10,7 @@ @article{ABN12 } @book{guting05, - title={Moving objects databases}, + title={Moving Objects Databases}, author={G{\"u}ting, Ralf Hartmut and Schneider, Markus}, year={2005}, publisher={Elsevier} @@ -31,7 +31,7 @@ @book{BRT15 } @article{D85, - title={A kernel method for smoothing point process data}, + title={A Kernel Method for Smoothing Point Process Data}, author={Diggle, Peter}, journal={Applied Statistics}, volume={34}, @@ -294,7 +294,7 @@ @book{D13 @article{baddeley05, - title={\pkg{Spatstat}: an \proglang{R} package for analyzing spatial point patterns}, + title={\pkg{Spatstat}: An \proglang{R} Package for Analyzing Spatial Point Patterns}, author={Baddeley, Adrian and Turner, Rolf}, journal = {Journal of Statistical Software, Articles}, volume = {12}, @@ -384,7 +384,7 @@ @article{gloaguen15 } @article{baddeley00, - title={Non-and semi-parametric estimation of interaction in inhomogeneous point patterns}, + title={Non-and Semi-Parametric Estimation of Interaction in Inhomogeneous Point Patterns}, author={Baddeley, Adrian and M{\o}ller, Jesper and Waagepetersen, Rasmus}, journal={Statistica Neerlandica}, volume={54}, @@ -402,7 +402,7 @@ @article{benes17 } @article{calenge06, - title={The package \pkg{adehabitat} for the \proglang{R} software: a tool for the analysis of space and habitat use by animals}, + title={The Package \pkg{adehabitat} for the \proglang{R} Software: A Tool for the Analysis of Space and Habitat Use by Animals}, author={Calenge, Cl{\'e}ment}, journal={Ecological modelling}, volume={197}, @@ -422,14 +422,14 @@ @Manual{trip } @book{daley07, - title={An Introduction to The theory of Point Processes: Volume II: General Theory and Structure}, + title={An Introduction to the Theory of Point Processes: Volume II: General Theory and Structure}, author={Daley, Daryl J and Vere-Jones, David}, year={2007}, publisher={Springer-Verlag Science \& Business Media} } @article{jones93, - title={Simple boundary correction for kernel density estimation}, + title={Simple Boundary Correction for Kernel Density Estimation}, author={Jones, M Chris}, journal={Statistics and Computing}, volume={3}, @@ -443,13 +443,13 @@ @article{jones93 @article{Ord78, author={Ord, J.K.}, year={1978}, -title={How many trees in a forest?}, +title={How Many Trees in a Forest?}, journal={Mathematical Sciences}, volume={3}, pages={23--33} } @article{BSV10, - title={On the {V}oronoi estimator for the intensity of an inhomogeneous planar Poisson process}, + title={On the {V}oronoi Estimator for the Intensity of an Inhomogeneous Planar Poisson Process}, author={Barr, Christopher D and Schoenberg, Frederic Paik}, journal={Biometrika}, volume={97}, @@ -460,7 +460,7 @@ @article{BSV10 } @article{ripley77, - title={Modelling spatial patterns}, + title={Modelling Spatial Patterns}, author={Ripley, Brian D}, journal={Journal of the Royal Statistical Society. Series B (Methodological)}, volume={39}, @@ -471,7 +471,7 @@ @article{ripley77 } @article{sumner2009, - title={Bayesian estimation of animal movement from archival and satellite tags}, + title={Bayesian Estimation of Animal Movement from Archival and Satellite Tags}, author={Sumner, Michael D and Wotherspoon, Simon J and Hindell, Mark A}, journal={PLoS One}, doi={https://doi.org/10.1371/journal.pone.0007324}, @@ -483,7 +483,7 @@ @article{sumner2009 } @Manual{argosf, - title = {\pkg{argosfilter}: Argos locations filter}, + title = {\pkg{argosfilter}: Argos Locations Flter}, author = {Carla Freitas}, year = {2012}, note = {\proglang{R} package version 0.63}, @@ -491,7 +491,7 @@ @Manual{argosf } @Manual{animalTrack, - title = {\pkg{animalTrack}: Animal track reconstruction for high frequency 2-dimensional (2D) or 3-dimensional (3D) movement data}, + title = {\pkg{animalTrack}: Animal Track Reconstruction for High Frequency 2-Dimensional (2D) or 3-Dimensional (3D) Movement Data}, author = {Ed Farrell and Lee Fuiman}, year = {2013}, note = {\proglang{R} package version 1.0.0}, @@ -499,7 +499,7 @@ @Manual{animalTrack } @Manual{BBMM, - title = {\pkg{BBMM}: Brownian bridge movement model}, + title = {\pkg{BBMM}: Brownian Bridge Movement Model}, author = {Nielson, R. M. and Sawyer, H. and McDonald, T. L.}, year = {2013}, note = {\proglang{R} package version 3.0}, @@ -507,7 +507,7 @@ @Manual{BBMM } @Manual{bcpa, - title = {\pkg{bcpa}: Behavioral change point analysis of animal movement}, + title = {\pkg{bcpa}: Behavioral Change Point Analysis of Animal Movement}, author = {Eliezer Gurarie}, year = {2014}, note = {\proglang{R} package version 1.1}, @@ -531,8 +531,7 @@ @Manual{BayesianAnimalTracker } @Manual{TrackReconstruction, - title = {\pkg{TrackReconstruction}: Reconstruct animal tracks from magnetometer, accelerometer, depth and optional speed data, -depth and optional speed data.}, + title = {\pkg{TrackReconstruction}: Reconstruct Animal Tracks from Magnetometer, Accelerometer, Depth and Optional Speed Data.}, author = {Brian Battaile}, year = {2014}, note = {\proglang{R} package version 1.1}, @@ -540,7 +539,7 @@ @Manual{TrackReconstruction } @Manual{mkde, - title = {\pkg{mkde}: 2D and 3D movement-based kernel density estimates (MKDEs).}, + title = {\pkg{mkde}: 2D and 3D Movement-Based Kernel Density Estimates (MKDEs).}, author = {Jeff A. Tracey and James Sheppard and Jun Zhu and Robert Sinkovts and Amit Chourasia and Glenn Lockwood and Robert N. Fisher}, year = {2014}, note = {\proglang{R} package version 0.1}, @@ -548,7 +547,7 @@ @Manual{mkde } @Article{moveHMM, - title = {\pkg{moveHMM}: an \proglang{R} package for the statistical modelling of animal movement data using hidden Markov models}, + title = {\pkg{moveHMM}: An \proglang{R} Package for the Statistical Modelling of Animal Movement Data Using Hidden Markov Models}, author = {Theo Michelot and Roland Langrock and Toby A. Patterson}, journal = {Methods in Ecology and Evolution}, year = {2016}, @@ -558,7 +557,7 @@ @Article{moveHMM } @Article{V-Track, - title = {\pkg{V-Track}: software for analysing and visualising animal movement from acoustic telemetry detections}, + title = {\pkg{V-Track}: Software for Analysing and Visualising Animal Movement from Acoustic Telemetry Detections}, journal={Marine and Freshwater Research}, volume={63}, number={9}, @@ -577,7 +576,7 @@ @Manual{SimilarityMeasures } @article{FLightR, - title={\pkg{FLightR}: an \proglang{R} package for reconstructing animal paths from solar geolocation loggers}, + title={\pkg{FLightR}: An \proglang{R} Package for Reconstructing Animal Paths from Solar Geolocation Loggers}, author={Rakhimberdiev, Eldar and Saveliev, Anatoly and Piersma, Theunis and Karagicheva, Julia}, journal={Methods in Ecology and Evolution}, volume={8}, @@ -588,7 +587,7 @@ @article{FLightR } @article{hanks15, - title={Continuous-time discrete-space models for animal movement}, + title={Continuous-Time Discrete-Space Models for Animal Movement}, author={Hanks, Ephraim M and Hooten, Mevin B and Alldredge, Mat W and others}, journal={The Annals of Applied Statistics}, volume={9}, @@ -599,7 +598,7 @@ @article{hanks15 } @article{hooten17, - title={Basis function models for animal movement}, + title={Basis Function Models for Animal Movement}, author={Hooten, Mevin B and Johnson, Devin S}, journal={Journal of the American Statistical Association}, volume={112}, @@ -610,7 +609,7 @@ @article{hooten17 } @article{russell16, - title={Dynamic models of animal movement with spatial point process interactions}, + title={Dynamic Models of Animal Movement with Spatial Point Process Interactions}, author={Russell, James C and Hanks, Ephraim M and Haran, Murali}, journal={Journal of Agricultural, Biological, and Environmental Statistics}, volume={21}, @@ -621,7 +620,7 @@ @article{russell16 } @Article{fishmove, - title = {Patterns and predictors of fish dispersal in rivers}, + title = {Patterns and Predictors of Fish Dispersal in Rivers}, author = {J. Radinger and C. Wolter}, journal = {Fish and Fisheries}, year = {2014}, @@ -630,7 +629,7 @@ @Article{fishmove } @article{spacetime, - title={\pkg{spacetime}: Spatio-Temporal data in \proglang{R}}, + title={\pkg{spacetime}: Spatio-Temporal Data in \proglang{R}}, author = {Edzer Pebesma}, journal = {Journal of Statistical Software, Articles}, volume = {51}, @@ -645,7 +644,7 @@ @article{spacetime } @inproceedings{yuan11, - title={Driving with knowledge from the physical world}, + title={Driving with Knowledge from the Physical World}, author={Yuan, Jing and Zheng, Yu and Xie, Xing and Sun, Guangzhong}, booktitle={Proceedings of the 17th ACM SIGKDD international conference on Knowledge discovery and data mining}, pages={316--324}, @@ -654,7 +653,7 @@ @inproceedings{yuan11 } @inproceedings{yuan10, - title={T-drive: driving directions based on taxi trajectories}, + title={T-Drive: Driving Directions Based on Taxi Trajectories}, author={Yuan, Jing and Zheng, Yu and Zhang, Chengyang and Xie, Wenlei and Xie, Xing and Sun, Guangzhong and Huang, Yan}, booktitle={Proceedings of the 18th SIGSPATIAL International conference on advances in geographic information systems}, pages={99--108}, @@ -680,7 +679,7 @@ @article{frick @article{gabriel2014, - title={Estimating second-order characteristics of inhomogeneous spatio-temporal point processes}, + title={Estimating Second-Order Characteristics of Inhomogeneous Spatio-Temporal Point Processes}, author={Gabriel, Edith}, journal={Methodology and Computing in Applied Probability}, volume={16}, @@ -690,7 +689,7 @@ @article{gabriel2014 } @article{niu2016modeling, - title={Modeling interdependent animal movement in continuous time}, + title={Modeling Interdependent Animal Movement in Continuous Time}, author={Niu, Mu and Blackwell, Paul G and Skarin, Anna}, journal={Biometrics}, volume={72},