Estimate probabilities to be in each state

estimate_pt(data, NAafterTmax = FALSE)

Arguments

data

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

NAafterTmax

if TRUE, return NA if t > Tmax otherwise return the state associated with Tmax (useful when individuals has different lengths)

Value

A list of two elements:

  • t: vector of time

  • pt: a matrix with K (= number of states) rows and with length(t) columns containing the probabilities to be in each state at each time.

Author

Cristian Preda, Quentin Grimonprez

Examples

# Simulate the Jukes-Cantor model of nucleotide replacement
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)

d_JK2 <- cut_data(d_JK, 10)

# estimate probabilities
estimate_pt(d_JK2)
#> $pt
#>   0 0.028 0.094 0.106 0.253 0.289 0.374 0.379 0.427 0.488 0.533 0.563 0.625
#> 1 1   0.9   0.8   0.7   0.8   0.7   0.7   0.7   0.7   0.6   0.5   0.6   0.5
#> 2 0   0.0   0.0   0.0   0.0   0.0   0.1   0.0   0.0   0.0   0.0   0.0   0.0
#> 3 0   0.1   0.1   0.1   0.0   0.0   0.0   0.1   0.0   0.0   0.1   0.1   0.2
#> 4 0   0.0   0.1   0.2   0.2   0.3   0.2   0.2   0.3   0.4   0.4   0.3   0.3
#>   0.823 0.859 0.944 0.947 0.976 1.011 1.076 1.281 1.311 1.524 1.555 1.602 1.667
#> 1   0.4   0.4   0.3   0.2   0.2   0.2   0.2   0.2   0.2   0.2   0.2   0.2   0.2
#> 2   0.1   0.2   0.2   0.2   0.1   0.2   0.1   0.1   0.0   0.1   0.2   0.1   0.2
#> 3   0.2   0.1   0.2   0.2   0.3   0.3   0.3   0.2   0.3   0.2   0.2   0.2   0.2
#> 4   0.3   0.3   0.3   0.4   0.4   0.3   0.4   0.5   0.5   0.5   0.4   0.5   0.4
#>   1.921 1.958 2.115 2.146 2.218 2.226 2.307 2.354 2.638 2.675 2.715 2.748 2.805
#> 1   0.3   0.4   0.4   0.4   0.3   0.3   0.2   0.1   0.0   0.0   0.1   0.2   0.2
#> 2   0.1   0.1   0.1   0.1   0.1   0.2   0.3   0.3   0.3   0.4   0.3   0.3   0.2
#> 3   0.2   0.2   0.1   0.2   0.3   0.2   0.2   0.2   0.3   0.3   0.3   0.2   0.2
#> 4   0.4   0.3   0.4   0.3   0.3   0.3   0.3   0.4   0.4   0.3   0.3   0.3   0.4
#>   2.923 2.949 3.107 3.152 3.18 3.257 3.363 3.404 3.536 3.592 3.886 3.95 4.024
#> 1   0.3   0.2   0.2   0.3  0.3   0.4   0.5   0.4   0.4   0.4   0.3  0.3   0.3
#> 2   0.1   0.1   0.1   0.1  0.2   0.2   0.1   0.1   0.0   0.1   0.2  0.3   0.2
#> 3   0.2   0.2   0.3   0.2  0.2   0.2   0.2   0.2   0.2   0.2   0.2  0.1   0.1
#> 4   0.4   0.5   0.4   0.4  0.3   0.2   0.2   0.3   0.4   0.3   0.3  0.3   0.4
#>   4.077 4.095 4.116 4.188 4.3 4.506 4.729 4.801 4.885 5.21 5.239 5.289 5.398
#> 1   0.4   0.3   0.3   0.3 0.3   0.2   0.2   0.2   0.2  0.3   0.2   0.2   0.2
#> 2   0.2   0.2   0.1   0.1 0.2   0.2   0.3   0.3   0.2  0.2   0.2   0.3   0.3
#> 3   0.1   0.1   0.1   0.2 0.1   0.2   0.2   0.3   0.4  0.3   0.4   0.3   0.4
#> 4   0.3   0.4   0.5   0.4 0.4   0.4   0.3   0.2   0.2  0.2   0.2   0.2   0.1
#>   5.496 5.791 5.8 5.816 6.021 6.109 6.139 6.224 6.226 6.332 6.35 6.383 6.498
#> 1   0.1   0.1 0.1   0.1   0.1   0.1   0.1   0.0   0.0   0.1  0.2   0.1   0.2
#> 2   0.4   0.3 0.3   0.3   0.2   0.2   0.3   0.4   0.5   0.4  0.3   0.4   0.4
#> 3   0.4   0.5 0.4   0.5   0.5   0.4   0.3   0.3   0.3   0.3  0.3   0.3   0.3
#> 4   0.1   0.1 0.2   0.1   0.2   0.3   0.3   0.3   0.2   0.2  0.2   0.2   0.1
#>   6.707 6.897 6.969 6.978 7.087 7.108 7.199 7.268 7.28 7.36 7.437 7.48 7.605
#> 1   0.1   0.1   0.1   0.2   0.1   0.0   0.1   0.1  0.1  0.2   0.1  0.1   0.2
#> 2   0.5   0.5   0.5   0.5   0.5   0.5   0.5   0.4  0.4  0.4   0.5  0.4   0.3
#> 3   0.3   0.2   0.1   0.1   0.1   0.2   0.2   0.3  0.2  0.1   0.1  0.2   0.2
#> 4   0.1   0.2   0.3   0.2   0.3   0.3   0.2   0.2  0.3  0.3   0.3  0.3   0.3
#>   7.644 7.76 7.912 7.93 7.997 8.032 8.328 8.419 8.504 8.528 8.608 8.634 8.635
#> 1   0.2  0.3   0.2  0.2   0.2   0.1   0.2   0.2   0.2   0.2   0.2   0.2   0.1
#> 2   0.4  0.4   0.4  0.3   0.4   0.5   0.5   0.6   0.7   0.6   0.6   0.6   0.7
#> 3   0.1  0.1   0.1  0.1   0.1   0.1   0.1   0.1   0.0   0.1   0.2   0.1   0.1
#> 4   0.3  0.2   0.3  0.4   0.3   0.3   0.2   0.1   0.1   0.1   0.0   0.1   0.1
#>   8.792 8.898 9.014 9.03 9.195 9.298 9.307 9.317 9.32 9.354 9.422 9.437 9.489
#> 1   0.0   0.1   0.2  0.2   0.2   0.1   0.0   0.0  0.0   0.0   0.1   0.2   0.3
#> 2   0.8   0.8   0.7  0.6   0.7   0.8   0.8   0.7  0.6   0.5   0.5   0.5   0.4
#> 3   0.1   0.0   0.0  0.0   0.0   0.0   0.1   0.1  0.1   0.1   0.1   0.1   0.1
#> 4   0.1   0.1   0.1  0.2   0.1   0.1   0.1   0.2  0.3   0.4   0.3   0.2   0.2
#>   9.686 9.857  10
#> 1   0.2   0.3 0.3
#> 2   0.4   0.4 0.4
#> 3   0.2   0.1 0.1
#> 4   0.2   0.2 0.2
#> 
#> $t
#>   [1]  0.00000000  0.02755240  0.09370509  0.10640850  0.25290377  0.28937582
#>   [7]  0.37449061  0.37931910  0.42730239  0.48777133  0.53345456  0.56337430
#>  [13]  0.62484774  0.82334431  0.85924055  0.94356750  0.94662363  0.97608685
#>  [19]  1.01140755  1.07594812  1.28123824  1.31109399  1.52409244  1.55534139
#>  [25]  1.60168136  1.66719715  1.92119632  1.95821066  2.11489079  2.14635918
#>  [31]  2.21795628  2.22644841  2.30733092  2.35373320  2.63788043  2.67527691
#>  [37]  2.71510565  2.74762224  2.80541116  2.92328515  2.94890936  3.10650492
#>  [43]  3.15153045  3.17990375  3.25706108  3.36328579  3.40426873  3.53550653
#>  [49]  3.59210510  3.88597177  3.95024470  4.02418914  4.07684936  4.09534683
#>  [55]  4.11582266  4.18822801  4.30037150  4.50644960  4.72908831  4.80092198
#>  [61]  4.88456999  5.20965145  5.23856971  5.28938896  5.39847150  5.49597440
#>  [67]  5.79124782  5.80000751  5.81590326  6.02106221  6.10868350  6.13876469
#>  [73]  6.22350061  6.22572965  6.33163800  6.34953384  6.38315936  6.49816604
#>  [79]  6.70717214  6.89713464  6.96928660  6.97810277  7.08655702  7.10774498
#>  [85]  7.19935150  7.26765439  7.28039476  7.36041711  7.43734252  7.48027194
#>  [91]  7.60455723  7.64443079  7.75968137  7.91157307  7.92977601  7.99703962
#>  [97]  8.03179696  8.32773497  8.41940166  8.50403122  8.52809897  8.60760633
#> [103]  8.63442683  8.63498440  8.79230153  8.89844938  9.01422385  9.03037631
#> [109]  9.19479834  9.29796501  9.30669196  9.31715795  9.31982081  9.35443685
#> [115]  9.42175231  9.43746113  9.48880374  9.68607408  9.85661948 10.00000000
#> 
#> attr(,"class")
#> [1] "pt"