Python Programming for Biology: Bioinformatics and Beyond



Download 7,75 Mb.
Pdf ko'rish
bet487/514
Sana30.12.2021
Hajmi7,75 Mb.
#91066
1   ...   483   484   485   486   487   488   489   490   ...   514
Bog'liq
[Tim J. Stevens, Wayne Boucher] Python Programming

Two-sample T-test

The two-sample T-test tests whether two independent samples have the same underlying,

true mean. In R there is a method, ‘t.test’, to carry this out. There are a few extra subtleties

in comparison with the RPy code for the binomial test.

The T-test involves comparing two collections of samples. These need to be converted

to  RPy  data  types  using  the  converter  R.FloatVector().  The  R  method,  ‘t.test’,  has  an

optional argument, var.equal,  which  specifies  whether  the  two  samples  should  be  treated

as  having  the  same  variance  or  not.  In  Python,  var.equal  cannot  be  used  as  a  key  in  a

function argument because it is not valid syntax. In RPy we can often use these arguments

by changing the dot (.) to an underscore (_). But replacing var.equal with var_equal does

not  work  here  and  instead  we  use  a  bit  of  Python  trickery.  In  Python  you  can  specify

‘key=value’ arguments by using a dictionary. But the trickery is that the dictionary itself is

not  passed  in  (the  function  is  not  expecting  a  dictionary  as  an  argument)  but  instead  we

use  a  magic  **  in  front  of  the  dictionary,  which  means  that  the  dictionary  contents  are

unwrapped  into  key=value  pairs.  This  is  the  safest  way  to  pass  arguments  with  dots  in

them in RPy.

We  pass  back  both  the  T  statistic,  which  happens  to  be  item  0,  and  the  probability,

which happens to be item 2, of the result.

def tTest(x, y, sameVariance=False):

func = R.r['t.test']

argDict = {'var.equal': sameVariance}



result = func(x=R.FloatVector(x), y=R.FloatVector(y), **argDict)

return result[0][0], result[2][0]

We can now test the function.

from numpy import array

samples1 = array([1.752, 1.818, 1.597, 1.697, 1.644, 1.593])

samples2 = array([1.878, 1.648, 1.819, 1.794, 1.745, 1.827])

print('Same variance result', tTest(samples1, samples2, sameVariance=True))

# Result is: -2.072, 0.0650

print('Not same variance result', tTest(samples1, samples2,

sameVariance=False))

# Result is: # -2.072 0.0654


Download 7,75 Mb.

Do'stlaringiz bilan baham:
1   ...   483   484   485   486   487   488   489   490   ...   514




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish