1: a:

table1 <- table(hr1$Work_accident, hr1$left)
chi1 <- chisq.test(table1)
print(chi1)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  table1
## X-squared = 357.56, df = 1, p-value < 2.2e-16

b: The p-value of 2.2e-16 suggests that the association between Work_accident and leaving the company is statistically significant.

c: Employees who have experienced work accidents are more likely to leave the company.

d:

ggplot(hr1, aes(x = factor(Work_accident), fill = factor(left))) +
  geom_bar(position = "fill") +
  labs(
    x = "Work Accident",
    y = "Proportion",
    fill = "Left",
    title = "Employees who have experienced work accidents are more likely to leave the company"
  ) +
  theme_minimal()

#2: a:

table2 <- table(hr1$promotion_last_5years, hr1$left)
chi2 <- chisq.test(table2)
print(chi2)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  table2
## X-squared = 56.262, df = 1, p-value = 6.344e-14

b: The p-value of 6.344e-14 suggests that the association between Promotion in the Last 5 Years and leaving the company is statistically significant.

c: Employees who have not been promoted are more likely to leave the company.

d:

ggplot(hr1, aes(x = factor(promotion_last_5years), fill = factor(left))) +
  geom_bar(position = "fill") +
  labs(
    x = "Promotion in Last 5 Years",
    y = "Proportion",
    fill = "Left",
    title = "Employees Who Have Not Been Promoted Are More Likely to Leave the Company"
  ) +
  theme_minimal()

#3: a:

table3 <- table(hr1$Department, hr1$left)
chi3 <- chisq.test(table3)
print(chi3)
## 
##  Pearson's Chi-squared test
## 
## data:  table3
## X-squared = 86.825, df = 9, p-value = 7.042e-15

b: The association between Department and leaving the company is statistically significant.

c: Employees from different departments have varying tendencies to stay or leave the company.”)

d:

ggplot(hr1, aes(x = factor(Department), fill = factor(left))) +
  geom_bar(position = "fill") +
  labs(x = "Department", y = "Proportion", fill = "Left",
       title = "Employees from different departments have varying tendencies to stay or leave the company") +
  theme_minimal()

#4: a:

table4 <- table(hr1$salary, hr1$left)
chi4 <- chisq.test(table4)
print(chi4)
## 
##  Pearson's Chi-squared test
## 
## data:  table4
## X-squared = 381.23, df = 2, p-value < 2.2e-16

b: The association between Salary and leaving the company is statistically significant.

c: Employees who have a lower salary are more likely ot leave tha company.

d:

ggplot(hr1, aes(x = salary, fill = factor(left))) +
  geom_bar(position = "fill") +
  labs(x = "Salary", y = "Proportion", fill = "Left",
       title = "Employees who have a lower salary are more likely ot leave tha company.
") +
  theme_minimal()