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.
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.
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)