How do I calculate p-values for Goodman and Kruskal's lambda and/or tau tests for association between categorical variables (measure improvement in predictability of the dependent variable given the value of the independent one based on modal probabilities [lambda] or marginal/conditional proportions [tau])? I know SPSS can do it, but I use R instead.
1 Answer
Let's create a synthesis data for illustration:
A <- sample(c("A1", "A2", "A3"), size=1000, replace = TRUE)
B <- sample(c("B1", "B2", "B3", "B4"), size=1000, replace = TRUE)
table(A, B)
Then this is the table of A and B
B
A B1 B2 B3 B4
A1 79 86 90 87
A2 76 89 79 93
A3 70 92 84 75
Now, you can get the p-value of the Goodman and Kruskal's lambda test
library(MESS)
gkgamma_test <- gkgamma(table(A, B))
gkgamma_test
This is what you will get:
Goodman-Kruskal's gamma for ordinal
categorical data
data: table(A, B)
Z = -0.35154, p-value = 0.7252
95 percent confidence interval:
-0.08784091 0.06112170
sample estimates:
Goodman-Kruskal's gamma
-0.0133596
You can also take only the p-value by using
gkgamma_test$p.value
then you will only have
[1] 0.7251808
NOTE: when using the gkgamma
test like above, we assume that A and A are ordinal categorial.
In case A and B are nomials, use:
library(DescTools)
Lambda(table(A, B))
and the value for λ is (The value λ lies between 0 and 1; values close to 1 correspond to a strong association.)
[1] 0.01437815
Read more about the two comments from https://search.r-project.org/CRAN/refmans/DescTools/html/Lambda.html
https://www.rdocumentation.org/packages/vcdExtra/versions/0.7-6/topics/GKgamma
chisq.test()
,fisher.test()
,wilcox.test()
orgkgamma()
(the latter from the MESS package) returnhtest
-type objects that include p-values, confidence intervals, degrees of freedom, parameters, intermediate stats, etc. I've been trying to find an equivalent for Goodman & Kruskal's lambda and/or tau, but so far I haven't. For instance, DescTools and GoodmanKruskal return only coefficients, no intervals or p-vals. $\endgroup$