
Tutorial 2
Purpose: monitoring chains

This repository contains 3 files
README		: This readme
arthro20_aa.nex	: The dataset
clean		: A cleaning script


0) Help menu
../../monitor -h
../../moncorrel -h
../../compchain -h
../../readtopo



1) Start two chains:
../../nhpb -d arthro20_aa.nex -f catbpfree1 -m catbp -y ../../
../../nhpb -d arthro20_aa.nex -f catbpfree2 -m catbp -y ../../



2) After about 30 seconds, first samples are written, then monitor the chains
../../monitor -f catbpfree1
../../monitor -f catbpfree2

This will tell you the number of saved samples, and the elapse time



3) More information in verbose mode (option -v):
../../monitor -f catbpfree1 -v
../../monitor -f catbpfree2 -v

This will give you informations about the proposal moves,
the time spent in each proposal, and the acceptance rates.



4) Obtaining plots and postscript files (with ".ps" extension) displaying the traceplots of some essential statistics (option -p)
../../monitor -f catbpfree1 -p
../../monitor -f catbpfree2 -p

File prefix with "mon_" are produced.
Suffix indicates the monitored distribution:
mon_catbpfree1.logsamp.ps		: Minus log likelihood
mon_catbpfree1.numberBP.ps		: Total number of breakpoints
mon_catbpfree1.length.ps		: Total tree length
mon_catbpfree1.HPrate.ps		: Hyperparameter shape of gamma discretized rate

File without .ps may be used with gnuplot (or excel), which yields a convenient way to evaluate the convergence
of two chains, by comparing their traceplots. For instance, under gnuplot:
> plot "mon_catbpfree1.logsamp", "mon_catbpfree2.logsamp"



5) Remove burnin from .ps plot
../../monitor -f catbpfree1 -p -b 5
../../monitor -f catbpfree2 -p -b 5

Option -b <n> indicates that plot will start from sample <n> (then avoid to show the burnin in .ps).
(For the current dataset, the typical burnin period is from 100 to 1000 first samples)


6) Obtaining more distritributions
../../monitor -f catbpfree1 -pm
../../monitor -f catbpfree2 -pm

Option -m or --moreplot allow the production of these additionnal plots:
mon_catbpfree1.BPstatEnt.ps		: Shanon entropy of mean breakpoint modulators
mon_catbpfree1.rootStatEnt.ps		: Entropy of root modulator (1 under CATBP)
mon_catbpfree1.CATent.ps		: Entropy of CAT profiles
mon_catbpfree1.MixtureEnt.ps		: Entropy of CAT mixture among sites
mon_catbpfree1.NbCAT.ps			: Number of categories (fixed with nhpb)
mon_catbpfree1.rateEnt.ps		: Entropy of RAS (constant with discrete rate categories)
mon_catbpfree1.HPmeanLength.ps		: Hyperparameter mean branch length
mon_catbpfree1.HPnbBP.ps		: Hyperparameter mean number of breakpoints
mon_catbpfree1.HPcenterBPent.ps		: Hyperparameter center of breakpoints modulators
mon_catbpfree1.HPconcentrationBP.ps	: Hyperparameter concentration of modulators around the center
mon_catbpfree1.CATcenterEnt.ps		: Hyperparameter center of CAT profiles
mon_catbpfree1.CATconcentration.ps	: Hyperparameter concentration of profiles around the center



7) Obtaining means, standard deviations, credibility interval and standard errors
../../moncorrel -f catbpfree1 -b 10
../../moncorrel -f catbpfree2 -b 10

Starting after a burnin of 10 sample (normally, this is not enough !!!)

Produced files COV_catbpfree1.general, COV_catbpfree2.general:
The columns denote:
param		: Name of the monitored parameter
mean		: Mean value
SD		: Standard deviation
SE		: Standard error
eff size	: Sample effective size (eff_size * t_decorrel = number_of_samples)
t decorrel	: Decorelation time 
95%CI		: Two bound for the 95% Credibility interval

Some options may provide you plot of auto-correlation times (option -e),
Or statistics on other parameters (statistic per branches, per sites...)

Default analyzed statistics are as for the monitor program:
0 logsamp                       : Minus log likelihood
1 length                        : Total tree length
2 numberBP                      : Total number of breakpoints
3 entropyStatBP                 : Shanon entropy of mean breakpoint modulators
4 entropyRootBP                 : Entropy of root modulator (1 under CATBP)
5 entropyStatMode               : Entropy of CAT profiles
6 entropyModeDistrib            : Entropy of CAT mixture among sites
7 HPentropyCenterStatBP         : Hyperparameter center of breakpoints modulators
8 HPstatBPconcentration         : Hyperparameter concentration of modulators around the center
9 HPmeanNbBP                    : Hyperparameter mean number of breakpoints
10 HPmodeAlpha                  : Hyperparameter concentration of profiles around the center
11 HPmodeCenter                 : Hyperparameter center of CAT profiles
12 HPmeanLength                 : Hyperparameter mean branch length
13 gamma                        : Hyperparameter shape of gamma discretized rate
14 rateent                      : Entropy of RAS (constant with discrete rate categories)


8) comparing two chains and convergence diagnostic:
../../compchain -f catbpfree1 -g catbpfree2 -b 10 -c 3

Use decorrelation times, standard error and 95%CI to estimates goodness of convergences
Output in COMP_catbpfree1_catbpfree2.convergence3SE
Fields are
converged		: Converged yes or no, depending on whether the mean1 falls into mean2+or- 3*SE (default)
name			: Statistic name (as for moncorrel)
absolute_diff		: Absolute difference between means 1 and 2
relative_diff		: Relative differences
(diff*SE)		: Absolute difference in SE units
(SE/SD)			: ratio of standard error on standard deviation, expected to be small (<<1)
95%CI_overlap		: Overlap of the two chain 95%CI, expected to be near 100% (but 70% 90% is good)


9) Obtaining consensus topologies
../../readtopo -c -x 10 1 catbpfree1
../../readtopo -c -x 10 1 catbpfree2

-c for consensus.
-x 10 1 for a burnin of 10, and a tree got each 1 samples.
produced a .tre phylip tree (use njplot in this package to visualize it):

../../../njplot/njplot.linux catbpfree2_sample.con.tre 


10) Stop the chains 
../../nhpb -s catbpfree1
../../nhpb -s catbpfree2

11) Clean repository with the tutorial cleaning script
./clean
