get_breakpts: Extract breakpoints for each animal ID

Description Usage Arguments Value Examples

View source: R/segmentation_helper_functions.R

Description

Extract breakpoints for each animal ID

Usage

1
get_breakpts(dat, MAP.est)

Arguments

dat

A list of lists where animal IDs are separated as well as the breakpoints estimated for each iteration of the MCMC chain. This is stored within breakpts of model results returned after running segment_behavior.

MAP.est

numeric. A vector of values at which the maximum a posteriori (MAP) estimate was identified for each of the animal IDs as returned by get_MAP. These must be in the same order as the data for the IDs supplied to segment_behavior().

Value

A data frame where breakpoints are returned per animal ID within each row. For animal IDs that have fewer breakpoints than the maximum number that were estimated, NA values are used as place holders for these breakpoints that do not exist.

Examples

 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
27
#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)  #run all MCMC chains in parallel
dat.res<- segment_behavior(data = tracks.list2, ngibbs = ngibbs, nbins = nbins,
                           alpha = alpha)


# Determine MAP iteration for selecting breakpoints and store breakpoints
MAP.est<- get_MAP(dat = dat.res$LML, nburn = ngibbs/2)
brkpts<- get_breakpts(dat = dat.res$brkpts, MAP.est = MAP.est)

bayesmove documentation built on Oct. 22, 2021, 9:08 a.m.