[R] Finding ties in data (be)for(e) BradleyTerry

Paul Lemmens paul.lemmens at gmail.com
Thu May 4 08:58:29 CEST 2006


Dear all,

I have carried out a pairwise comparison study that I want to analyze
using the BradleyTerry package to establish a rank order of my
stimuli. However, BT does not handle ties between stimuli, so I need
to find those in my data before I can use that model.

The code below goes from the format of my result file(s) to a data
frame suitable for BT, but as you can see, there are some ties. I need
to find the rows with identical (but swapped) winner and loser and
with the same frequency. How can I accomplish that using the R-way
(not looping through the entire thing; in reality, I have approx 40
stimuli with around 180 observations of an odd 40 subjects)?


# $lp was left picture; $rp, right one; $wr was the winner/chosen one
by subject.
dat <- data.frame(subjno=gl(4,3),
  lp=factor(c(1,3,2,2,3,1,3,1,2,1,2,3), labels=c('a','b','c')),
  rp=factor(c(2,1,3,3,1,2,1,2,3,3,1,2), labels=c('a', 'b', 'c')),
  wr=factor(c(1,1,2,1,2,2,1,1,2,2,1,2), labels=c('lp', 'rp')))
dat.lp <- subset(dat, wr=='lp')
dat.rp <- subset(dat, wr=='rp')
names(dat.rp)[c(2,3)] <- c('loser', 'winner')
names(dat.lp)[c(2,3)] <- c('winner', 'loser')
(dat <- with(merge(dat.lp, dat.rp, all=TRUE), data.frame(table(winner,loser))))


Thank you for your help!




More information about the R-help mailing list