-
Notifications
You must be signed in to change notification settings - Fork 4
/
AlleleFreqDyn.txt
55 lines (41 loc) · 1.41 KB
/
AlleleFreqDyn.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# AlleleFreqDyn.txt - examines aspects of allele frequency changes under drift for
# purposes of devising tests of departure from neutrality based on observed allele
# frequencies over generations.
# First show single generation allele frequency changes under binomial,
# from random starts
N<-1000
nsamp<-10000
p<-runif(nsamp)
x<-rbinom(nsamp,N,p)
p1<-x/N
delta<-p1-p
plot(p,delta)
# Next use the same bit of code from the Wright-Fisher sim to generate allele
# frequencies of replicate populations under the strict neutrality.
N<-200
nsamp<-8
ngen<-50
startfreq<-.5
pcur<-matrix(1:N)
#Wright-Fisher is simply recurrent binomial sampling over generations
x<-rbinom(nsamp,N,startfreq)
p<-x/N
pcur<-p
for (i in 1:ngen){
x<-rbinom(nsamp,N,p)
p<-x/N
pcur<-rbind(pcur,p)
}
gen<-seq(1,ngen)
for (k in 1:nsamp){
plot(gen,pcur[,k],type="l",ylim=c(0,1))
par(new=TRUE)
}
# ASSIGNMENT 1: For each of the sample data sets, try to devise a way to
# estimate the population size N from the rate of increase in variance in
# allele frequencies over generations.
# In the data sets, columns are distinct SNPs and rows are generations.
# ASSIGNMENT 2: It turns out that the sample data sets each have one SNP
# that deviates from the neutral dynamics. Use whatever test you can
# devise to determine which of the SNPs in the sample data sets appear to
# depart from neutrality.