options(scipen=999)
options(digits=9)
cat("\014") # clear screen
rm(list=ls(all=TRUE))


row1=c(26,30,6,5)
row2=c(21,30,11,7)
row3=c(25,25,45,9)
row4=c(11,32,17,11)
obs=rbind(row1,row2,row3,row4)
chisq.test(obs,correct = FALSE)



row1=c(26,30,6,5)
row2=c(21,30,11,7)
row3=c(25,25,45,9)
row4=c(11,32,17,11)
obs=rbind(row1,row2,row3,row4)
M <- as.table(obs)
dimnames(M) <- list(Age = c("<20","20-29","30-39",">=40"),
                    Effect = c("0","1-2","3-4",">4"))
Xsq <- chisq.test(M,correct = FALSE)  # Prints test summary
Xsq
Xsq$observed  # observed counts (same as M)
Xsq$expected  # expected counts under the null
