library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)

data <- read.csv("../Churn_Modelling.csv")

cor(data[c("Age", "Balance", "NumOfProducts")])
##               Age    Balance NumOfProducts
## Age             1         NA            NA
## Balance        NA  1.0000000    -0.3042261
## NumOfProducts  NA -0.3042261     1.0000000
model <- lm(Exited ~ Age + Balance + NumOfProducts + Age:Balance, data = data)

summary(model)
## 
## Call:
## lm(formula = Exited ~ Age + Balance + NumOfProducts + Age:Balance, 
##     data = data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.88800 -0.21393 -0.13493 -0.04414  1.03341 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   -1.781e-01  2.643e-02  -6.738 1.69e-11 ***
## Age            8.617e-03  5.776e-04  14.917  < 2e-16 ***
## Balance       -4.285e-07  2.369e-07  -1.809   0.0705 .  
## NumOfProducts -5.203e-03  6.920e-03  -0.752   0.4521    
## Age:Balance    2.912e-08  5.874e-09   4.958 7.24e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3831 on 9996 degrees of freedom
##   (1 observation deleted due to missingness)
## Multiple R-squared:  0.09587,    Adjusted R-squared:  0.0955 
## F-statistic:   265 on 4 and 9996 DF,  p-value: < 2.2e-16

The coefficients of the model indicate the estimated change in customer churn for a one-unit change in each predictor, accounting for the interaction effect. The results revealed that age remained a significant predictor of churn (p < 0.001), with a positive coefficient indicating that older customers were more likely to churn. However, the coefficient for balance alone did not reach conventional levels of significance (p = 0.0705), suggesting that its direct impact on churn may be less pronounced.

cor(data[c("Age", "Balance", "NumOfProducts", "Tenure")])
##               Age     Balance NumOfProducts      Tenure
## Age             1          NA            NA          NA
## Balance        NA  1.00000000   -0.30422614 -0.01228163
## NumOfProducts  NA -0.30422614    1.00000000  0.01341806
## Tenure         NA -0.01228163    0.01341806  1.00000000
model <- lm(Exited ~ Age + Balance + NumOfProducts + Tenure, data = data)

summary(model)
## 
## Call:
## lm(formula = Exited ~ Age + Balance + NumOfProducts + Tenure, 
##     data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.8171 -0.2209 -0.1395 -0.0287  1.0811 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   -2.583e-01  2.087e-02 -12.379   <2e-16 ***
## Age            1.083e-02  3.660e-04  29.592   <2e-16 ***
## Balance        7.013e-07  6.455e-08  10.866   <2e-16 ***
## NumOfProducts -4.036e-03  6.925e-03  -0.583    0.560    
## Tenure        -1.382e-03  1.327e-03  -1.042    0.298    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3836 on 9996 degrees of freedom
##   (1 observation deleted due to missingness)
## Multiple R-squared:  0.09374,    Adjusted R-squared:  0.09338 
## F-statistic: 258.5 on 4 and 9996 DF,  p-value: < 2.2e-16

The regression analysis was conducted to explore the factors influencing customer churn in the banking dataset. The model included predictors such as age, account balance, the number of bank products used (NumOfProducts), and tenure. Upon examination of the correlation matrix, age showed a significant positive correlation with customer churn, indicating that older customers were more likely to churn. Balance exhibited a negative correlation with churn, suggesting that customers with higher account balances were less likely to churn. However, the number of bank products and tenure did not show significant correlations with churn.

cor(data[c("Age", "Balance", "NumOfProducts", "IsActiveMember")])
##                Age    Balance NumOfProducts IsActiveMember
## Age              1         NA            NA             NA
## Balance         NA  1.0000000    -0.3042261             NA
## NumOfProducts   NA -0.3042261     1.0000000             NA
## IsActiveMember  NA         NA            NA              1
model <- lm(Exited ~ Age + Balance + NumOfProducts + IsActiveMember, data = data)

summary(model)
## 
## Call:
## lm(formula = Exited ~ Age + Balance + NumOfProducts + IsActiveMember, 
##     data = data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.77299 -0.23683 -0.12592  0.02008  1.16017 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    -2.147e-01  1.958e-02 -10.966   <2e-16 ***
## Age             1.143e-02  3.608e-04  31.691   <2e-16 ***
## Balance         6.910e-07  6.340e-08  10.899   <2e-16 ***
## NumOfProducts  -2.887e-03  6.801e-03  -0.425    0.671    
## IsActiveMember -1.455e-01  7.566e-03 -19.228   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3767 on 9995 degrees of freedom
##   (2 observations deleted due to missingness)
## Multiple R-squared:  0.126,  Adjusted R-squared:  0.1257 
## F-statistic: 360.2 on 4 and 9995 DF,  p-value: < 2.2e-16

The results revealed that age and account balance were significant predictors of customer churn (p < 0.001). Specifically, for each year increase in age, the likelihood of churn increased by 0.011, while for each unit increase in account balance, the likelihood of churn decreased by 7.013e-07. However, the number of bank products used and tenure did not demonstrate significant effects on churn (p > 0.05). The adjusted R-squared value of 0.09338 suggests that approximately 9.34% of the variance in customer churn can be explained by the predictors included in the model. Overall, while age and account balance emerged as important factors influencing churn, further investigation may be warranted to explore additional predictors contributing to customer churn in the banking industry.

ggplot(data, aes(x = Geography, y = Exited)) +
  geom_violin() +
  labs(title = "Violin plot of Exited by Geography")
## Warning: Groups with fewer than two data points have been dropped.