Re: [R] Comparing proportions between groups

From: Chuck Cleland <ccleland_at_optonline.net>
Date: Fri, 28 Mar 2008 05:47:36 -0400

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

______________________________________________
R-help_at_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.
Received on Fri 28 Mar 2008 - 09:57:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 28 Mar 2008 - 10:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive