2
$\begingroup$

My aim is to see if there exists a relation between the variables "Category" and "Types", spec. if there is a tendency for a particular category to use a particular type. These are the observed frequencies:

T1 T2 T3 T4 T5
A 800 1 9 245 2503
B 350 1560 1200 341 790
C 7 290 7 607 1
D 387 1001 1311 932 598
E 16 81 19 7 4
F 493 98 0 39 342
G 32 318 2 1 3
H 777 52 18 127 139
I 3 2 27 9 1
J 128 299 1 4 2
K 10 5 2 4 76
L 139 1 1 29 6

So I conducted a chi-square test. This is the code I used in R:

x <- matrix(c(800, 350, 7, 387, 16, 493, 32, 777, 
    3, 128, 10, 139, 10, 1560, 290, 1001, 81, 98, 
    318, 52, 4, 299, 15, 18, 19, 1200, 7, 1311, 
    19, 0, 2, 18, 27, 10, 2, 8, 245, 341, 607, 
    932, 7, 39, 10, 127, 9, 7, 8, 29, 2503, 790, 
    1, 598, 4, 342, 3, 139, 2, 3, 76, 6), ncol=5)

attr(x, "dimnames") <- list(Category=c("A", "B", 
    "C", "D", "E", "F", "G", "H", "I", "J", "K", 
    "L"), 
    Types = c("T1", "T2", "T3", "T4", "T5"))

x.test <- chisq.test(x, correct = FALSE)

x.test$expected

All the expected frequencies are > 5 and the result of the chi-square test is: X-squared = 13493, df = 44, p-value < 2.2e-16. I have also used Cramer's V to see how strong is the effect independently of the sample size (Cramer's V = 0.4543752).

I have also calculated Pearson and standardized residuals (It's not clear to me what should I use, if any) but the values are very large and I have read that this may indicate large errors, which may imply that the model can be inappropriate for the data.

These are the results of Pearson residuals:

enter image description here

And these are the results for standardized residuals:

enter image description here

Does it make any sense or would it be better to use another measure?

$\endgroup$

1 Answer 1

1
$\begingroup$

With such a large contingency table with large counts you are better off with visualizing methods, or simply reordering rows/columns of the table so that structure becomes more easily visible. The large chi-squared value, and large residuals makes it apparent that the independence model is untrue.

Correspondence analysis is your help. Some code in R, with your data:

mod.CA <- MASS::corresp(x, nf=2)
plot(mod.CA)   ### A biplot (not shown here)

I will use the row and column scores corresponding to the largest eigenvalue to reorder rows and columns, then the structure will be more visible:

RS <- mod.CA$rscore[, 1]
CS <- mod.CA$cscore[, 1]

X <- x[order(RS), order(CS)]

X
        Types
Category   T5  T1  T4   T3   T2
       A 2503 800 245   19   10
       F  342 493  39    0   98
       H  139 777 127   18   52
       K   76  10   8    2   15
       L    6 139  29    8   18
       B  790 350 341 1200 1560
       J    3 128   7   10  299
       D  598 387 932 1311 1001
       E    4  16   7   19   81
       I    2   3   9   27    4
       C    1   7 607    7  290
       G    3  32  10    2  318

We can also show the table as a mosaicplot:

mosaicplot(X, color=TRUE)

Mosaicplot of table

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.