[R] help needed with printing multiple arguments as vectors, not matrices

Angel Russo angerusso1980 at gmail.com
Mon Jun 24 17:35:49 CEST 2013


Sample data is as follows (for simplicity assume mat1 and mat2 are the same
matrices). Also attached as an excel file.

I want to get the pairwise interaction fischer test results. Not just the
pvalues but also want to wrote the n00, n01, n10 and n11 in the file as:


ADCK2_mat1 ADCK3_mat2 n00 n01 n10 n11 pvalue



ADCK2_mat1 ADCK4_mat2 n00 n01 n10 n11 pvalue

 GENE SYMBOL Sample-A1-A0SK-01 Sample-A1-A0SO-01 Sample-A1-A0SP-01
Sample-A2-A04P-01 Sample-A2-A04Q-01 Sample-A2-A04U-01 Sample-A2-A0CL-01
Sample-A2-A0CM-01 Sample-A2-A0D0-01 Sample-A2-A0D2-01 Sample-A2-A0ST-01
Sample-A2-A0SX-01 Sample-A2-A0T0-01  ADCK2 0 0 0 0 0 0 0 0 0 1 0 0 0  ADCK3
0 0 0 0 0 1 0 0 1 0 0 1 0  ADCK4 0 0 0 0 0 0 0 0 0 0 0 1 0  ADCK5 1 0 0 0 0
0 0 0 0 0 0 0 1  ADRBK1 0 0 0 0 0 0 0 0 0 0 0 0 0  ADRBK2 0 0 0 0 0 1 0 0 0
0 0 0 0  AKT1 0 0 0 0 0 0 0 0 0 0 0 0 0  AKT2 0 0 0 0 0 0 0 0 0 0 0 1 0
AKT3 0 0 0 0 0 0 0 0 1 0 0 1 0  ALK 0 0 0 0 0 0 0 0 0 0 0 0 0


On Mon, Jun 24, 2013 at 11:03 AM, Adams, Jean <jvadams at usgs.gov> wrote:

> Could you provide an example of mat1 and mat2 as well as an example of the
> output you would like from them.
>
> Your code is very difficult to follow as written.  It will be easier for
> readers of the list to interpret if you use carriage returns rather than
> semi colons, for example ...
>
> fish <- function(x, y) {
> n00 = sum((1-x)*(1-y))
> n01 = sum((1-x)*y)
> n10 = sum(x*(1-y))
>  n11 = sum(x*y)
> a = matrix(c(n00, n01, n10, n11), nrow=2)
> pval = fisher.test(a)$p.value
>  return(pval)
> }
>
> Jean
>
>
> On Mon, Jun 24, 2013 at 6:09 AM, Angel Russo <angerusso1980 at gmail.com>wrote:
>
>> **
>>
>> I am using the following way to get p-values from fiser exact test.
>> However, I do need to print for each pair the values "n00, n01, n10, n11".
>> How can I print that as a table and not a matrix as below along with the
>> p-value? Any help will be greatly appreciated
>>
>>  fish <- function(y, x) {n00 = sum((1-x)*(1-y)); n01 = sum((1-x)*y);
>> n10 = sum(x*(1-y)); n11 = sum(x*y); a = matrix(c(n00, n01, n10, n11),
>> nrow = 2); pval = fisher.test(a)$p.value; return(pval);}
>>
>>  chiArray <- function(x) {  apply(mat1, 1, fish, x); }
>>  sapply(1:nrow(mat2), function(j){chiArray(mat2[j, ]);});
>>  chisq.cna.mut.test <- sapply(1:nrow(mat2), function(j){chiArray(mat2[j,
>> ]);});
>>
>> I want output to be:
>>
>> name1_mat1 name1_mat2 n00 n01 n10 n11 pvalue
>>
>>
>>
>> name1_mat1 name2_mat2 n00 n01 n10 n11 pvalue
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>>
>
>
-------------- next part --------------
GENE SYMBOL	Sample-A1-A0SK-01	Sample-A1-A0SO-01	Sample-A1-A0SP-01	Sample-A2-A04P-01	Sample-A2-A04Q-01	Sample-A2-A04U-01	Sample-A2-A0CL-01	Sample-A2-A0CM-01	Sample-A2-A0D0-01	Sample-A2-A0D2-01	Sample-A2-A0ST-01	Sample-A2-A0SX-01	Sample-A2-A0T0-01
ADCK2	0	0	0	0	0	0	0	0	0	1	0	0	0
ADCK3	0	0	0	0	0	1	0	0	1	0	0	1	0
ADCK4	0	0	0	0	0	0	0	0	0	0	0	1	0
ADCK5	1	0	0	0	0	0	0	0	0	0	0	0	1
ADRBK1	0	0	0	0	0	0	0	0	0	0	0	0	0
ADRBK2	0	0	0	0	0	1	0	0	0	0	0	0	0
AKT1	0	0	0	0	0	0	0	0	0	0	0	0	0
AKT2	0	0	0	0	0	0	0	0	0	0	0	1	0
AKT3	0	0	0	0	0	0	0	0	1	0	0	1	0
ALK	0	0	0	0	0	0	0	0	0	0	0	0	0


More information about the R-help mailing list