Loading...

Correlation and Dependency

Finding links between variables is a very important task. The main purpose of data science is to find relationships between variables, and to understand how these relationships can help us make better decisions.

Machine learning models are also sensitive to the number of variables and how they relate and affect each other, so finding correlations and dependencies can help us make better use of our machine learning algorithms.

Let’s use the Telco Churn dataset to understand how we can find links between different variables in vastorbit.

import vastorbit as vo

churn = vo.read_csv("customers.csv")
churn.head(100)
Abc
customerid
Varchar(50)
100%
Abc
gender
Varchar(50)
100%
123
seniorcitizen
Integer
100%
Abc
partner
Varchar(50)
100%
Abc
dependents
Varchar(50)
100%
123
tenure
Integer
100%
Abc
phoneservice
Varchar(50)
100%
Abc
multiplelines
Varchar(50)
100%
Abc
internetservice
Varchar(50)
100%
Abc
onlinesecurity
Varchar(50)
100%
Abc
onlinebackup
Varchar(50)
100%
Abc
deviceprotection
Varchar(50)
100%
Abc
techsupport
Varchar(50)
100%
Abc
streamingtv
Varchar(50)
100%
Abc
streamingmovies
Varchar(50)
100%
Abc
contract
Varchar(50)
100%
Abc
paperlessbilling
Varchar(50)
100%
Abc
paymentmethod
Varchar(50)
100%
123
monthlycharges
Double
100%
123
totalcharges
Double
99%
Abc
churn
Varchar(50)
100%
15141-ZUVBHFemale0NoYes9YesNoFiber opticYesNoYesYesNoYesMonth-to-monthNoBank transfer (automatic)93.0870.25No
21089-HDMKPMale1NoYes11YesNoDSLNoYesNoYesNoNoMonth-to-monthYesElectronic check54.55601.25No
37623-HKYRKMale0NoYes6YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceMonth-to-monthNoMailed check19.7111.65No
40310-SUCINFemale0YesNo71YesNoDSLYesYesYesYesYesYesOne yearYesBank transfer (automatic)84.86046.1No
55197-PYEPUFemale0YesYes42YesYesFiber opticYesYesNoNoYesNoOne yearYesCredit card (automatic)94.453923.8No
62929-ERCFZFemale0YesYes8YesNoFiber opticNoNoYesNoYesYesMonth-to-monthYesElectronic check94.2777.3Yes
77548-SEPYIFemale0NoNo5YesNoFiber opticNoYesNoNoYesYesMonth-to-monthYesElectronic check96.25512.45Yes
88835-VSDSEFemale0YesNo2YesNoFiber opticNoNoNoNoNoNoMonth-to-monthYesElectronic check70.7141.45Yes
96619-RPLQZFemale0YesYes45YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceTwo yearNoMailed check20.85892.15No
103275-RHRNEMale0YesYes28NoNo phone serviceDSLNoYesYesYesYesYesOne yearYesCredit card (automatic)60.01682.05No
113503-TYDAYFemale0YesNo43YesYesFiber opticNoYesNoNoNoNoMonth-to-monthNoElectronic check80.453398.9No
126901-GOGZGMale0NoYes60YesYesDSLYesNoYesYesYesYesTwo yearYesElectronic check84.954984.85No
131623-NLDOTFemale0YesNo42NoNo phone serviceDSLNoYesNoYesNoNoOne yearNoMailed check33.551445.3Yes
147021-XSNYEMale0YesYes7NoNo phone serviceDSLYesNoYesYesNoYesTwo yearNoCredit card (automatic)49.65305.55No
159621-OUPYDFemale0YesNo25YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceOne yearYesBank transfer (automatic)20.2507.9No
169898-KZQDZFemale1YesYes40YesYesFiber opticNoNoNoNoYesYesMonth-to-monthYesCredit card (automatic)94.553640.45Yes
178982-NHAVYMale0NoNo27YesYesFiber opticNoNoYesNoYesYesOne yearYesBank transfer (automatic)100.52673.45No
184307-KWMXEMale0NoNo10NoNo phone serviceDSLNoYesNoYesNoNoMonth-to-monthNoElectronic check35.75389.8No
190141-YEAYSFemale1NoNo27YesYesFiber opticNoYesYesNoNoNoMonth-to-monthYesBank transfer (automatic)86.452401.05No
202450-ZKEEDFemale0NoNo11YesNoDSLNoNoYesYesNoNoOne yearNoBank transfer (automatic)53.8651.55No
213694-DELSOMale0YesYes4NoNo phone serviceDSLYesNoNoNoYesNoMonth-to-monthNoCredit card (automatic)38.55156.1No
223893-JRNFSMale0NoNo68NoNo phone serviceDSLNoNoYesNoNoYesMonth-to-monthYesBank transfer (automatic)39.92796.35No
239603-OAIHCMale1NoNo1YesNoFiber opticNoNoNoNoNoNoMonth-to-monthYesElectronic check70.0570.05No
241133-KXCGEFemale0NoNo18YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceOne yearNoMailed check20.1407.05No
255236-PERKLFemale0NoNo57YesYesFiber opticYesYesYesNoYesYesTwo yearYesBank transfer (automatic)112.956465.0Yes
260142-GVYSNMale0NoNo26YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceMonth-to-monthYesElectronic check20.3511.25No
271049-FYSYGFemale0YesNo17NoNo phone serviceDSLNoYesYesNoNoNoMonth-to-monthYesCredit card (automatic)35.65646.05No
287854-FOKSFMale0NoNo1NoNo phone serviceDSLNoNoNoNoNoYesMonth-to-monthNoElectronic check35.935.9Yes
292519-FAKODMale0NoYes38YesYesFiber opticNoNoYesNoYesYesMonth-to-monthYesBank transfer (automatic)99.253777.15Yes
308406-LNMHFMale1YesNo59YesNoFiber opticYesYesYesNoNoNoOne yearYesCredit card (automatic)82.954903.15No
311821-BUCWYMale0NoNo30YesNoDSLYesNoYesNoNoNoTwo yearYesMailed check55.651653.85No
328263-JQAIKMale1NoNo2NoNo phone serviceDSLNoNoNoNoNoNoMonth-to-monthYesMailed check24.4547.5Yes
330023-UYUPNFemale1YesNo50YesYesNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceOne yearNoElectronic check25.21306.3No
348314-DPQHLMale0NoNo9NoNo phone serviceDSLYesNoYesYesNoYesOne yearNoMailed check50.8463.6No
351465-WCZVTFemale0YesYes3YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceMonth-to-monthNoMailed check19.6560.65No
369481-SFCQYFemale0NoYes14YesNoDSLNoNoYesNoYesNoMonth-to-monthYesCredit card (automatic)59.8824.85No
376360-SVNWVFemale1NoNo31YesNoFiber opticYesNoNoNoNoNoMonth-to-monthYesCredit card (automatic)73.552094.65No
380567-GGCACFemale0NoNo7YesNoDSLYesYesYesNoNoNoMonth-to-monthNoElectronic check61.4438.9No
397089-IVVAZFemale0NoNo8YesYesFiber opticYesNoNoYesYesYesMonth-to-monthYesBank transfer (automatic)103.35847.3Yes
408884-MRNSUMale0YesYes17YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceOne yearNoBank transfer (automatic)19.9329.75No
412171-UDMFDMale0YesYes32YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceMonth-to-monthYesCredit card (automatic)19.45674.55No
429050-IKDZAFemale1NoNo2YesNoFiber opticNoNoNoNoYesNoMonth-to-monthNoMailed check81.5162.55No
432205-YMZZJMale1NoNo7YesYesFiber opticNoNoNoNoYesNoMonth-to-monthYesElectronic check84.8546.95Yes
449802-CAQUTFemale0YesYes72YesYesFiber opticYesYesYesNoYesYesTwo yearNoCredit card (automatic)109.557887.25No
451254-IZEYFFemale1NoNo31YesYesFiber opticNoYesNoNoYesYesMonth-to-monthYesElectronic check99.953186.65Yes
460187-WZNABFemale0YesYes27YesNoFiber opticYesNoNoNoNoNoMonth-to-monthNoMailed check74.41972.35No
479492-TOKRIFemale0NoNo18YesYesFiber opticNoYesNoNoYesNoMonth-to-monthYesCredit card (automatic)90.01527.35Yes
481475-VWVDOMale0NoNo7YesNoFiber opticNoNoYesNoNoNoMonth-to-monthYesElectronic check74.9490.55No
499221-OTIVJFemale1NoNo14YesYesFiber opticNoYesYesNoYesYesMonth-to-monthYesElectronic check104.851531.4Yes
501357-MVDOZMale0YesYes11YesNoDSLNoNoYesNoYesNoMonth-to-monthYesBank transfer (automatic)59.65683.25No
517602-MVRMBFemale0YesYes72YesYesFiber opticYesNoYesYesYesYesTwo yearYesBank transfer (automatic)110.458058.85No
523325-FUYCGMale0YesYes28YesYesFiber opticYesYesNoNoYesYesOne yearNoElectronic check106.12847.4Yes
535908-QMGOEMale1NoNo15YesYesFiber opticNoNoNoNoNoNoMonth-to-monthYesCredit card (automatic)74.21133.9Yes
541197-BVMVGFemale1NoNo4YesYesFiber opticNoNoNoNoNoNoMonth-to-monthYesElectronic check74.45294.45No
555406-KGRMXFemale0NoNo71YesYesNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceTwo yearNoElectronic check24.551719.15No
568481-YYXWGFemale0NoNo5YesNoFiber opticNoYesNoYesNoYesMonth-to-monthYesElectronic check89.35461.7Yes
575968-HYJRZMale0YesYes47YesYesNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceTwo yearNoMailed check24.551160.45No
585198-EFNBMMale1YesNo57YesNoFiber opticNoYesYesNoYesNoOne yearYesElectronic check90.655199.8No
597516-GMHUVMale1YesNo50YesYesFiber opticYesNoYesNoYesYesTwo yearYesCredit card (automatic)105.055163.3No
607140-ADSMJMale0NoNo8YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceMonth-to-monthYesCredit card (automatic)20.45162.3No
612230-XTUWLFemale0YesYes48YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceTwo yearNoMailed check19.55883.35No
627706-YLMQAFemale0NoNo70YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceOne yearNoBank transfer (automatic)19.71341.5No
632585-KTFREMale0NoYes1YesNoDSLYesYesNoYesNoYesMonth-to-monthYesBank transfer (automatic)70.4570.45No
647994-UYIVZMale0YesNo8YesYesFiber opticNoNoNoNoNoYesMonth-to-monthYesBank transfer (automatic)85.65659.45No
652609-IAICYFemale0NoNo1YesYesFiber opticNoNoNoNoNoNoMonth-to-monthYesElectronic check77.1577.15Yes
661740-CSDJPMale0NoNo1NoNo phone serviceDSLNoNoNoNoNoYesMonth-to-monthYesBank transfer (automatic)35.2535.25Yes
677717-BICXIMale0YesYes60YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceTwo yearNoMailed check20.551205.05No
686559-RAKOZMale0YesYes49YesYesFiber opticNoNoNoYesYesYesOne yearYesElectronic check97.954917.9No
692636-OHFMNMale0YesNo4NoNo phone serviceDSLNoYesNoNoYesYesMonth-to-monthYesElectronic check48.55201.0Yes
704716-MRVENFemale0NoNo29YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceOne yearNoMailed check20.0599.3No
712143-LJULTFemale0YesNo67YesYesNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceTwo yearYesCredit card (automatic)25.251733.15No
721323-OOEPCFemale0YesNo53YesYesFiber opticNoYesNoNoYesYesMonth-to-monthYesCredit card (automatic)98.45149.5Yes
733200-MNQTFMale0YesNo67YesYesDSLYesYesYesYesNoNoTwo yearNoCredit card (automatic)70.94677.1No
746164-HXUGHFemale0YesYes6YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceMonth-to-monthNoMailed check19.85119.3No
755630-IXDXVFemale0NoNo47YesYesFiber opticNoYesYesNoYesYesMonth-to-monthYesElectronic check106.354849.1No
760320-DWVTUFemale0NoNo53YesNoFiber opticYesYesYesYesNoYesTwo yearNoMailed check99.55424.25No
779135-MGVPYMale0YesNo69YesNoDSLYesYesYesYesYesYesTwo yearYesMailed check84.75878.9No
781212-GLHMDMale0NoNo3YesNoFiber opticYesNoNoNoNoYesMonth-to-monthYesMailed check86.05244.85No
797878-JGDKKMale0NoNo4YesNoDSLNoNoNoNoNoNoMonth-to-monthNoMailed check44.55220.75No
801088-AUUZZMale0YesYes56YesYesDSLYesYesNoYesNoYesTwo yearYesCredit card (automatic)75.854261.2No
810397-GZBBCMale1YesNo59YesYesFiber opticNoNoNoNoYesYesMonth-to-monthYesBank transfer (automatic)93.855574.75Yes
826614-YWYSCMale1YesNo61YesYesNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceTwo yearNoBank transfer (automatic)25.01501.75No
839588-OZDMQFemale0YesNo2YesNoDSLNoNoNoNoNoNoMonth-to-monthYesElectronic check45.089.75No
847641-EUYETMale1YesYes46YesYesFiber opticYesYesYesNoYesNoMonth-to-monthYesElectronic check100.74541.2Yes
856476-EPYZRMale0YesYes12YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceMonth-to-monthNoMailed check20.5255.5No
869921-ZVRHGFemale0NoNo14YesYesFiber opticNoNoYesNoNoNoMonth-to-monthYesElectronic check80.451072.0Yes
871174-FGIFNFemale0YesYes28YesYesFiber opticNoNoNoYesNoYesOne yearYesElectronic check90.452509.25No
886620-HVDUJMale0NoNo24YesNoDSLYesYesNoYesNoNoMonth-to-monthNoBank transfer (automatic)60.451440.75No
894701-MLJPNMale0NoNo31YesNoDSLNoNoYesYesNoNoMonth-to-monthYesElectronic check55.251715.65Yes
901032-MAELWFemale0YesYes68YesYesDSLYesYesYesYesNoYesOne yearYesElectronic check78.455333.35No
917641-TQFHNMale0NoYes39YesYesFiber opticNoNoNoYesYesYesTwo yearNoMailed check100.553895.35No
921552-TKMXSFemale0YesNo42YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceMonth-to-monthNoCredit card (automatic)20.35869.9No
939206-GVPEQMale0YesNo13NoNo phone serviceDSLYesNoNoYesYesYesMonth-to-monthYesElectronic check54.45706.85Yes
948622-ZLFKOFemale0YesNo6YesYesFiber opticNoYesNoNoNoYesMonth-to-monthYesElectronic check90.75512.25No
951596-BBVTGMale0NoNo35YesYesFiber opticNoNoNoNoNoNoMonth-to-monthNoCredit card (automatic)75.352636.05Yes
966188-UXBBRFemale0YesNo38YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceOne yearYesCredit card (automatic)20.25814.75No
972333-KWEWWMale0NoNo18YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceTwo yearNoCredit card (automatic)20.05388.6No
985702-SKUOBFemale0YesNo4YesNoNoNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceNo internet serviceMonth-to-monthNoMailed check19.693.45No
991134-YWTYFMale0YesNo27YesNoDSLNoYesNoYesNoNoMonth-to-monthYesElectronic check53.81389.85No
1006061-GWWAVMale0NoYes41YesNoDSLYesYesYesNoYesNoOne yearNoMailed check70.22894.55No

The Pearson correlation coefficient is a very common correlation function. In this case, it helped us to find linear links between the variables. Having a strong Pearson relationship means that the two input variables are linearly correlated.

churn.corr(method = "pearson")

We can see that tenure is well-correlated to the TotalCharges, which makes sense.

churn.scatter(["tenure", "TotalCharges"])
churn.corr(["tenure", "TotalCharges"], method = "pearson")

Note, however, that having a low Pearson relationship imply that the variables aren’t correlated. For example, let’s compute the Pearson correlation coefficient between tenure and TotalCharges to the power of 20.

churn["TotalCharges^20"] = churn["TotalCharges"] ** 20
churn.corr(["tenure", "TotalCharges^20"], method = "pearson")

We know that the tenure and TotalCharges are strongly linearly correlated. However we can notice that the correlation between the tenure and TotalCharges to the power of 20 is not very high. Indeed, the Pearson correlation coefficient is not robust for monotonic relationships, but rank-based correlations are. Knowing this, we’ll calculate the Spearman’s rank correlation coefficient instead.

churn.corr(method = "spearman", show = False)
"seniorcitizen""tenure""monthlycharges""totalcharges""TotalCharges^20"
"seniorcitizen"1.00.019076790.221092520.105795340.10579534
"tenure"0.019076791.00.276342240.88310340.8831034
"monthlycharges"0.221092520.276342241.00.63395840.6339584
"totalcharges"0.105795340.88310340.63395841.01.0
"TotalCharges^20"0.105795340.88310340.63395841.01.0
churn.corr(method = "spearman")

