[R] Create 2x2 table from summary data and run chi square test.

John Sorkin JSorkin at grecc.umaryland.edu
Fri Apr 22 20:37:57 CEST 2011


R 2.12
windows 7

I am summary data that I would like to make into a 2x2 table representing counts positive vs. negative counts:
28/289  20/276

My table should look something like the following:

          group1 group2
Positive    28     20
Negative   289     276

How can a (1) create the 2x2 table
          (2) run a chi square test on the table?

I have tried the following code, but I don't know if it is correct, and it does not give me an explicit 2x2 table:

> xx <- c(28,20)
> pp <- c(317/(317+296), 296/(317+296))
> chisq.test(xx,p=pp)

        Chi-squared test for given probabilities

data:  xx 
X-squared = 0.8425, df = 1, p-value = 0.3587


John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)

Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:6}}



More information about the R-help mailing list