gbradburd / SpaceMix

29 stars 10 forks source link

Chains not mixing #15

Open renhamm opened 1 year ago

renhamm commented 1 year ago

When running my Spacemix Model, I don't think my chains are mixing correctly (no fuzzy caterpillar). In other packages, I have tried running the model longer, but that hasn't seem to improve anything. How can I go about optimizing the run.spacemix.analysis parameters to fix this? Below I have included my run code and various troubleshooting graphs

run.spacemix.analysis(n.fast.reps = 10, fast.MCMC.ngen = 1e5, fast.model.option = "source_and_target", long.model.option = "source_and_target", data.type = "sample.frequencies", sample.frequencies = allele.frequencies, mean.sample.sizes = mean.sample.sizes, counts = NULL, sample.sizes = NULL, sample.covariance= NULL, target.spatial.prior.scale=NULL, source.spatial.prior.scale=NULL, spatial.prior.X.coordinates = LonLat_sorted[,1], spatial.prior.Y.coordinates = LonLat_sorted[,2], round.earth = TRUE, long.run.initial.parameters=NULL, k = nrow(allele.frequencies), loci = ncol(allele.frequencies), ngen = 1e6, printfreq = 1e2, samplefreq = 1e3, mixing.diagn.freq = 50, savefreq = 1e5, directory=NULL, prefix = "G4t90_110")

image image image image image image

gbradburd commented 1 year ago

SpaceMix uses an "auto-tuning" approach to adaptively update the scale of the various tuning parameters to aim for an optimal acceptance ratio (that's why the acceptance rate plot for the nugget parameters looks kind of like a dampened sine wave converging on 45%). So, if you're not seeing good mixing behavior, there's not much you can tweak to change the acceptance rate. You could try one of a few alternative approaches:

  1. increase the number of iterations. maybe the chain just needs more time?
  2. increase the number of "fast" initial runs, which may help the longer chain find a reasonable area of parameter space to explore.
  3. If you go with route 1, you could start from the last location in parameter space from another long run
  4. From the plot of the nugget parameters, it looks like you have a lot of samples. You could try dropping some, or collapsing some into a multi-individual sample (e.g., by location), which will certainly make things go faster, and may help improve mixing as well.

Sorry I don't see an easy fix here!