Comparing proportions between groups
On 3/28/2008 5:33 AM, Lila86 wrote:
Hello there,
I have two groups (men and women) and I know per group how many of them
smoke or don't smoke (women 40 of 200; men 100 of 300). I would like to know
how I can compare in R if men and women differ significantly in their
smoking. However, because there are more men in the sample than women I
cannot just compare the number of smokers and non-smokers in both groups,
right?! (I would not really know how to do that either, to be honest :().
I have done this:
gensmoke <- table(data$gender,data$smoke) #save table
old.digits = options("digits") # store the number of digits
options(digits=3) # only print 3 decimal places
gensmokePROP = prop.table(gensmoke,1) #table of the proportions I'd like
to compare
smoker non-smoker
women 0.200 0.800
men 0.333 0.667
But then when I try to run a t-test on it, for example
t.test(gensmokePROP[3], gensmokePROP[4], alternative = "less")
then R tells me that there are not enough observations in x.
Could anyone help me? That would be really great. Thank you,
Lila
prop.test(x=c(40,100), n=c(200,300)) OR prop.test(matrix(c(40,100,160,200), ncol=2)) ?prop.test
Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894