library(MASS)
#Then use the chisq.test() function to carry out the test

# can more succinctly input frequencies instead of raw data

sex <- rep(1:2, c(293,182))
region <- c(rep(1,199),rep(2,27),rep(3,67),rep(1,134),rep(2,25),rep(3,23))
result <- chisq.test(table(sex,region))

# see where difference is
result$expected
result$observed
z <- (result$observed-result$expected)/sqrt(result$expected)
pout <- 2*pnorm(-abs(z),0,1)
chisq.test(table(sex,region))$stdres

# if any expected counts less than 5 user Fisher's test
fisher.test(table(sex,region))

X <- cbind(c(19,2), c(10,9))
mcnemar.test(X, correct=TRUE)
# check entered 2x2 table correctly
X 
#install.packages("fmsb")
library(fmsb)
Kappa.test(X,y=NULL, conf.level=0.95)

region2 <- c(rep(0,100),rep(1,193),rep(0,82),rep(1,100))
glm(region2 ~ sex, family=binomial)
exp(-0.459)
table(region2,sex)
(100*100)/(82*193)