# \donttest{
##This example will take a little while to run.
#This should be challenging as there are actually 2 stocks and we fit a model with 3.
tmpDat1 <- sim.stock.data( nAnimals=100, nSNP=5000, nSampleGrps=100, K=2, ninform=5000,
sds=c(alpha=1.6,beta.inform=0.75,beta.noise=0.0005))
#EM estimation from Kmeans starting values
tmp <- stockSTRUCTURE( tmpDat1, sample.grps=attr(tmpDat1,"sampleGrps"), K=3, start.grps=NULL)
#in general, you'll want to use as many cores as possible, or close to.
#mc.cores=1 is used here to please the CRAN submission checks
tmpBOOT <- stockBOOT( tmp, B=100, mc.cores=1)
print( round( apply( tmpBOOT$postProbs, FUN=quantile, MARGIN=1:2, probs=c(0.025,0.975))), 5)
#Note that, in this case, the posterior probabilities are not very informative; they could
#be anywhere between 0 and 1. There are likely to be a few individuals, of course, where
#they have a very low chance of belonging to a particular stock (and this is chance). There
#may even some individuals that get assigned to a group with almost certainty.
#Let's visualise it.
plot( tmpBOOT, locations=NULL, plotTitle="Data contains 2 groups, model fits 3")
#You can try it with 2 groups.
#Let's now pretend that there are sampling regions
plot( tmpBOOT, locations=data.frame( locations=rep(1:4, each=25),
order=rep( c(4,3,1,2), each=25)), plotTitle="Plot with grouping")
# }
Run the code above in your browser using DataLab