pct_change: Compute percentage change of values in 'covidcast_signal'...

Description Usage Arguments Value Examples

View source: R/change.R

Description

Computes the percentage change of the values in a covidcast_signal data frame. (When multiple issue dates are present, only the latest issue is considered.) See the percentage change vignette for examples.

Usage

1
pct_change(x, n = 14, col_name = "pct_change")

Arguments

x

The covidcast_signal data frame under consideration.

n

Size of the local window (in days) to use (bumped up to the nearest even integer, if needed). For example, if n = 10, then to compute the percentage change on November 10, we use 100 * (B - A) / A, where A is the sum of the values between November 6 and November 10, and A is the sum of the values between November 1 and November 5. Default is 14.

col_name

String indicating the name of the new column that will contain the percentage change values. Default is "pct_change"; note that we can set col_name = "value" to overwrite the existing "value" column.

Value

A data frame given by appending a new column to x named according to the col_name argument, containing the percentage change values.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## Not run: 
df <- covidcast::covidcast_signal("fb-survey", "smoothed_cli", 
    start_day = "2021-01-01", 
    end_day = "2021-01-31",
    geo_type = "state")

# percentage change between back-to-back weeks (default, as n = 14)
pct_change(df)

# percentage change between back-to-back days
pct_change(df, n = 2)

## End(Not run)

dshemetov/modeltools-mirror documentation built on Jan. 7, 2022, 12:23 a.m.