Skip to contents

Takes a numeric vector and will return the acceleration of that vector.

Usage

ts_acceleration_augment(.data, .value, .names = "auto")

Arguments

.data

The data being passed that will be augmented by the function.

.value

This is passed rlang::enquo() to capture the vectors you want to augment.

.names

The default is "auto"

Value

A augmented tibble

Details

Takes a numeric vector and will return the acceleration of that vector. The acceleration of a time series is computed by taking the second difference, so $$(x_t - x_t1) - (x_t - x_t1)_t1$$

This function is intended to be used on its own in order to add columns to a tibble.

See also

Other Augment Function: ts_velocity_augment()

Author

Steven P. Sanderson II, MPH

Examples

suppressPackageStartupMessages(library(dplyr))

len_out    = 10
by_unit    = "month"
start_date = as.Date("2021-01-01")

data_tbl <- tibble(
  date_col = seq.Date(from = start_date, length.out = len_out, by = by_unit),
  a    = rnorm(len_out),
  b    = runif(len_out)
)

ts_acceleration_augment(data_tbl, b)
#> # A tibble: 10 × 4
#>    date_col         a     b acceleration_b
#>    <date>       <dbl> <dbl>          <dbl>
#>  1 2021-01-01  0.0139 0.491        NA     
#>  2 2021-02-01  0.989  0.531        NA     
#>  3 2021-03-01  0.935  0.468        -0.104 
#>  4 2021-04-01 -0.452  0.889         0.485 
#>  5 2021-05-01  1.09   0.319        -0.991 
#>  6 2021-06-01 -0.782  0.291         0.541 
#>  7 2021-07-01  0.350  0.238        -0.0251
#>  8 2021-08-01 -0.0651 0.647         0.463 
#>  9 2021-09-01  1.79   0.553        -0.504 
#> 10 2021-10-01  0.785  0.620         0.161