[R] creating 3-way tables for mantelhaen.test

Taka Matzmoto sell_mirage_ne at hotmail.com
Fri Feb 17 09:53:32 CET 2006


Hi R users
I have serveral binary variables (e.g., X1, X2, X3, X4, X5, X,6, and X7) and 
one continuous variable (e.g., Y1).

I combined these variables using data.frame()

mydata <- data.frame(X1,X2,X3,X4,X5,X6,X7,Y1)

after that, I sorted this data.frame

rank.by.Y1<-order(mydata[,8])
sorted.mydata<-mydata[rank.by.Y1,]

after that, I replaced Y1's values with values ranging from 1 to 10 ( 1 
represents the lowest group on Y1 and 10 presents the hight group on Y1). 
Now Y1 becomes a grouping variable.

What I like to do is to apply mantelhaen.test for each binary variable pair 
(e.g, X1 and X2, X1 and X3, X1 and X4, .... , X6 and X7)

In order to apply mantelhaen.test, a 3-dimensional contingency table is 
required.

Could you provide some advice on how to create a 3-dimensional contingency 
table (first dimension represents the first variable of  variable pair, 
second dimension the second variable of  variable  pair, and third dimension 
represents 1 to 10 ) and apply mantelhaen.test ?

I looked at arrary, xtabs, table commands but I couldn't figure out yet.

Thank you




More information about the R-help mailing list