Skip to content
Prev 361883 / 398506 Next

R help contingency table

Hi Lucie,
You can visualize this using the sizetree function (plotrix). You
supply a data frame of the individual choice sequences.

# form a data frame of "random" choices
coltrans<-data.frame(choice1=sample(c("High","Medium","Low"),100,TRUE),
 choice2=sample(c("High","Medium","Low"),100,TRUE))
sizetree(coltrans,main="Random color choice transitions")
# test the two way table of transitions for independence
chisq.test(table(coltrans))
# now try a data frame of "habitual" choices
coltrans2<-data.frame(choice1=rep(c("High","Medium","Low"),c(33,33,34)),
 choice2=c(sample(c("High","Medium","Low"),33,TRUE,prob=c(0.6,0.2,0.2)),
 sample(c("High","Medium","Low"),33,TRUE,prob=c(0.2,0.6,0.2)),
 sample(c("High","Medium","Low"),34,TRUE,prob=c(0.2,0.2,0.6))))
sizetree(coltrans2,main="Habitual color choice transitions")
# test the table again
chisq.test(table(coltrans2))

This may be what you want.

Jim
On Mon, Jun 20, 2016 at 12:09 PM, Lucie Dupond <loupiote93 at hotmail.fr> wrote:
Message-ID: <CA+8X3fUpo2hbCLPNCCxmRrPivKF5GnS1MXrukOYvMZYLNjL0Fw@mail.gmail.com>
In-Reply-To: <DB5PR03MB147949B7C7EF9A538867A0A7A12A0@DB5PR03MB1479.eurprd03.prod.outlook.com>