Title: | Bivariate Segmentation/Clustering Methods and Tools |
---|---|
Description: | Provides two methods for segmentation and joint segmentation/clustering of bivariate time-series. Originally intended for ecological segmentation (home-range and behavioural modes) but easily applied on other series, the package also provides tools for analysing outputs from R packages 'moveHMM' and 'marcher'. The segmentation method is a bivariate extension of Lavielle's method available in 'adehabitatLT' (Lavielle, 1999 <doi:10.1016/S0304-4149(99)00023-X> and 2005 <doi:10.1016/j.sigpro.2005.01.012>). This method rely on dynamic programming for efficient segmentation. The segmentation/clustering method alternates steps of dynamic programming with an Expectation-Maximization algorithm. This is an extension of Picard et al (2007) <doi:10.1111/j.1541-0420.2006.00729.x> method (formerly available in 'cghseg' package) to the bivariate case. The method is fully described in Patin et al (2018) <doi:10.1101/444794>. |
Authors: | Remi Patin [aut, cre], Marie-Pierre Etienne [aut], Emilie Lebarbier [aut], Simon Benhamou [aut] |
Maintainer: | Remi Patin <[email protected]> |
License: | GPL-3 |
Version: | 0.3.3 |
Built: | 2024-11-20 04:37:01 UTC |
Source: | https://github.com/rpatin/segclust2d |
Add several covariates to movement observations
add_covariates
add several covariates to a data frame with movement
information. It adds : distance between location, spatial angle, speed,
smoothed speed, persistence and rotation velocity (calculated with spatial
angle).
add_covariates(x, ...) ## S3 method for class 'Move' add_covariates(x, coord.names = c("x", "y"), ...) ## S3 method for class 'ltraj' add_covariates(x, coord.names = c("x", "y"), ...) ## S3 method for class 'data.frame' add_covariates( x, coord.names = c("x", "y"), smoothed = FALSE, timecol = "dateTime", units = "hour", radius = NULL, ... )
add_covariates(x, ...) ## S3 method for class 'Move' add_covariates(x, coord.names = c("x", "y"), ...) ## S3 method for class 'ltraj' add_covariates(x, coord.names = c("x", "y"), ...) ## S3 method for class 'data.frame' add_covariates( x, coord.names = c("x", "y"), smoothed = FALSE, timecol = "dateTime", units = "hour", radius = NULL, ... )
x |
movement data |
... |
additional arguments |
coord.names |
names of coordinates column in |
smoothed |
whether speed are smoothed or not |
timecol |
names of POSIXct time column |
units |
units for time calculation. Default "hour" |
radius |
for spatial angle calculations |
data.frame with additional covariates
## Not run: add_covariates(move_object, coord.names = c("x","y"), smoothed = T) ## Not run: data(simulmode) simple_data <- simulmode[,c("dateTime","x","y")] full_data <- add_covariates(simple_data, coord.names = c("x","y"), timecol = "dateTime",smoothed = TRUE, units ="min") ## End(Not run)
## Not run: add_covariates(move_object, coord.names = c("x","y"), smoothed = T) ## Not run: data(simulmode) simple_data <- simulmode[,c("dateTime","x","y")] full_data <- add_covariates(simple_data, coord.names = c("x","y"), timecol = "dateTime",smoothed = TRUE, units ="min") ## End(Not run)
angular_speed
calculate turning angle between locations, taking a
dataframe as input.
angular_speed(x, coord.names = c("x", "y"))
angular_speed(x, coord.names = c("x", "y"))
x |
data.frame with locations |
coord.names |
names of coordinates column in |
vector of turning angle.
Remi Patin, Simon Benhamou.
Internal function for Expectation-Maximization (EM) algorithm.
apply_rowSums(rupt, x)
apply_rowSums(rupt, x)
rupt |
current estimated breaks in signal |
x |
bivariate signal |
if subsample = FALSE do nothing.
apply_subsampling(x, is_segclust, subsample, subsample_over, subsample_by)
apply_subsampling(x, is_segclust, subsample, subsample_over, subsample_by)
x |
data.frame to be subsampled |
is_segclust |
TRUE or FALSE whether the function was called from 'segclust()' or 'segmentation()' |
subsample |
if FALSE disable subsampling |
subsample_over |
maximum number of row accepted |
subsample_by |
subsampling parameters |
else if subsample_by is missing, subsample only if nrow(x) > subsample_over, then it subsample with the minimum needed to get a data.frame smaller than subsample_over
if subsample_by is provided, use it to subsample.
a data.frame
Check whether argument 'diag.var' was provided. If not, propose default value.
argcheck_diag.var(diag.var, seg.var)
argcheck_diag.var(diag.var, seg.var)
diag.var |
names of the variables on which statistics are calculated. |
seg.var |
for behavioral segmentation: names of the variables used for segmentation (either one or two names). |
a vector of character string
Check whether argument 'Kmax' was provided and is adequate before subsampling. Propose adequate value if Kmax is not provided.
argcheck_Kmax(Kmax, lmin, datalength)
argcheck_Kmax(Kmax, lmin, datalength)
Kmax |
maximum number of segments. |
lmin |
minimum length of segments. |
datalength |
length of data provided |
an integer
Check whether argument 'lmin' was provided and is adequate before subsampling
argcheck_lmin(lmin, is_segclust)
argcheck_lmin(lmin, is_segclust)
lmin |
minimum length of segments. |
is_segclust |
TRUE if function is called from |
a NULL object
Check whether argument 'ncluster' was provided and is adequate
argcheck_ncluster(ncluster, Kmax)
argcheck_ncluster(ncluster, Kmax)
ncluster |
number of cluster into which segments should be grouped. Can be a vector if one want to test several number of clusters. |
Kmax |
maximum number of segments. |
a NULL object
Check whether argument 'order.var' was provided. If not, propose default value.
argcheck_order.var(order.var, diag.var)
argcheck_order.var(order.var, diag.var)
order.var |
names of the variable with which states are ordered. |
diag.var |
names of the variables on which statistics are calculated. |
a vector of character string
Check whether argument 'order' was provided for plot.segmentation and segmap. If not, propose default value.
argcheck_ordering(order, seg.type, order.var)
argcheck_ordering(order, seg.type, order.var)
order |
TRUE or FALSE depending on whether cluster be ordered |
seg.type |
types of the segmentation |
order.var |
name of the variable to order the cluster |
a boolean
Check whether argument 'scale.variable' was provided. If not, propose default value.
argcheck_scale.variable(scale.variable, is_segclust)
argcheck_scale.variable(scale.variable, is_segclust)
scale.variable |
minimum length of segments. |
is_segclust |
TRUE if function is called from |
a boolean
Check whether argument 'seg.var' was adequately provided. If provided, also check for its length (1 or 2) and for the existence of corresponding column names in x If unprovided, use default value (segmentation only) and tests if column names exists.
argcheck_seg.var(x, seg.var, is_segclust)
argcheck_seg.var(x, seg.var, is_segclust)
x |
data used for segmentation. Supported: data.frame, Move object, ltraj object |
seg.var |
for behavioral segmentation: names of the variables used for segmentation (either one or two names). |
is_segclust |
TRUE if function is called from |
a list with a data.frame and a vector with two character strings
Check whether argument 'ncluster' and 'nseg' were provided. If not, propose default value based on BIC.
argcheck_segclust(ncluster, nseg, ncluster.BIC, Kopt.BIC)
argcheck_segclust(ncluster, nseg, ncluster.BIC, Kopt.BIC)
ncluster |
number of cluster |
nseg |
number of segment |
ncluster.BIC |
optimal number of cluster selected by BIC |
Kopt.BIC |
optimal number of segment selected by BIC for each number of cluster |
a list with two integers
Check whether argument 'nseg' was provided. If not, propose default value based on Lavielle's criterium
argcheck_segmentation(nseg, Kopt.lavielle)
argcheck_segmentation(nseg, Kopt.lavielle)
nseg |
number of segment |
Kopt.lavielle |
optimal number of segment selected with Lavielle's criterium |
an integer
Check whether argument 'type' and 'coord.names' were provided and communicate adequately if need be.
argcheck_type_coord(...)
argcheck_type_coord(...)
... |
additional parameters transmitted from |
a NULL object
C++ Armadillo version for repmat function. Repeat a matrix in bloc.
arma_repmat(A, n, m)
arma_repmat(A, n, m)
A |
matrix |
n |
number of repetition in line |
m |
number of repetition in column |
see broom::augment for more informations
augment(x, ...)
augment(x, ...)
x |
object to be augmented |
... |
additional arguments |
bisig_plot draws the plots of the bivariate signal on the same plot (scale free)
bisig_plot(x, rupt = NULL, mu = NULL, pop = NULL, merge.seg = FALSE)
bisig_plot(x, rupt = NULL, mu = NULL, pop = NULL, merge.seg = FALSE)
x |
the signal to be plotted |
rupt |
optional, if given add vertical lines at change points (rupt should a vector) |
mu |
optional the mean of each class of segment, |
pop |
optional the cluster to whom each segment belongs to, |
merge.seg |
should segment be merged ? |
no value
BIC
calculates BIC given log-likelihood, number of segment and number
of class
calc_BIC(likelihood, ncluster, nseg, n)
calc_BIC(likelihood, ncluster, nseg, n)
likelihood |
log-likelihood |
ncluster |
number of cluster |
nseg |
number of segment |
n |
number of observations |
a data.frame with BIC, number of cluster and number of segment
calc_dist
calculate distance between locations, taking a dataframe as
input. Distance can also be smoothed over the two steps before and after the
each point.
calc_dist(x, coord.names = c("x", "y"), smoothed = FALSE)
calc_dist(x, coord.names = c("x", "y"), smoothed = FALSE)
x |
data.frame with locations |
coord.names |
names of coordinates column in |
smoothed |
whether distance are smoothed or not |
vector of distance
Remi Patin
## Not run: calc_dist(df,coord.names = c("x","y"), smoothed = T)
## Not run: calc_dist(df,coord.names = c("x","y"), smoothed = T)
calc_dist
calculate speed between locations, taking a dataframe as
input. Speed can also be smoothed over the two steps before and after the
each point.
calc_speed( x, coord.names = c("x", "y"), timecol = "dateTime", smoothed = FALSE, units = "hour" )
calc_speed( x, coord.names = c("x", "y"), timecol = "dateTime", smoothed = FALSE, units = "hour" )
x |
data.frame with locations |
coord.names |
names of coordinates column in |
timecol |
names of POSIXct time column |
smoothed |
whether speed are smoothed or not |
units |
units for time calculation. Default "hour" |
vector of distance
Remi Patin
## Not run: calc_speed(df,coord.names = c("x","y"), timecol = "dateTime", smoothed = T) ## End(Not run)
## Not run: calc_speed(df,coord.names = c("x","y"), timecol = "dateTime", smoothed = T) ## End(Not run)
calc_stat_states
calculates statistics of a given segmentation : mean
and variance of the different states.
calc_stat_states(data, df.segm, diag.var, order.var = NULL)
calc_stat_states(data, df.segm, diag.var, order.var = NULL)
data |
the data.frame with the different variable |
df.segm |
output of prep_segm function |
diag.var |
names of the variables on which statistics are calculated |
order.var |
names of the variable with which states are ordered |
a data.frame with mean and variance of the different states
## Not run: calc_stat_states(data, diag.var = c("dist","angle"), order.var='dist', type='hmm',hmm.model=mod1.hmm) ## End(Not run)
## Not run: calc_stat_states(data, diag.var = c("dist","angle"), order.var='dist', type='hmm',hmm.model=mod1.hmm) ## End(Not run)
check_repetition
checks whether the series have identical or
near-identical repetition larger than lmin. if that is the case, throw an
error, the algorithm cannot yet handle these repetition, because variance on
the segment would be null.
check_repetition(x, lmin, rounding = FALSE, magnitude = 3)
check_repetition(x, lmin, rounding = FALSE, magnitude = 3)
x |
the bivariate series to be tested |
lmin |
minimum length of segment |
rounding |
whether or not series are rounded |
magnitude |
number of magnitude of standard deviation below which values are rounded. i.e if magnitude = 3, difference smaller than one thousandth of the standard deviation are rounded to the same value. |
a boolean, TRUE if there is any repetition larger or equal to lmin.
set.seed(42) dat <- rbind(base::sample(seq(1,10), size= 100, replace = TRUE), base::sample(seq(1,10), size= 100, replace = TRUE)) check_repetition(dat, lmin = 3) check_repetition(dat, lmin = 5)
set.seed(42) dat <- rbind(base::sample(seq(1,10), size= 100, replace = TRUE), base::sample(seq(1,10), size= 100, replace = TRUE)) check_repetition(dat, lmin = 3) check_repetition(dat, lmin = 5)
Choosing optimal number of segment using Marc Lavielle's method. From Emilie Lebarbier. Method based on identifying breaks in the slope of the contrast.
choose_kmax(x, S = 0.75)
choose_kmax(x, S = 0.75)
x |
|
S |
threshold for choosing the number of segment. See adehabitatLT::chooseseg |
the optimal number of segment given threshold S.
## Not run: res.seg <- segmentation(df, coord.names = c("x","y"), Kmax = 30, lmin = 10) # find the optimal number of segment according to Lavielle's criterium with a # different threshold. choose_kmax(res.seg, S = 0.60) ## End(Not run)
## Not run: res.seg <- segmentation(df, coord.names = c("x","y"), Kmax = 30, lmin = 10) # find the optimal number of segment according to Lavielle's criterium with a # different threshold. choose_kmax(res.seg, S = 0.60) ## End(Not run)
Choosing optimal number of segment using Marc Lavielle's method. From Emilie Lebarbier. Method based on identifying breaks in the slope of the contrast.
chooseseg_lavielle(J, S = 0.75, ...)
chooseseg_lavielle(J, S = 0.75, ...)
J |
likelihood for each number of segment |
S |
threshold for choosing the number of segment. See adehabitatLT::chooseseg |
... |
additional arguments |
a list with optimal number of segment and full data.frame of the calculus
Internal function for Expectation-Maximization (EM) algorithm.
colsums_sapply(i, rupt, x, mu, tau)
colsums_sapply(i, rupt, x, mu, tau)
i |
number of signal |
rupt |
current estimated breaks in signal |
x |
bivariate signal |
mu |
mean parameter for each signal |
tau |
tau |
C++ function for cumulative sum (replacing R cumsum)
cumsum_cpp(x)
cumsum_cpp(x)
x |
Numerical Vector |
DynProg computes the change points given a cost matrix matD and a maximum number of segments Kmax
DynProg(matD, Kmax)
DynProg(matD, Kmax)
matD |
the cost Matrix os size n x n |
Kmax |
the maximal number of segments |
a list with J.est a vector with Kmax value, the Kth is the minimum contrast for a model with K segments (-J.est is the log-likelihood) and with t.test a matrix, line K are the coordinates of the change points for a model with K segments
This function finds the best segmentation given a Cost Matrix using a dynamic programming algorithm. C++ implementation of DynProg
DynProg_algo_cpp(matD, Kmax)
DynProg_algo_cpp(matD, Kmax)
matD |
Cost Matrix |
Kmax |
number of segments |
EM.algo_simultanee calculates the MLE of phi for given change-point instants
EM.algo_simultanee(x, rupt, P, phi, eps = 1e-06, sameSigma = FALSE)
EM.algo_simultanee(x, rupt, P, phi, eps = 1e-06, sameSigma = FALSE)
x |
bivariate signal |
rupt |
the sequence of change points |
P |
number of clusters |
phi |
starting value for the parameter |
eps |
eps |
sameSigma |
TRUE if segments have the same variance |
a list with phi, the MLE, tau =(taukj) the probability for segment k to belong to class,lvinc = lvinc,empty = empty,dv = dv
EM.algo_simultanee calculates the MLE of phi for given change-point instants and for a fixed number of clusters
EM.algo_simultanee_Cpp(x, rupt, P, phi, eps = 1e-06, sameSigma = FALSE)
EM.algo_simultanee_Cpp(x, rupt, P, phi, eps = 1e-06, sameSigma = FALSE)
x |
bivariate signal |
rupt |
the sequence of change points |
P |
number of clusters |
phi |
starting value for the parameter |
eps |
eps |
sameSigma |
TRUE if segments have the same variance |
a list with phi, the MLE, tau =(taukj) the probability for segment k to belong to class,lvinc = lvinc,empty = empty,dv = dv
EM.init_simultanee proposes an initial value for the EM algorithm based on a hierarchical clustering algorithm (ascending)
EM.init_simultanee(x, rupt, K, P)
EM.init_simultanee(x, rupt, K, P)
x |
the bivariate signal |
rupt |
the change point instants, data.frame |
K |
number of segments |
P |
number of clusters |
phi0 : candidate for the EM algorithm
Estep_simultanee computes posterior probabilities and incomplete-data log-likelihood for mixture models
Estep_simultanee(logdensity, phi, eps = 1e-09)
Estep_simultanee(logdensity, phi, eps = 1e-09)
logdensity |
is a K*P matrix containing the conditional log-densities for each segment |
phi |
a list containing the parameters of the mixture |
eps |
eps |
a list with tau a K*P matrix, tau kj is the posterior probability for segment k to belong to class j and lvinc, the incomplete log likelihood P(X=x)
find_mu_sd
calculates statistics of a given segmentation : mean
and variance of the different states.
find_mu_sd(df.states, diag.var)
find_mu_sd(df.states, diag.var)
df.states |
a list of data.frame |
diag.var |
names of the variables on which statistics are calculated |
a data.frame with mean and variance of the different states
Gmean_simultanee calculates the cost matrix for a segmentation model with changes in the mean and variance for all signals
Gmean_simultanee(Don, lmin, sameVar = FALSE)
Gmean_simultanee(Don, lmin, sameVar = FALSE)
Don |
the bivariate signal |
lmin |
minimum size for a segment, default value is 2 |
sameVar |
whether variance is the same for each segment. |
the cost matrix G(i,j) which contains the variance of the data between point (i+1) to point j
Internal C++ algorithm for computing the cost matrix.
Gmixt_algo_cpp(zi, lgi, P, mvec, wk, svec, prop)
Gmixt_algo_cpp(zi, lgi, P, mvec, wk, svec, prop)
zi |
vector of observations |
lgi |
vector of indices |
P |
number of class |
mvec |
vector of means for each class |
wk |
temporary vector for calculations |
svec |
vector of standard deviations for each class |
prop |
mixture vector |
Return matrix G(i,j), the mixture density for segment between points (i+1) to j :
Rq: this density if factorized in order to avoid numerical zeros in the log
Gmixt_simultanee(Don, lmin, phi)
Gmixt_simultanee(Don, lmin, phi)
Don |
the bivariate signal |
lmin |
the minimum size for a segment |
phi |
the parameters of the mixture |
a matrix
C++ function replacing Gmixt_simultanee
Gmixt_simultanee_fullcpp(Don, lmin, prop, mu, s)
Gmixt_simultanee_fullcpp(Don, lmin, prop, mu, s)
Don |
Bivariate Signal |
lmin |
minimum length of segments |
prop |
mixture parameters |
mu |
mean parameters |
s |
standard deviation parameters |
hybrid_simultanee
performs a simultaneous seg - clustering for
bivariate signals.It is an algorithm which combines dynamic programming and the EM algorithm to calculate the MLE of phi and T, which are the mixture parameters and the change point instants. this algorithm is run for a given number of clusters, and estimates the parameters for a segmentation/clustering model with P clusters and 1:Kmax segments
hybrid_simultanee( x, P, Kmax, lmin = 3, sameSigma = TRUE, sameVar.init = FALSE, eps = 1e-06, lissage = TRUE, pureR = FALSE, ... )
hybrid_simultanee( x, P, Kmax, lmin = 3, sameSigma = TRUE, sameVar.init = FALSE, eps = 1e-06, lissage = TRUE, pureR = FALSE, ... )
x |
the two-dimensional signal, one line per dimension |
P |
the number of classes |
Kmax |
the maximal number of segments |
lmin |
minimum length of segment |
sameSigma |
should segment have the same variance |
sameVar.init |
sameVar.init |
eps |
eps |
lissage |
should likelihood be smoothed |
pureR |
should algorithm run in full R or use Rcpp speed improvements |
... |
additional parameters |
a list with Linc, the incomplete loglikelihood =Linc,param=paramtau posterior probability
initialisePhi is the constructor for a set of parameters for a segclust model
initialisePhi(P, val = -Inf)
initialisePhi(P, val = -Inf)
P |
number of classes |
val |
the value used for initialisation default is -Inf |
a set of parameter phi
Generic function for likelihood
likelihood(x, ...)
likelihood(x, ...)
x |
object from which likelihood can be extracted |
... |
additional parameters |
Calculate logdensity of a bivariate signal
logdens_simultanee_cpp(xk, mu, sigma, prop) logdens_simultanee(xk, phi)
logdens_simultanee_cpp(xk, mu, sigma, prop) logdens_simultanee(xk, phi)
xk |
the bivariate signal |
mu |
mean parameter for each signal |
sigma |
standard deviation parameter for each signal |
prop |
mixture parameter |
phi |
parameters of the mixture, P components |
the value of the log density
plot_segm
plot segmented movement data on a map.plot_segm
plot segmented movement data on a map.
map_segm( data, output, interactive = FALSE, html = FALSE, scale = 1, UTMstring = "+proj=longlat +datum=WGS84 +no_defs", width = 400, height = 400, order = NULL, pointsize = 1, linesize = 0.5, coord.names = c("x", "y"), ... )
map_segm( data, output, interactive = FALSE, html = FALSE, scale = 1, UTMstring = "+proj=longlat +datum=WGS84 +no_defs", width = 400, height = 400, order = NULL, pointsize = 1, linesize = 0.5, coord.names = c("x", "y"), ... )
data |
the data.frame with the different variable |
output |
outputs of the segmentation or segclust algorithm for one number of segment |
interactive |
should graph be interactive with leaflet ? |
html |
should the graph be incorporated in a markdown file through htmltools::tagList() |
scale |
for dividing coordinates to have compatibility with leaflet |
UTMstring |
projection of the coordinates |
width |
width |
height |
height |
order |
should cluster be ordered |
pointsize |
size of points |
linesize |
size of lines |
coord.names |
names of coordinates |
... |
additional arguments |
a ggplot object
## Not run: #res.seg is a result of the segmentation-only algorithm : nseg = 10 outputs = res.seg$outputs[[paste(nseg, "segments")]] map <- map_segm(data=res.seg$data,output=outputs) #res.segclust is a result of the segmentation-clusturing algorithm : nseg = 10; ncluster = 3 outputs = res.segclust$outputs[[paste(ncluster,"class -",nseg, "segments")]] map <- map_segm(data=res.seg$data,output=outputs) ## End(Not run)
## Not run: #res.seg is a result of the segmentation-only algorithm : nseg = 10 outputs = res.seg$outputs[[paste(nseg, "segments")]] map <- map_segm(data=res.seg$data,output=outputs) #res.segclust is a result of the segmentation-clusturing algorithm : nseg = 10; ncluster = 3 outputs = res.segclust$outputs[[paste(ncluster,"class -",nseg, "segments")]] map <- map_segm(data=res.seg$data,output=outputs) ## End(Not run)
matrixRupt transforms a vector of change point into a data.frame with start and end of every segment
matrixRupt(x, vectorRupt)
matrixRupt(x, vectorRupt)
x |
the |
vectorRupt |
the vector containing the change point |
the matrix of change point
Mstep_simultanee computes the MLE within the EM framework
Mstep_simultanee(x, rupt, tau, phi, sameSigma = TRUE)
Mstep_simultanee(x, rupt, tau, phi, sameSigma = TRUE)
x |
the bivariate signal |
rupt |
the rupture dataframe |
tau |
the K*P matrix containing posterior probabilities of membership to clusters |
phi |
the parameters of the mixture |
sameSigma |
TRUE if all segment have the same variance |
phi the updated value of the parameters
Mstep_simultanee computes the MLE within the EM framework
Mstep_simultanee_cpp(x, rupt, tau, phi, sameSigma = TRUE)
Mstep_simultanee_cpp(x, rupt, tau, phi, sameSigma = TRUE)
x |
the bivariate signal |
rupt |
the rupture dataframe |
tau |
the K*P matrix containing posterior probabilities of membership to clusters |
phi |
the parameters of the mixture |
sameSigma |
whether segments have the same variance |
phi the updated value of the parameters
neighbors tests whether neighbors of point k,P can be used to re-initialize the EM algorithm and to improve the log-likelihood.
neighborsbis( kv.hull, x, L, k, param, P, lmin, eps, sameSigma = TRUE, pureR = FALSE )
neighborsbis( kv.hull, x, L, k, param, P, lmin, eps, sameSigma = TRUE, pureR = FALSE )
kv.hull |
convex hull of likelihood |
x |
the initial dataset |
L |
the likelihood |
k |
the points of interest |
param |
param outputs of segmentation |
P |
the number of class |
lmin |
minimal size of the segment to be implemented |
eps |
eps |
sameSigma |
should segments have same variance ? |
pureR |
should algorithm use only R functions or benefit from Rcpp faster algorithm |
smoothing likelihood
plot_segm
plot segmented time serie.
plot_segm( data, output, interactive = FALSE, diag.var, x_col = "expectTime", html = FALSE, order = FALSE, stationarity = FALSE )
plot_segm( data, output, interactive = FALSE, diag.var, x_col = "expectTime", html = FALSE, order = FALSE, stationarity = FALSE )
data |
the data.frame with the different variable |
output |
outputs of the segmentation or segclust algorithm for one number of segment |
interactive |
should graph be interactive through leaflet ? |
diag.var |
names of the variables on which statistics are calculated |
x_col |
column name for time |
html |
should the graph be incorporated in a markdown file through htmltools::tagList() |
order |
should cluster be ordered |
stationarity |
if TRUE, cut each segment in three and plot each part with its own mean to assess stationarity of each segment |
a graph
## Not run: #res.segclust is the results of the segmentation-clustering algorithm ncluster = 3 nseg = 10 g <- plot_segm(data = res.segclust$data, output = res.segclust$outputs[[paste(ncluster,"class -",nseg, "segments")]], diag.var = x$`Diagnostic variables`,x_col = 'dateTime) #res.seg is the results of the segmentation-only algorithm nseg = 10 g <- plot_segm(data = res.segclust$data, output = res.segclust$outputs[[paste(nseg, "segments")]], diag.var = x$`Diagnostic variables`,x_col = 'dateTime) ## End(Not run)
## Not run: #res.segclust is the results of the segmentation-clustering algorithm ncluster = 3 nseg = 10 g <- plot_segm(data = res.segclust$data, output = res.segclust$outputs[[paste(ncluster,"class -",nseg, "segments")]], diag.var = x$`Diagnostic variables`,x_col = 'dateTime) #res.seg is the results of the segmentation-only algorithm nseg = 10 g <- plot_segm(data = res.segclust$data, output = res.segclust$outputs[[paste(nseg, "segments")]], diag.var = x$`Diagnostic variables`,x_col = 'dateTime) ## End(Not run)
plot_states
plot states statistics
plot_states(outputs, diag.var, position_width = 0.3, order = FALSE)
plot_states(outputs, diag.var, position_width = 0.3, order = FALSE)
outputs |
outputs of the segmentation or segclust algorithm for one number of segment |
diag.var |
names of the variables on which statistics are calculated |
position_width |
width between different model if several models are compared |
order |
should cluster be ordered |
a graph
## Not run: #res.segclust is the results of the segmentation-clustering algorithm ncluster = 3 nseg = 10 g <- plot_states(output = res.segclust$outputs[[ paste(ncluster,"class -",nseg, "segments") ]], diag.var = c("dist","angle2") #res.seg is the results of the segmentation-only algorithm nseg = 10 g <- plot_states(output = res.segclust$outputs[[paste(nseg, "segments")]], diag.var = c("dist","angle2")) ## End(Not run)
## Not run: #res.segclust is the results of the segmentation-clustering algorithm ncluster = 3 nseg = 10 g <- plot_states(output = res.segclust$outputs[[ paste(ncluster,"class -",nseg, "segments") ]], diag.var = c("dist","angle2") #res.seg is the results of the segmentation-only algorithm nseg = 10 g <- plot_states(output = res.segclust$outputs[[paste(nseg, "segments")]], diag.var = c("dist","angle2")) ## End(Not run)
prep_segm
find the different segment and states of a given HMM
model
prep_segm(data, param, seg.type = NULL, nseg = NULL)
prep_segm(data, param, seg.type = NULL, nseg = NULL)
data |
the data.frame with the different variable |
param |
the param output of the segmentation |
seg.type |
either 'hybrid' or 'dynprog' |
nseg |
number of segment chosen |
a data.frame with states of the different segments
prep_segm_HMM
prep_segm_HMM(data, hmm.model)
prep_segm_HMM(data, hmm.model)
data |
data |
hmm.model |
hmm.model |
prep_segm_shiftfit
prep_segm_shiftfit(data, shiftfit.model)
prep_segm_shiftfit(data, shiftfit.model)
data |
data |
shiftfit.model |
shiftfit.model |
prepare_HMM
prepare_HMM(data, hmm.model = NULL, diag.var, order.var = diag.var[1])
prepare_HMM(data, hmm.model = NULL, diag.var, order.var = diag.var[1])
data |
data |
hmm.model |
hmm.model |
diag.var |
diag.var |
order.var |
order.var |
## Not run: # Example taken from moveHMM package. # 1. simulate data # define all the arguments of simData nbAnimals <- 1 nbStates <- 2 nbCovs <- 2 mu<-c(15,50) sigma<-c(10,20) angleMean <- c(pi,0) kappa <- c(0.7,1.5) stepPar <- c(mu,sigma) anglePar <- c(angleMean,kappa) stepDist <- "gamma" angleDist <- "vm" zeroInflation <- FALSE obsPerAnimal <- c(50,100) data <- moveHMM::simData(nbAnimals=nbAnimals,nbStates=nbStates, stepDist=stepDist,angleDist=angleDist, stepPar=stepPar,anglePar=anglePar,nbCovs=nbCovs, zeroInflation=zeroInflation, obsPerAnimal=obsPerAnimal) ### 2. fit the model to the simulated data # define initial values for the parameters mu0 <- c(20,70) sigma0 <- c(10,30) kappa0 <- c(1,1) stepPar0 <- c(mu0,sigma0) # no zero-inflation, so no zero-mass included anglePar0 <- kappa0 # the angle mean is not estimated, # so only the concentration parameter is needed formula <- ~cov1+cos(cov2) m <- moveHMM::fitHMM(data=data,nbStates=nbStates,stepPar0=stepPar0, anglePar0=anglePar0,formula=formula, stepDist=stepDist,angleDist=angleDist,angleMean=angleMean) ### 3. Transform into a segmentation-class object res.hmm <- prepare_HMM(data=data, hmm.model = m, diag.var = c("step","angle")) ### 4. you can now apply the same function than for segclust2d outputs plot(res.hmm) segmap(res.hmm) ## End(Not run)
## Not run: # Example taken from moveHMM package. # 1. simulate data # define all the arguments of simData nbAnimals <- 1 nbStates <- 2 nbCovs <- 2 mu<-c(15,50) sigma<-c(10,20) angleMean <- c(pi,0) kappa <- c(0.7,1.5) stepPar <- c(mu,sigma) anglePar <- c(angleMean,kappa) stepDist <- "gamma" angleDist <- "vm" zeroInflation <- FALSE obsPerAnimal <- c(50,100) data <- moveHMM::simData(nbAnimals=nbAnimals,nbStates=nbStates, stepDist=stepDist,angleDist=angleDist, stepPar=stepPar,anglePar=anglePar,nbCovs=nbCovs, zeroInflation=zeroInflation, obsPerAnimal=obsPerAnimal) ### 2. fit the model to the simulated data # define initial values for the parameters mu0 <- c(20,70) sigma0 <- c(10,30) kappa0 <- c(1,1) stepPar0 <- c(mu0,sigma0) # no zero-inflation, so no zero-mass included anglePar0 <- kappa0 # the angle mean is not estimated, # so only the concentration parameter is needed formula <- ~cov1+cos(cov2) m <- moveHMM::fitHMM(data=data,nbStates=nbStates,stepPar0=stepPar0, anglePar0=anglePar0,formula=formula, stepDist=stepDist,angleDist=angleDist,angleMean=angleMean) ### 3. Transform into a segmentation-class object res.hmm <- prepare_HMM(data=data, hmm.model = m, diag.var = c("step","angle")) ### 4. you can now apply the same function than for segclust2d outputs plot(res.hmm) segmap(res.hmm) ## End(Not run)
prepare_shiftfit
prepare_shiftfit( data, shiftfit.model = NULL, diag.var, order.var = diag.var[1] )
prepare_shiftfit( data, shiftfit.model = NULL, diag.var, order.var = diag.var[1] )
data |
data |
shiftfit.model |
shiftfit.model |
diag.var |
diag.var |
order.var |
order.var |
## Not run: data(simulshift) # 1. subsample to a reasonable size subdata <- simulshift[seq(1,30000,by = 100),] # 2. use algorithm from marcher package MWN.fit <- with(subdata, marcher::estimate_shift(T=indice, X=x, Y=y,n.clust = 3)) # 3. convert output MWN.segm <- prepare_shiftfit(subdata,MWN.fit,diag.var = c("x","y")) # 4. use segclust2d functions plot(MWN.segm) plot(MWN.segm,stationarity = TRUE) segmap(MWN.segm) ## End(Not run)
## Not run: data(simulshift) # 1. subsample to a reasonable size subdata <- simulshift[seq(1,30000,by = 100),] # 2. use algorithm from marcher package MWN.fit <- with(subdata, marcher::estimate_shift(T=indice, X=x, Y=y,n.clust = 3)) # 3. convert output MWN.segm <- prepare_shiftfit(subdata,MWN.fit,diag.var = c("x","y")) # 4. use segclust2d functions plot(MWN.segm) plot(MWN.segm,stationarity = TRUE) segmap(MWN.segm) ## End(Not run)
relabel_states
relabel the states of a segmentation/clustering output.
This allows merging different states into the same if for instance several of
the model states represent the same behavioural states.
relabel_states(mode.segclust, newlabel, ncluster, nseg, order = TRUE)
relabel_states(mode.segclust, newlabel, ncluster, nseg, order = TRUE)
mode.segclust |
segclust output |
newlabel |
a vector with the new names ordered, corresponding to state_ordered |
ncluster |
the number of cluster for which you want relabeling |
nseg |
the number of segment for which you want relabeling |
order |
boolean, whether this changes the ordered states or not. FALSE value obsolete for now |
a segmentation object with state names changed for the segmentation specified by ncluster and nseg
repmat repeats a matrix
repmat(a, n, m)
repmat(a, n, m)
a |
the base matrix |
n |
number of repetition in lines |
m |
number of repetition in columns |
a matrix with n repeats of a in lines et m in columns
ruptAsMat is an internal function to transform a vector giving the change point to matrix 2 columns matrix in which each line gives the beginning and the end of a segment
ruptAsMat(vectRupt)
ruptAsMat(vectRupt)
vectRupt |
the vector of change point |
the matrix containing the segments
Joint Segmentation/Clustering of movement data. Method available for data.frame, move and ltraj objects. The algorithm finds the optimal segmentation for a given number of cluster and segments using an iterated alternation of a Dynamic Programming algorithm and an Expectation-Maximization algorithm. Among the different segmentation found, the best one can be chosen using the maximum of a BIC penalized likelihood.
segclust(x, ...) ## S3 method for class 'data.frame' segclust(x, ...) ## S3 method for class 'Move' segclust(x, ...) ## S3 method for class 'ltraj' segclust(x, ...)
segclust(x, ...) ## S3 method for class 'data.frame' segclust(x, ...) ## S3 method for class 'Move' segclust(x, ...) ## S3 method for class 'ltraj' segclust(x, ...)
x |
data.frame with observations |
... |
additional parameters given to |
a segmentation-class
object
#' @examples df <- test_data()$data #' # data is a data.frame with column 'x' and 'y' # Simple segmentation with automatic subsampling # if data has more than 1000 rows: res <- segclust(df, Kmax = 15, lmin = 10, ncluster = 2:4, seg.var = c("x","y")) # Plot results plot(res) segmap(res, coord.names = c("x","y")) # check penalized likelihood of # alternative number of segment possible. # There should be a clear break if the segmentation is good plot_BIC(res) ## Not run: # Advanced options: # Run with automatic subsampling if df has more than 500 rows: res <- segclust(df, Kmax = 30, lmin = 10, ncluster = 2:4, seg.var = c("x","y"), subsample_over = 500) # Run with subsampling by 2: res <- segclust(df, Kmax = 30, lmin = 10, ncluster = 2:4, seg.var = c("x","y"), subsample_by = 2) # Disable subsampling: res <- segclust(df, Kmax = 30, lmin = 10, ncluster = 2:4, seg.var = c("x","y"), subsample = FALSE) # Disabling automatic scaling of variables for segmentation (standardazing # the variables) : res <- segclust(df, Kmax = 30, lmin = 10, seg.var = c("dist","angle"), scale.variable = FALSE) ## End(Not run)
#' @examples df <- test_data()$data #' # data is a data.frame with column 'x' and 'y' # Simple segmentation with automatic subsampling # if data has more than 1000 rows: res <- segclust(df, Kmax = 15, lmin = 10, ncluster = 2:4, seg.var = c("x","y")) # Plot results plot(res) segmap(res, coord.names = c("x","y")) # check penalized likelihood of # alternative number of segment possible. # There should be a clear break if the segmentation is good plot_BIC(res) ## Not run: # Advanced options: # Run with automatic subsampling if df has more than 500 rows: res <- segclust(df, Kmax = 30, lmin = 10, ncluster = 2:4, seg.var = c("x","y"), subsample_over = 500) # Run with subsampling by 2: res <- segclust(df, Kmax = 30, lmin = 10, ncluster = 2:4, seg.var = c("x","y"), subsample_by = 2) # Disable subsampling: res <- segclust(df, Kmax = 30, lmin = 10, ncluster = 2:4, seg.var = c("x","y"), subsample = FALSE) # Disabling automatic scaling of variables for segmentation (standardazing # the variables) : res <- segclust(df, Kmax = 30, lmin = 10, seg.var = c("dist","angle"), scale.variable = FALSE) ## End(Not run)
Internal segmentation/clustering function
segclust_internal( x, seg.var, diag.var, order.var, Kmax, ncluster, lmin, scale.variable, sameSigma = FALSE, ... )
segclust_internal( x, seg.var, diag.var, order.var, Kmax, ncluster, lmin, scale.variable, sameSigma = FALSE, ... )
x |
data.frame with observations |
seg.var |
names of the variables used for segmentation (either one or two names). |
diag.var |
names of the variables on which statistics are calculated. |
order.var |
names of the variable with which states are ordered. |
Kmax |
maximum number of segments. |
ncluster |
number of cluster into which segments should be grouped. Can be a vector if one want to test several number of clusters. |
lmin |
minimum length of segments. |
scale.variable |
TRUE or FALSE for automatic scaling of variables (reduction and centering) |
sameSigma |
does segments have same variance ? |
... |
additional arguments given to |
Provides two methods for segmentation and joint segmentation/clustering of bivariate time-series. Originally intended for ecological segmentation (home-range and behavioural modes) but easily applied on other series, the package also provides tools for analysing outputs from R packages moveHMM and marcher.
The segmentation method is a bivariate extension of Lavielle's method available in adehabitatLT (Lavielle 1999; and 2005). This method rely on dynamic programming for efficient segmentation.
The segmentation/clustering method alternates steps of dynamic programming with an Expectation-Maximization algorithm. This is an extension of Picard et al (2007) method (formerly available in cghseg package) to the bivariate case.
The full description of the method is published in Patin et al. (2020).
References:
Lavielle, M. (1999) Detection of multiple changes in a sequence of dependent variables. Stochastic Processes and their Applications, 83: 79–102.
Lavielle, M. (2005) Using penalized contrasts for the change-point problem. Report number 5339, Institut national de recherche en informatique et en automatique.
Patin, R., Etienne, M. P., Lebarbier, E., Chamaille-Jammes, S., & Benhamou, S. (2020). Identifying stationary phases in multivariate time series for highlighting behavioural modes and home range settlements. Journal of Animal Ecology, 89(1), 44-56.
Picard, F., Robin, S., Lebarbier, E. and Daudin, J.-J. (2007), A Segmentation/Clustering Model for the Analysis of Array CGH Data. Biometrics, 63: 758-766. doi:10.1111/j.1541-0420.2006.00729.x
Maintainer: Remi Patin [email protected]
Authors:
Marie-Pierre Etienne
Emilie Lebarbier
Simon Benhamou
Useful links:
segmap_list
create maps with a list of object of segmentation
classsegmap_list
create maps with a list of object of segmentation
class
segmap_list( x_list, ncluster_list = NULL, nseg_list = NULL, pointsize = 1, linesize = 0.5, coord.names = c("x", "y") )
segmap_list( x_list, ncluster_list = NULL, nseg_list = NULL, pointsize = 1, linesize = 0.5, coord.names = c("x", "y") )
x_list |
list of segmentation objects for different individuals or path |
ncluster_list |
list of number of cluster to be selected for each individual. If empty, the function takes the default one |
nseg_list |
list of number of segment to be selected for each individual. If empty, the function takes the default one |
pointsize |
size of points |
linesize |
size of lines |
coord.names |
names of coordinates |
a ggplot2 graph
Segmentation of movement data. No clustering. Method available for data.frame, move and ltraj object. The algorithm finds for each number of segment the optimal segmentation using a Dynamic Programming approach. The number of segment is then chosen using Lavielle's (2005) procedure based on locating rupture in the penalized likelihood.
segmentation(x, ...) ## S3 method for class 'data.frame' segmentation(x, ...) ## S3 method for class 'Move' segmentation(x, ...) ## S3 method for class 'ltraj' segmentation(x, ...) segmentation_internal( x, seg.var, diag.var, order.var, lmin, Kmax, scale.variable, sameSigma = FALSE, ... )
segmentation(x, ...) ## S3 method for class 'data.frame' segmentation(x, ...) ## S3 method for class 'Move' segmentation(x, ...) ## S3 method for class 'ltraj' segmentation(x, ...) segmentation_internal( x, seg.var, diag.var, order.var, lmin, Kmax, scale.variable, sameSigma = FALSE, ... )
x |
data.frame with observations |
... |
additional parameters given to chooseseg_lavielle |
seg.var |
names of the variables used for segmentation (either one or two names). |
diag.var |
names of the variables on which statistics are calculated. |
order.var |
names of the variable with which states are ordered. |
lmin |
minimum length of segments. |
Kmax |
maximum number of segments. |
scale.variable |
TRUE or FALSE for automatic scaling of variables (reduction and centering) |
sameSigma |
does segments have same variance ? |
a segmentation-class
object
df <- test_data()$data #' # data is a data.frame with column 'x' and 'y' # Simple segmentation with automatic subsampling # if data has more than 1000 rows: res <- segmentation(df, Kmax = 30, lmin = 10, seg.var = c("x","y")) # Plot results plot(res) segmap(res) # check likelihood of alternative number of segment possible. There should # be a clear break if the segmentation is good plot_likelihood(res) ## Not run: # Advanced options: # Run with automatic subsampling if df has more than 500 rows: res <- segmentation(df, Kmax = 30, lmin = 10, seg.var = c("x","y"), subsample_over = 500) # Run with subsampling by 2: res <- segmentation(df, Kmax = 30, lmin = 10, seg.var = c("x","y"), subsample_by = 2) # Disable subsampling: res <- segmentation(df, Kmax = 30, lmin = 10, seg.var = c("x","y"), subsample = FALSE) # Run on other kind of variables : res <- segmentation(df, Kmax = 30, lmin = 10, seg.var = c("dist","angle")) # Automatic scaling of variables for segmentation (set a mean of 0 and a standard deviation of 1 for both variables) res <- segmentation(df, Kmax = 30, lmin = 10, seg.var = c("dist","angle"), scale.variable = TRUE) ## End(Not run)
df <- test_data()$data #' # data is a data.frame with column 'x' and 'y' # Simple segmentation with automatic subsampling # if data has more than 1000 rows: res <- segmentation(df, Kmax = 30, lmin = 10, seg.var = c("x","y")) # Plot results plot(res) segmap(res) # check likelihood of alternative number of segment possible. There should # be a clear break if the segmentation is good plot_likelihood(res) ## Not run: # Advanced options: # Run with automatic subsampling if df has more than 500 rows: res <- segmentation(df, Kmax = 30, lmin = 10, seg.var = c("x","y"), subsample_over = 500) # Run with subsampling by 2: res <- segmentation(df, Kmax = 30, lmin = 10, seg.var = c("x","y"), subsample_by = 2) # Disable subsampling: res <- segmentation(df, Kmax = 30, lmin = 10, seg.var = c("x","y"), subsample = FALSE) # Run on other kind of variables : res <- segmentation(df, Kmax = 30, lmin = 10, seg.var = c("dist","angle")) # Automatic scaling of variables for segmentation (set a mean of 0 and a standard deviation of 1 for both variables) res <- segmentation(df, Kmax = 30, lmin = 10, seg.var = c("dist","angle"), scale.variable = TRUE) ## End(Not run)
segmentation class description
print.segmentation
prints object of segmentation
class
plot.segmentation
plot object of segmentation
class -
wrapper for plot_segm
likelihood.segmentation
deprecated function for plotting likelihood
estimates of segmentation
object. Now use plot_likelihood.
plot_likelihood
plot likelihood estimates of a segmentation
object - works only for picard segmentation.
get_likelihood
returns
likelihood estimates of a segmentation
object.
Deprecated, now use logLik.segmentation.
logLik.segmentation
returns
log-likelihood estimates of a segmentation
object
plot_BIC
plot BIC estimates of a segmentation
object
- works only for segclust algorithm.
BIC
returns BIC-based penalized log-likelihood estimates of a
segmentation
object when segmentation/clustering has been run.
stateplot
plot state distribution of a segmentation
object
states
return data.frame with states statistics a segmentation
object
segment
return data.frame with segment information of a
segmentation
object
augment.segmentation
return data.frame with original data and state
information of a segmentation
object
segmap
create maps with object of segmentation
class
(interpreting latitude/longitude)
## S3 method for class 'segmentation' print(x, max.level = 1, ...) ## S3 method for class 'segmentation' plot(x, nseg, ncluster, interactive = FALSE, xcol = "indice", order, ...) ## S3 method for class 'segmentation' likelihood(x, ...) plot_likelihood(x) get_likelihood(x) ## S3 method for class 'segmentation' logLik(object, ...) plot_BIC(x) ## S3 method for class 'segmentation' BIC(object, ...) stateplot(x, nseg, ncluster, order) states(x, nseg, ncluster) segment(x, nseg, ncluster) ## S3 method for class 'segmentation' augment(x, nseg, ncluster, colname_state = "state", ...) segmap( x, interactive = FALSE, nseg, ncluster, html = FALSE, scale = 1, width = 400, height = 400, order, pointsize = 1, linesize = 0.5, ... )
## S3 method for class 'segmentation' print(x, max.level = 1, ...) ## S3 method for class 'segmentation' plot(x, nseg, ncluster, interactive = FALSE, xcol = "indice", order, ...) ## S3 method for class 'segmentation' likelihood(x, ...) plot_likelihood(x) get_likelihood(x) ## S3 method for class 'segmentation' logLik(object, ...) plot_BIC(x) ## S3 method for class 'segmentation' BIC(object, ...) stateplot(x, nseg, ncluster, order) states(x, nseg, ncluster) segment(x, nseg, ncluster) ## S3 method for class 'segmentation' augment(x, nseg, ncluster, colname_state = "state", ...) segmap( x, interactive = FALSE, nseg, ncluster, html = FALSE, scale = 1, width = 400, height = 400, order, pointsize = 1, linesize = 0.5, ... )
x |
a |
max.level |
argument to be passed to utils::str() |
... |
additional arguments |
nseg |
number of segment chosen |
ncluster |
number of classes chosen |
interactive |
whether plot are interactive (dygraphs/leaflet) or not (ggplot2) |
xcol |
column for x axis. can be POSIXct |
order |
should cluster be ordered |
object |
a segmentation-class object, created by segclust. |
colname_state |
column name for the added state column |
html |
whether htmltools::tagList should be applied on the returned object object for integrating in html pages |
scale |
for dividing coordinates to have compatibility with leaflet |
width |
width |
height |
height |
pointsize |
size of points |
linesize |
size of lines |
## Not run: plot(res.segclust) plot(res.segclust, nseg = 10, ncluster = 3) ## End(Not run) ## Not run: plot_likelihood(res.seg) ## End(Not run) ## Not run: logLik(res.seg) ## End(Not run) ## Not run: plot_BIC(res.segclust) ## End(Not run) ## Not run: plot_BIC(res.segclust) ## End(Not run) ## Not run: stateplot(res.segclust) stateplot(res.seg) ## End(Not run) ## Not run: states(res.segclust) states(res.seg) ## End(Not run) ## Not run: segment(res.segclust) segment(res.segclust, ncluster = 3, nseg = 30) segment(res.seg) segment(res.seg, nseg = 4) ## End(Not run) ## Not run: augment(res.segclust) augment(res.segclust, ncluster = 3, nseg = 30) augment(res.seg) augment(res.seg, nseg = 4) ## End(Not run) ## Not run: segmap(res.segclust, coord.names = c("x", "y")) segmap(res.segclust, ncluster = 3, nseg = 30) segmap(res.seg) segmap(res.seg, nseg = 4) ## End(Not run)
## Not run: plot(res.segclust) plot(res.segclust, nseg = 10, ncluster = 3) ## End(Not run) ## Not run: plot_likelihood(res.seg) ## End(Not run) ## Not run: logLik(res.seg) ## End(Not run) ## Not run: plot_BIC(res.segclust) ## End(Not run) ## Not run: plot_BIC(res.segclust) ## End(Not run) ## Not run: stateplot(res.segclust) stateplot(res.seg) ## End(Not run) ## Not run: states(res.segclust) states(res.seg) ## End(Not run) ## Not run: segment(res.segclust) segment(res.segclust, ncluster = 3, nseg = 30) segment(res.seg) segment(res.seg, nseg = 4) ## End(Not run) ## Not run: augment(res.segclust) augment(res.segclust, ncluster = 3, nseg = 30) augment(res.seg) augment(res.seg, nseg = 4) ## End(Not run) ## Not run: segmap(res.segclust, coord.names = c("x", "y")) segmap(res.segclust, ncluster = 3, nseg = 30) segmap(res.seg) segmap(res.seg, nseg = 4) ## End(Not run)
A dataset containing a simulation of 3 different behavioural mode
simulmode
simulmode
A data frame with 302 rows and 10 variables:
index of position
x coordinates
y coordinates
smoothed speed
angle at constant step length
raw speed
angular speed
persistence speed
rotation speed
persistence speed calculated with spatial angles
rotation speed calculated with spatial angles
arbitrary date in POSIXct format
A dataset containing a simulation of home-range shift
simulshift
simulshift
A data frame with 53940 rows and 10 variables:
index of position
x coordinates
y coordinates
arbitrary date in POSIXct format
spatial_angle
calculate spatial angle between locations, taking a
dataframe as input. Spatial angle is considered as the angle between the
focus point, the first location entering a given circle and the last location
inside.
spatial_angle(x, coord.names = c("x", "y"), radius = NULL)
spatial_angle(x, coord.names = c("x", "y"), radius = NULL)
x |
data.frame with locations |
coord.names |
names of coordinates column in |
radius |
for angle calculation. Default is median of step length. |
vector of spatial angle.
Remi Patin, Simon Benhamou.
## Not run: data(simulmode) spatial_angle(simulmode) ## End(Not run)
## Not run: data(simulmode) spatial_angle(simulmode) ## End(Not run)
stat_segm
calculates statistics of a given segmentation : mean and
variance of the different states. it also creates standard objects for plot.
stat_segm( data, diag.var, order.var = NULL, param = NULL, seg.type = NULL, nseg )
stat_segm( data, diag.var, order.var = NULL, param = NULL, seg.type = NULL, nseg )
data |
the data.frame with the different variable |
diag.var |
names of the variables on which statistics are calculated |
order.var |
names of the variable with which states are ordered |
param |
parameters of output segmentation |
seg.type |
either 'hybrid' or 'dynprog' |
nseg |
number of segment chosen |
a list which first element is a data.frame with states of the different segments and which second element is a data.frame with mean and variance of the different states
## Not run: #res.segclust is a result of a segmentation-clustering algorithm param <- res.segclust$param[["3 class"]] nseg = 10 out <- stat_segm(data, diag.var = c("dist","angle"), order.var = "dist", param = param, nseg=nseg, seg.type = "segclust") ## End(Not run)
## Not run: #res.segclust is a result of a segmentation-clustering algorithm param <- res.segclust$param[["3 class"]] nseg = 10 out <- stat_segm(data, diag.var = c("dist","angle"), order.var = "dist", param = param, nseg=nseg, seg.type = "segclust") ## End(Not run)
stat_segm_HMM
stat_segm_HMM(data, hmm.model = NULL, diag.var, order.var = NULL)
stat_segm_HMM(data, hmm.model = NULL, diag.var, order.var = NULL)
data |
data |
hmm.model |
hmm.model |
diag.var |
diag.var |
order.var |
order.var |
stat_segm_shiftfit
stat_segm_shiftfit(data, shiftfit.model = NULL, diag.var, order.var = NULL)
stat_segm_shiftfit(data, shiftfit.model = NULL, diag.var, order.var = NULL)
data |
data |
shiftfit.model |
shiftfit.model |
diag.var |
diag.var |
order.var |
order.var |
merge subsampled data.frame df with fulldata to add segmentation information on the full data.frame
subsample_rename(df, fulldata, colname)
subsample_rename(df, fulldata, colname)
df |
subsampled data.frame with additional information on segmentation |
fulldata |
full data.frame |
colname |
column name |
Test function generating fake data
test_data()
test_data()
DynProg Rcpp DynProg computes the change points given a cost matrix matD and a maximum number of segments Kmax
wrap_dynprog_cpp(G, K)
wrap_dynprog_cpp(G, K)
G |
the cost Matrix os size n x n |
K |
the number of segments considered |
a list with J.est a vector with Kmax value, the Kth is the minimum contrast for a model with K segments (-J.est is the log-likelihood) and with t.test a matrix, line K are the coordinates of the change points for a model with K segments