A habit that costs the one doing it and helps others — how could that ever spread? Set up a population that never helps, drop in a helping type, and find where it tips.
An altruism allele is introduced at frequency 0.1 in a population where no one is related to anyone else (r = 0). The allele pays the cost c and gets nothing back from a random partner. With no kin structure, there is nothing for Hamilton's rule to bite on. Each replicate is one possible future.
set.seed(42)N <- 500; gens <- 100; p <- 0.1for (g in 1:gens) p <- rbinom(1,2*N,p)/(2*N)
Pairs of individuals interact. With probability r, each pair shares the altruism allele (they're related). The altruist pays c to give benefit b to its partner. Track allele frequency over generations.
set.seed(42)N <- 500; r <- 0.5; b <- 0.3; cc <- 0.1; p <- 0.2; gens <- 200# Mean fitness of altruist: 1 - c + r*b (recipient has altruist allele w.p. r)# Mean fitness of selfish: 1 + p*r*b (gets benefit from altruistic relatives at rate p*r... simplified)for (g in 1:gens) { w_alt <- 1 - cc + r * b w_sel <- 1 p_new <- p * w_alt / (p * w_alt + (1-p) * w_sel) p <- rbinom(1,2*N,p_new)/(2*N)}
The line r·b = c divides the (b, c) plane into two regions. With r = 0.5, the line is c = 0.5·b: altruism spreads only when the benefit is at least twice the cost. With r = 1 (clones), any net benefit spreads. With r = 0 (strangers), nothing spreads.
r <- 0.5; b <- 0.6; cc <- 0.2r*b > cc # Hamilton's rule satisfied?
Same Hamilton's rule for all three. Different relatedness values for each because of how they inherit DNA:
For each, ask: with a fixed (b, c), which kin is it most worth helping?
# Three inheritance systems; one rule.diploid <- c(sister=0.5, daughter=0.5, brother=0.5)haplo <- c(sister=0.75, daughter=0.5, brother=0.25)clonal <- c(sister=1, daughter=1, brother=1)# Hamilton's rule: helping spreads if r * b > c, regardless of which row you're in.