Skip to contents

Computes the two-sample t-Test for each feature.

It internally calls functions from thematrixTests package for the various tests.

Usage

rowTwoSampleT(
  x,
  g,
  null = 0,
  alternative = c("two.sided", "greater", "less"),
  conf.level = 0.95,
  var = c("unequal", "equal"),
  paired = FALSE
)

Arguments

x

matrix or data.frame.

g

a vector or factor object giving the group for the corresponding elements of x.

null

numerical value or numeric vector of length nrow(x). The true values of the difference in means between the two groups of observations for each row.

alternative

character string or vector of length nrow(x). The alternative hypothesis for each row of x. Values must be one of "two.sided" (default), "greater" or "less".

conf.level

numerical value or numeric vector of length nrow(x). The confidence levels of the intervals. All values must be in the range of \([0:1]\) or NA.

var

character string indicating whether to treat the two variances as being unequal (default) or equal. If var = "unequal", the Welch approximation to the degrees of freedom is used.

paired

logical, whether to compute a paired t-test.

Value

A list containing two elements:

statistic

A numeric vector, the values of the test statistic

significance

A numeric vector, the p-values of the selected test

Author

Alessandro Barberis

Examples

#Seed
set.seed(1010)

#Data
x = matrix(rnorm(100 * 20), 100, 20)
g = c(rep(0,10),rep(1,10))

#Compute two-sample t-test
rowTwoSampleT(x = x, g = g, var = "equal")
#> $statistic
#>   [1]  0.102676176 -1.255674441  1.009402036 -1.237770832  3.251202948
#>   [6]  0.586284859  0.520225291 -0.141475320 -0.948511498  0.674698017
#>  [11] -1.022351747 -2.496378631 -0.655968326 -1.575800588  1.057233097
#>  [16] -0.530750639  0.409757861 -1.607537177  0.279997032  0.128966494
#>  [21] -0.287075784  2.994178224 -2.203390428 -0.871274583 -0.334204444
#>  [26]  0.409025903  0.566782238 -0.638101641 -1.184092693 -1.679836826
#>  [31] -0.721286836  3.615202539  1.802000892 -0.196559583 -1.137994612
#>  [36]  1.077868675 -0.314362822 -0.799890234 -0.656369393 -1.253169140
#>  [41] -0.005552096 -0.279588844 -1.374669767  0.400438416  1.088915724
#>  [46] -0.548711279  1.958619444  1.092793480  1.331147893  3.312522804
#>  [51]  2.301033016  1.083756592 -1.537450818  0.887750585  1.350977367
#>  [56] -2.897789078  0.274498666  0.143336030  1.613243068 -1.563316698
#>  [61]  0.667419180 -2.875775296  0.564010203  0.057365908 -0.199990851
#>  [66] -1.403634965 -1.003047155 -1.000690073 -1.196339943 -0.184978275
#>  [71] -0.083562698 -1.919106312 -0.378104381 -0.241135913 -0.351667434
#>  [76] -2.058370404 -0.039747824  1.738751100 -0.285289949  0.855519118
#>  [81] -0.598599076 -0.894315159  0.110935680 -0.336404112  0.785460995
#>  [86] -0.579353773  1.393753778 -0.044333375  0.318441009 -1.209110014
#>  [91]  1.065621129  2.374783231 -1.090742397  0.988782525  1.463761477
#>  [96]  0.574539802 -0.839251626 -1.416406351  1.119889351 -1.858972037
#> 
#> $significance
#>   [1] 0.919355225 0.225289846 0.326159210 0.231703997 0.004433645 0.564964558
#>   [7] 0.609246253 0.889065817 0.355430883 0.508441700 0.320159127 0.022476540
#>  [13] 0.520142129 0.132484045 0.304388448 0.602079323 0.686818897 0.125335676
#>  [19] 0.782672122 0.898814276 0.777332860 0.007783309 0.040831705 0.395076719
#>  [25] 0.742087679 0.687346319 0.577862105 0.531442454 0.251777489 0.110261665
#>  [31] 0.479997783 0.001979117 0.088318073 0.846374432 0.270043886 0.295326063
#>  [37] 0.756859983 0.434204498 0.519890012 0.226179035 0.995631162 0.782980346
#>  [43] 0.186106877 0.693546429 0.290555909 0.589945650 0.065837082 0.288894885
#>  [49] 0.199755766 0.003872737 0.033557907 0.292776600 0.141575790 0.386383871
#>  [55] 0.193441522 0.009591080 0.786827048 0.887617230 0.124085657 0.135388348
#>  [61] 0.512970932 0.010057629 0.579707462 0.954885744 0.843729805 0.177444738
#>  [67] 0.329132501 0.330240154 0.247085125 0.855314345 0.934326441 0.070968065
#>  [73] 0.709775111 0.812175187 0.729170841 0.054330083 0.968731723 0.099152986
#>  [79] 0.778678790 0.403508491 0.556898887 0.382955899 0.912894965 0.740456211
#>  [85] 0.442400255 0.569531017 0.180362442 0.965126789 0.753815627 0.242263524
#>  [91] 0.300680824 0.028881256 0.289772593 0.335875804 0.160504432 0.572713854
#>  [97] 0.412336066 0.173730243 0.277482043 0.079459503
#> 

