R独立性的卡方检验结果的残差分析

时间:2018-10-05 01:06:17

标签: r chi-squared

如何根据图片中R的独立性卡方检验的结果进行残差分析?

## From Agresti(2007) p.39
M <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
dimnames(M) <- list(gender = c("F", "M"),
                    party = c("Democrat","Independent", "Republican"))
(Xsq <- chisq.test(M))  # Prints test summary\

enter image description here

2 个答案:

答案 0 :(得分:0)

您可以在chsq$stdres下访问标准化残差,其中chsqchisq.test返回对象。

要使用?chisq.test

中的示例
M <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
dimnames(M) <- list(
    gender = c("F", "M"),
    party = c("Democrat","Independent", "Republican"))

chsq <- chisq.test(M)

chsq$stdres
#      party
#gender   Democrat Independent Republican
#     F  4.5020535   0.6994517 -5.3159455
#     M -4.5020535  -0.6994517  5.3159455

答案 1 :(得分:-1)

我找到了答案:

df <- as.data.frame(M)
df

library(gmodels)

x <- CrossTable(df$gender, 
           df$party, 

           chisq=T, 
           expected=T, 
           asresid=T, 
           format="SPSS", 
           prop.t=F, 
           prop.chisq=F, 
           prop.r=F, 
           prop.c=F, 
           digits=2)

enter image description here