R : Copyright 2002, The R
Development Core Team
Version 1.5.0 (2002-04-29)
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.
Type `demo()' for some demos,
`help()' for on-line help, or
`help.start()' for a HTML browser
interface to help.
Type `q()' to quit R.
> setwd("Hope:Users:dave:Documents:Trabajo:Source
code G3:R:R source")
NULL
> source("MultTests.r")
[1] "Fri May 2 18:19:31 2003"
> seed.random(1)
[1] "Knuth-TAOCP-2002 with
seed 1 as of Fri May 2 18:19:36
2003"
> gene.scales
<- 1:50 # Simulation of different expression scales for 50 different genes.
> (microarrays1
<- random.matrix(5, c(10, rep(0, 48), 500), gene.scales)) # Expression values for 5 microarrays
of 50 genes each. The first and last genes have more relative expression in
this group than in microarrays2. microarrays1 can be seen as the treatment
group and microarrays2 as the control group.
[,1] [,2]
[,3] [,4]
[,5]
[1,]
9.3137462
9.4559427 10.1599860 9.3213044 11.2512963
[2,]
2.5662118
-1.5742964 -4.0539279 -0.6842048 1.4443480
[3,]
2.8429561 2.7686932 3.3278253 0.9934874 -0.6799268
[4,]
-1.3821105
8.7231396 3.0750876 -0.2525415 2.7160389
[5,]
1.2328106
3.5316648 6.6085530 -3.1409178 0.9847892
[6,]
-7.3163095
0.3400947 -6.0523820 -1.1999928 -1.4415230
[7,]
10.6980694
-1.5368891 -5.8716095
-10.7468949 2.9181667
[8,]
3.4882601 -15.2572333 -0.1291465 9.5981555
-2.4990510
[9,]
-7.1896035
4.7783718 10.3230899 -2.0922312 6.1341975
[10,] 14.5291580
-16.2925797 -11.8174199 -15.0104922 -8.7869882
[11,] 1.7484095
-24.5973575
2.6272718 13.5274454
-13.7236807
[12,] 1.8045427
-16.6712676 -0.4995225 14.6214175 -5.7673979
[13,] -1.8374763
7.4877543 -14.3166975 -24.4307295
-1.4807425
[14,] 15.8819169
-1.0615608 -15.7269067 18.2591398 -16.8635552
[15,] -1.1444381
-5.0937296 -17.2359278
-0.0993400 9.7775595
[16,] 2.5953409
13.0330103 -5.4975613
-33.6774030 16.7243699
[17,] 5.3735960 1.3854575 -13.6078947 -1.3418695
17.0218526
[18,] 47.2177691
-32.4199409 14.4900453 -2.3626233 11.8068401
[19,] 33.7148816
-14.6588594 17.3927808 9.4547644 30.1168029
[20,] 0.2958211
-31.6110341 6.9844764
-26.7222667 -35.9588375
[21,] -13.8706572 -11.6977017 -42.9035775 -6.4487491 -26.0555705
[22,] -15.7472418 11.4525979
26.1087080 -9.8500910
-30.6563491
[23,] -3.9337470
4.8954825 14.2648947
-59.0111005 -23.6212729
[24,] 2.3989024
-14.9565588 -49.5721962
44.5723994 20.2103144
[25,] 1.5706291
31.2455812 -20.5547262
1.4395973 -7.8201934
[26,] 36.4447996
15.9905698
1.4217068 -4.7371774
-36.0752171
[27,] -35.7835804 -48.7174995 30.6848297 -10.0695276 -18.8639853
[28,] -24.3249685 -20.5585391 -18.8989765 -5.2387354 10.6064716
[29,] 44.1295905
-9.0573061 11.3464762 22.9207068 25.8701148
[30,] 9.9574932
-7.3088303 -13.7017651 -12.8524202
-5.2694322
[31,] 16.3023886
-3.6135305 -31.0792550
23.0953731 -13.6383384
[32,] 1.3787214
-41.3217844 58.9132757 -2.3148850 17.8056671
[33,] 38.9062959
1.9988956 -29.0905211
13.4232761 -6.7524730
[34,] 6.1746676 3.8571518 -17.5802880 11.1082663
-1.1554330
[35,] 55.6544610
-18.0690699 -59.8884312
26.0671841 13.7703470
[36,] 15.5403076
-32.3281278 -13.8601365 -21.2064983 -11.2742540
[37,] -69.9339880 -7.2330785 5.0896586 -40.1723504 -0.2313831
[38,] 9.5767262
31.9027622 40.0678483 36.1805319 -13.3867600
[39,] -25.7230827 52.8260429 -5.0938798 -67.7963268 31.0226803
[40,] -32.7307112 -48.3775683 -72.8320611 -5.5345633 -22.0544824
[41,] 25.0535888
-8.4056905 -72.6338085
1.1080706 -77.7444837
[42,] -40.0910127 -71.9955020 -21.9021846 53.9851789 -37.7875317
[43,] 88.4151023
50.3153357 -22.4911177
13.6666721 -20.7736228
[44,] 11.4051902
11.6350779 57.5005441 -6.0764744 2.5081856
[45,] -33.9102831 -17.7318580 19.9908814
36.4608578 -6.7986497
[46,] 33.7100821
-3.6724950 41.0676781 34.7550369 53.2332405
[47,] 9.7067986 -104.5902390 56.4898087
25.9544930 35.9442666
[48,] -42.7879606 -4.6154714 102.4007569 -81.4290053 72.3839326
[49,] -20.1761854 125.2203842 -30.2409190 50.8917759 23.5307452
[50,] 537.3100773 519.2842041 442.0353110 481.3872550
414.2502064
> (microarrays2
<- random.matrix(5, rep(0, 50), gene.scales)) # Again, rows are genes and
columns are microarrays.
[,1] [,2]
[,3] [,4]
[,5]
[1,]
-0.3871018
0.9159686 -0.1917428 -0.6145891 -0.8499166
[2,]
-0.4174267 -3.1386746 1.8995596 0.9591741 -0.1175146
[3,]
2.5908764 -2.0725474 0.7284000 -1.6303520 6.5916688
[4,]
6.7818815
1.0358852 1.7463080 -1.4397230 4.7150755
[5,]
-7.9635747
8.9831125 -3.4034390 6.8121073 -5.3460568
[6,] -15.4591846
6.5252712 0.7365531
-10.6038214 5.8087338
[7,]
14.0492789
6.9441996 3.3137225 17.5774287 -10.8999664
[8,]
2.1009349 -8.1007042
-10.5372099 -12.9887294
2.1852404
[9,]
-5.5581867
7.2912862 4.7368748 7.5625132 1.3463343
[10,] 13.0426551
17.9069536 -0.6222825
-11.8736206 -21.8179278
[11,] 8.6389648 -21.7975048 -13.0786994 17.6648745 -24.3889333
[12,] -5.6645254 -18.2272648
26.2824467 4.1710340
-23.7980736
[13,] -5.1382499
5.2036292
8.4053821 22.6896491 -1.7269276
[14,] 18.1279270
5.8850710
9.9933657 10.7356452
-25.8321909
[15,] -15.9546306 38.1763004 -3.7076384 -11.1824113
16.7737859
[16,] -9.8450038
4.5400538 -18.3487152
13.7074401 -14.4274678
[17,] -6.9516037
15.6847437 -9.3312655 53.6506221 16.5127551
[18,] -0.6768434
22.1357661 12.4757426 -14.6606214
-35.6752578
[19,] -3.1604021 -16.5120249 8.4617388
-3.9500770 3.0187743
[20,] -7.8354491
-5.6509055 22.7576031
-13.5163475 2.0479977
[21,] -16.5676546 18.9001452 -9.7139066
19.1641582 24.8008991
[22,] -17.0366683 -3.0381418 -9.9637029
10.2646866 -14.0486333
[23,] 27.6134131 -11.6978521 -22.4207965 -40.1775883 3.7273295
[24,] 34.6441089 -17.2029980 -12.8653010 -9.2785348
7.7597021
[25,] 36.1840582
-5.2097048 49.1339461 -3.6579982 -0.9479562
[26,] -6.0088930
7.8846228 46.5842810 23.8884466 62.6271226
[27,] 28.6761568 -38.4697100
35.7767570 -23.7352002 -36.3714974
[28,] -21.5736639 -8.9970099 -6.3294932 -48.9226183
74.1942256
[29,] -29.6431342 -44.2137782 8.7409083 15.0949472 5.9061009
[30,] -81.4554877 -46.7477896 22.7424357 9.6090062 -32.5033664
[31,] 19.3640883
39.2830345 -34.4066561 -45.2753042 -47.2025900
[32,] -73.3080487 30.6516510 -25.2366917 -8.5815517 -43.9851242
[33,] -30.3680474 -23.8440854 25.6820354 68.5691692 10.8068189
[34,] 17.6667737
49.6049853 47.1401879
-18.6992148 33.9242853
[35,] -14.9489365 -52.0221473 32.1130478 -3.9088759
-2.6864887
[36,] 7.9471324
-2.5672758 -8.8377774 26.9645445 21.3332428
[37,] -14.1063075 -11.1214029 35.9484938 11.0123864
-4.7046108
[38,] -20.8776373 -19.4110565
-22.6491775 -30.6254885 30.9069702
[39,] 28.1253652
16.4317217 -60.3705920 -37.9194551
-1.1276264
[40,] 3.4270728 -12.0122698 83.3019493
2.4687942 58.9990515
[41,] -2.8889904
63.6675826 -50.6108693 59.1742340 -36.4327466
[42,] -39.0371316 -18.1631632
-35.3340484 -61.0396493 41.9391225
[43,] -12.8794759 8.9519032 -60.1631353
-78.7289916 -8.9310789
[44,] -26.7679738 -18.4964041 59.3199722 -26.7146917 -0.3481849
[45,] 39.6668854 -13.6703287 -56.6465248 67.8110790
52.4198051
[46,] -50.1679459 41.6271561 31.0742863 -15.5279463 -91.2422402
[47,] -35.1412097 -26.1394032 24.0500507 -3.0019400
9.1298109
[48,] 43.3540822
23.9198888 -75.3366877 -45.7927516 -26.3565445
[49,] 39.6534486 -77.4927392 6.1089734 -57.4279231 67.0781786
[50,] -7.4638443 -56.3883936
39.0591653 44.3593798
-15.7994257
> bdt
<- boot.diff.tests(list(microarrays1, microarrays2), 500, file.base = 'bdt
demo') # Performs multiple hypothesis tests by bootstrapping, saving the main
results to a file called "bdt demo.xls". This takes on the order of a
minute on typical PCs.
> bdt #
This shows the p.value for each gene, after adjusting for multiple comparisons.
variable p.value fdr.value stat weighted.stat
null.prop.ge
test comparison
alternative
1 1 0.000 0.0000000 14.328437601 14.328437601 0.00000 boot.diff.tests sample1 v.
sample2 two.sided
2 2 0.998 0.9036889 -0.142313467 -0.142313467 0.60160 boot.diff.tests sample1 v.
sample2 two.sided
3 3 0.998 0.9563243 0.228843008 0.228843008 0.35932 boot.diff.tests sample1 v.
sample2 two.sided
4 4 0.998 0.9946000 0.002437512 0.002437512 0.50432 boot.diff.tests sample1 v.
sample2 two.sided
5 5 0.998 0.9265000 0.328558072 0.328558072 0.30140 boot.diff.tests sample1 v.
sample2 two.sided
6 6 0.998 0.9645532 -0.068540827 -0.068540827 0.55408 boot.diff.tests sample1 v.
sample2 two.sided
7 7 0.980 0.5456471 -0.793885301 -0.793885301 0.90740 boot.diff.tests sample1 v.
sample2 two.sided
8 8 0.996 0.7487826 0.578962497 0.578962497 0.17388 boot.diff.tests sample1 v.
sample2 two.sided
9 9 0.998 0.9290000 -0.110614024 -0.110614024 0.58132 boot.diff.tests sample1 v.
sample2 two.sided
10 10 0.998 0.8500000 -0.490538971 -0.490538971 0.79068 boot.diff.tests sample1 v.
sample2 two.sided
11 11 0.998 0.9240455
0.142435134
0.142435134 0.41484 boot.diff.tests sample1 v.
sample2 two.sided
12 12 0.998 0.9446512
0.143078691
0.143078691 0.41440 boot.diff.tests sample1 v.
sample2 two.sided
13 13 0.662 0.2188333 -1.145403525 -1.145403525 0.97336 boot.diff.tests sample1 v.
sample2 two.sided
14 14 0.998 0.9794444 -0.230707874 -0.230707874 0.65252 boot.diff.tests sample1 v.
sample2 two.sided
15 15 0.998 0.8765926 -0.442483577 -0.442483577 0.76868 boot.diff.tests sample1 v.
sample2 two.sided
16 16 0.998 0.9523684
0.215465381
0.215465381 0.36692 boot.diff.tests sample1 v.
sample2 two.sided
17 17 0.986 0.6570000 -0.714269034 -0.714269034 0.88192 boot.diff.tests sample1 v.
sample2 two.sided
18 18 0.998 0.8633846
0.466614608
0.466614608 0.22880 boot.diff.tests sample1 v.
sample2 two.sided
19 19 0.494 0.1880000
1.269508990
1.269508990 0.01452 boot.diff.tests sample1 v.
sample2 two.sided
20 20 0.866 0.3926154 -0.970553745 -0.970553745 0.94832 boot.diff.tests sample1 v.
sample2 two.sided
21 21 0.176 0.0900000 -1.555251707 -1.555251707
0.99596
boot.diff.tests sample1 v. sample2
two.sided
22 22 0.998 0.9247143
0.172134403
0.172134403 0.39552 boot.diff.tests sample1 v.
sample2 two.sided
23 23 0.998 0.9243415 -0.186795679 -0.186795679 0.62760 boot.diff.tests sample1 v.
sample2 two.sided
24 24 0.998 1.0141224 -0.002943963 -0.002943963 0.51008 boot.diff.tests sample1 v.
sample2 two.sided
25 25 0.996 0.6976364 -0.622466383 -0.622466383 0.84796 boot.diff.tests sample1 v.
sample2 two.sided
26 26 0.884 0.3717333 -0.946825172 -0.946825172 0.94340 boot.diff.tests sample1 v.
sample2 two.sided
27 27 0.998 0.9387059 -0.289421833 -0.289421833 0.68568 boot.diff.tests sample1 v.
sample2 two.sided
28 28 0.998
0.9083030 -0.322943047
-0.322943047 0.70500 boot.diff.tests sample1 v.
sample2 two.sided
29 29 0.626 0.2085455
1.179552609
1.179552609 0.02256 boot.diff.tests sample1 v.
sample2 two.sided
30 30 0.994 0.6985000
0.656174026
0.656174026 0.14052 boot.diff.tests sample1 v.
sample2 two.sided
31 31 0.998 0.9536667
0.348216948
0.348216948 0.29108 boot.diff.tests sample1 v.
sample2 two.sided
32 32 0.908 0.3731250
0.926679168
0.926679168 0.05904 boot.diff.tests sample1 v.
sample2 two.sided
33 33 0.998 0.9354359 -0.209745666 -0.209745666 0.64048 boot.diff.tests sample1 v.
sample2 two.sided
34 34 0.488 0.2131429 -1.271940713 -1.271940713 0.98456 boot.diff.tests sample1 v.
sample2 two.sided
35 35 0.998 0.9414839
0.336884669
0.336884669 0.29684 boot.diff.tests sample1 v.
sample2 two.sided
36 36 0.284 0.1103333 -1.438528332 -1.438528332 0.99256 boot.diff.tests sample1 v.
sample2 two.sided
37 37 0.882 0.3865714 -0.955177734 -0.955177734 0.94496 boot.diff.tests sample1 v.
sample2 two.sided
38 38 0.220 0.0964000
1.496973602
1.496973602 0.00412 boot.diff.tests sample1 v.
sample2 two.sided
39 39 0.998 0.9399500
0.191982513
0.191982513 0.38252 boot.diff.tests sample1 v.
sample2 two.sided
40 40 0.066 0.0360000 -1.785798529 -1.785798529 0.99876 boot.diff.tests sample1 v.
sample2 two.sided
41 41 0.996 0.7028571 -0.636890545 -0.636890545 0.85384 boot.diff.tests sample1 v.
sample2 two.sided
42 42 0.998 0.9924167 -0.033183930 -0.033183930 0.53124 boot.diff.tests sample1 v.
sample2 two.sided
43 43 0.606 0.2160000
1.195675518
1.195675518 0.02136 boot.diff.tests sample1 v.
sample2 two.sided
44 44 0.994 0.7246316
0.661402122
0.661402122 0.13852 boot.diff.tests sample1 v.
sample2 two.sided
45 45 0.998 0.8734286 -0.428374818 -0.428374818 0.76112 boot.diff.tests sample1 v.
sample2 two.sided
46 46 0.586 0.2226667
1.210497740
1.210497740 0.02016 boot.diff.tests sample1 v.
sample2 two.sided
47 47 0.998 0.9604000
0.257371255
0.257371255 0.34164 boot.diff.tests
sample1 v. sample2 two.sided
48 48 0.998 0.9206207
0.384148099
0.384148099 0.27184 boot.diff.tests sample1 v.
sample2 two.sided
49 49 0.996 0.7478333
0.563168633
0.563168633 0.18116 boot.diff.tests sample1 v.
sample2 two.sided
50 50 0.000 0.0000000 10.345326007 10.345326007 0.00000 boot.diff.tests sample1 v.
sample2 two.sided
> args(rejections)
# Rejections is used to determine which genes to consider differentially
expressed.
function (err.rates.out =
"errRates.xls", fdr = NULL, fwer = NULL,
posterior = (if (is.null(fdr) &&
is.null(fwer)) 0.9 else NULL),
file = "rejections.xls", fdr.name =
"fdr.value", tolerance = 0.01)
NULL
> rejections(bdt,
fwer = .05) # Returns the rows (genes) with adjusted p-values less than 5%.
(FWER stands for the family-wise error rate.)
variable p.value fdr.value stat weighted.stat null.prop.ge
test comparison
alternative
1 1 0 0 14.32844 14.32844
0 boot.diff.tests sample1 v. sample2 two.sided
50 50 0 0 10.34533 10.34533
0 boot.diff.tests sample1 v. sample2 two.sided
> # As
expected from the simulations, only two genes are considered differentially
expressed.
> rejections(bdt,
fdr = .05) # returns the rows (genes) such that the expected false discovery
rate is less than 5%
variable p.value fdr.value stat weighted.stat null.prop.ge
test comparison
alternative
1 1 0.000 0.000 14.328438 14.328438 0.00000 boot.diff.tests sample1 v.
sample2 two.sided
50 50 0.000 0.000 10.345326 10.345326 0.00000 boot.diff.tests sample1 v.
sample2 two.sided
40 40 0.066 0.036 -1.785799 -1.785799 0.99876 boot.diff.tests sample1 v.
sample2 two.sided
> #
Gene 40 was also considered differentially expressed, reflecting the more
liberal nature of FDR control.
> rejections('bdt
demo.xls', fdr = .05, file = 'bdt demo fdr05.xls') # Reads the bootstrap
results from the first file (useful when bdt is no longer available in RAM) and
saves the results to the second file ('rejections.xls' is the default).
variable p.value fdr.value stat weighted.stat
null.prop.ge
test comparison
alternative
X1 1 0.000 0.000 14.328438 14.328438 0.00000 boot.diff.tests sample1 v.
sample2 two.sided
X50 50 0.000 0.000 10.345326 10.345326 0.00000 boot.diff.tests sample1 v.
sample2 two.sided
X40 40 0.066 0.036 -1.785799 -1.785799 0.99876 boot.diff.tests sample1 v.
sample2 two.sided
>