Last data update: 2014.03.03

R: Utility to apply a t-test to all rows of a matrix
applyttestR Documentation

Utility to apply a t-test to all rows of a matrix

Description

Generate fold change and t-test p-value for all rows of a data matrix

Usage

applyttest(mat, Group, doLogs = TRUE, numerator = levels(Group)[1])

Arguments

mat

Matrix containing data, possibly with missing values

Group

Group with two levels of length equal to the number of matrix columns

doLogs

True/false, log data before applying test

numerator

The level of the group used as numerator for the fold change, by default the first one

Value

Data frame with two values, t-test p-value and fold change.

See Also

applyttestPep

Examples

mat = matrix(rnorm(600), nrow=100)
mat[1:20, 1:3] = 3+mat[1:20, 1:3] # create some differences
mat[30, 1:3] = NA # and some missing values
mat[100,] = NA


applyttest(mat, Group = rep(c("A", "B"), each=3), doLogs=FALSE)
applyttest(abs(mat), Group = rep(c("A", "B"), each=3), doLogs=TRUE)


Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(SwathXtend)
Loading required package: e1071
Loading required package: openxlsx
Loading required package: VennDiagram
Loading required package: grid
Loading required package: futile.logger
Loading required package: lattice
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/SwathXtend/applyttest.Rd_%03d_medium.png", width=480, height=480)
> ### Name: applyttest
> ### Title: Utility to apply a t-test to all rows of a matrix
> ### Aliases: applyttest
> ### Keywords: ~kwd1 ~kwd2
> 
> ### ** Examples
> 
> mat = matrix(rnorm(600), nrow=100)
> mat[1:20, 1:3] = 3+mat[1:20, 1:3] # create some differences
> mat[30, 1:3] = NA # and some missing values
> mat[100,] = NA
> 
> 
> applyttest(mat, Group = rep(c("A", "B"), each=3), doLogs=FALSE)
Error in t.test.formula(mat[i, ] ~ Group, var.equal = TRUE) : 
  grouping factor must have exactly 2 levels
Error in t.test.formula(mat[i, ] ~ Group, var.equal = TRUE) : 
  grouping factor must have exactly 2 levels
            pval            FC
1   0.0810025284  -11.15763853
2   0.0342395664    6.78093873
3   0.0223198811  -10.56537076
4   0.0335726128    2.66882065
5   0.0873273973   -8.28900686
6   0.0560851150    4.86472497
7   0.0052049174   -2.74919183
8   0.0007338572 -103.04500967
9   0.0126459926  -16.07553718
10  0.0351705873  -33.23450320
11  0.0312485927    7.32024910
12  0.0027662619   -2.88667417
13  0.0233984972   10.39021308
14  0.0281171019  -14.59217093
15  0.0317053729   19.44392224
16  0.0183814928    6.41894115
17  0.1168863714  -19.95757582
18  0.0615116652    5.07596203
19  0.0203750637  -15.76359876
20  0.0073314211    6.17866945
21  0.0834825778   -3.32528488
22  0.8902444562    1.09768718
23  0.8354402470    0.12969898
24  0.6304561921    3.71010150
25  0.5304879227    0.03454302
26  0.4904347185   -0.20905349
27  0.4365634012   -0.33234834
28  0.0145082873   -0.71744007
29  0.0037143178   -0.85570327
30            NA           NaN
31  0.4979591451   -1.75717629
32  0.1572318002   -6.51852868
33  0.1903979713   -0.45658090
34  0.6700176579   -1.86445781
35  0.5904252393    0.32186809
36  0.7616090032    1.83970338
37  0.3120093718   -8.82979105
38  0.6448385650    1.79948123
39  0.7023728726    0.54906835
40  0.7863559079    2.76417020
41  0.1292153550   -0.21530747
42  0.9396190012    0.90369338
43  0.1672643227    0.29750626
44  0.6318645366   -1.24618611
45  0.0533938057   -1.43694497
46  0.1523269414    0.01277283
47  0.3304436358    0.19678665
48  0.7805559353    0.53346932
49  0.1164430586   -5.30853901
50  0.1901830297   -0.03337110
51  0.4395765609   -0.61586123
52  0.9125314324    1.24058548
53  0.3964776075    0.11902439
54  0.7936529904    3.08623465
55  0.4317766737    0.23704507
56  0.4736308628  -29.35617379
57  0.7434489964   -4.34073460
58  0.4686839559  -12.20353951
59  0.0417084375   -2.17058382
60  0.7973163194    0.24927577
61  0.8352067947    0.07881814
62  0.3588162336    4.74970510
63  0.1746844466   -1.91948765
64  0.8589453735    1.48753794
65  0.1846058599   -0.18024783
66  0.0582895674   -8.61441360
67  0.6258250972   -6.67270745
68  0.8137636875   -0.39211082
69  0.9664686693    1.05012628
70  0.6658145049    2.62366952
71  0.4814276185    2.04353029
72  0.1271443710   -3.01461797
73  0.9085978952    0.64104650
74  0.3152318558    0.43123896
75  0.0815970040    0.03657867
76  0.0318914600   -0.36326398
77  0.3830287354   -0.27377454
78  0.0873816374  142.12685950
79  0.9288848094    1.63788424
80  0.5812134087   -0.77387393
81  0.9224637295    1.88815022
82  0.5054022630    0.21291632
83  0.1703957963   -0.33304859
84  0.8686221769    4.06993410
85  0.8437196333    0.39145825
86  0.9294478714    0.90371381
87  0.3437949116   -0.75113029
88  0.9673062200    1.10446693
89  0.3015567533    1.99753001
90  0.7215470371   -0.42393824
91  0.0949345711   -0.54735635
92  0.5228732835   -6.06146236
93  0.2477123763    1.95639328
94  0.6940814547    3.84721787
95  0.7442534185    0.74601234
96  0.4885094912  -10.63899936
97  0.5414681831   -0.76006052
98  0.8975491675    0.74861008
99  0.7049418924    1.88315661
100           NA           NaN
> applyttest(abs(mat), Group = rep(c("A", "B"), each=3), doLogs=TRUE)
Error in t.test.formula(mat[i, ] ~ Group, var.equal = TRUE) : 
  grouping factor must have exactly 2 levels
