[R] Multiple sets of proportion tests

Allaisone 1 allaisone1 at hotmail.com
Fri Nov 24 12:09:00 CET 2017


Hi all ,


I have a dataframe  of 200 columns and 2 rows. The first row in each column contains the frequency of cases in group I . The second row in each column contains the frequency of cases in group II. The frequency of trails is a fixed value for group I(e.g.200) and it is also another fixed values for group II (e.g. 100). The dataset looks like this :-


> Mydata


                                      variable I      variable II    Variable III  ......... 200

Freq.of cases (gp I)      6493               9375               5524

Freq. of cases (gpII)     509                  462                 54



The result I need for the first column can be given using this code :


 MyResultsI <- prop.test(Mydata$variable I ,c(200,100))
for the second  column :-
MyResultsII <- prop.test(Mydata$variable II ,c(200,100))  and so on ..


I need to do the analysis for all columns and have only the columns with significant p-value results to be written in the the third row under each column so the final output has to be something like this :-


                                      variable I        Variable III  .........

Freq.of cases (gp I)      6493                   5524

Freq. of cases (gpII)     509                      54

p-values                          0.02               0.010

Note, for example, that the 2nd column has bee removed as it resulted in a non-significant p-value result while col 1 and col 3 were included since p-value is less than 0.05.

I'm not sure how to get the p-values only without other details but for the analysis itself , I believe it can be done with apply() function but its not clear to me how to specify the 2nd argument(n=samlpe sizes) in the prop.test.

 MyResults <- apply(Mydata, 2, function(x)prop.test(Mydata,c(200,100))

How can I modify the "n" argument part to solve the issue of non-equivalent length between "x" and "n" ?. How can I modify this further to return only significant p-values results ?. Any help would be very appreciated ..

Regards

	[[alternative HTML version deleted]]



More information about the R-help mailing list