Re: [R] Chi-squared test when observed near expected
When you typed x as a command, R runs the command print(x). That function produces a summary of the results which may include round off numbers to a few decimal places to make them more readable. When you typed x$statistic, you got the unrounded version of the result 5.6e-31 which I think you will agree is pretty close to 0. -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Troy S Sent: Monday, December 03, 2012 3:41 PM To: r-help@r-project.org Subject: [R] Chi-squared test when observed near expected Dear UseRs, I'm running a chi-squared test where the expected matrix is the same as the observed, after rounding. R reports a X-squared of zero with a p value of one. I can justify this because any other result will deviate at least as much from the expected because what we observe is the expected, after rounding. But the formula for X-squared, sum (O-E)^2/E gives a positive value. What is the reason for X-Squared being zero in this case? Troy trial-as.table(matrix(c(26,16,13,7),ncol=2)) x-chisq.test(trial) x data: trial X-squared = 0, df = 1, p-value = 1 x$expected A B A 26.41935 12.580645 B 15.58065 7.419355 x$statistic X-squared 5.596653e-31 (x$observed-x$expected)^2/x$expected A B A 0.006656426 0.013978495 B 0.011286983 0.023702665 sum((x$observed-x$expected)^2/x$expected) [1] 0.05562457 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Chi-squared test when observed near expected
Dear UseRs, I'm running a chi-squared test where the expected matrix is the same as the observed, after rounding. R reports a X-squared of zero with a p value of one. I can justify this because any other result will deviate at least as much from the expected because what we observe is the expected, after rounding. But the formula for X-squared, sum (O-E)^2/E gives a positive value. What is the reason for X-Squared being zero in this case? Troy trial-as.table(matrix(c(26,16,13,7),ncol=2)) x-chisq.test(trial) x data: trial X-squared = 0, df = 1, p-value = 1 x$expected A B A 26.41935 12.580645 B 15.58065 7.419355 x$statistic X-squared 5.596653e-31 (x$observed-x$expected)^2/x$expected A B A 0.006656426 0.013978495 B 0.011286983 0.023702665 sum((x$observed-x$expected)^2/x$expected) [1] 0.05562457 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Chi-squared test when observed near expected
sum((x$observed-x$expected)^2/x$expected) [1] 0.05562457 Read about Yate's continuity correction - your formula does not use it and chisq.test does unless you suppress it: chisq.test(trial) Pearson's Chi-squared test with Yates' continuity correction data: trial X-squared = 0, df = 1, p-value = 1 chisq.test(trial, correct=FALSE) Pearson's Chi-squared test data: trial X-squared = 0.0556, df = 1, p-value = 0.8136 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Troy S Sent: Monday, December 03, 2012 1:41 PM To: r-help@r-project.org Subject: [R] Chi-squared test when observed near expected Dear UseRs, I'm running a chi-squared test where the expected matrix is the same as the observed, after rounding. R reports a X-squared of zero with a p value of one. I can justify this because any other result will deviate at least as much from the expected because what we observe is the expected, after rounding. But the formula for X-squared, sum (O-E)^2/E gives a positive value. What is the reason for X-Squared being zero in this case? Troy trial-as.table(matrix(c(26,16,13,7),ncol=2)) x-chisq.test(trial) x data: trial X-squared = 0, df = 1, p-value = 1 x$expected A B A 26.41935 12.580645 B 15.58065 7.419355 x$statistic X-squared 5.596653e-31 (x$observed-x$expected)^2/x$expected A B A 0.006656426 0.013978495 B 0.011286983 0.023702665 sum((x$observed-x$expected)^2/x$expected) [1] 0.05562457 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Chi-squared test when observed near expected
On 03-Dec-2012 21:40:35 Troy S wrote: Dear UseRs, I'm running a chi-squared test where the expected matrix is the same as the observed, after rounding. R reports a X-squared of zero with a p value of one. I can justify this because any other result will deviate at least as much from the expected because what we observe is the expected, after rounding. But the formula for X-squared, sum (O-E)^2/E gives a positive value. What is the reason for X-Squared being zero in this case? Troy trial-as.table(matrix(c(26,16,13,7),ncol=2)) x-chisq.test(trial) x data: trial X-squared = 0, df = 1, p-value = 1 x$expected A B A 26.41935 12.580645 B 15.58065 7.419355 x$statistic X-squared 5.596653e-31 (x$observed-x$expected)^2/x$expected A B A 0.006656426 0.013978495 B 0.011286983 0.023702665 sum((x$observed-x$expected)^2/x$expected) [1] 0.05562457 The reason is that (by default, see ?chisq.test ) the statistic is caluclated using the continuity correction (1/2 is subtracted from each abs(O-E) difference). The default setting in chisq.test() is correct = TRUE. Try it with correct = FALSE: x0-chisq.test(trial,correct=FALSE) x0 # Pearson's Chi-squared test # data: trial # X-squared = 0.0556, df = 1, p-value = 0.8136 which agrees with your calculation of sum((x$observed-x$expected)^2/x$expected) # [1] 0.05562457 Hoping this helps, Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 03-Dec-2012 Time: 22:44:14 This message was sent by XFMail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Chi-squared test when observed near expected
On Dec 3, 2012, at 1:40 PM, Troy S wrote: Dear UseRs, I'm running a chi-squared test where the expected matrix is the same as the observed, after rounding. ... after rounding you say? R reports a X-squared of zero with a p value of one. I can justify this because any other result will deviate at least as much from the expected because what we observe is the expected, after rounding. But the formula for X-squared, sum (O-E)^2/E gives a positive value. If O==E that sum would be identically 0 if the conditions stated held ... which they do NOT for the case below. What is the reason for X-Squared being zero in this case? Troy trial-as.table(matrix(c(26,16,13,7),ncol=2)) x-chisq.test(trial) x data: trial X-squared = 0, df = 1, p-value = 1 x$expected A B A 26.41935 12.580645 B 15.58065 7.419355 x$statistic X-squared 5.596653e-31 (x$observed-x$expected)^2/x$expected A B A 0.006656426 0.013978495 B 0.011286983 0.023702665 sum((x$observed-x$expected)^2/x$expected) [1] 0.05562457 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.