SlideShare a Scribd company logo
fst.R
secondmath
Tue Oct 28 20:12:47 2014
############## 2014 SNU GEPI population genetics by Jinseob Kim ###################
############## 1. Fst calculation ##################################################
## Load package & Set directory
library(hierfstat)
## Loading required package: gtools
## Loading required package: ade4
setwd("/home/secondmath/Dropbox/GSPH/myteaching/pop_gene/")
## Read example file. 7 pop & 289 SNPs (PER3 gene)
a=read.table("fstexample.txt",header=T)
a[1:10,1:10] # see data
## pop rs2001142 rs1894654 rs2071924 rs17350193 rs6662782 rs11120896
## 1 SASIA 22 44 33 24 11 33
## 2 SASIA 44 24 33 44 13 13
## 3 SASIA 44 22 33 44 11 11
## 4 SASIA 44 22 33 44 11 33
## 5 SASIA 44 22 13 44 13 13
## 6 SASIA 24 44 33 44 13 33
## 7 SASIA 44 22 13 44 13 33
## 8 SASIA 24 24 33 44 11 33
## 9 SASIA 24 24 33 44 11 13
## 10 SASIA 44 24 13 44 33 33
## rs9660884 rs12410983 rs10489142
## 1 33 11 11
## 2 13 11 13
## 3 33 11 11
## 4 33 11 11
## 5 33 11 11
## 6 13 11 13
## 7 11 13 13
## 8 NA 13 11
## 9 33 11 11
## 10 11 11 33
## Basic stat: original Fst
gg=basic.stats(a)
perloc1=gg$perloc # per locus statistics
head(perloc1)
1
## Ho Hs Ht Dst Htp Dstp Fst Fstp Fis
## rs2001142 0.2722 0.2807 0.2964 0.0158 0.2990 0.0184 0.0531 0.0615 0.0300
## rs1894654 0.3299 0.3369 0.3540 0.0172 0.3569 0.0200 0.0485 0.0561 0.0208
## rs2071924 0.3772 0.3910 0.4215 0.0305 0.4266 0.0356 0.0724 0.0834 0.0353
## rs17350193 0.0498 0.0528 0.0551 0.0023 0.0555 0.0026 0.0409 0.0474 0.0568
## rs6662782 0.3988 0.4168 0.4480 0.0312 0.4532 0.0365 0.0697 0.0804 0.0432
## rs11120896 0.3645 0.3896 0.3923 0.0027 0.3928 0.0032 0.0069 0.0080 0.0645
## Dest
## rs2001142 0.0255
## rs1894654 0.0302
## rs2071924 0.0584
## rs17350193 0.0028
## rs6662782 0.0625
## rs11120896 0.0052
fstloc1=perloc1$Fst # per locus Fst
all1=gg$overall # overall locus statistics
all1
## Ho Hs Ht Dst Htp Dstp Fst Fstp Fis Dest
## 0.2823 0.3071 0.3316 0.0245 0.3357 0.0286 0.0740 0.0853 0.0807 0.0413
fst1=all1[7] # overall locus Fst
## Weir & Cockerham's theta
gg2=wc(a)
fstloc2=gg2$per.loc$FST # per locus fst
fstloc2
## 1 2 3 4 5
## 0.052426375 0.051901748 0.064390803 0.044631901 0.061101023
## 6 7 8 9 10
## 0.010805742 0.084424434 0.019530769 0.042595316 0.024048371
## 11 12 13 14 15
## 0.093010994 0.042172548 0.039478819 0.192633459 0.044971892
## 16 17 18 19 20
## 0.070157956 0.244806030 0.038940279 0.049389356 0.022615752
## 21 22 23 24 25
## 0.033183043 0.084127700 0.092273438 0.081908731 0.058302092
## 26 27 28 29 30
## 0.038110973 0.060156731 0.039210191 0.055371303 0.117279665
## 31 32 33 34 35
## 0.087762303 0.026666092 0.030153663 0.046526129 0.066012782
## 36 37 38 39 40
## 0.061041214 0.065332626 0.052962014 0.075426081 0.075463795
## 41 42 43 44 45
## 0.143851689 0.022441398 0.160989656 0.085724512 0.159376136
## 46 47 48 49 50
## 0.028792527 0.031761370 0.082197528 0.028375636 0.083978371
## 51 52 53 54 55
## 0.106743349 0.027738761 0.023558877 0.054323945 0.098209168
## 56 57 58 59 60
2
## 0.150600548 0.031533695 0.148855507 0.061552962 0.019935431
## 61 62 63 64 65
## 0.016629213 0.006049883 0.041119269 0.006287292 0.051063811
## 66 67 68 69 70
## 0.038257279 0.011084482 0.013817984 0.030726323 0.069563187
## 71 72 73 74 75
## 0.045359467 0.080328008 0.179663626 0.154162874 0.036787540
## 76 77 78 79 80
## 0.156474076 0.059713676 0.149472370 0.084625996 0.064651443
## 81 82 83 84 85
## 0.028755981 0.077093453 0.065962172 0.037836763 0.117841464
## 86 87 88 89 90
## 0.042180940 0.026789562 0.042122817 0.048523877 0.094996177
## 91 92 93 94 95
## 0.024541259 0.040236171 0.057711277 0.192378574 0.112027893
## 96 97 98 99 100
## 0.071100721 0.040958278 0.039804008 0.098646412 0.013432562
## 101 102 103 104 105
## 0.095766221 0.160937898 0.069724684 0.064214996 0.082597542
## 106 107 108 109 110
## 0.039028556 0.054556318 0.021502018 0.077457039 0.063175584
## 111 112 113 114 115
## 0.039896285 0.037271113 0.010461731 0.043870960 0.043724436
## 116 117 118 119 120
## 0.077800288 0.027988693 0.080775828 0.008932556 0.017080343
## 121 122 123 124 125
## 0.041276127 0.021382201 0.039066360 0.056839625 0.026916643
## 126 127 128 129 130
## 0.059286386 0.048044486 0.074539391 0.079925351 0.123555960
## 131 132 133 134 135
## 0.323591116 0.128787657 0.021784255 0.021430313 0.121233912
## 136 137 138 139 140
## 0.140351465 0.081686765 0.080744510 0.053169580 0.096458025
## 141 142 143 144 145
## 0.127744975 0.130914573 0.105859961 0.001699597 0.039567999
## 146 147 148 149 150
## 0.085991955 0.079364338 0.074371382 0.086226802 0.049037529
## 151 152 153 154 155
## 0.063945390 0.117413909 0.035727230 0.109651599 0.059974495
## 156 157 158 159 160
## 0.104324316 0.052068810 0.035235836 0.032422676 0.060364201
## 161 162 163 164 165
## 0.068006516 0.172619348 0.170746133 0.029443785 0.029540385
## 166 167 168 169 170
## 0.015170422 0.084822476 0.056898134 0.085222951 0.024341643
## 171 172 173 174 175
## 0.054741121 0.107398335 0.053295969 0.029420780 0.036229460
## 176 177 178 179 180
## 0.092176278 0.048550131 0.078728362 0.092591991 0.038693395
## 181 182 183 184 185
## 0.018883138 0.038350569 0.042581405 0.038474303 0.023212745
## 186 187 188 189 190
## 0.083181022 0.144283966 0.035368442 0.058273478 0.020144811
## 191 192 193 194 195
3
## 0.072092926 0.013574145 0.085529217 0.076189229 0.091166342
## 196 197 198 199 200
## 0.252546077 0.088750827 0.368615111 0.077587130 0.075699531
## 201 202 203 204 205
## 0.090949566 0.208493410 0.105717288 -0.000533255 0.249551248
## 206 207 208 209 210
## 0.085167668 0.129824466 0.027673612 0.077444448 0.139613076
## 211 212 213 214 215
## 0.318675887 0.015282752 0.073725744 0.078902430 0.073697552
## 216 217 218 219 220
## 0.195310925 0.195029487 0.053908628 0.086935114 0.009942154
## 221 222 223 224 225
## 0.062965097 0.142364332 0.012293135 0.063887472 0.312969039
## 226 227 228 229 230
## 0.160067128 0.056967522 0.228764639 0.031508745 0.131429003
## 231 232 233 234 235
## 0.222464312 0.223424855 0.185299901 0.050734606 0.185346302
## 236 237 238 239 240
## 0.115079447 0.069571321 0.119554978 0.071766978 0.111983227
## 241 242 243 244 245
## 0.214351264 0.029049366 0.042517478 0.087912279 0.048054601
## 246 247 248 249 250
## 0.151666017 0.053766103 0.038967702 0.020957993 0.019959893
## 251 252 253 254 255
## 0.026871676 0.035843600 0.026101353 0.256582892 0.099687908
## 256 257 258 259 260
## 0.119433181 0.196222456 0.119811602 0.090002108 0.107603627
## 261 262 263 264 265
## 0.101644046 0.035834332 0.028407850 0.069964605 0.039280632
## 266 267 268 269 270
## 0.127843935 0.052368189 0.085909558 0.120783113 0.072057826
## 271 272 273 274 275
## 0.051028973 0.077276447 0.026610008 0.023447421 0.049813392
## 276 277 278 279 280
## 0.030823804 0.050077302 0.148805161 0.103889542 0.081591341
## 281 282 283 284 285
## 0.118742163 0.135124404 0.149371409 0.106368373 0.098163375
## 286 287 288 289
## 0.077650054 0.050969890 0.078311214 0.171643330
fst2=gg2$FST # overall locus: mean
fst2
## [1] 0.07931026
## Compare
plot(fstloc1,fstloc2) ## compare Wright's Fst & Cockerham's theta
4
0.00 0.05 0.10 0.15 0.20 0.25
0.00.10.20.3
fstloc1
fstloc2
cor.test(fstloc1,fstloc2) ## Correlation test
##
## Pearson's product-moment correlation
##
## data: fstloc1 and fstloc2
## t = 68.9918, df = 287, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.9637612 0.9770505
## sample estimates:
## cor
## 0.9711504
5