The Spearman’s rank correlation coefficient determines the monotonic relationships between the variables.

churn.corr(["tenure", "TotalCharges^20"], method = "spearman")

We can notice that Spearman’s rank correlation coefficient stays the same if one of the variables can be expressed using a monotonic function on the other. The same applies to Kendall rank correlation coefficient.

churn.corr(method = "kendall")

Notice that the Kendall rank correlation coefficient will also detect the monotonic relationship.

churn.corr(["tenure", "TotalCharges^20"], method = "kendall")

However, the Kendall rank correlation coefficient is very computationally expensive, so we’ll generally use Pearson and Spearman when dealing with correlations between numerical variables.

Binary features are considered numerical, but this isn’t technically accurate. Since binary variables can only take two values, calculating correlations between a binary and numerical variable can lead to misleading results. To account for this, we’ll want to use the Biserial Point method to calculate the Point-Biserial correlation coefficient. This powerful method will help us understand the link between a binary variable and a numerical variable.

churn.corr(method = "biserial")

Lastly, we’ll look at the relationship between categorical columns. In this case, the Cramer's V method is very efficient. Since there is no position in the Euclidean space for those variables, the Cramer's V coefficients cannot be negative (which is a sign of an opposite relationship) and they will range in the interval [0,1].

churn.corr(method = "cramer")

