Loading...

verticapy.vDataFrame.acf

vDataFrame.acf(column: str, ts: str, by: Annotated[str | list[str], 'STRING representing one column or a list of columns'] | None = None, p: int | list = 12, unit: str = 'rows', method: Literal['pearson', 'kendall', 'spearman', 'spearmand', 'biserial', 'cramer'] = 'pearson', confidence: bool = True, alpha: float = 0.95, show: bool = True, kind: Literal['line', 'heatmap', 'bar'] = 'bar', mround: int = 3, chart: PlottingBase | TableSample | Axes | mFigure | Highchart | Highstock | Figure | None = None, **style_kwargs) PlottingBase | TableSample | Axes | mFigure | Highchart | Highstock | Figure

Calculates the correlations between the specified vDataColumn and its various time lags. This function is particularly useful for time series analysis and forecasting as it helps uncover relationships between data points at different time intervals. Understanding these correlations can be vital for making predictions and gaining insights into temporal data patterns.

Parameters

column: str

Input vDataColumn used to compute the Auto Correlation Plot.

ts: str

TS (Time Series) vDataColumn used to order the data. It can be of type date or a numerical vDataColumn.

by: SQLColumns, optional

vDataColumns used in the partition.

p: int | list, optional

Int equal to the maximum number of lag to consider during the computation or List of the different lags to include during the computation. p must be positive or a list of positive integers.

unit: str, optional

Unit used to compute the lags.

  • rows:

    Natural lags.

  • else:

    Any time unit. For example, you can write ‘hour’ to compute the hours lags or ‘day’ to compute the days lags.

method: str, optional

Method used to compute the correlation.

  • pearson:

    Pearson’s correlation coefficient (linear).

  • spearman:

    Spearman’s correlation coefficient (monotonic - rank based).

  • spearmanD:

    Spearman’s correlation coefficient using the DENSE RANK function instead of the RANK function.

  • kendall:

    Kendall’s correlation coefficient (similar trends). The method computes the Tau-B coefficient.

    Warning

    This method uses a CROSS JOIN during computation and is therefore computationally expensive at O(n * n), where n is the total count of the vDataFrame.

  • cramer:

    Cramer’s V (correlation between categories).

  • biserial:

    Biserial Point (correlation between binaries and a numericals).

confidence: bool, optional

If set to True, the confidence band width is drawn.

alpha: float, optional

Significance Level. Probability to accept H0. Only used to compute the confidence band width.

show: bool, optional

If set to True, the Plotting object is returned.

kind: str, optional

ACF Type.

  • bar:

    Classical Autocorrelation Plot using bars.

  • heatmap:

    Draws the ACF heatmap.

  • line:

    Draws the ACF using a Line Plot.

mround: int, optional

Round the coefficient using the input number of digits. It is used only to display the ACF Matrix (kind must be set to ‘heatmap’).

chart: PlottingObject, optional

The chart object used to plot.

**style_kwargs

Any optional parameter to pass to the plotting functions.

Returns

obj

Plotting Object.

Examples

Import the amazon dataset from VerticaPy.

from verticapy.datasets import load_amazon

data = load_amazon()
📅
date
Date
Abc
state
Varchar(32)
123
number
Integer
11998-01-01AMAPÁ0
21998-01-01AMAZONAS0
31998-01-01DISTRITO FEDERAL0
41998-01-01ESPÍRITO SANTO0
51998-01-01MARANHÃO0
61998-01-01PARANÁ0
71998-01-01PIAUÍ0
81998-01-01RORAIMA0
91998-01-01SERGIPE0
101998-01-01SÃO PAULO0
111998-02-01GOIÁS0
121998-02-01MATO GROSSO DO SUL0
131998-02-01MINAS GERAIS0
141998-02-01PARAÍBA0
151998-02-01SANTA CATARINA0
161998-02-01SÃO PAULO0
171998-03-01AMAPÁ0
181998-03-01BAHIA0
191998-03-01MATO GROSSO DO SUL0
201998-03-01PARÁ0
211998-03-01PERNAMBUCO0
221998-03-01RIO GRANDE DO SUL0
231998-04-01CEARÁ0
241998-04-01PARANÁ0
251998-04-01PARAÍBA0
261998-04-01PARÁ0
271998-05-01ALAGOAS0
281998-05-01AMAPÁ0
291998-05-01MARANHÃO0
301998-05-01MATO GROSSO DO SUL0
311998-05-01RIO GRANDE DO SUL0
321998-05-01TOCANTINS0
331998-06-01ESPÍRITO SANTO6
341998-06-01RIO DE JANEIRO3
351998-06-01RIO GRANDE DO NORTE1
361998-06-01SÃO PAULO451
371998-07-01ESPÍRITO SANTO37
381998-07-01MARANHÃO274
391998-07-01MATO GROSSO360
401998-07-01MATO GROSSO DO SUL3712
411998-07-01PARAÍBA0
421998-07-01PARÁ638
431998-07-01RONDÔNIA365
441998-07-01SÃO PAULO596
451998-08-01ALAGOAS1
461998-08-01BAHIA815
471998-08-01DISTRITO FEDERAL48
481998-08-01ESPÍRITO SANTO38
491998-08-01MARANHÃO1176
501998-08-01MATO GROSSO228
511998-08-01MINAS GERAIS875
521998-08-01PIAUÍ711
531998-08-01RIO GRANDE DO SUL9
541998-08-01RORAIMA0
551998-08-01SERGIPE0
561998-09-01AMAPÁ20
571998-09-01DISTRITO FEDERAL33
581998-09-01PIAUÍ1991
591998-09-01RORAIMA2
601998-10-01AMAZONAS83
611998-10-01GOIÁS1034
621998-10-01MATO GROSSO576
631998-10-01PARAÍBA179
641998-10-01PARÁ3665
651998-10-01PIAUÍ2586
661998-10-01SERGIPE0
671998-11-01ALAGOAS19
681998-11-01AMAPÁ131
691998-11-01CEARÁ575
701998-11-01DISTRITO FEDERAL0
711998-11-01MARANHÃO2237
721998-11-01RIO DE JANEIRO6
731998-11-01RIO GRANDE DO SUL28
741998-11-01SÃO PAULO488
751998-12-01BAHIA82
761998-12-01MARANHÃO1399
771998-12-01MATO GROSSO100
781998-12-01PARAÍBA51
791998-12-01PERNAMBUCO59
801998-12-01RIO DE JANEIRO1
811998-12-01RONDÔNIA33
821998-12-01TOCANTINS9
831999-01-01ALAGOAS58
841999-01-01GOIÁS14
851999-01-01MATO GROSSO239
861999-01-01MINAS GERAIS36
871999-01-01PARÁ87
881999-01-01PERNAMBUCO102
891999-01-01RONDÔNIA1
901999-01-01SÃO PAULO7
911999-01-01TOCANTINS36
921999-02-01ACRE0
931999-02-01CEARÁ16
941999-02-01MATO GROSSO69
951999-02-01MATO GROSSO DO SUL28
961999-02-01PERNAMBUCO13
971999-02-01RONDÔNIA1
981999-02-01SANTA CATARINA2
991999-02-01TOCANTINS1
1001999-03-01AMAPÁ2
Rows: 1-100 | Columns: 3

Draw the ACF Plot.

data.acf(
    column = "number",
    ts = "date",
    by = "state",
    method = "pearson",
    p = 24,
)

For more examples, please look at the Auto-Correlation Plot page of the Chart Gallery.

See also

vDataFrame.pacf() : Computes the partial autocorrelations.