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.150 0.0955         NA    
#>  2 2021-02-01  0.920 0.475          NA    
#>  3 2021-03-01  1.06  0.742          -0.112
#>  4 2021-04-01 -0.384 0.752          -0.258
#>  5 2021-05-01 -0.273 0.0153         -0.746
#>  6 2021-06-01 -0.695 0.404           1.13 
#>  7 2021-07-01 -1.09  0.918           0.125
#>  8 2021-08-01 -0.886 0.426          -1.01 
#>  9 2021-09-01  0.987 0.140           0.206
#> 10 2021-10-01  0.764 0.490           0.636