R index between two products is somewhat dependent on other products

March 12, 2012

(This article was first published on Wiekvoet, and kindly contributed to R-bloggers)

I explained earlier how R-index is used in sensory is used to examine ranking data. The legitimization to use R-index is in the link with d’ and with Mann-Whitney statistic. In this post I show there is a dependence on the number of products and position of other products on the R index. It is a small effect. However, if data is analyzed by looking only and rigidly at the p value, then the result might chance from just under significant to just over significance.

Using simulations, I will show that presence of other samples influences the R-index. I think this effect occurs because the R index is, mathematically, calculated from an aggregated matrix of counts of product against ranks. It is my feeling, that when there are more products, there are less chances to get equal rankings than with few products and hence slightly different scores.
R index calculation
Below the calculation when comparing 2 products from a total of 4
R index calculation matrix
               rank 1 rank 2 rank 3 rank 4
    product 1       a      b      c      d
    product 2       e      f      g      h
          Note a to h are the counts in the respective cells. 
The R index is composed of three parts:
1 The number of wins of product 1 over product 2:
   a*(f+g+h) + b*(g+h) + c*h
2 The number of equal rankings divided by two 
   (a*e + b*f + c*g + d*h) /2
3  Normalization 
R index = 100* wins*equal normalization
Effect of number of products
Figure 1 shows the simulation R index dependence on the number of products, using a ranking with 25 panelists. With a low number of products, the distribution of the R index is a bit wider than with more products. Most of the difference in distribution is in the region 3 to 6 products, which is also the number of products often used in sensory.
(Critical values of R-indices are given by the red and blue lines (Bi and O’Mahony 1995 respectively 2007, Journal of Sensory Studies))

Effect of neighborhood of other products
Figure 2 shows the dependence on location of the other products. I have chosen 5 products, two have the same location. The other 3 move away from this location. Again 25 panelists. In this figure it shows that the two products R-index has a smaller distribution under H0 (no product differences) when all products are similar. This is about the same as the 5 products in the first plot. When the other products are far away, the distribution becomes wider, getting closer to the 3 product distribution in figure 1.

It should be written that with one product rather than three products moving away from the centre location the effect is smaller. Effect of number of panelists is for a next post.
Code for figure 1:


makeRanksNoDiff <- function(nprod,nrep) {
  inList <- lapply(1:nrep,function(x) sample(1:nprod,nprod)   )

tab2Rindex <- function(t1,t2) {
  Rindex <- crossprod(rev(t1)[-1],cumsum(rev(t2[-1]))) + 0.5*crossprod(t1,t2)

FastAllRindex <- function(rankExperiment) {
  crst <- xtabs(~ prod + rank,data=rankExperiment)
  nprod <- nlevels(rankExperiment$prod)
  Rindices <- unlist(   lapply(1:(nprod-1),function(p1) {
            lapply((p1+1):nprod,function(p2) tab2Rindex(crst[p1,],crst[p2,])) }) )

nprod <- seq(3,25,by=1)
last <- lapply(nprod,function(xo) {
      nsamples <- ceiling(10000/xo)
      li <- lapply(1:nsamples,function(xi) {
            re <- makeRanksNoDiff(nprod=xo,nrep=25)
      li2 <- as.data.frame(do.call(rbind,li))
      li2$nprod <- xo
    } )   

last2 <- lapply(last,function(x) {
      qq <- quantile(as.matrix(x[,grep(‘nprod’,names(x),invert=TRUE)]) ,c(0.025,.5,.975))
      qq <- as.data.frame(t(qq))
      qq$nprod <- x$nprod[1]
    }   )

summy <- do.call(rbind,last2)
g1 <- ggplot(summy,aes(nprod,`50%`) )
g1 <- g1+ geom_errorbar(aes(ymax = `97.5%`, ymin=`2.5%`))
g1 <- g1 + scale_y_continuous(name=’R-index’ )
g1 <- g1 + scale_x_continuous(name=’Number of products to compare’)
g1 <- g1 + geom_hline(yintercept=50 + 18.57*c(-1,1),colour=’red’)
g1 <- g1 + geom_hline(yintercept=50 + 15.21*c(-1,1),colour=’blue’)


Additional code for figure 2
makeRanksDiff <- function(prods,nrep) {
  nprod <- length(prods)
  inList <- lapply(1:nrep,function(x)  rank(rnorm(n=nprod,mean=prods)))

location <- seq(0,3,by=.25)
last <- lapply(location,function(xo) {
      li <- sapply(1:10000,function(xi) {
            re <- makeRanksDiff(prod=c(0,0,xo,xo,xo),nrep=25)
            crst <- xtabs(~ prod + rank,data=re)
      li2 <- data.frame(location=xo,Rindex=li)
    } )

last2 <- lapply(last,function(x) {
      qq <- quantile( x$Rindex,c(0.025,.5,.975))
      qq <- as.data.frame(t(qq))
      qq$location <- x$location[1]
    }   )

summy <- do.call(rbind,last2)
g1 <- ggplot(summy,aes(location,`50%`) )
g1 <- g1+ geom_errorbar(aes(ymax = `97.5%`, ymin=`2.5%`))
g1 <- g1 + scale_y_continuous(name=’R-index between equal products’ )
g1 <- g1 + scale_x_continuous(name=’Location of odd products’)
g1 <- g1 + geom_hline(yintercept=50 + 18.57*c(-1,1),colour=’red’)
g1 <- g1 + geom_hline(yintercept=50 + 15.21*c(-1,1),colour=’blue’)


To leave a comment for the author, please follow the link and comment on their blog: Wiekvoet.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)