adjust_linear: Adjust for Linear Drift

Description Usage Arguments Value Examples

View source: R/adjust.r

Description

Adjust a regular time series for an assumed linear drift over a known period while maintaining an assumed linear trend over the entire period.

Usage

1
adjust_linear(x, mask)

Arguments

x

A vector of data with missing values.

mask

A logical mask that identifies a subgroup of x to correct for drift. Values outside the subgroup are used to determine the overall linear trend. If no mask is specified, no overall trend is assumed.

Value

The vector x with corrected values for the subgroup specified by mask.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# no trend, only drift
x = rnorm(100, 10) + 0.1 * (1:100)
newx = adjust_linear(x)
if (interactive()) {
  plot(x, type = 'l')
  lines(newx, col = 'red')
}
# trend and drift
x = rnorm(100, 10) - 0.05 * (1:100)
mask = seq_along(x) %in% 20:80
x[mask] = x[mask] - 0.1 * cumsum(mask)[mask]
newx = adjust_linear(x, mask)
if (interactive()) {
  plot(x, type = 'l')
  lines(newx, col = 'red')
}

SuisunMarshBranch/wqptools documentation built on May 1, 2021, 2:21 a.m.