In [1]:
# install.packages("comprehenr")
library(comprehenr)
Oij = matrix(c(95,40,80,25,65,50,40,5), ncol=2)
m1 = sum(Oij[,1]); m2 = sum(Oij[,2])
D = rbind(Oij, c(m1, m2)); D
C = to_vec(for(i in 1:5) sum(D[i,])); C
D = cbind(D, C); D
dimnames(D) = list(c("30대", "40대", "50대", "60대", "합계"), 
	c("흡연", "비흡연", "합계")); D
A matrix: 5 × 2 of type dbl
95 65
40 50
80 40
25 5
240160
  1. 160
  2. 90
  3. 120
  4. 30
  5. 400
A matrix: 5 × 3 of type dbl
C
95 65160
40 50 90
80 40120
25 5 30
240160400
A matrix: 5 × 3 of type dbl
흡연비흡연합계
30대 95 65160
40대 40 50 90
50대 80 40120
60대 25 5 30
합계240160400
In [2]:
n = sum(Oij)
ni = as.vector(D[1:4,3]); ni
mj = as.vector(D[5,1:2]); mj

#
# 이 부분에 코드를 써 넣는다.
#

cat(sprintf("chi.val = %.2f, chi.cv = %.2f\n", chi.val, chi.cv))
cat(sprintf("chi.val > chi.cv : %s\n", ans <- chi.val > chi.cv))
if(ans) {
	cat("H0 rejected\n")
} else {
	cat("H0 not rejected\n")
}
  1. 160
  2. 90
  3. 120
  4. 30
  1. 240
  2. 160
chi.val = 18.13, chi.cv = 7.81
chi.val > chi.cv : TRUE
H0 rejected