r:chi-square_test:code03
# or the below works also chisq <- chisq.test(df$treatment, df$improvement, correct=F) chisq o <- chisq$observed e <- chisq$expected o round(e,2) r <- (e-o)/sqrt(e) # this is called residuals round(r, 3) round(chisq$residuals, 3) cs.tmp <- sum(chisq$residuals^2) cs.tmp cs.cal <- sum((e-o)^2/e) pchisq(cs.cal, 1,lower.tail = F) cs.cal chisq library(corrplot) corrplot(chisq$residuals, is.cor = FALSE) contrib <- 100*chisq$residuals^2/chisq$statistic round(contrib, 3) # Visualize the contribution corrplot(contrib, is.cor = FALSE)
r/chi-square_test/code03.txt · Last modified: by hkimscil
