Tsunhin John Wong
2010-Jul-21 12:07 UTC
[R] Contingency Table Analysis - specific cell to specific cell comparisons
Dear R users, I have a question of how to do some specific cell to cell comparisons on a R x C contingency table. The table is a 3 x 5 table with frequency / count data.> langcons.table <- table(lang, cons) > langcons.table[cbind(lang,cons)] <- freq > langcons.tableAdj Int Oth Pas Tra C 69 221 17 3 198 E 56 214 33 31 174 J 36 291 8 9 164 I know how to do an independent model test using Poisson in glm> glm.out1 <- glm(freq~lang+cons, family=poisson, data=langcons.data) > summary(glm.out1)And then fit the saturated model> glm.out2 <- glm(freq~lang*cons, family=poisson, data=langcons.data) > summary(glm.out2)However, the results are difficult to interpret: C and Adj are used to as a baseline. And I can only see main effects and interactions and *always according to the baseline*. Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) lang1 lang2 cons1 cons2 cons3 cons4 lang1:cons1 lang2:cons1 lang1:cons2 lang2:cons2 lang1:cons3 lang2:cons3 lang1:cons4 lang2:cons4 If anyone know, please suggest me some way to do specific cell to cell comparison on such a contingency table. Say, to compare pairs of cells: along a column: 3 vs 31, 9 vs 31, 3 vs 9 along a row: 36 vs 9 or even across column and row: 36 vs 31, and 36 vs 3 Thanks for your help in advance. Best, John
David Winsemius
2010-Jul-21 12:24 UTC
[R] Contingency Table Analysis - specific cell to specific cell comparisons
On Jul 21, 2010, at 8:07 AM, Tsunhin John Wong wrote:> Dear R users, > > I have a question of how to do some specific cell to cell comparisons > on a R x C contingency table. > The table is a 3 x 5 table with frequency / count data. > >> langcons.table <- table(lang, cons) >> langcons.table[cbind(lang,cons)] <- freq >> langcons.table > > Adj Int Oth Pas Tra > C 69 221 17 3 198 > E 56 214 33 31 174 > J 36 291 8 9 164 > > I know how to do an independent model test using Poisson in glm >> glm.out1 <- glm(freq~lang+cons, family=poisson, data=langcons.data) >> summary(glm.out1) > > And then fit the saturated model >> glm.out2 <- glm(freq~lang*cons, family=poisson, data=langcons.data) >> summary(glm.out2) > > However, the results are difficult to interpret: > C and Adj are used to as a baseline. > And I can only see main effects and interactions and *always according > to the baseline*. > Coefficients: > Estimate Std. Error z value Pr(>|z|) > (Intercept) > lang1 > lang2 > cons1 > cons2 > cons3 > cons4 > lang1:cons1 > lang2:cons1 > lang1:cons2 > lang2:cons2 > lang1:cons3 > lang2:cons3 > lang1:cons4 > lang2:cons4 > > If anyone know, please suggest me some way to do specific cell to cell > comparison on such a contingency table.Even if you are daunted by the task of plugging the covariates into the formula, exp(intercept+sum(beta_N*var_n)), you can always use the predict function to create an estimate for all (or a specific set) of the covariates. They come out on the log(rate) scale so would need to be exponentiated. Consult your instructor for further help.> Say, to compare pairs of cells: > along a column: 3 vs 31, 9 vs 31, 3 vs 9 > along a row: 36 vs 9 > or even across column and row: 36 vs 31, and 36 vs 3David Winsemius, MD West Hartford, CT
Michael Friendly
2010-Jul-22 12:50 UTC
[R] Contingency Table Analysis - specific cell to specific cell comparisons
If you want to *see* the contributions of the cells to the association between lang and cons, try library(vcd) mosaic(~lang+cons, data=langcons.table, shade=TRUE) Tsunhin John Wong wrote:> Dear R users, > > I have a question of how to do some specific cell to cell comparisons > on a R x C contingency table. > The table is a 3 x 5 table with frequency / count data. > >> langcons.table <- table(lang, cons) >> langcons.table[cbind(lang,cons)] <- freq >> langcons.table > > Adj Int Oth Pas Tra > C 69 221 17 3 198 > E 56 214 33 31 174 > J 36 291 8 9 164 > > I know how to do an independent model test using Poisson in glm >> glm.out1 <- glm(freq~lang+cons, family=poisson, data=langcons.data) >> summary(glm.out1) > > And then fit the saturated model >> glm.out2 <- glm(freq~lang*cons, family=poisson, data=langcons.data) >> summary(glm.out2) > > However, the results are difficult to interpret: > C and Adj are used to as a baseline. > And I can only see main effects and interactions and *always according > to the baseline*. > Coefficients: > Estimate Std. Error z value Pr(>|z|) > (Intercept) > lang1 > lang2 > cons1 > cons2 > cons3 > cons4 > lang1:cons1 > lang2:cons1 > lang1:cons2 > lang2:cons2 > lang1:cons3 > lang2:cons3 > lang1:cons4 > lang2:cons4 > > If anyone know, please suggest me some way to do specific cell to cell > comparison on such a contingency table. > Say, to compare pairs of cells: > along a column: 3 vs 31, 9 vs 31, 3 vs 9 > along a row: 36 vs 9 > or even across column and row: 36 vs 31, and 36 vs 3 > > Thanks for your help in advance. > > Best, > > John >-- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA