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

Jacques VESLOT jacques.veslot at cirad.fr
Fri Feb 17 10:14:41 CET 2006


library(gtools)
index <- cbind(combinations(7,2),8)
lapply(as.data.frame(t(index)), function(x) 
mantelhaen.test(table(mydata[,x])))


Taka Matzmoto a écrit :

>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
>
>______________________________________________
>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