Sometimes, we just need to look at the correlation between a response and other variables. The parameter focus will isolate and show us the specified correlation vector.

churn.corr(method = "cramer", focus = "Churn")

Sometimes a correlation coefficient can lead to incorrect assumptions, so we should always look at the coefficient p-value.

churn.corr_pvalue("Churn", "customerID", method = "cramer")

We can see that churning correlates to the type of contract (monthly, yearly, etc.) which makes sense: you would expect that different types of contracts differ in flexibility for the customer, and particularly restrictive contracts may make churning more likely.

The type of internet service also seems to correlate with churning. Let’s split the different categories to binaries to understand which services can influence the global churning rate.

churn["InternetService"].one_hot_encode()
churn.corr(
    method = "spearman",
    focus = "Churn",
    columns = [
        "InternetService_DSL",
        "InternetService_Fiber_optic",
    ],
)

We can see that the Fiber Optic option in particular seems to be directly linked to a customer’s likelihood to churn. Let’s compute some aggregations to find a causal relationship.

churn["contract"].one_hot_encode()
churn.groupby(
    [
        "InternetService_Fiber_optic",
    ],
    [
        "AVG(tenure) AS tenure",
        "AVG(totalcharges) AS totalcharges",
        'AVG("contract_month-to-month") AS "contract_month-to-month"',
        'AVG("monthlycharges") AS "monthlycharges"',
    ],
)
123
internetservice_Fiber_optic
Integer
100%
123
tenure
Double
100%
123
totalcharges
Double
100%
123
contract_month-to-month
Double
100%
123
monthlycharges
Double
100%
1132.917958656330753205.30457041343650.687338501291989791.50012919896639
2031.9422346085634671558.06548526422760.4426146440334431443.788244236128705

