Rep=c(34,31,19,23) Dem=c(61,19,23,39) Ind=c(16,17,16,12) CLG <- matrix(c(Rep,Dem,Ind),ncol=3) CLG fit <- chisq.test(CLG,correct=FALSE) fit fit$expected fit$residual