# autocorr

Sample autocorrelation

## Syntax

## Description

`[`

returns the sample autocorrelation function (ACF)
and associated lags of the input univariate time series.`acf`

,`lags`

] = autocorr(`y`

)

returns a table containing variables for the sample ACF and associated lags of the last
variable in the input table or timetable. To select a different variable for which to
compute the ACF, use the `ACFTbl`

= autocorr(`Tbl`

)`DataVariable`

name-value argument.* (since R2022a)*

`[___,`

uses any input-argument combination in the previous
syntaxes, and returns the output-argument combination for the corresponding input
arguments and the approximate upper and lower confidence bounds on the ACF.`bounds`

]
= autocorr(___)

`[___] = autocorr(___,`

uses additional options specified by one or more name-value arguments. For example,
`Name=Value`

)`autocorr(Tbl,DataVariable="RGDP",NumLags=10,NumSTD=1.96)`

returns 10
lags of the sample ACF of the table variable `"RGDP"`

in
`Tbl`

and 95% confidence bounds.

`autocorr(___)`

plots the sample ACF of the input
series with confidence bounds.

`autocorr(`

plots on the axes specified by `ax`

,___)`ax`

instead of
the current axes (`gca`

). `ax`

can precede any of the input
argument combinations in the previous syntaxes.

`[___,`

plots the sample ACF of the input series and
additionally returns handles to plotted graphics objects. Use elements of
`h`

]
= autocorr(___)`h`

to modify properties of the plot after you create it.

## Examples

## Input Arguments

## Output Arguments

## More About

## Tips

To plot the ACF without confidence bounds, set

`NumSTD=0`

.

## Algorithms

If the input series is a fully observed series (that is, it does not contain any

`NaN`

values),`autocorr`

uses a Fourier transform to compute the ACF in the frequency domain, then converts back to the time domain using an inverse Fourier transform.If the input series is not fully observed (that is, it contains at least one

`NaN`

value),`autocorr`

computes the ACF at lag*k*in the time domain, and includes in the sample average only those terms for which the cross product*y*_{t}*y*_{t+k}exists. Consequently, the effective sample size is a random variable.`autocorr`

plots the ACF when you do not return any output or when you return the fourth output`h`

.

## References

[1] Box, George E. P., Gwilym M. Jenkins, and Gregory C. Reinsel. *Time Series Analysis: Forecasting and Control*. 3rd ed. Englewood Cliffs, NJ: Prentice Hall, 1994.

[2] Hamilton, James D. *Time Series Analysis*. Princeton, NJ: Princeton University Press, 1994.

## Version History

**Introduced before R2006a**