---
title: "mFLICA_demo"
author: " C. Amornbunchornvej"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{mFLICA_demo} 
  %\VignetteEngine{knitr::knitr}
  \usepackage[utf8]{inputenc}
---

# EXAMPLE: Simple Simulation
In the first step, we have a build-in dataset of 30-individual  time series where ID1, ID2, ID3 are leaders at coordination intervals: [1,200], [201,400], and [401,600] respectively. These individuals move within two-dimensional space. Time series of each individual represents a sequence of coordinate (x,y) at each time step. A leader is an initiator who initiates coordinated movement that everyone in a faction follows. 
```{r}
library(mFLICA)

# mFLICA::TS[i,t,d] is an element of ith time series at time t in the dimension d. Here, we have only two dimensions: x and y. The time series length is 800, so, t is in the range [1,800]. There are 30 individuals, so, i is in the range [1,30].
plotMultipleTimeSeries(TS=mFLICA::TS[,,1],strTitle="x axis")
```


```{r}
plotMultipleTimeSeries(TS=mFLICA::TS[,,2],strTitle="y axis")
?followingRelation
```

To make it short, we choose only the interval [1,200] that ID1 is a leader. The framework is used to analyze the data below.
```{r}
obj1<-mFLICA(TS=mFLICA::TS[,1:200,],timeWindow=60,sigma=0.5)

```
The network densities of a dynamic following network is shown below.
```{r}
 plotMultipleTimeSeries(TS=obj1$dyNetOut$dyNetBinDensityVec, strTitle="Network Dnesity")
```
We plot time series of faction size ratios of all leaders
```{r}
 plotMultipleTimeSeries(TS=obj1$factionSizeRatioTimeSeries, strTitle="Faction Size Ratios")
```


