The simplest IBD model

30 views
Skip to first unread message

Lidia Dell'Elba

unread,
Dec 7, 2025, 9:57:10 PM (8 days ago) Dec 7
to slim-discuss

Hello everyone!

I’m using SLiM for my Master’s thesis in Statistics, and I'm still quite new to the software  (I've been learning and experimenting for about a month now). I'm trying to build a spatial model with Isolation by Distance (IBD).  I'm running into a problem that I cannot quite understand, and I would be very grateful for your help.

I want to simulate a neutral population on a 2D landscape where spatial genetic patterns depend only on the movement parameter SIGMA_MIG. I don't want spatial competition or spatial density regulation in the model. Now the individuals in my simulation tend to form spatial cluster over time, and I can see this clearly in the snapshot. The SLiM manual refers to this behavior in Section 17.1 “A simple 2D continuous-space model”, and according to the manual, clustering often appears unless some form of spatial competition is included. However, I would like to avoid spatial competition entirely, I want mobility and IBD to be driven only by SIGMA_MIG, without local density regulation.

My question is: "Is there a recommended way to prevent the formation of spatial clusters without introducing spatial competition?". And also I noticed that the dispersion of the individuals depends on the dispersal sigma, but I would like the mobility to depend only on the SIGMA_MIG.

So, this is the code I'm using (now I'm sampling at the final generation but I also tried a stochastic sampling): 

initialize() {
    initializeSLiMModelType("nonWF");
    initializeSLiMOptions(dimensionality="xy", nucleotideBased=T);
    defineConstant("L", 1e6);
    initializeMutationTypeNuc("m1", 0.5, "f", 0.0);
    m1.convertToSubstitution = F;
    initializeGenomicElementType("g1", m1, 1.0,
        mutationMatrix = mmKimura(1.2e-8, 4e-9));
    initializeGenomicElement(g1, 0, L-1);
    initializeRecombinationRate(1e-8);
    initializeAncestralNucleotides(randomNucleotides(L));
    defineConstant("W", 100.0);

    defineConstant("SIGMA_MIG", 0.05); //this is the parameter I'm trying to study

    defineConstant("SIGMA_MATING", 1.0);
    defineConstant("SIGMA_DISP", 1.0);
    initializeInteractionType("i2", "xy", reciprocal=T, maxDistance=SIGMA_MATING * 3);
    i2.setInteractionFunction("n", 1.0, SIGMA_MATING);
    defineConstant("FINAL_GEN", 10000);

defineConstant("K",1000);  //carrying capacity

}


1 late() {
    sim.addSubpop("p1", 10000);
    p1.setSpatialBounds(c(0.0, 0.0, W, W));
    p1.individuals.setSpatialPosition(p1.pointUniform(10000));
    p1.individuals.age = 0;
    writeFile(OUT_DIR + "sample_metadata_all.txt", "sampleID\tx\ty\tgeneration\ttimepoint\n", append=F);
    writeFile(OUT_DIR + "spatial_samples_all.fasta", "", append=F);
}

2 early() {
    inds = p1.individuals;
    pos = inds.spatialPosition;
    offsets = rnorm(2 * inds.size(), 0.0, SIGMA_MIG);
    newPos = pos + offsets;
    p1.individuals.setSpatialPosition(p1.pointReflected(newPos));
    i2.evaluate(p1);
}

late() { i2.evaluate(p1); }

reproduction() {
    if (p1.individualCount > K * 2)
        return;
    mate = i2.drawByStrength(individual, 1);
    if (size(mate) > 0)
        offspring = subpop.addCrossed(individual, mate);

    else { // here I tried to fight the clustering but I don't know if it's the right thing to do (anyway the clumping effect is still there)
        mate = subpop.sampleIndividuals(1, exclude=individual);

        if (size(mate) > 0)
            offspring = subpop.addCrossed(individual, mate);
        else
            return;
    }
    pos = individual.spatialPosition + rnorm(2, 0, SIGMA_DISP);
    offspring.setSpatialPosition(p1.pointReflected(pos));
}

late() { p1.individuals.fitnessScaling = 1.0; }

survival() {
    N = p1.individualCount;
    survivalProb = K / N;
    if (survivalProb > 1.0) survivalProb = 1.0;
    return runif(1) < survivalProb;
}

