compute.state.prob.Rd
Compute probability to be in a given state
compute.state.prob(state_base, tree, state, state_change)
vector of base states.
matrix of probability of being in a given branch. First column is for the basic states, the other are for the change states. Beware tree must be "cumulative".
vector of all admissible states
vector of change states.
matrix of probability to be in a given state (columns) at give year (rows)
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 1 0 0 0
#> 1 0 0 1 0
#> 2 0 0 0 1
#> 3 0 0 1 0
#> 4 1 0 0 0
#> 5 0 0 1 0
#> 6 0 0 1 0
#> 7 0 1 0 0
#> 8 0 0 0 1
#> 9 0 0 0 1
#> 10 0 1 0 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