
Compute probability to be in a given state
compute_state_prob.RdCompute probability to be in a given state
Author
Frédéric Grelot, frederic.grelot.1994_cran@m4x.org
Examples
state = 1:4
year = 0:10
tree = matrix(1, nrow = length(year), dimnames = list(year = year))
state_base = sample(1:4, length(year), replace = TRUE)
compute_state_prob(state_base, tree, state)
#> state
#> year 1 2 3 4
#> 0 0 1 0 0
#> 1 0 1 0 0
#> 2 0 0 1 0
#> 3 0 0 1 0
#> 4 0 0 0 1
#> 5 0 0 0 1
#> 6 0 1 0 0
#> 7 0 0 1 0
#> 8 1 0 0 0
#> 9 0 1 0 0
#> 10 0 0 1 0
state_change = sample(1:4, length(year), replace = TRUE)
tree = structure(
rbind(c(1, 0), matrix(.5, nrow = length(year) - 1, ncol = 2)),
dimnames = list(year = year))
result = compute_state_prob(state_base, tree, state, state_base)
rowSums(result)
#> 0 1 2 3 4 5 6 7 8 9 10
#> 1.0 1.0 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5
tree = structure(
rbind(c(1, 0, 0), c(.5, .5, 0), matrix(1/3, nrow = length(year) - 2, ncol = 3)),
dimnames = list(year = year))
result = compute_state_prob(state_base, tree, state, state_base)
rowSums(result)
#> 0 1 2 3 4 5 6 7
#> 1.0000000 1.0000000 1.0000000 0.3333333 0.3333333 0.3333333 0.3333333 0.3333333
#> 8 9 10
#> 0.3333333 0.3333333 0.3333333