FINAL_GEN late() {
    sampleSize = 300;
    if (p1.individualCount < sampleSize)
        sampled_inds = p1.individuals;
    else
        sampled_inds = sample(p1.individuals, sampleSize);
    for (ind in sampled_inds) {
        sampleID = "gen" + sim.cycle + "_ind" + ind.index;
        seq = ind.haploidGenome1.nucleotides();
        writeFile(OUT_DIR + "spatial_samples_all.fasta", ">" + sampleID + "\n" + seq, append=T);
        info = sampleID + "\t" +
               ind.spatialPosition[0] + "\t" +
               ind.spatialPosition[1] + "\t" +
               25 * (sim.cycle - ind.age) + "\t" +
               sim.cycle;
        writeFile(OUT_DIR + "sample_metadata_all.txt", info, append=T);
    }
    sim.simulationFinished();
}

I have a background in statistics, but not in population genetics, so I apologize if my explanation is not completely clear. This is my first time using SLiM, and I just want to make sure I'm not missing a more appropriate modelling strategy in SLiM.

Thank you very much for your time and help!

Best,

Lidia Dell'Elba

Ben Haller

unread,
Dec 7, 2025, 10:21:50 PM (8 days ago) Dec 7
to slim-d...@googlegroups.com
Hi Lidia,

Consider an initial population that is randomly, uniformly distributed across space.  If some of those individuals have no offspring and some have several, due to chance, you will immediately – in one generation – have a non-random spatial distribution with clusters and holes.  In each subsequent generation, some individuals will again have no offspring and some will have several, producing further clustering and holes, and further non-uniformity.  This is analogous to genetic drift: some alleles rise in frequency and some are lost, again because of the demographic stochasticity that some individuals have multiple offspring and some have none (this is a bit of a hand-wavy approximation really, but close enough).

In the real world, I think this is generally offset by spatial competition, or more generally by spatial density regulation.  This doesn't prevent the seeds of clustering from occurring; but it tends to fill in the holes and smooth out the clusters.  Maybe this is analogous to negative frequency-dependent selection, promoting rare alleles and selecting against very common ones; or maybe I'm trying to stretch the analogy too far.  :->

If you don't want spatial density regulation in the form of competition or a similar ecological effect, then you would need to enforce some other kind of spatial uniformity from the top down, I think.  A very interesting possibility is something like the model of Chotai, Wei, and Messer (2025), at https://doi.org/10.1093/genetics/iyaf183.  Maybe that model will be interesting to you.  If there is no mechanism forcing the dynamics of the model towards a uniform spatial distribution, then clustering will inevitably occur, or so it seems to me.  So you'll need to decide what that mechanism ought to be.  But maybe that paper I cited will be useful to you, if you don't want it to be competition.  :->

Good luck and happy modeling!

Cheers,
-B.

Benjamin C. Haller
Messer Lab
Cornell University
--
SLiM forward genetic simulation: http://messerlab.org/slim/
Before posting, please read http://benhaller.com/slim/bugs_and_questions.html
---
You received this message because you are subscribed to the Google Groups "slim-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to slim-discuss...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/slim-discuss/ed9a4dd8-7c50-484d-9435-e754083b26c9n%40googlegroups.com.

Lidia Dell'Elba

unread,
Dec 10, 2025, 9:22:18 PM (5 days ago) Dec 10
to slim-discuss

Hi Ben,

Thank you very much for your clear and quick reply , it helped me understand better why the clustering appears so quickly in my simulations.

I tried implementing the model from Chotai, Wei and Messer as you suggested, and it indeed solves the issue of cluster formation by enforcing a uniform spatial distribution. However, for the purposes of my Master’s thesis I actually need to estimate the physical mobility of individuals from the genetic data. Because of that, constraining individuals to fixed cells in a grid would remove exactly the kind of spatial movement that I'm trying to study. So I guess I will accept the presence of some clustering as a consequence of neutral spatial dynamics, since movement is the component of the process that I want to model.

I have one further question: in this model, is it appropriate to introduce spatial variation in the movement parameter using a function such as the one below?

function (float) localSigma(float x, float y) {

    if (x < 33.0) return 0.5;
    if (x < 66.0) return 1.0;
    return 2.0;
}

My intention is to introduce regions with different levels of mobility, while keeping everything else neutral. Before proceeding, I wanted to check whether this is a conceptually reasonable approach in SLiM.

Thank you again for your very helpful explanation, and I wish you a great day! :)