More Related Content

PDF
Tablas%20estadisticas[1]
PDF
Antaryami
PPTX
La computadora y sus partes
DOCX
Brandy Moore
PDF
PDF
Survey Research (SOC2029). Seminar 8: formulating a research question
PDF
Survey Research (SOC2029). Seminar 4: measuring concepts
PDF
The function of_mangrov
Tablas%20estadisticas[1]
Antaryami
La computadora y sus partes
Brandy Moore
Survey Research (SOC2029). Seminar 8: formulating a research question
Survey Research (SOC2029). Seminar 4: measuring concepts
The function of_mangrov

Viewers also liked (8)

PPTX
Olivia's Food Chain Story
PDF
Gasto energético
PPTX
Runs of Homozygosity presentation
PPT
Leadership communications in difficult times
PDF
A Business Guide to Visual Communication
PDF
PDF
PPTX
Professional communication
Olivia's Food Chain Story
Gasto energético
Runs of Homozygosity presentation
Leadership communications in difficult times
A Business Guide to Visual Communication
Professional communication
Ad

More from Jinseob Kim (20)

PDF
Unsupervised Deep Learning Applied to Breast Density Segmentation and Mammogr...
PDF
Fst, selection index
PDF
Why Does Deep and Cheap Learning Work So Well
PDF
괴델(Godel)의 불완전성 정리 증명의 이해.
PDF
New Epidemiologic Measures in Multilevel Study: Median Risk Ratio, Median Haz...
DOCX
가설검정의 심리학
PDF
Win Above Replacement in Sabermetrics
PDF
Regression Basic : MLE
PDF
iHS calculation in R
PDF
Selection index population_genetics
PDF
질병부담계산: Dismod mr gbd2010
PDF
DALY & QALY
PDF
Case-crossover study
PDF
Generalized Additive Model
PDF
Deep Learning by JSKIM (Korean)
PDF
Machine Learning Introduction
PDF
Tree advanced
PDF
Deep learning by JSKIM
PDF
Main result
PDF
Multilevel study
Unsupervised Deep Learning Applied to Breast Density Segmentation and Mammogr...
Fst, selection index
Why Does Deep and Cheap Learning Work So Well
괴델(Godel)의 불완전성 정리 증명의 이해.
New Epidemiologic Measures in Multilevel Study: Median Risk Ratio, Median Haz...
가설검정의 심리학
Win Above Replacement in Sabermetrics
Regression Basic : MLE
iHS calculation in R
Selection index population_genetics
질병부담계산: Dismod mr gbd2010
DALY & QALY
Case-crossover study
Generalized Additive Model
Deep Learning by JSKIM (Korean)
Machine Learning Introduction
Tree advanced
Deep learning by JSKIM
Main result
Multilevel study
Ad

