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_growth_rate_augment(), 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 -1.91   0.519         NA     
#>  2 2021-02-01 -0.279  0.846         NA     
#>  3 2021-03-01 -0.313  0.718         -0.455 
#>  4 2021-04-01  1.07   0.241         -0.349 
#>  5 2021-05-01  0.0700 0.547          0.783 
#>  6 2021-06-01 -0.639  0.835         -0.0180
#>  7 2021-07-01 -0.0500 0.0280        -1.09  
#>  8 2021-08-01 -0.251  0.469          1.25  
#>  9 2021-09-01  0.445  0.806         -0.105 
#> 10 2021-10-01  2.76   0.814         -0.328