dsdive.impute: Impute a complete dive trajectory from partial observations

Description Usage Arguments Examples

View source: R/dsdive.impute.R

Description

Uses properties of homogeneous Continuous time Markov Chains (CTMCs) to impute trajectory segments between observations. The sampler begins by sampling the number of transitions between observations N, then samples a length N path that connects the trajectory segment at its start and end states.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
dsdive.impute(
  depths,
  times,
  t.stages,
  rate.unif,
  P.raw,
  P.tx,
  n.bins = nrow(depths),
  max.tx
)

Arguments

depths

Depth bin indices visited

times

Times at which each of depths was visited

t.stages

Stage transition times for the dive; will be used to compute the dive stage for each observation

rate.unif

uniformization rate, for standardizing transition rates between states

P.raw

list of continuous time probability transition matrices, and components.

P.tx

list of discrete time probability transition matrices

n.bins

number of rows in the depths matrix

max.tx

maximum number of transitions between observations that will be allowed during imputation

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
28
29
30
31
32
33
34
35
36
37
38
39
data('dive.sim')
attach(dive.sim)
attach(dive.sim$params)

# true stage transition times for the dive
t.stages = sim$times[c(FALSE, diff(sim$stages)==1)]

# uniformized transition rate
rate.unif = max(outer(lambda, 2*depth.bins[,2], '/'))

# time between observations
tstep = diff(sim.obs$times[1:2])

# probability transition matrix for observations
P.raw = lapply(1:3, function(s) {
  dsdive.obstx.matrix(depth.bins = depth.bins, beta = beta, 
                      lambda = lambda, s0 = s, tstep = tstep, 
                      include.raw = TRUE, delta = 1e-10)
})

# probability transition matrix for uniformized DTMC
P.tx = lapply(1:3, function(s) {
  dsdive.tx.matrix.uniformized(depth.bins = depth.bins, beta = beta, 
                               lambda = lambda, s0 = s, 
                               rate.uniformized = rate.unif)
})

# impute dive trajectory
x = dsdive.impute(
  depths = sim.obs$depths, times = sim.obs$times, t.stages = t.stages, 
  rate.unif = rate.unif, P.raw = P.raw, P.tx = P.tx, n.bins = nrow(depth.bins), 
  max.tx = 100)

# overlay trajectory over observations
pl = plot(x = sim.obs, depth.bins = depth.bins, stages = sim.obs$stages, 
          errorbars = TRUE, imputed.list = x)

detach(dive.sim$params)
detach(dive.sim)

jmhewitt/dsdive documentation built on May 29, 2020, 5:18 p.m.