#Introduction
Question: Are customers with low account balances more likely to churn?
Hypothesis: Customers with low balances churn more than customers with higher balances.
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.5.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.5.3
##
## 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
churn <- read.csv("Bank_Churn.csv")
churn$Status <- factor(churn$Exited, levels = c(0, 1), labels = c("Stayed", "Churned"))
#Question 1:Graph
ggplot(churn, aes(x = Status, y = Balance)) +
geom_boxplot() +
labs(title = "Account Balance by Churn Status",
x = "Customer Status",
y = "Account Balance ($)")
The boxplot compares balances of customers who stayed and customers who churned. The median line for churned customers (around $109,000) is higher than for customers who stayed (around $92,000). Many customers who stayed have a $0 balance. This is the opposite of what my hypothesis predicted.
#Question 2:Average Balance
churn %>%
group_by(Status) %>%
summarise(Count = n(), Mean = mean(Balance), Median = median(Balance), SD = sd(Balance))
## # A tibble: 2 × 5
## Status Count Mean Median SD
## <fct> <int> <dbl> <dbl> <dbl>
## 1 Stayed 7963 72745. 92073. 62848.
## 2 Churned 2037 91109. 109349. 58361.
The average balance of customer who stayed was abour $72,745 and the balance of customers who churned was $91,109. The median was about the same pattern- $92,073 and $109,349. My hypothesis or I predicted that people with very low to none balances would churn, so i expected them to hvae lower average balance. But, The result turned out to be opposite, as customer who churned had higher account balances.
#Question 3:Correlation
result <- cor.test(churn$Balance, churn$Exited)
result
##
## Pearson's product-moment correlation
##
## data: churn$Balance and churn$Exited
## t = 11.936, df = 9998, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.09916308 0.13781267
## sample estimates:
## cor
## 0.1185328
result$estimate^2
## cor
## 0.01405002
ggplot(churn, aes(x = Balance, y = Exited)) +
geom_jitter(height = 0.05, alpha = 0.15) +
geom_smooth(method = "lm", color = "blue") +
labs(title = "Account Balance vs. Churn",
x = "Account Balance ($)",
y = "Exited (0 = Stayed, 1 = Churned)")
## `geom_smooth()` using formula = 'y ~ x'
The correlation between balance and churn is r = 0.119, and R-squared is 0.014. The p-value is below 2.2e-16, so the relationship is statistically significant. However, balance explains only about 1.4% of the variation in churn, so it is a weak predictor. The blue regression line goes up, so customers with higher balances are slightly more likely to churn. This does not support my hypothesis either.
#Question 4:Distribution of Balance
ggplot(churn, aes(x = Balance)) +
geom_histogram(bins = 40, fill = "lightblue", color = "white") +
labs(title = "Distribution of Account Balances",
x = "Account Balance ($)",
y = "Number of Customers")
The distribution of balances in the graph is not normal. There is a very large spike at $0, and the remaining customers make a bell-shaped curve in the center. Since, there are two peaks, the distribution is not symmetric.
#Question 5:Stayed vs. Churned
stayed <- churn$Balance[churn$Exited == 0]
churned <- churn$Balance[churn$Exited == 1]
t.test(churned, stayed)
##
## Welch Two Sample t-test
##
## data: churned and stayed
## t = 12.471, df = 3347.8, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 15476.26 21250.22
## sample estimates:
## mean of x mean of y
## 91108.54 72745.30
wilcox.test(churned, stayed)
##
## Wilcoxon rank sum test with continuity correction
##
## data: churned and stayed
## W = 9371187, p-value < 2.2e-16
## alternative hypothesis: true location shift is not equal to 0
I split customers into 2 groups, who stayed (n is 7,963) and who churned (n is 2,037). The histogram showed the balance was not normally distributed so I used the Wilcoxon test as it doest need data ti be normally distributed and welch t test because the sample size was too big. Both p values are less than 2.2e-16, showing that there is a statistically significant difference in blanace between the groups. The customers who churned had a balance of $91,109 compared to $72745.30 who stayed. So, overall the results dont support my hypothesis of the relationship of lower balances associated with more churning in bank.
#Conclusion
My hypothesis was that lower balances are more likely to churn than the customers with higher balances. However, the results didnt support my hypothesis. Customers who churned had higher average and median account balances. The correlation between balances and churn was small but positive, and booth statistical tests showed a significant difference but in the oppostie direction of my prediction. One possible reason could b ehtat customers with higher balances have more financial options and choose to move their money into another bank with more benefits, however this is not tested, would need more analysis.