[R] R help contingency table

Lucie Dupond loupiote93 at hotmail.fr
Tue Jun 21 01:18:33 CEST 2016


Thank you for your answer !

I'm sorry, i've made a mistake in the second matrix, they should have the same row/column labels, I just used another label vector by mistake.

My supervisor doesn't have a solution for this, and neither have every one I asked around me.

Thanks for your solution, but I'm afraid that I will loose the interaction between the variable "first color" and "second color" if I convert the matrix into a vector.


Thank you for your help



________________________________
De : David L Carlson <dcarlson at tamu.edu>
Envoyé : lundi 20 juin 2016 21:06
À : Lucie Dupond; r-help at r-project.org
Objet : RE: R help contingency table

You should consult with your adviser or someone at your institution who has more experience in statistical analysis than you do. You want to compare the matrices, but the row/column labels are different so you may be comparing completely different categories.

Technically, you need to convert the two matrices into a single matrix. You can do that by converting each into a vector with the c() function. BUT this will compare High with High, Medium with Low, and Low with Stick which seems inadvisable.

> rbind(c(transitions1), c(transitions2))
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,]   51   12   37   17   21   15   27   13   60
[2,]   13    5   11    7   16    8    8   18   17
> chisq.test(rbind(c(transitions1), c(transitions2)))

        Pearson's Chi-squared test

data:  rbind(c(transitions1), c(transitions2))
X-squared = 22.411, df = 8, p-value = 0.004208

Warning message:
In chisq.test(rbind(c(transitions1), c(transitions2))) :
  Chi-squared approximation may be incorrect

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Lucie Dupond
Sent: Sunday, June 19, 2016 9:10 PM
To: r-help at r-project.org
Subject: [R] R help contingency table

Hello,
I'm sorry if my question is really basic, but I'm having some troubles with the statistics for my thesis, and especially the khi square test and contingency tables.

For what I understood, there are two "kinds" of khisquare test, that are quite similar :
- Homogeneity, when we have one variable and we want to compare it with a theorical distribution
- Independence test, when we have 2 variable and we want to see if they are linked

-- -

I'm working on color transitions, with 3 possible factors : ? High ? , ? Medium ? and ? Low ?
I want to know if an individual will go preferably from a color ? High ? to another color ? High ?, more than from a color ? High ? to a color ? Medium ? (for example)

I have this table :

trans1<-c(51,17,27,12,21,13,37,15,60)
transitions1<-matrix(trans1, nrow=3, ncol=3, byrow=T)
rownames(transitions1) <- c("High"," Medium", "Low")
colnames(transitions1) <- c("High"," Medium", "Low")

The first colomn is showing the first color, and the second is showing the second color of the transition

It looks like I'm in the case of an Independence test, in order to see if the variable "second color" is linked to the "first color".

So I'm making the test :

chisq.test(transitions1)


(If I understood well, the test on the matrix is the independence  test, and the test on the vector trans1 is the homogeneity test ?)

The result is significatif, it means that some transitions are prefered.

My problem is that I have other transition tables like this one (with other individuals or other conditions)
For example, I also have this one :


trans2<-c(13,7,8,5,16,18,11,8,17)
transitions2<-matrix(trans2, nrow=3, ncol=3, byrow=T)
rownames(transitions2) <- c("High","Low", "Stick")
colnames(transitions2) <- c("High","Low", "Stick")

I want to know if the "prefered" transitions in the table 1 are the same in the table 2.
But if I try a khisquare test on those two matrix, R only takes the first one.

How can I compare those tables
Maybe with another test ?

Thanks in advance !

Kind regards

Lucie S.

        [[alternative HTML version deleted]]


	[[alternative HTML version deleted]]



More information about the R-help mailing list