Examples used during the lectures

Day 3

Moran model -- fecundity altruism

Clear["Global`*"];

(* relatedness in Moran Model in a monomorphic population *)
r ==((n-1)/n)((n-2)/(n-1))r+(1-((n-1)/n)((n-2)/(n-1))) (1-m)((1/n)+((n-1)/n)r)   ;
solr = Flatten@Solve[%,r] //FullSimplify

((1-m)/(1+m (-1+n))) == ((1-m)/(1+m (n-1))) ;

(* usual expansion relatedness in Moran Model in a monomorphic population *)
r ==((n-1)/n)r+(1/n) (1-m)((1/n)+((n-1)/n)r)   ;
Flatten@Solve[%,r] //FullSimplify

(* individual fitness on terms of fecundity *)
w =((n-1)/n) +(1/n) ((( (1-m)fFocal)/((1-m)(fFocal +f1+(n-2)fRes )/n+ m  f  ))+((m fFocal  )/f)) ;

(* fitness where the trait is an altruistic trait with effect in fecundity *)
w =w  /. fFocal -> 1+ δ b  (((z1+(n-2)x ))/(n-1)) - δ c  zfocal  /. f1 -> 1+ δ b  (((zfocal+(n-2)x ))/(n-1)) - δ c z1  /. fRes ->  1+ δ b  (((zfocal+z1+(n-3)x ))/(n-1)) - δ c x /. f ->  1+ δ b  x - δ c x  ;

w /. zfocal -> x /. z1-> x   //Simplify

(* Selection gradient *)
Sg = D[w,zfocal] + (n-1)r D[w,z1]/. zfocal -> x /. z1-> x  /. solr  //Simplify   ;
Series[%,{δ,0,1}]  //Normal     ;

% ==(( m (n+1-m) (n-1) δ)/(n+m (n-1) n))(b((1-m)/(n+1-m))-c) // Simplify

Plot[Evaluate[{((1-m)/(n+1-m)),((1-m)/(1+m (-1+n)))}/. n->10],{m,0,1},PlotRange->{0,1},AxesLabel->{m}]

Wright Fisher -- Cancellation result

Clear["Global`*"];

(* relatedness in WF Model in a monomorphic population *)
r == (((1-m))^2) ((1/n)+((n-1)/n)r) ;
Solve[% , r ] //FullSimplify

-((((-1+m))^2)/(-1+(-2+m) m (-1+n))) == ((((1-m))^2)/(1+(n-1)(2-m) m ))  //Simplify

w = (((1-m)ffocal)/((1-m)( ffocal+fneighbour+(n-2)fRes )/n +m f)) + ((m ffocal)/f)  ;

w /. ffocal-> f /. fneighbour -> f  /. fRes-> f //Simplify

(* scale of competition -- note : same as in Moran *)
((-(n-1)D[w,fneighbour] )/(D[w,ffocal]))  /. ffocal-> f /. fneighbour -> f  /. fRes-> f //FullSimplify  ;

% ==(((((1-m))^2) (n-1))/(n-(((1-m))^2)  ))  //Simplify

(* Scaled relatedness *)
(1/( 1- r a )) (r-(a/(n-1))(1+r(n-2) ) )/. r->((((1-m))^2)/(1+(n-1)(2-m) m )) /. a-> (((((1-m))^2) (n-1))/(n-(((1-m))^2)  ))  //FullSimplify

Reciprocity in well mixed population

General selection gradient

Clear["Global`*"];

fmut = 1 + δ b a[x,y] - δ c a[y,x]  //Simplify  ; 
fres  = 1 + δ b a[y,x] -δ  c a[x,y]  /.y->x  //Simplify ;
W = (fmut/fres)  //Simplify

S = D[W,y] /. y-> x  //Simplify   ;
Series[%,{δ,0,1}]  //Normal   ;
% /. δ-> 1  ;

% ==Derivative[1,0][a][x,x]( b λ -c ) /. λ -> ((Derivative[0,1][a][x,x])/(Derivative[1,0][a][x,x])) //Simplify

where λ is the responsiveness coefficient : it quantifies how much a trait change in the mutant elicits a change in the contribution or action of its partner, relative to the change it elicits in its own contribution.

The evolution of reciprocity

Clear["Global`*"];

((d ay)/dt) == a0 - ay + y ax ; 
((d ax)/dt) ==a0-ax + x  ay   ;

solSys=Flatten@Solve[{ a0 - ay + y ax ==0 ,a0-ax + x  ay   == 0 },{ay,ax}] //Simplify

sol = DSolve[{ ay'[t]==a0 - ay[t] + y ax[t]  ,ax'[t]== a0-ax[t] + x  ay[t]  ,ay[0]==0 ,ax[0] ==0  } /.a0->10 /. x->0.2 /.y->0.5 ,{ay,ax},t]
Plot[Evaluate[{ay[t],ax[t]}/.sol /.a-> 10],{t,0,20},PlotRange->All]

fmut = 1 + δ b ax - δ c ay /. solSys  //Simplify  ; 
fres  = 1 + δ b  ay -δ  c ax /. solSys   /.y->x //Simplify ;
W = (fmut/fres)  //Simplify

S = D[W,y] /. y-> x  //Simplify 
Series[%,{δ,0,1}]

sing = Flatten@Solve[S ==0,x]

J = D[S,x] /.sing  //Simplify

D[f[g[x]],x]