acf_by_group: Calculate Auto Correlations by Group

Description Usage Arguments Details Value Examples

View source: R/acf_by_group.R

Description

acf_by_group takes a data frame with a grouping column and returns a data frame with the autocorrelation values for each group.

Usage

1
2
acf_by_group(.data, .group_var, .value_var, ..., .ci = c("none",
  "white_noise", "ma"), .cl = 0.95)

Arguments

.data

the data frame the data is contained in

.group_var

the unquoted variable to be used as the grouping variable

.value_var

the name of the time series value to use

...

extra parameters to pass to the acf function (see ?stats::acf)

.ci

the type of confidence interval to use, defaults to none

.cl

confidence level for the confidence intervals, defaults to .95

Details

Each row in the resulting data frame will refer to a group-lag auto-correlation value.

white_noise will return confidence intervals for the series assuming the autocorrelations come from a white noise distribution. ma will apply the correction needed if the autocorrelations have some moving average correlation.

Value

a data frame with the acf values by group and lag

Examples

1
2
3
4
pres_ratings <- data.frame(approval = as.numeric(presidents), pre_1965 = c(rep(1, 60), rep(0, 60)))
ratings_acf <- acf_by_group(pres_ratings[!is.na(pres_ratings$approval), ], pre_1965, approval)
## pass params to acf
ratings2_acf <- acf_by_group(pres_ratings, pre_1965, approval, na.action = na.pass)

mattmills49/modeler documentation built on May 21, 2019, 1:25 p.m.