observed_matrix <- matrix(c(70,15,10,65,22,13), nrow = 3, ncol = 2)
rownames(observed_matrix) <- c("A", "B", "C")
colnames(observed_matrix) <- c("2023", "2024")
print(observed_matrix)
## 2023 2024
## A 70 65
## B 15 22
## C 10 13
expected_matrix <- matrix(c(65.77,18.03,11.21,69.23,18.97,11.79), nrow = 3, ncol = 2)
rownames(expected_matrix) <- c("A", "B", "C")
colnames(expected_matrix) <- c("2023", "2024")
print(expected_matrix)
## 2023 2024
## A 65.77 69.23
## B 18.03 18.97
## C 11.21 11.79
chi_squared_matrix <- ((observed_matrix - expected_matrix)^2) / expected_matrix
chi_squared_value <- sum(chi_squared_matrix)
print(chi_squared_matrix)
## 2023 2024
## A 0.2720526 0.2584559
## B 0.5092013 0.4839694
## C 0.1306066 0.1241815
print(chi_squared_value)
## [1] 1.778467