[R] Chi square test on data frame

Bansal, Vikas vikas.bansal at kcl.ac.uk
Wed Aug 17 16:26:11 CEST 2011


Is there anyone who can help me with chi square test on data frame.I am struggling from last 2 days.I will be very  thankful to you.

Dear all,

I have been working on this problem from so many hours but did not find any solution.
I have a data frame with 8 columns-
       V1   V2       V3       V4      W1   W2        W3       W4
1     0    84       22       10       0      84          0          0
2    35    84        0        0     22      84          0          0
3     0     0          0      48       0       0            0         48
4     0    48        0        0       0      48           0          0
5     0    84        0        0       0      84           0          0
6     0     0        0       48       0       0            0         48

from first four columns, for each row I have to take two largest values. and these two values will be considered as observed values.And from last four column we will get the expected values.So i have to perform chi square test for each row to get p values.

example for first row is-

first two largest values are 84(in V2) and 22 (in V3).so these are considered as observed values.Now if the largest values are in V2 and V3,we have to pick expected values from W2 and W3 which are 84 and 0.I know for chi square test values should not be 0 but we will ignore the warning.
Now as we have observed value as well as expected we have to perform chi square test to get p values for each row in a new column.


So far I was working as returning the index for two largest value with-
sort.int(df,index.return=TRUE)$ix[c(4,3)]
 but it does not accept data frame.

Can you please give some idea how to do this,because it is very tricky and after studying a lot, I am not able to perform.Please help.



Thanking you,
Warm Regards
Vikas Bansal
Msc Bioinformatics
Kings College London
______________________________________________
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.



More information about the R-help mailing list