short_term: Calculate short-term changes for binned data

Description Usage Arguments Value Details Examples

View source: R/short_term.R

Description

short_term computes the bin-to-bin change of a specified value using linear regression.

Usage

1
2
3
4
5
6
7
8
short_term(
  data,
  value,
  bin,
  bin.one = "oldest",
  mult.observations = FALSE,
  print.result = "df"
)

Arguments

data

(data.frame) A data frame or tibble containing the value column and the bin column

value

(unquoted expression) Variable name of the value for which the short-term changes should be calculated.

bin

(unquoted expression) Variable name of the discrete bin numbers.

bin.one

(character) Either "oldest" when the first bin is the oldest out of all bins or "youngest" when the first bin is the most recent one. "oldest" is the default and corresponds to the convention that stage 1 is the oldest geologic stage.

mult.observations

(logical) Are there more observations per bin? Defaults to one observation per bin.

print.result

(character) Either "vector" for output given in a named vector or "df" for output given within a tibble (default).

Value

The output is a tibble data frame (default) containing the value column, the bin column and the calculated short-term change.

Details

To calculate the short-term change for each row, the coefficient of a linear regression between the value and bin of interest and each corresponding lag (the value and bin before the focal bin) is used. This corresponds to a unit change of the value compared to the previous bin. For example, if we have 20°C at bin 10, and 22°C at bin 11, the short-term temperature change from bin 10 to 11 is 2. If bin 11 is older than bin 10, one needs to specify this by setting bin.one = "youngest" and the corresponding short-term temperature change would hence be calculated from bin 11 to bin 10. If there is more than one observation per bin, and mult.observations is set to TRUE, the regression is based on all values per bin. The default output is a data frame (tibble) with the first column corresponding to the raw value of interest, the second column the bins, and the third columns to the calculated short-term change. The data frame is ordered starting with the oldest bin in the first row. If there are more observations per bin (mult.observations = "TRUE"), the output is a nested data frame with all observations per bin grouped together. If print.result is set to "vector", the output is a named vector with the short-term change as values and each corresponding bin as name.

Examples

1
2
dfr <- data.frame(x = rnorm(10), stg = 1:10)
short_term(data = dfr, value = x, bin = stg)

Ischi94/palint documentation built on Feb. 7, 2021, 4:37 a.m.