sweepRACVM: Sweep RACVM

View source: R/sweepRACVM.R

sweepRACVMR Documentation

Sweep RACVM

Description

Sets a window (a subset of movement data within specific time window), computes likelihoods for a set of candidate change points within the window, and steps the window forward, filling out a likelihood matrix.

Usage

sweepRACVM(Z, ...)

## Default S3 method:
sweepRACVM(
  Z,
  T,
  windowsize,
  windowstep,
  model = "UCVM",
  progress = TRUE,
  time.unit = "hours",
  ...,
  .parallel = FALSE
)

## S3 method for class 'data.frame'
sweepRACVM(Z, ...)

## S3 method for class 'ltraj'
sweepRACVM(Z, ...)

## S3 method for class 'Move'
sweepRACVM(Z, ...)

Arguments

Z

location data. Can be: a complex vector, a two-column matrix or data frame, an ltraj object from adehabitatLT or a move object from the move package.

...

additional parameters to pass to the estimateRACVM function, notably the option "criterion" allows you to select models based on AIC or BIC (the former is more liberal with more complex models).

T

time vector, ignored if Z is an ltraj or move

windowsize

time window of analysis to scan, IMPORTANTLY: in units of time (T).

windowstep

step (in time) by which the window advances. The smaller the step, the slower but more thorough the estimation.

model

model to fit for the change point sweep - typically the most complex model in the candidate model set.

progress

whether or not to show a progress bar

time.unit

of the windowsize AND the windowstep. The default is "hours" - can be any of "secs", "mins", "hours", "days", "weeks" (See difftime). Ignored if time is not POSIX.

.parallel

if set TRUE, will use foreach to parallelize the optimization. Requires establishing the

See Also

plotWindowSweep, estimateRACVM, testCP

Examples

if(interactive() && FALSE){
  # Three stage example (from vignette)
  require(smoove)
  require(plyr)
  require(magrittr)
  
  taus <- c(3, 3, 1)
  mus <- c(3, 0, 0)
  etas <- c(2, 1, 1)
  tmaxes <- c(40,60,100)
  
  Z.raw <- 0
  T.raw <- 0
  mycvm <- list()
  
  for(i in 1:length(taus)){
    if(i > 1)  v0 <- mycvm$V[length(mycvm)]  else v0 = mus[1]
    mycvm <- simulateRACVM(tau = taus[i], eta = etas[i], mu = mus[i], v0 = v0,
                           Tmax = tmaxes[i], dt = 0.01)
    Z.raw <- c(Z.raw, mycvm$Z + Z.raw[length(Z.raw)])
    T.raw <- c(T.raw, mycvm$T + T.raw[length(T.raw)])
  }
  
  multicvm <- data.frame(Z = Z.raw, T = T.raw)[sample(1:length(Z.raw), 400),] %>% 
    arrange(T)
  plot_track(multicvm$Z)
  
  # Perform sweep
  simSweep <- with(multicvm,
                   sweepRACVM(
                     Z = Z,
                     T = T,
                     windowsize = 80,
                     windowstep = 10,
                     model = "ACVM"
                   ))
  
  # Perform sweep in parallel (can greatly improve speed)
  if(!requireNamespace('doParallel',quietly = TRUE))
    warning("package \"doParallel\" is needed for this example. 
         Please install it first and then run this example",
         call. = FALSE)
    
    cl <- parallel::makeCluster(parallel::detectCores())
    doParallel::registerDoParallel(cl)
    simSweep <- with(
      multicvm,
      sweepRACVM(
        Z = Z,
        T = T,
        windowsize = 80,
        windowstep = 5,
        model = "UCVM",
        .parallel = TRUE
      )
    )
    # plot result of window sweep
    plotWindowSweep(simSweep)
}

EliGurarie/smoove documentation built on Aug. 2, 2022, 10:26 p.m.