1. Is there an association between leaving the company and having a work accident?
str(`HR_comma_sep(3)`)
if (length(`HR_comma_sep(3)`$Work_accident) != length(`HR_comma_sep(3)`$left)) {
  stop("Error: 'work_accident' and 'left' columns must have the same length.")
}

contingency_table <- table(`HR_comma_sep(3)`$Work_accident, `HR_comma_sep(3)`$left)


print(contingency_table)


chi_sq_result <- chisq.test(contingency_table)


print(chi_sq_result)

num_values <- length(`HR_comma_sep(3)`$left)
print(num_values)


num_values2 <- length(`HR_comma_sep(3)`$Work_accident)
print(num_values2)

Interpretation of Problem 1: While there is some additional coding, (this was error checking as I was initially having issues due to typos that I decided to keep as I learned some new coding applications. The Chi Square test provides a P value ,2.2e-16 which is a scientific notation for a miniscule decimal, much smaller than the atypical 0.05 required to accept the null hypothesis. Essentially as this number given is practically approaching 0, there is a strong correlation between someone having a work accident and then leaving the company.

  1. Is there an association between leaving the company and getting a promotion in the past 5 years?
contingency_table <- table(`HR_comma_sep(3)`$promotion_last_5years, `HR_comma_sep(3)`$left)


print(contingency_table)


chi_sq_result2 <- chisq.test(contingency_table)

print(chi_sq_result2)

The Chi Square test in this problem brings a P value of 6.344e-14 which is yet another puny decimal rejecting the null hypothesis and most importantly indictating that there is a strong correlation with employees leaving and not have been recieving some sort of promotion within the last 5 years.

  1. Is there an association between leaving the company and salary?
contingency_table <- table(`HR_comma_sep(3)`$salary, `HR_comma_sep(3)`$left)


print(contingency_table)


chi_sq_result3 <- chisq.test(contingency_table)

print(chi_sq_result3)
  1. The P value is for a final time, extremely small and therefore indicates a strong correlation between one’s salary level and deciding to leave. While this falls short of demarcating which exact salary point, be it low, medium, or high is responsible. The low salary seems apparent, as a promotion within the last five years, moreso, lackthereof in the previous problem was a catalyst in employees leaving the company, making low salary have a high correlation with leaving the company.