### Name: mcmcFmodel
### Title: Inference in a spatial statistical model
### Aliases: mcmcFmodel


### ** Examples

  # Below is a sequence 
  # of R commands using Geneland functions

  # we assume that Geneland is installed
  # and loaded by library("Geneland")

 # Simulation of a dataset made of 2 populations
 # 5 loci and 10 alleles per locus
 # on a spatial domain enclosed in a rectangle
 # (x coord. in [0,3], y coord. in [0,1])
 # domain of populations are centered around 
 # points (0.5,0.5) and (2.5,0.5) respectively 
 # (so that the boundary is the vertical line x = 1.5)
sim = simFmodel(nindiv=100,
          coord.lim=c(0,3,0,1),
          number.nuclei=2,
          coord.nuclei=cbind(c(0.5,0.5),c(2.5,0.5)),
          color.nuclei=c(1,2),
          nall=rep(10,5),
          npop=2,
          drift=c(.3,.3),
          plots=FALSE,
          ploth=FALSE,
          seed=123)

  # you can check the simulated dataset by
ls()  ## gives a list of existing objects

summary(sim) ## describes what object sim actually contains

  #  define a place for MCMC outputs
path.mcmc = paste(tempdir(),"/",sep="")

## Not run: 
##D   # First run of MCMC algorithm
##D   # in order to get the posterior mode of the number of populations
##D 
##D mcmcFmodel(sim$coordinates,
##D            sim$genotypes,
##D            path.mcmc=path.mcmc,
##D            rate.max=100,
##D            delta.coord=0,
##D            npopmin=1,
##D            npopinit=5,
##D            npopmax=10,
##D            nb.nuclei.max=200,
##D            nit=50000,
##D            thinning=50,
##D            freq.model="Dirichlet",
##D            varnpop=TRUE,
##D            spatial=TRUE)
##D 
##D   # Trace of number of populations
##D   # Should display a mode at 2
##D Plotnpop(path.mcmc)
##D 
##D  # Then re-run the chain with fixed number of populations
##D mcmcFmodel(sim$coordinates,
##D            sim$genotypes,
##D            path.mcmc=path.mcmc,
##D            rate.max=100,
##D            delta.coord=0,
##D            npopmin=1,
##D            npopinit=2,
##D            npopmax=2,
##D            nb.nuclei.max=200,
##D            nit=5000,
##D            thinning=10,
##D            freq.model="Dirichlet",
##D            varnpop=FALSE,
##D            spatial=TRUE)
##D 
##D    # Post-processing the chain 
##D PostProcessChain(sim$coordinates,sim$genotypes,
##D                   path.mcmc=path.mcmc,
##D                   nxdom=50,
##D                   nydom=50,
##D                   burnin=0)
##D 
##D    # Plots allele frequencies of allele #1 at locus  #1 in sub-population  #1
##D  PlotFreq(sim$allele.numbers,
##D path.mcmc=path.mcmc,ipop=1,iloc=1,iall=1)
##D 
##D    # Map of posterior probabilites
##D    # of population membership
##D  PlotTessellation(sim$coordinates,path.mcmc=path.mcmc)
##D 
##D    # Map of posterior mode 
##D    # of population membership
##D  PosteriorMode(sim$coordinates,path.mcmc=path.mcmc,
##D                write=FALSE,plotit=TRUE)
##D 
##D  # read the estimated population for indivuals
##D  pppm.indiv <- scan(paste(path.mcmc,"modal.pop.indiv.txt",sep=""))
##D 
##D  # add a plot of the individual colored as their estimated population of origin
##D points(sim$coordinates,col=pppm.indiv,pch=16)
##D 
## End(Not run)




