##The Chi-Square test yielded a p-value of <2.2e-16. Since this p-value is significantly less than the stricter significance level of 0.01 (p < 0.01), we reject the null hypothesis. This confirms a highly significant statistical dependence between salary level and employee attrition, indicating the relationship is not due to random chance.

# Create plot
plot_ly(prop_salary) %>%
  add_bars(x = ~salary, y = ~Stayed, name = "Stayed", 
           marker = list(color = "#2ca02c")) %>%
  add_bars(x = ~salary, y = ~Left, name = "Left", 
           marker = list(color = "#d62728")) %>%
  layout(
    barmode = "stack",
    xaxis = list(title = "Salary Level"),
    yaxis = list(title = "Proportion", tickformat = ",.0%"),
    title = "Employees with low salaries are significantly more likely to leave"
  )

##The test resulted in a p-value of < 2.2e-16. Because this p-value is well below the 0.01 threshold, we reject the null hypothesis of independence. This confirms that the relationship between the department and attrition is statistically significant at the 99% confidence level.

# Create plot with Green/Red styling
plot_ly(prop_dept) %>%
  add_bars(x = ~Department, y = ~Stayed, name = "Stayed", 
           marker = list(color = "#2ca02c")) %>%   # Green
  add_bars(x = ~Department, y = ~Left, name = "Left", 
           marker = list(color = "#d62728")) %>%   # Red
  layout(
    barmode = "stack",
    xaxis = list(title = "Department"),
    yaxis = list(title = "Proportion", tickformat = ",.0%"),
    title = "Turnover rates vary by department (HR and Accounting show higher risk)"
  )

##The Chi-Square test produced a p-value of < 2.2e-16. As this is less than the alpha of 0.01, we reject the null hypothesis. Statistically, this indicates that the lack of independence between promotion history and attrition is robust and significant, even under this stricter testing standard.

# 2. Visualization

# Create plot with Green/Red styling
plot_ly(prop_promo) %>%
  add_bars(x = ~promo_label, y = ~Stayed, name = "Stayed", 
           marker = list(color = "#2ca02c")) %>%   # Green
  add_bars(x = ~promo_label, y = ~Left, name = "Left", 
           marker = list(color = "#d62728")) %>%   # Red
  layout(
    barmode = "stack",
    xaxis = list(title = "Promotion History (Last 5 Years)"),
    yaxis = list(title = "Proportion", tickformat = ",.0%"),
    title = "Employees who are not promoted are most likely to leave"
  )