Error in t.test.formula(mat[i, ] ~ Group, var.equal = TRUE) : 
  grouping factor must have exactly 2 levels
           pval         FC
1   0.140676549  2.4355900
2   0.009836482  3.7255863
3   0.045111624  2.8143909
4   0.159910518  4.4173190
5   0.117380239  2.4624688
6   0.128425007  9.0616661
7   0.115351474  3.2857803
8   0.009538683  9.7856775
9   0.040897102 12.2501109
10  0.046115217  2.7163271
11  0.004903017  6.7051705
12  0.024793967  2.9313569
13  0.040118694  4.8303291
14  0.119796444  5.7590052
15  0.007684249  3.6141291
16  0.021039196  5.2866003
17  0.218678484  2.3537544
18  0.099570166  8.0480565
19  0.100824016  6.5932481
20  0.121562093 19.1734214
21  0.271997824  3.4063001
22  0.810043808  1.1933894
23  0.188300256  2.2915936
24  0.083250823  4.1721439
25  0.709732013  1.8288582
26  0.158589612  2.5682610
27  0.799829362  0.8173999
28  0.401091252  0.2415776
29  0.634890559  0.8380297
30           NA        NaN
31  0.130674585  0.2370526
32  0.574055913  1.2197795
33  0.451248860  0.3389118
34  0.616794427  0.4345848
35  0.972337316  0.9728027
36  0.817875960  0.8208271
37  0.690855953  1.5526996
38  0.774398482  0.8009464
39  0.419239962  2.2611101
40  0.096854569  2.9514098
41  0.716335544  0.7519046
42  0.436737004  1.9123091
43  0.158634783  0.3823757
44  0.411015697  0.5685563
45  0.854116277  1.0874855
46  0.686618719  0.5780348
47  0.566675437  0.7705614
48  0.164091668  0.1584693
49  0.218035576  5.9487163
50  0.549196766  0.5281110
51  0.282984709  2.3695833
52  0.128549908  1.6906689
53  0.951724917  1.0603814
54  0.971326416  1.0181782
55  0.552029495  1.2527982
56  0.928547297  0.8980324
57  0.896562995  1.1310332
58  0.431666362  0.3066904
59  0.578771953  1.8552476
60  0.178445389  6.4780300
61  0.044243478  0.1560700
62  0.606875913  2.4027056
63  0.997741673  1.0020163
64  0.300534970  2.1458473
65  0.973242853  1.0232496
66  0.071727251  1.8194773
67  0.372470464  2.2574476
68  0.222189331  1.7337455
69  0.796736585  0.7652565
70  0.029886957  4.9840876
71  0.734852062  2.0001921
72  0.320474127  2.9705287
73  0.435758500  1.7309708
74  0.912909220  0.8685110
75  0.147756738  0.2933686
76  0.291731793  0.1938574
77  0.257915434  0.4900980
78  0.062851568  4.3390618
79  0.859929055  1.1331184
80  0.623464525  1.4329782
81  0.025282862  2.3827660
82  0.631314980  0.7462474
83  0.641812969  1.9104137
84  0.060479725  0.1201896
85  0.277554972  0.5423767
86  0.252044757  1.5518294
87  0.121144408  0.4430541
88  0.132843668  0.3842232
89  0.307220693  1.8125484
90  0.743790554  1.3982225
91  0.936921087  1.0564132
92  0.824085538  1.4298277
93  0.227729368  2.0056496
94  0.338952695  0.3748996
95  0.650893862  0.4951649
96  0.306047824  1.7753457
97  0.018606444  0.4100313
98  0.884421717  1.1719962
99  0.040159411  3.9638346
100          NA        NaN
> 
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>