#某一矩阵
data<-matrix( c(46,38,50,87),nrow=2, byrow=FALSE)
#卡方检验function
chisq <- function(Obs){
Expected<- outer(rowSums(Obs), colSums(Obs)/sum(Obs))
sum((Obs-Expected)^2/Expected)
}
chisq(data)
1-pchisq(chisq(data),1) #p检验
#r自带 卡方检验
chisq.test(data)
chisq.test(data,correct=FALSE)