Best regards,
Lidia Dell’Elba


Ben Haller

unread,
Dec 10, 2025, 9:44:53 PM (5 days ago) Dec 10
to slim-d...@googlegroups.com
Hi Lidia!

OK, your plan seems reasonable, perhaps.  :->  I can't really advise further on that, since all this depends on your research questions, but I don't see a problem with your decision, offhand.  If you decide later on that the clustering is a problem, you can always add competition in to smooth things out.  I'm not sure exactly why you don't want that to be in the model; but presumably you have your reasons.  :->

Regarding your function, I guess your intention is that for a given individual you'd call localSigma() with the x and y of that individual, get a sigma for its dispersal, and then draw x and y deviations from a 2D dispersal kernel of some shape with that sigma?  Sure, I don't see a problem with that, if that's what you want to do.  Note that you could make a SpatialMap object for this, which (a) would be faster than your function, and (b) would let you represent any pattern of spatial heterogeneity in dispersal quite easily, such as by loading a PNG image representing the dispersal map.  But your function is fine if it does what you want it to do.  Happy modeling!


Cheers,
-B.

Benjamin C. Haller
Messer Lab
Cornell University


Peter Ralph

unread,
Dec 11, 2025, 12:18:53 PM (4 days ago) Dec 11
to slim-d...@googlegroups.com, Ben Haller
>My question is: "Is there a recommended way to prevent the formation of spatial clusters without introducing spatial competition?".

I agree with what was said above, but to add a bit more: my first answer to this question is "no", and there's some discussion of this, and a lot more explanation of spatial models, in https://onlinelibrary.wiley.com/doi/full/10.1002/ece3.71098 .

However - if you want to regulate density without competition, then you've got to have external regulation, so you've got to have some external force deciding how many individuals you have. One option for this would be to say that there's some other process that randomly allocates a fixed number of "spots" for individuals to live in each tick, and the only viable offspring will occupy these spots. You could, for instance, sample the locations of these spots uniformly across the landscape, and then choose nearby parents to place their offspring there. This can run into problems if the density/dispersal combination doesn't ensure there's always available parents, but otherwise, it should work fine.

--peter

From: 'Ben Haller' via slim-discuss <slim-d...@googlegroups.com>
Sent: Wednesday, December 10, 2025 6:44 PM
To: slim-d...@googlegroups.com <slim-d...@googlegroups.com>
Subject: Re: The simplest IBD model
 
Hi Lidia! OK, your plan seems reasonable, perhaps. :-> I can't really advise further on that, since all this depends on your research questions, but I don't see a problem with your decision, offhand. If you decide later on that the clustering
ZjQcmQRYFpfptBannerStart
This message originated outside the UO email ecosystem.
Use caution with links and attachments. Learn more about this email warning tag.
 
ZjQcmQRYFpfptBannerEnd

Ben Haller

unread,
Dec 11, 2025, 12:24:39 PM (4 days ago) Dec 11
to Peter Ralph, slim-d...@googlegroups.com
Hi Peter!  Yes, interesting idea.  However, it would interfere with the dispersal protocol that Lidia wants to enforce, as I understand it.  But a neat idea nevertheless, and perhaps useful for some other problem...


Cheers,
-B.

Benjamin C. Haller
Messer Lab
Cornell University


Peter Ralph

unread,
Dec 11, 2025, 12:52:58 PM (4 days ago) Dec 11
to slim-d...@googlegroups.com, Ben Haller
LOL yes, good point. But it illustrates the point, I guess - there is, as far as I know (and I've thought a lot about this question), no good way to have a stable-ish population density and intrinsic dispersal without something like 'competition'. (Note however that the model I proposed does still have a "dispersal" parameter, and one could analyze the realized dispersal distances.)

From: 'Ben Haller' via slim-discuss <slim-d...@googlegroups.com>
Sent: Thursday, December 11, 2025 9:24 AM
To: Peter Ralph <p...@uoregon.edu>; slim-d...@googlegroups.com <slim-d...@googlegroups.com>

Subject: Re: The simplest IBD model
 
Hi Peter! Yes, interesting idea. However, it would interfere with the dispersal protocol that Lidia wants to enforce, as I understand it. But a neat idea nevertheless, and perhaps useful for some other problem. . . Cheers, -B. Benjamin C. Haller
Reply all
Reply to author
Forward
0 new messages