

## overview

This package is an R implementation (of dependent discrete models) derived from 'BayesTraits' V5.0.3 (https://github.com/AndrewPMeade/BayesTraits-Release/tree/Release). 


## major differences from BayesTraits, limitations, and other things to note

- This implementation takes numeric (e.g. c(0.25, 0.25, 0.25, 0.25)) input as root state frequencies (specified by 'pis' command in BayesTraits V5.0.3, which allows only 'none', 'uniform' or 'empirical'). This would enable analyses that take reconstructed probabilities at the root (from previous analyses) as input. 
- Character file must contain two fully-specified binary traits. It must not contain NA values or multi-valued taxa. 
- Tree file expects a list of trees. If you only have a single tree, put it inside a list first, e.g.
```r
treeset<-list()
treeset[[1]]<-ttree
```
- Reversible jump MCMC, with or without hyper priors are supported.
- MCMC without reversible jump, is supported.
- Supports one prior for all rates.



## examples
```r
#load test data

libarary(rphylo)

data(ttree)
data(tdata)
data(ttree2)
data(tdata2)

xx<-list()
xx[[1]]<-ttree
```

```r
#m1: model with 
#   - exponential prior, whose mean is drawn from (hyper prior) uniform (0,10). 
#   - MCMC is used but without reversible jump. 
#   - State frequencies are set equal.

m1<-run_dep_model(xx,
   charfile    = tdata,
   burnin      = 1000,
   iterations  = 10000,
   sample_freq = 1000,
   prior       = list(type = "exponential"),
   hp          =list(mean     = c(0, 10)),
   revjump        = F,
   recon_nodes = NULL,
   tags        = NULL,
   pis         = c(1,1,1,1),
   seed        = 42
 )
 
m1$rates 
```


```r
#m2: model with 
#   - exponential prior, whose mean is 10. 
#   - RJMCMC,
#   - State frequencies are set as following empirical distribution.

m2<-run_dep_model(ttree2,
   charfile    = tdata2,
   burnin      = 1000,
   iterations  = 100000,
   sample_freq = 1000,
   prior       = list(type = "exponential", mean=10),
   hp          = NULL,
   revjump     = TRUE,
   recon_nodes = c("root_node"),
   tags        =list(root_node = ttree2[[1]]$tip.label),
   pis         = get_emp_freq(tdata),
   seed        = 42
 )
 
m2$rates 

#get posterior probs for reconstructed node
m2$anc
```



## citation

If you use this package in your research, please cite:

- Pagel, M., A. Meade and D. Barker (2004). "Bayesian estimation of ancestral character states on phylogenies." Systematic biology 53(5): 673-684.

- Pagel, M. (1994). "Detecting correlated evolution on phylogenies: a general method for the comparative analysis of discrete characters." Proceedings of the Royal Society of London. Series B: Biological Sciences 255(1342): 37-45.

- Pagel, M. and A. Meade (2006). "Bayesian analysis of correlated evolution of discrete characters by reversible-jump Markov chain Monte Carlo." The American Naturalist 167(6): 808-825.


## license
GPL-3
