Description Usage Arguments Details Value Examples
View source: R/segmentation_gibbs_sampler.R
This function performs the reversible-jump MCMC algorithm using a Gibbs sampler, which estimates the breakpoints of the movement variables for each of the animal IDs. This is the first stage of the two-stage Bayesian model that estimates proportions of behavioral states by first segmenting individual tracks into relatively homogeneous segments of movement.
1 2 3 4 5 6 7 | segment_behavior(
data,
ngibbs,
nbins,
alpha,
breakpt = purrr::map(names(data), ~NULL)
)
|
data |
A list where each element stores the data for a separate animal ID. List elements are data frames that only contain columns for the animal ID and for each of the discretized movement variables. |
ngibbs |
numeric. The total number of iterations of the MCMC chain. |
nbins |
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
|
alpha |
numeric. A single value used to specify the hyperparameter for
the prior distribution. A standard value for |
breakpt |
A list where each element stores a vector of breakpoints if
pre-specifying where they may occur for each animal ID. By default this is
set to |
This model is run in parallel using the future
package. To ensure that
the model is run in parallel, the plan
must be used
with future::multisession
as the argument for most operating systems.
Otherwise, model will run sequentially by default if this is not set before
running segment_behavior
.
A list of model results is returned where elements include the breakpoints, number of breakpoints, and log marginal likelihood at each iteration of the MCMC chain for all animal IDs. The time it took the model to finish running for each animal ID are also stored and returned.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #load data
data(tracks.list)
#subset only first track
tracks.list<- tracks.list[1]
#only retain id and discretized step length (SL) and turning angle (TA) columns
tracks.list2<- purrr::map(tracks.list,
subset,
select = c(id, SL, TA))
set.seed(1)
# Define model params
alpha<- 1
ngibbs<- 1000
nbins<- c(5,8)
future::plan(future::multisession, workers = 3) #run all MCMC chains in parallel
dat.res<- segment_behavior(data = tracks.list2, ngibbs = ngibbs, nbins = nbins,
alpha = alpha)
future::plan(future::sequential) #return to single core
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.