This function performs a Gibbs sampler within the Latent Dirichlet Allocation (LDA) model to estimate proportions of each behavioral state for all time segments generated by segment_behavior. This is the second stage of the two-stage Bayesian model that estimates proportions of behavioral states by first segmenting individual tracks into relatively homogeneous segments of movement.

cluster_segments(dat, gamma1, alpha, ngibbs, nmaxclust, nburn, ndata.types)

## Arguments

dat A data frame returned by summarize_tsegs that summarizes the counts of observations per bin and movement variable for all animal IDs. numeric. A hyperparameter for the truncated stick-breaking prior for estimating the theta matrix. numeric. A hyperparameter for the Dirichlet distribution when estimating the phi matrix. numeric. The total number of iterations of the MCMC chain. numeric. A single number indicating the maximum number of clusters to test. numeric. The length of the burn-in phase. numeric. A vector of the number of bins used to discretize each movement variable. These must be in the same order as the columns within dat.

## Value

A list of model results is returned where elements include the phi matrix for each data stream, theta matrix, log likelihood estimates for each iteration of the MCMC chain loglikel, and matrices of the latent cluster estimates for each data stream z.agg.

## Details

The LDA model analyzes all animal IDs pooled together, thereby providing population-level estimates of behavioral states.

## Examples

# \donttest{
data(tracks.seg)

#select only id, tseg, SL, and TA columns
tracks.seg2<- tracks.seg[,c("id","tseg","SL","TA")]

#summarize data by track segment
obs<- summarize_tsegs(dat = tracks.seg2, nbins = c(5,8))

#cluster data with LDA
res<- cluster_segments(dat = obs, gamma1 = 0.1, alpha = 0.1, ngibbs = 1000,
nburn = 500, nmaxclust = 7, ndata.types = 2)
# }