#Compute two-sample t-test with Welch approximation
rowTwoSampleT(x = x, g = g)
#> $statistic
#>   [1]  0.102676176 -1.255674441  1.009402036 -1.237770832  3.251202948
#>   [6]  0.586284859  0.520225291 -0.141475320 -0.948511498  0.674698017
#>  [11] -1.022351747 -2.496378631 -0.655968326 -1.575800588  1.057233097
#>  [16] -0.530750639  0.409757861 -1.607537177  0.279997032  0.128966494
#>  [21] -0.287075784  2.994178224 -2.203390428 -0.871274583 -0.334204444
#>  [26]  0.409025903  0.566782238 -0.638101641 -1.184092693 -1.679836826
#>  [31] -0.721286836  3.615202539  1.802000892 -0.196559583 -1.137994612
#>  [36]  1.077868675 -0.314362822 -0.799890234 -0.656369393 -1.253169140
#>  [41] -0.005552096 -0.279588844 -1.374669767  0.400438416  1.088915724
#>  [46] -0.548711279  1.958619444  1.092793480  1.331147893  3.312522804
#>  [51]  2.301033016  1.083756592 -1.537450818  0.887750585  1.350977367
#>  [56] -2.897789078  0.274498666  0.143336030  1.613243068 -1.563316698
#>  [61]  0.667419180 -2.875775296  0.564010203  0.057365908 -0.199990851
#>  [66] -1.403634965 -1.003047155 -1.000690073 -1.196339943 -0.184978275
#>  [71] -0.083562698 -1.919106312 -0.378104381 -0.241135913 -0.351667434
#>  [76] -2.058370404 -0.039747824  1.738751100 -0.285289949  0.855519118
#>  [81] -0.598599076 -0.894315159  0.110935680 -0.336404112  0.785460995
#>  [86] -0.579353773  1.393753778 -0.044333375  0.318441009 -1.209110014
#>  [91]  1.065621129  2.374783231 -1.090742397  0.988782525  1.463761477
#>  [96]  0.574539802 -0.839251626 -1.416406351  1.119889351 -1.858972037
#> 
#> $significance
#>   [1] 0.919355565 0.225498303 0.327926982 0.231704014 0.004433713 0.565744962
#>   [7] 0.609371656 0.889073643 0.356900302 0.508976873 0.323487234 0.023097064
#>  [13] 0.521593493 0.132936995 0.312570107 0.602766300 0.687936658 0.125347359
#>  [19] 0.782785601 0.898943920 0.777342794 0.007790077 0.040859008 0.395393049
#>  [25] 0.742424572 0.687398493 0.580358313 0.531442474 0.258087520 0.110322655
#>  [31] 0.480034043 0.002805636 0.089170201 0.846517832 0.270634228 0.295782644
#>  [37] 0.756969288 0.434351225 0.520192629 0.226179284 0.995631781 0.783016396
#>  [43] 0.186139782 0.693717434 0.294759989 0.590424914 0.067481757 0.290641896
#>  [49] 0.208323530 0.003873903 0.034777790 0.292794911 0.141589501 0.386812811
#>  [55] 0.193449744 0.012225435 0.786957165 0.887722484 0.124105028 0.142943388
#>  [61] 0.512989334 0.010446752 0.579972511 0.954937027 0.844245059 0.177492964
#>  [67] 0.329215192 0.330461027 0.248591623 0.855396423 0.934435822 0.071772789
#>  [73] 0.709860021 0.812775539 0.729180470 0.054588769 0.968847134 0.099205344
#>  [79] 0.778712892 0.403566434 0.556899611 0.383009711 0.913604691 0.740810191
#>  [85] 0.444296395 0.569579666 0.181500232 0.965132689 0.753855932 0.250390848
#>  [91] 0.302559049 0.029224795 0.292843365 0.336112398 0.160515295 0.572784792
#>  [97] 0.414641418 0.174739914 0.277710893 0.080399378
#> 