Fst in R

  • 1. fst.R secondmath Tue Oct 28 20:12:47 2014 ############## 2014 SNU GEPI population genetics by Jinseob Kim ################### ############## 1. Fst calculation ################################################## ## Load package & Set directory library(hierfstat) ## Loading required package: gtools ## Loading required package: ade4 setwd("/home/secondmath/Dropbox/GSPH/myteaching/pop_gene/") ## Read example file. 7 pop & 289 SNPs (PER3 gene) a=read.table("fstexample.txt",header=T) a[1:10,1:10] # see data ## pop rs2001142 rs1894654 rs2071924 rs17350193 rs6662782 rs11120896 ## 1 SASIA 22 44 33 24 11 33 ## 2 SASIA 44 24 33 44 13 13 ## 3 SASIA 44 22 33 44 11 11 ## 4 SASIA 44 22 33 44 11 33 ## 5 SASIA 44 22 13 44 13 13 ## 6 SASIA 24 44 33 44 13 33 ## 7 SASIA 44 22 13 44 13 33 ## 8 SASIA 24 24 33 44 11 33 ## 9 SASIA 24 24 33 44 11 13 ## 10 SASIA 44 24 13 44 33 33 ## rs9660884 rs12410983 rs10489142 ## 1 33 11 11 ## 2 13 11 13 ## 3 33 11 11 ## 4 33 11 11 ## 5 33 11 11 ## 6 13 11 13 ## 7 11 13 13 ## 8 NA 13 11 ## 9 33 11 11 ## 10 11 11 33 ## Basic stat: original Fst gg=basic.stats(a) perloc1=gg$perloc # per locus statistics head(perloc1) 1
  • 2. ## Ho Hs Ht Dst Htp Dstp Fst Fstp Fis ## rs2001142 0.2722 0.2807 0.2964 0.0158 0.2990 0.0184 0.0531 0.0615 0.0300 ## rs1894654 0.3299 0.3369 0.3540 0.0172 0.3569 0.0200 0.0485 0.0561 0.0208 ## rs2071924 0.3772 0.3910 0.4215 0.0305 0.4266 0.0356 0.0724 0.0834 0.0353 ## rs17350193 0.0498 0.0528 0.0551 0.0023 0.0555 0.0026 0.0409 0.0474 0.0568 ## rs6662782 0.3988 0.4168 0.4480 0.0312 0.4532 0.0365 0.0697 0.0804 0.0432 ## rs11120896 0.3645 0.3896 0.3923 0.0027 0.3928 0.0032 0.0069 0.0080 0.0645 ## Dest ## rs2001142 0.0255 ## rs1894654 0.0302 ## rs2071924 0.0584 ## rs17350193 0.0028 ## rs6662782 0.0625 ## rs11120896 0.0052 fstloc1=perloc1$Fst # per locus Fst all1=gg$overall # overall locus statistics all1 ## Ho Hs Ht Dst Htp Dstp Fst Fstp Fis Dest ## 0.2823 0.3071 0.3316 0.0245 0.3357 0.0286 0.0740 0.0853 0.0807 0.0413 fst1=all1[7] # overall locus Fst ## Weir & Cockerham's theta gg2=wc(a) fstloc2=gg2$per.loc$FST # per locus fst fstloc2 ## 1 2 3 4 5 ## 0.052426375 0.051901748 0.064390803 0.044631901 0.061101023 ## 6 7 8 9 10 ## 0.010805742 0.084424434 0.019530769 0.042595316 0.024048371 ## 11 12 13 14 15 ## 0.093010994 0.042172548 0.039478819 0.192633459 0.044971892 ## 16 17 18 19 20 ## 0.070157956 0.244806030 0.038940279 0.049389356 0.022615752 ## 21 22 23 24 25 ## 0.033183043 0.084127700 0.092273438 0.081908731 0.058302092 ## 26 27 28 29 30 ## 0.038110973 0.060156731 0.039210191 0.055371303 0.117279665 ## 31 32 33 34 35 ## 0.087762303 0.026666092 0.030153663 0.046526129 0.066012782 ## 36 37 38 39 40 ## 0.061041214 0.065332626 0.052962014 0.075426081 0.075463795 ## 41 42 43 44 45 ## 0.143851689 0.022441398 0.160989656 0.085724512 0.159376136 ## 46 47 48 49 50 ## 0.028792527 0.031761370 0.082197528 0.028375636 0.083978371 ## 51 52 53 54 55 ## 0.106743349 0.027738761 0.023558877 0.054323945 0.098209168 ## 56 57 58 59 60 2
  • 3. ## 0.150600548 0.031533695 0.148855507 0.061552962 0.019935431 ## 61 62 63 64 65 ## 0.016629213 0.006049883 0.041119269 0.006287292 0.051063811 ## 66 67 68 69 70 ## 0.038257279 0.011084482 0.013817984 0.030726323 0.069563187 ## 71 72 73 74 75 ## 0.045359467 0.080328008 0.179663626 0.154162874 0.036787540 ## 76 77 78 79 80 ## 0.156474076 0.059713676 0.149472370 0.084625996 0.064651443 ## 81 82 83 84 85 ## 0.028755981 0.077093453 0.065962172 0.037836763 0.117841464 ## 86 87 88 89 90 ## 0.042180940 0.026789562 0.042122817 0.048523877 0.094996177 ## 91 92 93 94 95 ## 0.024541259 0.040236171 0.057711277 0.192378574 0.112027893 ## 96 97 98 99 100 ## 0.071100721 0.040958278 0.039804008 0.098646412 0.013432562 ## 101 102 103 104 105 ## 0.095766221 0.160937898 0.069724684 0.064214996 0.082597542 ## 106 107 108 109 110 ## 0.039028556 0.054556318 0.021502018 0.077457039 0.063175584 ## 111 112 113 114 115 ## 0.039896285 0.037271113 0.010461731 0.043870960 0.043724436 ## 116 117 118 119 120 ## 0.077800288 0.027988693 0.080775828 0.008932556 0.017080343 ## 121 122 123 124 125 ## 0.041276127 0.021382201 0.039066360 0.056839625 0.026916643 ## 126 127 128 129 130 ## 0.059286386 0.048044486 0.074539391 0.079925351 0.123555960 ## 131 132 133 134 135 ## 0.323591116 0.128787657 0.021784255 0.021430313 0.121233912 ## 136 137 138 139 140 ## 0.140351465 0.081686765 0.080744510 0.053169580 0.096458025 ## 141 142 143 144 145 ## 0.127744975 0.130914573 0.105859961 0.001699597 0.039567999 ## 146 147 148 149 150 ## 0.085991955 0.079364338 0.074371382 0.086226802 0.049037529 ## 151 152 153 154 155 ## 0.063945390 0.117413909 0.035727230 0.109651599 0.059974495 ## 156 157 158 159 160 ## 0.104324316 0.052068810 0.035235836 0.032422676 0.060364201 ## 161 162 163 164 165 ## 0.068006516 0.172619348 0.170746133 0.029443785 0.029540385 ## 166 167 168 169 170 ## 0.015170422 0.084822476 0.056898134 0.085222951 0.024341643 ## 171 172 173 174 175 ## 0.054741121 0.107398335 0.053295969 0.029420780 0.036229460 ## 176 177 178 179 180 ## 0.092176278 0.048550131 0.078728362 0.092591991 0.038693395 ## 181 182 183 184 185 ## 0.018883138 0.038350569 0.042581405 0.038474303 0.023212745 ## 186 187 188 189 190 ## 0.083181022 0.144283966 0.035368442 0.058273478 0.020144811 ## 191 192 193 194 195 3
  • 4. ## 0.072092926 0.013574145 0.085529217 0.076189229 0.091166342 ## 196 197 198 199 200 ## 0.252546077 0.088750827 0.368615111 0.077587130 0.075699531 ## 201 202 203 204 205 ## 0.090949566 0.208493410 0.105717288 -0.000533255 0.249551248 ## 206 207 208 209 210 ## 0.085167668 0.129824466 0.027673612 0.077444448 0.139613076 ## 211 212 213 214 215 ## 0.318675887 0.015282752 0.073725744 0.078902430 0.073697552 ## 216 217 218 219 220 ## 0.195310925 0.195029487 0.053908628 0.086935114 0.009942154 ## 221 222 223 224 225 ## 0.062965097 0.142364332 0.012293135 0.063887472 0.312969039 ## 226 227 228 229 230 ## 0.160067128 0.056967522 0.228764639 0.031508745 0.131429003 ## 231 232 233 234 235 ## 0.222464312 0.223424855 0.185299901 0.050734606 0.185346302 ## 236 237 238 239 240 ## 0.115079447 0.069571321 0.119554978 0.071766978 0.111983227 ## 241 242 243 244 245 ## 0.214351264 0.029049366 0.042517478 0.087912279 0.048054601 ## 246 247 248 249 250 ## 0.151666017 0.053766103 0.038967702 0.020957993 0.019959893 ## 251 252 253 254 255 ## 0.026871676 0.035843600 0.026101353 0.256582892 0.099687908 ## 256 257 258 259 260 ## 0.119433181 0.196222456 0.119811602 0.090002108 0.107603627 ## 261 262 263 264 265 ## 0.101644046 0.035834332 0.028407850 0.069964605 0.039280632 ## 266 267 268 269 270 ## 0.127843935 0.052368189 0.085909558 0.120783113 0.072057826 ## 271 272 273 274 275 ## 0.051028973 0.077276447 0.026610008 0.023447421 0.049813392 ## 276 277 278 279 280 ## 0.030823804 0.050077302 0.148805161 0.103889542 0.081591341 ## 281 282 283 284 285 ## 0.118742163 0.135124404 0.149371409 0.106368373 0.098163375 ## 286 287 288 289 ## 0.077650054 0.050969890 0.078311214 0.171643330 fst2=gg2$FST # overall locus: mean fst2 ## [1] 0.07931026 ## Compare plot(fstloc1,fstloc2) ## compare Wright's Fst & Cockerham's theta 4
  • 5. 0.00 0.05 0.10 0.15 0.20 0.25 0.00.10.20.3 fstloc1 fstloc2 cor.test(fstloc1,fstloc2) ## Correlation test ## ## Pearson's product-moment correlation ## ## data: fstloc1 and fstloc2 ## t = 68.9918, df = 287, p-value < 2.2e-16 ## alternative hypothesis: true correlation is not equal to 0 ## 95 percent confidence interval: ## 0.9637612 0.9770505 ## sample estimates: ## cor ## 0.9711504 5