É a medida de associação linear entre duas variáveis númericas.
Intervalo:
-1 r 1
r > 0 -> relação positiva (maior)
r < 0 -> relação negativa (menor)
r = 0 -> sem relação linear
Intensidade
0 a 0.3 - fraca
0.3 a 0.6 - moderada
0.6 a 0.9 - forte
> 0.9 - muito forte
Funciona do mesmo modo para numeros negativos.
Pacotes
library(tidyverse)
Warning: pacote 'dplyr' foi compilado no R versão 4.5.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.2.0 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.2 ✔ tibble 3.3.0
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.1.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(skimr)
Warning: pacote 'skimr' foi compilado no R versão 4.5.2
library(gt)
Warning: pacote 'gt' foi compilado no R versão 4.5.2
library(readr)library(ggthemes)
Dados
churn <-read_csv("churn_clean.csv")
Rows: 7043 Columns: 21
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (18): customer_id, gender, senior_citizen, partner, dependents, phone_se...
dbl (3): tenure, monthly_charges, total_charges
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(churn)
Correlação
Correlação simples
Função cor(), seleciona as duas variaveis e arredonda com round()
Grafico de dispersão das colunas mais correlacionadas
churn %>%ggplot(aes(x = tenure, y = total_charges)) +geom_point(alpha =0.4, color ="lightblue") +geom_smooth(method ="lm", se =FALSE, color ="red") +theme_minimal()