[R] Pearson chi-square test
meyners.m at pg.com
Tue Sep 27 13:27:41 CEST 2011
Not sure what you want to test here with two matrices, but reading the manual helps here as well:
y a vector; ignored if x is a matrix.
x and y are matrices in your example, so it comes as no surprise that you get different results. On top of that, your manual calculation is not correct if you want to test whether two samples come from the same distribution (so don't be surprised if R still gives a different value...).
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Michael Haenlein
> Sent: Tuesday, September 27, 2011 12:45
> To: r-help at r-project.org
> Subject: [R] Pearson chi-square test
> Dear all,
> I have some trouble understanding the chisq.test function.
> Take the following example:
> A <- cut(runif(100),c(0.0, 0.35, 0.50, 0.65, 1.00), labels=FALSE)
> B <- cut(runif(100),c(0.0, 0.25, 0.40, 0.75, 1.00), labels=FALSE)
> C <- cut(runif(100),c(0.0, 0.25, 0.50, 0.80, 1.00), labels=FALSE)
> x <- table(A,B)
> y <- table(A,C)
> When I calculate the test statistic by hand I get a value of
> But when I do chisq.test(x,y) I get a value of 12.2 while
> gives a value of 10.3.
> I understand that I must be doing something wrong here, but I'm not
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help