Intuition : nous verrons une baisse du taux de yeux bleus jusqu’à un certain seuil pour une population importante. Pour une population faible : disparition des yeux bleus ou des yeux marrons après un certain temps due à la forte influence de l’aléatoire.

``````set.seed(150)
nextGen = function(Po){
P = nrow(Po)
fm = matrix(nrow = 0, ncol = 2)
for(i in 1:P)
fm = rbind(fm, sample(1:P,2))
Af = cbind(fm[,1],sample(1:2,P,T))
Am = cbind(fm[,2],sample(1:2,P,T))
cbind(Po[Af],Po[Am])
}

count = function(Po){
c(sum(Po[,1] & Po[,2]),sum(!Po[,1] & !Po[,2]))
}

init = function(P,I,BB0,MM0){
P0 = cbind(rep(T,P),rep(F,P))
for(i in 1:BB0)
P0[i,2]=T
for(i in 1:MM0)
P0[i+BB0,1]=F
P0
}

draw = function(P,I,BB,MM){
plot(c(0,I),c(0,1),type="n",xlab="Generation", ylab="", cex.axis = 0.5, cex.lab = 0.5)
polygon(c(c(0,I),c(I,0)),c(c(0,0),c(1,1)), col="burlywood")
polygon(c(0:I,rev(0:I)),c(BB/P,rep(0,I+1)), col="skyblue")
polygon(c(0:I,rev(0:I)),c(1-MM/P,rep(1,I+1)), col="tan4")
}

simulation = function(P,I,BB0,MM0){
BB = numeric(I+1)
MM = numeric(I+1)

Pi = init(P,I,BB0,MM0)
C = count(Pi)
BB[1] = C[1]
MM[1] = C[2]
for(i in 1:I){
Pi = nextGen(Pi)
C = count(Pi)
BB[i+1] = C[1]
MM[i+1] = C[2]
}
draw(P,I,BB,MM)
}``````

Question 1

``````for(i in 1:4)
simulation(P=20,I=20,BB0=4,MM0=12)``````

``````for(i in 1:4)
simulation(P=20,I=20,BB0=12,MM0=4)``````

``````for(i in 1:4)
simulation(P=20,I=20,BB0=5,MM0=5)``````

``````for(i in 1:4)
simulation(P=20,I=100,BB0=5,MM0=5)``````