#Compute two-sample paired t-test
rowTwoSampleT(x = x, g = g, paired = TRUE)
#> $statistic
#>   [1]  0.105846642 -1.226066457  0.933934421 -1.188231761  3.464396651
#>   [6]  0.842077479  1.144499292 -0.173302153 -0.806080402  0.558394598
#>  [11] -0.985378713 -2.713690594 -0.653815335 -1.654687005  1.031975003
#>  [16] -0.494881934  0.449574782 -1.803658453  0.215272438  0.139165914
#>  [21] -0.356861393  3.426546800 -2.032570216 -1.047425674 -0.579835348
#>  [26]  0.616875137  0.575104052 -0.477912629 -1.320900894 -1.919637167
#>  [31] -0.704886562  4.363388296  2.098441892 -0.314608823 -1.731951723
#>  [36]  1.018514762 -0.296800214 -0.915867468 -1.483291946 -0.999254476
#>  [41] -0.005859077 -0.279279608 -1.187075604  0.344343077  0.938509422
#>  [46] -0.529167965  1.942391536  1.240516329  1.168882007  3.679833178
#>  [51]  2.225412187  1.375351762 -1.325044174  0.874555960  1.228400760
#>  [56] -2.935832351  0.290564498  0.135850613  1.497595462 -1.522978283
#>  [61]  0.894265416 -2.442443525  0.430641608  0.057264512 -0.179048797
#>  [66] -1.399424743 -0.858911640 -2.472199259 -1.161983005 -0.187989620
#>  [71] -0.093156228 -2.679082345 -0.308042742 -0.236298424 -0.358293729
#>  [76] -1.906006842 -0.039285775  1.956415638 -0.237303229  1.009791671
#>  [81] -0.706780344 -0.920758455  0.113955442 -0.274247407  0.648897152
#>  [86] -0.502341383  1.162301553 -0.050237610  0.285373393 -1.281896029
#>  [91]  1.014856566  2.065955751 -0.986794564  1.038803611  1.457049907
#>  [96]  0.800263487 -0.790084646 -1.367524716  1.205469111 -1.789471257
#> 
#> $significance
#>   [1] 0.918025662 0.251285313 0.374715471 0.265150997 0.007111320 0.421556589
#>   [7] 0.281941054 0.866248992 0.440974411 0.590194360 0.350185799 0.023852928
#>  [13] 0.529579909 0.132373864 0.329017211 0.632539543 0.663648866 0.104782066
#>  [19] 0.834354129 0.892383391 0.729419519 0.007549351 0.072632160 0.322216585
#>  [25] 0.576251176 0.552600390 0.579312274 0.644106442 0.219132110 0.087107106
#>  [31] 0.498715006 0.001814482 0.065283135 0.760229868 0.117325052 0.335030238
#>  [37] 0.773354682 0.383620146 0.172147130 0.343778169 0.995452976 0.786341966
#>  [43] 0.265584277 0.738497450 0.372484537 0.609490560 0.083986374 0.246148506
#>  [49] 0.272477973 0.005076784 0.053092953 0.202284235 0.217809707 0.404548850
#>  [55] 0.250449590 0.016598828 0.777968661 0.894929437 0.168463117 0.162096094
#>  [61] 0.394465405 0.037215173 0.676858202 0.955585711 0.861865313 0.195195361
#>  [67] 0.412680398 0.035442158 0.275129352 0.855055017 0.927820245 0.025243991
#>  [73] 0.765059856 0.818491190 0.728383631 0.089028641 0.969520207 0.082116053
#>  [79] 0.817735236 0.338971204 0.497592376 0.381194616 0.911774743 0.790085272
#>  [85] 0.532611568 0.627487859 0.275006476 0.961030320 0.781816739 0.231914966
#>  [91] 0.336678726 0.068813325 0.349527929 0.325998229 0.179089885 0.444167975
#>  [97] 0.449793471 0.204636031 0.258758723 0.107160561
#>