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

Jacques VESLOT jacques.veslot at good.ibl.fr
Thu May 4 10:28:47 CEST 2006


z <-  apply(dat, 1, function(x) paste(sort(x), collapse=""))
zz <- outer(z,z,"==")
data.frame(first=col(zz)[lower.tri(zz)][zz[lower.tri(zz)]],second=row(zz)[lower.tri(zz)][zz[lower.tri(zz)]])

there should be a bettter solution...

-------------------------------------------------------------------
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
-------------------------------------------------------------------


Paul Lemmens a écrit :
> 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!
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list