Bug 15842 - quade.test reports other results for reordered data frames
Summary: quade.test reports other results for reordered data frames
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Analyses (show other bugs)
Version: R 3.0.3
Hardware: x86_64/x64/amd64 (64-bit) Windows 64-bit
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2014-06-26 14:09 UTC by L Kahl
Modified: 2014-06-26 14:09 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description L Kahl 2014-06-26 14:09:09 UTC
Data to quade.test() can be passed in a matrix or a data frame. If the the lines in the data frame are reordered the quade.test() has a different result.

Comparing this behavior with the freidman.test(), the friedman.test() is invariant to reordered data frames. I can only speculate if this is connected to the lines from source code of friedman.test() that seem to lack in the quade.test() code:

## Need to ensure consistent order of observations within
## blocks.
o <- order(groups, blocks)
y <- y[o]
groups <- groups[o]
blocks <- blocks[o]




The following example code invokes quade.test() with a data frame, a reordered data frame and matrices converted from both data frames. In case of the original data frame and both matrices it yields the same result. Only in case of the reordered data frame it shows a different result.
 	

## constructing a data frame with the same data as in the quade.test help	
Store <- c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5,6,6,6,6,6,7,7,7,7,7)
Brand <- c("A","B","C","D","E","A","B","C","D","E","A","B","C","D","E","A","B","C","D","E","A","B","C","D","E","A","B","C","D","E","A","B","C","D","E")
nsold <- c( 5,  4,  7, 10, 12, 1,  3,  1,  0,  2, 16, 12, 22, 22, 35, 5,  4,  3,  5,  4,	10,  9,  7, 13, 10,	19, 18, 28, 37, 58,	10,  7,  6,  8,  7)

df.example <- data.frame(Store, Brand, nsold)


# this data.frame can be converted to a matrix that is the same
# than the one from the help
matrix.example <- xtabs(nsold~Store+Brand,data=df.example)

# as expected this yields the same result 
quade.test(matrix.example)


# using the interface with formula and data frame yields also the same result
quade.test(nsold~Brand|Store,data=df.example)



# now the rows in the data frame are put in another order
df.reorder <-df.example[with(df.example, order(nsold)), ]



# again this reordered data frame can be converted to a matrix 
matrix.from.reordered <- xtabs(nsold~Store+Brand,data=df.reorder)

# the matrix is identical to the first matrix
# (only some attributes are different and are deleted first)
attr(matrix.example, "class") <- NULL
attr(matrix.example, "call") <- NULL
attr(matrix.from.reordered, "class") <- NULL
attr(matrix.from.reordered, "call") <- NULL
identical(matrix.from.reordered,matrix.example)

# it therefore yields the same result
quade.test(matrix.from.reordered)


# using quade.test now with the reordered data frame it shows a 
# different result
quade.test(nsold~Brand|Store,data=df.reorder)


# the expected behavior would be that quade.test is invariant 
# to a different order of the rows and show the same result as 
# in the first three cases






# with the similar friedman.test() the different order is no problem
# all 4 cases show the same result
friedman.test(matrix.example)
friedman.test(nsold~Brand|Store,data=df.example)
friedman.test(matrix.from.reordered)
friedman.test(nsold~Brand|Store,data=df.reorder)