Skip to content
Back to formatted view

Raw Message

Message-ID: <7822395.1164972342692.SLOX.WebMail.wwwrun@billa.wsr.ac.at>
Date: 2006-12-01T11:25:42Z
From: Serguei Kaniovski
Subject: A different contingency table of counts by case

Dear All,

the following code, by courtesy of Jacques VESLOT, collates the
following contingency table from DATA (read in as "df", sample listed
below)

"led" represents (court) cases,
"jid" the (justices) persons, and
"vote" is the binary state.

The command:

smat<-t(apply(combinations(nlevels(df$jid), 2), 1, function(x)
with(df[df$jid %in% levels(df$jid)[x],],
table(factor(unlist(sapply(split(vote, led), function(y)
ifelse(length(y) == 2, paste(y, collapse=""), NA))),
levels=c("00","01","10","11"))))))

collates a contingency table of number of cases any two persons

a. both have "1",
b. the first has "0" - the second has "1",
c. the first has "1" - the second has "0",
d. both have "0".

QUESTION: I would like to collate a table counting all possible
combinations of binary states, ie voting outcomes. Each "led" contains 9
"jid", so there will be 2^9=512 different possibilities. These are, in
the order of the decimals the vectors represent,
(1,1,1,1,1,1,1,1,1)
(1,1,1,1,1,1,1,1,0)
(1,1,1,1,1,1,1,0,1)
etc. until
(0,0,0,0,0,0,0,0,1)
(0,0,0,0,0,0,0,0,0)
What I need to know is how often each of the 512 outcomes occurs.

Thanks,
Serguei

DATA:
jid,led,vote
breyer;143/0154;0
ginsberg;143/0154;0
kennedy;143/0154;1
oconnor;143/0154;0
rehnquist;143/0154;0
scalia;143/0154;0
souter;143/0154;0
stevens;143/0154;0
thomas;143/0154;1
breyer;143/0171;1
ginsberg;143/0171;1
kennedy;143/0171;1
oconnor;143/0171;0
rehnquist;143/0171;0
scalia;143/0171;0
souter;143/0171;1
stevens;143/0171;1
thomas;143/0171;0
breyer;143/0238;1
ginsberg;143/0238;1
kennedy;143/0238;1
oconnor;143/0238;1
rehnquist;143/0238;1
scalia;143/0238;1
souter;143/0238;1
stevens;143/0238;1
thomas;143/0238;1
breyer;143/0258;1
ginsberg;143/0258;1
kennedy;143/0258;1
oconnor;143/0258;1
rehnquist;143/0258;1
scalia;143/0258;1
souter;143/0258;1
stevens;143/0258;1
thomas;143/0258;1
breyer;143/0270;0
ginsberg;143/0270;0
kennedy;143/0270;1
oconnor;143/0270;0
rehnquist;143/0270;1
scalia;143/0270;1
souter;143/0270;0
stevens;143/0270;0
thomas;143/0270;1
breyer;143/0311;0
ginsberg;143/0311;1
kennedy;143/0311;0
oconnor;143/0311;0
rehnquist;143/0311;0
scalia;143/0311;1
souter;143/0311;1
stevens;143/0311;1
thomas;143/0311;1
breyer;143/0388;1
ginsberg;143/0388;1
kennedy;143/0388;1
oconnor;143/0388;1
rehnquist;143/0388;1
scalia;143/0388;0
souter;143/0388;1
stevens;143/0388;0
thomas;143/0388;1
breyer;143/0399;1
ginsberg;143/0399;1
kennedy;143/0399;1
oconnor;143/0399;1
rehnquist;143/0399;1
scalia;143/0399;1
souter;143/0399;1
stevens;143/0399;1
thomas;143/0399;1
breyer;143/0408;1
ginsberg;143/0408;0
kennedy;143/0408;1
oconnor;143/0408;1
rehnquist;143/0408;1
scalia;143/0408;1
souter;143/0408;0
stevens;143/0408;0
thomas;143/0408;1