Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chains not mixing #15

Open
renhamm opened this issue Nov 21, 2023 · 1 comment
Open

Chains not mixing #15

renhamm opened this issue Nov 21, 2023 · 1 comment

Comments

@renhamm
Copy link

renhamm commented Nov 21, 2023

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
Copy link
Owner

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants