---
title: "CoDaLoMic Package"
output: pdf_document
vignette: >
  %\VignetteIndexEntry{README}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
devtools::load_all()
```

## Overview

The *CoDaLoMic* is a package designed to analyse microbiome compositional time series. The models implemented in this package are the Frequency Balances Model (FBM) described in Creus-Martí et al (2021); the Bayesien Principal Balances Model (BPBM) presented in Creus-Martí et al (2022); and the model described in Creus-Martí et al (2018) that it is based in the Generalized Lotka-Volterra equations where the data follows a Dirichlet distribution and is transformed using the alr transformation.

## Installation

First of all you will need to install the program Just Another Gibbs Sampler (JAGS) (Plummer, 2003) in your computer. You can find the information of the program and its download in https://mcmc-jags.sourceforge.io/

<!-- Secondly, you will need to execute the following code in your Rconsole: -->
<!--  -->
<!-- ```{r} -->
<!-- devtools::install$\_$github("dgrtwo/broom") -->
<!-- ``` -->

Finally, you can install the package from CRAN

```{r,eval=FALSE}
install.packages("CoDaLoMic")
```


```{r, eval=FALSE}
library(CoDaLoMic)
```


## Data


The package contains a simulated microbiome dataset with the information of 5 bacteria during 10 time points.

```{r}
data(Simulated)
head(Simulated)
```


The package contains gut microbiome time series of a *Blatella germanica* cockroach treated by kanamycin during three periods of time (days: 1–10,  36–45, 71–80). The data is extracted from Marín-Miret et al (2024), more specifically, the data is the information of the K3 cockroach in the article. The dataset contains 105 time points and 210 genera.

```{r}
data(cockroach)
cockroach[c(1,2,3,4,5,6),c(1,2,3,4,5)]
```


## Usage

Table \ref{tab} contain the functions of the package that serve for each model. There are functions that appeared two times, one finished in "Pred" or "Prediction" and another without this ending. If you want to predict part of your data you should use the function with the prediction ending. If you are not interested in prediction, use the other function. 


\begin{table}[h]
\scriptsize
\caption{Functions present in the package to process the data.}
\label{tab}
\begin{tabular}{|c|c|c|c|}
\hline
 Function & Dirich-gLV & FBM & BPBM\\
\hline
 &  \multicolumn{3}{|c|}{ZeroData}\\
Preparing & \multicolumn{3}{|c|}{PreparingTheData}\\
\cline{2-4}
the data &  \multicolumn{2}{|c|}{MaxBacteria/MaxBacteriaPred} &  \\
\hline
&  Estimate$\_$Param$\_$EstParmFunc& ridgeregression & PlotDendogram  \\
Estimate&  & TauAndParameters$\_$EstParmFunc$\_$FBM &ObtainigValueSPBal  \\
the&  &  & Estimating$\_$BPBM \\
model&  &  & StudyingParam \\
&  &  & ObtainingDIC \\
\hline
Expected&ExpectedValue$\_$EstParmFunc  &ExpectedValues$\_$EstParmFunc$\_$FBM  &ExpectedValuess$\_$BPBM  \\
values&  &  &  \\
\hline
Prediction& PredictionEstParmFunc &PredictionFBM  & PredictionBPBM \\
\hline
& \multicolumn{2}{|c|}{Graphics/GraphicsPrediction}&  Graphics/GraphicsPredictionBPBM \\ \cline{2-4}
Results& \multicolumn{3}{|c|}{QualityControl}   \\
\cline{2-4}
&Table$\_$alr$\_$Dirich$\_$glv  &TableFBM  & TableBPBM \\
&  &PCAbiplot  & GraphicsSPBal \\
\hline
\end{tabular}
\label{tab}
\end{table}


## References

 (a) Creus Marti, I., Moya, A., Santonja, F. J. (2021), A Dirichlet autoregressive model for the analysis of microbiota time-series data, Complexity, 2021, 1-16.
 
 (b) Creus Marti, I., Moya, A., Santonja, F. J. (2022), Bayesian hierarchical compositional models for analysing longitudinal abundance data from microbiome studies, Complexity, 2022.
 
 (c)  Creus Marti, I., Moya, A., Santonja, F. J. (2018), A Statistical Model with a Lotka-Volterra Structure for Microbiota Data, Lucas Jodar, Juan Carlos Cortes and Luis Acedo,  Modelling for engineering and human behaviour 2018, Instituto Universitario de Matematica Multidisciplinar, ISBN: 978-84-09-07541-6. 
 
 (d) Marín-Miret, J., Pérez-Cobas, A. E., Domínguez-Santos, R., Pérez-Rocher, B., Latorre, A., & Moya, A. (2024). Adaptability of the gut microbiota of the German cockroach Blattella germanica to a periodic antibiotic treatment. Microbiological Research, 287, 127863.

 (e) Plummer, M. (2003, March). JAGS: A program for analysis of Bayesian graphical models using Gibbs sampling. In Proceedings of the 3rd international workshop on distributed statistical computing (Vol. 124, No. 125.10, pp. 1-10).

