acf_tidiers {broom} | R Documentation

## Tidying method for the acf function

### Description

Tidy an "acf" object, which is the output of `acf` and the related `pcf` and `ccf` functions.

### Usage

    ## S3 method for class 'acf'
    tidy(x, ...)

### Arguments

`x` | acf object
`...` | (not used)

### Value

`data.frame` with columns

`lag` | lag values
`acf` | calucated correlation

### Examples

    # acf
    result <- acf(lh, plot=FALSE)
    tidy(result)

    # ccf
    result <- ccf(mdeaths, fdeaths, plot=FALSE)
    tidy(result)

    # pcf
    result <- pacf(lh, plot=FALSE)
    tidy(result)

    # lag plot
    library(ggplot2)
    result <- tidy(acf(lh, plot=FALSE))
    p <- ggplot(result, aes(x=lag, y=acf)) +
             geom_bar(stat='identity', width=0.1) +
             theme_bw()
    p

    # with confidence intervals
    conf.level <- 0.95
    # from \code{plot.acf} method
    len.data <- length(lh) # same as acf$n.used
    conf.int <- qnorm((1 + conf.level) / 2) / sqrt(len.data)
    p + geom_hline(yintercept = c(-conf.int, conf.int),
                   color='blue', linetype='dashed')

[Package broom version 0.4.2 Index]