Cut data to a maximal given time

cut_data(
  data,
  Tmax,
  prolongLastState = "all",
  NAstate = "Not observed",
  warning = FALSE
)

Arguments

data

data.frame containing id, id of the trajectory, time, time at which a change occurs and state, associated state.

Tmax

max time considered

prolongLastState

list of states to prolong (can be "all"). In the case where the last state of a trajectory is lesser than Tmax, we can assume that this trajectory will be in the same state at time Tmax only if it is an absorbing state. Otherwise it will add NAstate and throw a warning. Set `prolongLastState = c()` to indicate there is no absorbing state.

NAstate

state value used when the last state is not prolonged.

warning

if TRUE, the function raises warnings when it has prolonged a trajectory with NAstate

Value

a data.frame with the same format as data where each individual has Tmax as last time entry.

See also

Author

Cristian Preda

Examples

# Simulate the Jukes-Cantor model of nucleotide replacement
set.seed(42)
K <- 4
PJK <- matrix(1 / 3, nrow = K, ncol = K) - diag(rep(1 / 3, K))
lambda_PJK <- c(1, 1, 1, 1)
d_JK <- generate_Markov(n = 10, K = K, P = PJK, lambda = lambda_PJK, Tmax = 10)
tail(d_JK)
#>     id     time state
#> 103  9 7.534493     2
#> 104  9 9.419641     4
#> 105 10 0.000000     1
#> 106 10 3.661730     3
#> 107 10 7.634647     2
#> 108 10 8.873610     1

# cut at Tmax = 8
d_JK2 <- cut_data(d_JK, Tmax = 8)
tail(d_JK2)
#>    id     time state
#> 94  9 7.534493     2
#> 95  9 8.000000     2
#> 96 10 0.000000     1
#> 97 10 3.661730     3
#> 98 10 7.634647     2
#> 99 10 8.000000     2

# do not prolong any state
try(d_JK2 <- cut_data(d_JK, Tmax = 12, prolongLastState = c()))