despike: Remove spikes from a time series

Description Usage Arguments Details Value Author(s) Examples

View source: R/misc.R

Description

The method identifies spikes with respect to a "reference" time-series, and replaces these spikes with the reference value, or with NA according to the value of action; see “Details”.

Usage

1
2
despike(x, reference = c("median", "smooth", "trim"), n = 4, k = 7,
  min = NA, max = NA, replace = c("reference", "NA"), skip)

Arguments

x

a vector of (time-series) values, a list of vectors, a data frame, or an object that inherits from class oce.

reference

indication of the type of reference time series to be used in the detection of spikes; see ‘Details’.

n

an indication of the limit to differences between x and the reference time series, used for reference="median" or reference="smooth"; see ‘Details.’

k

length of running median used with reference="median", and ignored for other values of reference.

min

minimum non-spike value of x, used with reference="trim".

max

maximum non-spike value of x, used with reference="trim".

replace

an indication of what to do with spike values, with "reference" indicating to replace them with the reference time series, and "NA" indicating to replace them with NA.

skip

optional vector naming columns to be skipped. This is ignored if x is a simple vector. Any items named in skip will be passed through to the return value without modification. In some cases, despike will set up reasonable defaults for skip, e.g. for a ctd object, skip will be set to c("time", "scan", "pressure") if it is not supplied as an argument.

Details

Three modes of operation are permitted, depending on the value of reference.

Value

A new vector in which spikes are replaced as described above.

Author(s)

Dan Kelley

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
n <- 50
x <- 1:n
y <- rnorm(n=n)
y[n/2] <- 10                    # 10 standard deviations
plot(x, y, type='l')
lines(x, despike(y), col='red')
lines(x, despike(y, reference="smooth"), col='darkgreen')
lines(x, despike(y, reference="trim", min=-3, max=3), col='blue')
legend("topright", lwd=1, col=c("black", "red", "darkgreen", "blue"),
       legend=c("raw", "median", "smooth", "trim"))

# add a spike to a CTD object
data(ctd)
plot(ctd)
T <- ctd[["temperature"]]
T[10] <- T[10] + 10
ctd[["temperature"]] <- T
CTD <- despike(ctd)
plot(CTD)

oce documentation built on Aug. 29, 2017, 1:05 a.m.