Non-destructive filter for track data using penalty smoothing on velocity.

filter_penSS(tr, lambda, first = TRUE, last = TRUE, ...)

Arguments

tr

A trip object.

lambda

Smoothing parameter, see Details.

first

Fix the first location and prevent it from being updated by the filter.

last

Fix the last location and prevent it from being updated by the filter.

...

Arguments passed on to nlm

Value

A trip object with updated coordinate values based on the filter - all the data, including original coordinates which are maintained in the trip data frame.

Details

Destructive filters such as speedfilter can be recast using a penalty smoothing approach in the style of Green and Silverman (1994).

This filter works by penalizing the fit of the smoothed track to the observed locations by the sum of squared velocities. That is, we trade off goodness of fit against increasing the total sum of squared velocities.

When lambda=0 the smoothed track reproduces the raw track exactly. Increasing lambda favours tracks requiring less extreme velocities, at the expense of reproducing the original locations.

References

Green, P. J. and Silverman, B. W. (1994). Nonparametric regression and generalized linear models: a roughness penalty approach. CRC Press.

See also

Author

Simon Wotherspoon and Michael Sumner

Examples

if (FALSE) ## Example takes a few minutes ## Fake some data ## Brownian motion tethered at each end brownian.bridge <- function(n, r) { x <- cumsum(rnorm(n, 0, 1)) x <- x - (x[1] + seq(0, 1, length=n) * (x[n] - x[1])) r * x } ## Number of days and number of obs days <- 50 n <- 200 ## Make separation between obs gamma distributed x <- rgamma(n, 3) x <- cumsum(x) x <- x/x[n] ## Track is lissajous + brownian bridge b.scale <- 0.6 r.scale <- sample(c(0.1, 2, 10.2), n, replace=TRUE, prob=c(0.8, 0.18, 0.02)) set.seed(44) tms <- ISOdate(2001, 1, 1) + trunc(days * 24 * 60 * 60 *x) lon <- 120 + 20 * sin(2 * pi * x) + brownian.bridge(n, b.scale) + rnorm(n, 0, r.scale)
#> Error in brownian.bridge(n, b.scale): could not find function "brownian.bridge"
lat <- -40 + 10 *(sin(3 * 2 * pi * x) + cos(2 * pi * x) - 1) + brownian.bridge(n, b.scale) + rnorm(n, 0, r.scale)
#> Error in brownian.bridge(n, b.scale): could not find function "brownian.bridge"
tr <- new("trip", SpatialPointsDataFrame(cbind(lon, lat), data.frame(gmt=tms, id="lbb")), TimeOrderedRecords(c("gmt", "id")))
#> Error in cbind(lon, lat): object 'lon' not found
plot(tr)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'tr' not found
## the filtered version trf <- filter.penSS(tr, lambda=1, iterlim=400, print.level=1)
#> Error in filter.penSS(tr, lambda = 1, iterlim = 400, print.level = 1): could not find function "filter.penSS"
lines(trf)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'lines': object 'trf' not found