It seems that users with the Fiber Optic option tend more to churn not because of the option itself, but probably because of the type of contracts and the monthly charges the users are paying to get it. Be careful when dealing with identifying correlations! Remember: correlation doesn’t imply causation!

Another important type of correlation is the autocorrelation. Let’s use the amazon dataset to understand it.

from vastorbit.datasets import load_amazon

amazon = load_amazon()
amazon.head(100)
📅
date
Date
100%
Abc
state
Varchar(32)
100%
123
number
Integer
100%
12013-09-01MATO GROSSO DO SUL5576
22013-10-01MATO GROSSO DO SUL1986
32013-11-01MATO GROSSO DO SUL1064
42013-12-01MATO GROSSO DO SUL447
52013-01-01MINAS GERAIS75
62013-02-01MINAS GERAIS143
72013-03-01MINAS GERAIS110
82013-04-01MINAS GERAIS61
92013-05-01MINAS GERAIS150
102013-06-01MINAS GERAIS144
112013-07-01MINAS GERAIS462
122013-08-01MINAS GERAIS911
132013-09-01MINAS GERAIS1656
142013-10-01MINAS GERAIS1221
152013-11-01MINAS GERAIS277
162013-12-01MINAS GERAIS98
172013-01-01PARANÁ28
182013-02-01PARANÁ9
192013-03-01PARANÁ18
202013-04-01PARANÁ72
212013-05-01PARANÁ85
222013-06-01PARANÁ52
232013-07-01PARANÁ168
242013-08-01PARANÁ481
252013-09-01PARANÁ476
262013-10-01PARANÁ233
272013-11-01PARANÁ126
282013-12-01PARANÁ155
292013-01-01PARAÍBA38
302013-02-01PARAÍBA9
312013-03-01PARAÍBA3
322013-04-01PARAÍBA6
332013-05-01PARAÍBA3
342013-06-01PARAÍBA3
352013-07-01PARAÍBA1
362013-08-01PARAÍBA3
372013-09-01PARAÍBA25
382013-10-01PARAÍBA58
392013-11-01PARAÍBA95
402013-12-01PARAÍBA78
412013-01-01PARÁ167
422013-02-01PARÁ30
432013-03-01PARÁ19
442013-04-01PARÁ20
452013-05-01PARÁ42
462013-06-01PARÁ173
472013-07-01PARÁ447
482013-08-01PARÁ2161
492013-09-01PARÁ3360
502013-10-01PARÁ4921
512013-11-01PARÁ3688
522013-12-01PARÁ5514
532013-01-01PERNAMBUCO55
542013-02-01PERNAMBUCO29
552013-03-01PERNAMBUCO40
562013-04-01PERNAMBUCO11
572013-05-01PERNAMBUCO9
582013-06-01PERNAMBUCO12
592013-07-01PERNAMBUCO4
602013-08-01PERNAMBUCO14
612013-09-01PERNAMBUCO143
622013-10-01PERNAMBUCO161
632013-11-01PERNAMBUCO110
642013-12-01PERNAMBUCO141
652013-01-01PIAUÍ72
662013-02-01PIAUÍ68
672013-03-01PIAUÍ14
682013-04-01PIAUÍ34
692013-05-01PIAUÍ40
702013-06-01PIAUÍ263
712013-07-01PIAUÍ361
722013-08-01PIAUÍ1015
732013-09-01PIAUÍ2311
742013-10-01PIAUÍ1269
752013-11-01PIAUÍ640
762013-12-01PIAUÍ468
772013-01-01RIO DE JANEIRO9
782013-02-01RIO DE JANEIRO12
792013-03-01RIO DE JANEIRO9
802013-04-01RIO DE JANEIRO9
812013-05-01RIO DE JANEIRO16
822013-06-01RIO DE JANEIRO17
832013-07-01RIO DE JANEIRO58
842013-08-01RIO DE JANEIRO74
852013-09-01RIO DE JANEIRO117
862013-10-01RIO DE JANEIRO44
872013-11-01RIO DE JANEIRO28
882013-12-01RIO DE JANEIRO12
892013-01-01RIO GRANDE DO NORTE25
902013-02-01RIO GRANDE DO NORTE24
912013-03-01RIO GRANDE DO NORTE6
922013-04-01RIO GRANDE DO NORTE7
932013-05-01RIO GRANDE DO NORTE2
942013-06-01RIO GRANDE DO NORTE1
952013-07-01RIO GRANDE DO NORTE0
962013-08-01RIO GRANDE DO NORTE2
972013-09-01RIO GRANDE DO NORTE7
982013-10-01RIO GRANDE DO NORTE71
992013-11-01RIO GRANDE DO NORTE77
1002013-12-01RIO GRANDE DO NORTE46

Our goal is to predict the number of forest fires in Brazil. To do this, we can draw an autocorrelation plot and a partial autocorrelation plot.

amazon.acf(
    column = "number",
    ts = "date",
    by = ["state"],
    p = 24,
    method = "pearson",
)
amazon.pacf(
    column = "number",
    ts = "date",
    by = ["state"],
    p = 8,
)

We can see the seasonality forest fires.

It’s mathematically impossible to build the perfect correlation function, but we still have several powerful functions at our disposal for finding relationships in all kinds of datasets.