Get the posterior probability matrix with element \((i,j)\) indicating the probability of trajectory \(i\) belonging to cluster \(j\).

postprob(object, ...)

# S4 method for class 'lcModel'
postprob(object, ...)

Arguments

object

The model.

...

Not used.

Value

An I-by-K numeric matrix with I = nIds(object) and K = nClusters(object).

Details

This method should be extended by lcModel implementations. The default implementation returns uniform probabilities for all observations.

Implementation

Classes extending lcModel should override this method.


setMethod("postprob", "lcModelExt", function(object, ...) {
  # return trajectory-specific posterior probability matrix
})

Troubleshooting

If you are getting errors about undefined model signatures when calling postprob(model), check whether the postprob() function is still the one defined by the latrend package. It may have been overridden when attaching another package (e.g., lcmm). If you need to attach conflicting packages, load them first.

Examples

data(latrendData)
method <- lcMethodLMKM(Y ~ Time, id = "Id", time = "Time")
model <- latrend(method, latrendData)

postprob(model)
#>        A B
#>   [1,] 1 0
#>   [2,] 1 0
#>   [3,] 1 0
#>   [4,] 1 0
#>   [5,] 1 0
#>   [6,] 1 0
#>   [7,] 1 0
#>   [8,] 1 0
#>   [9,] 1 0
#>  [10,] 1 0
#>  [11,] 1 0
#>  [12,] 1 0
#>  [13,] 1 0
#>  [14,] 1 0
#>  [15,] 1 0
#>  [16,] 1 0
#>  [17,] 1 0
#>  [18,] 1 0
#>  [19,] 1 0
#>  [20,] 1 0
#>  [21,] 1 0
#>  [22,] 1 0
#>  [23,] 1 0
#>  [24,] 1 0
#>  [25,] 1 0
#>  [26,] 1 0
#>  [27,] 1 0
#>  [28,] 1 0
#>  [29,] 1 0
#>  [30,] 1 0
#>  [31,] 1 0
#>  [32,] 1 0
#>  [33,] 1 0
#>  [34,] 1 0
#>  [35,] 1 0
#>  [36,] 1 0
#>  [37,] 1 0
#>  [38,] 1 0
#>  [39,] 1 0
#>  [40,] 1 0
#>  [41,] 1 0
#>  [42,] 1 0
#>  [43,] 1 0
#>  [44,] 1 0
#>  [45,] 1 0
#>  [46,] 1 0
#>  [47,] 1 0
#>  [48,] 1 0
#>  [49,] 1 0
#>  [50,] 1 0
#>  [51,] 1 0
#>  [52,] 1 0
#>  [53,] 1 0
#>  [54,] 1 0
#>  [55,] 1 0
#>  [56,] 1 0
#>  [57,] 1 0
#>  [58,] 1 0
#>  [59,] 1 0
#>  [60,] 1 0
#>  [61,] 1 0
#>  [62,] 1 0
#>  [63,] 1 0
#>  [64,] 1 0
#>  [65,] 1 0
#>  [66,] 1 0
#>  [67,] 1 0
#>  [68,] 1 0
#>  [69,] 1 0
#>  [70,] 1 0
#>  [71,] 1 0
#>  [72,] 1 0
#>  [73,] 1 0
#>  [74,] 1 0
#>  [75,] 1 0
#>  [76,] 1 0
#>  [77,] 1 0
#>  [78,] 1 0
#>  [79,] 1 0
#>  [80,] 1 0
#>  [81,] 0 1
#>  [82,] 0 1
#>  [83,] 0 1
#>  [84,] 0 1
#>  [85,] 0 1
#>  [86,] 0 1
#>  [87,] 0 1
#>  [88,] 0 1
#>  [89,] 0 1
#>  [90,] 0 1
#>  [91,] 0 1
#>  [92,] 0 1
#>  [93,] 0 1
#>  [94,] 0 1
#>  [95,] 0 1
#>  [96,] 0 1
#>  [97,] 0 1
#>  [98,] 0 1
#>  [99,] 0 1
#> [100,] 0 1
#> [101,] 0 1
#> [102,] 0 1
#> [103,] 0 1
#> [104,] 0 1
#> [105,] 0 1
#> [106,] 0 1
#> [107,] 0 1
#> [108,] 0 1
#> [109,] 0 1
#> [110,] 0 1
#> [111,] 0 1
#> [112,] 0 1
#> [113,] 0 1
#> [114,] 0 1
#> [115,] 0 1
#> [116,] 0 1
#> [117,] 0 1
#> [118,] 0 1
#> [119,] 0 1
#> [120,] 0 1
#> [121,] 0 1
#> [122,] 0 1
#> [123,] 0 1
#> [124,] 0 1
#> [125,] 0 1
#> [126,] 0 1
#> [127,] 0 1
#> [128,] 0 1
#> [129,] 0 1
#> [130,] 0 1
#> [131,] 0 1
#> [132,] 0 1
#> [133,] 0 1
#> [134,] 0 1
#> [135,] 0 1
#> [136,] 0 1
#> [137,] 0 1
#> [138,] 0 1
#> [139,] 0 1
#> [140,] 0 1
#> [141,] 0 1
#> [142,] 0 1
#> [143,] 0 1
#> [144,] 0 1
#> [145,] 0 1
#> [146,] 0 1
#> [147,] 0 1
#> [148,] 0 1
#> [149,] 0 1
#> [150,] 0 1
#> [151,] 0 1
#> [152,] 0 1
#> [153,] 0 1
#> [154,] 0 1
#> [155,] 0 1
#> [156,] 0 1
#> [157,] 0 1
#> [158,] 0 1
#> [159,] 0 1
#> [160,] 0 1
#> [161,] 0 1
#> [162,] 0 1
#> [163,] 0 1
#> [164,] 0 1
#> [165,] 0 1
#> [166,] 0 1
#> [167,] 0 1
#> [168,] 0 1
#> [169,] 0 1
#> [170,] 0 1
#> [171,] 0 1
#> [172,] 0 1
#> [173,] 0 1
#> [174,] 0 1
#> [175,] 0 1
#> [176,] 0 1
#> [177,] 0 1
#> [178,] 0 1
#> [179,] 0 1
#> [180,] 0 1
#> [181,] 0 1
#> [182,] 0 1
#> [183,] 0 1
#> [184,] 0 1
#> [185,] 0 1
#> [186,] 0 1
#> [187,] 0 1
#> [188,] 0 1
#> [189,] 0 1
#> [190,] 0 1
#> [191,] 0 1
#> [192,] 0 1
#> [193,] 0 1
#> [194,] 0 1
#> [195,] 0 1
#> [196,] 0 1
#> [197,] 0 1
#> [198,] 0 1
#> [199,] 0 1
#> [200,] 0 1

if (rlang::is_installed("lcmm")) {
  gmmMethod = lcMethodLcmmGMM(
    fixed = Y ~ Time,
    mixture = ~ Time,
    id = "Id",
    time = "Time",
    idiag = TRUE,
    nClusters = 2
  )
  gmmModel <- latrend(gmmMethod, data = latrendData)
  postprob(gmmModel)
}
#>                A            B
#> 1   2.547309e-17 1.000000e+00
#> 2   5.411522e-22 1.000000e+00
#> 3   3.041642e-19 1.000000e+00
#> 4   2.235736e-20 1.000000e+00
#> 5   8.499348e-10 1.000000e+00
#> 6   1.428899e-22 1.000000e+00
#> 7   7.217099e-20 1.000000e+00
#> 8   4.601011e-22 1.000000e+00
#> 9   2.465789e-18 1.000000e+00
#> 10  1.487810e-17 1.000000e+00
#> 11  4.431033e-18 1.000000e+00
#> 12  1.048311e-23 1.000000e+00
#> 13  1.624114e-19 1.000000e+00
#> 14  8.535574e-17 1.000000e+00
#> 15  9.154080e-19 1.000000e+00
#> 16  2.775977e-20 1.000000e+00
#> 17  3.751780e-19 1.000000e+00
#> 18  1.074618e-14 1.000000e+00
#> 19  3.429499e-19 1.000000e+00
#> 20  5.383558e-18 1.000000e+00
#> 21  8.954243e-15 1.000000e+00
#> 22  8.071920e-17 1.000000e+00
#> 23  3.636239e-18 1.000000e+00
#> 24  5.106287e-20 1.000000e+00
#> 25  3.644339e-17 1.000000e+00
#> 26  1.171056e-21 1.000000e+00
#> 27  1.186961e-19 1.000000e+00
#> 28  1.506209e-14 1.000000e+00
#> 29  5.704580e-19 1.000000e+00
#> 30  5.336798e-19 1.000000e+00
#> 31  1.202215e-17 1.000000e+00
#> 32  1.410158e-12 1.000000e+00
#> 33  1.841029e-16 1.000000e+00
#> 34  1.571870e-21 1.000000e+00
#> 35  2.531197e-23 1.000000e+00
#> 36  1.134933e-21 1.000000e+00
#> 37  8.624020e-20 1.000000e+00
#> 38  8.734216e-18 1.000000e+00
#> 39  3.199024e-20 1.000000e+00
#> 40  1.589164e-15 1.000000e+00
#> 41  6.669018e-21 1.000000e+00
#> 42  1.013342e-18 1.000000e+00
#> 43  7.838956e-18 1.000000e+00
#> 44  9.027838e-15 1.000000e+00
#> 45  4.032962e-18 1.000000e+00
#> 46  1.606951e-13 1.000000e+00
#> 47  1.326813e-15 1.000000e+00
#> 48  6.837974e-17 1.000000e+00
#> 49  1.112480e-18 1.000000e+00
#> 50  5.127967e-18 1.000000e+00
#> 51  6.227700e-20 1.000000e+00
#> 52  5.071706e-22 1.000000e+00
#> 53  1.910355e-16 1.000000e+00
#> 54  1.315540e-15 1.000000e+00
#> 55  1.489717e-20 1.000000e+00
#> 56  3.086665e-17 1.000000e+00
#> 57  1.051878e-14 1.000000e+00
#> 58  2.876305e-21 1.000000e+00
#> 59  1.715890e-19 1.000000e+00
#> 60  1.321604e-15 1.000000e+00
#> 61  9.535077e-18 1.000000e+00
#> 62  9.190271e-20 1.000000e+00
#> 63  2.424449e-16 1.000000e+00
#> 64  7.904951e-23 1.000000e+00
#> 65  1.599877e-22 1.000000e+00
#> 66  2.884337e-19 1.000000e+00
#> 67  6.949903e-17 1.000000e+00
#> 68  1.967578e-14 1.000000e+00
#> 69  1.408407e-17 1.000000e+00
#> 70  3.518169e-15 1.000000e+00
#> 71  2.106024e-17 1.000000e+00
#> 72  2.756480e-16 1.000000e+00
#> 73  4.318563e-15 1.000000e+00
#> 74  1.844605e-23 1.000000e+00
#> 75  1.737188e-17 1.000000e+00
#> 76  1.314989e-21 1.000000e+00
#> 77  6.142480e-13 1.000000e+00
#> 78  2.824823e-19 1.000000e+00
#> 79  4.868013e-15 1.000000e+00
#> 80  1.192237e-17 1.000000e+00
#> 81  9.999999e-01 5.541483e-08
#> 82  1.000000e+00 1.687982e-09
#> 83  1.000000e+00 1.237469e-08
#> 84  1.000000e+00 2.646910e-11
#> 85  1.000000e+00 2.743526e-11
#> 86  1.000000e+00 2.225112e-12
#> 87  1.000000e+00 3.498192e-09
#> 88  1.000000e+00 3.840670e-10
#> 89  1.000000e+00 4.912743e-09
#> 90  1.000000e+00 4.347079e-10
#> 91  1.000000e+00 6.570054e-11
#> 92  1.000000e+00 9.025892e-10
#> 93  1.000000e+00 7.647599e-11
#> 94  1.000000e+00 2.499976e-10
#> 95  1.000000e+00 1.745679e-08
#> 96  1.000000e+00 3.376375e-10
#> 97  1.000000e+00 7.724647e-09
#> 98  1.000000e+00 3.138129e-09
#> 99  1.000000e+00 7.196848e-09
#> 100 1.000000e+00 3.432416e-09
#> 101 1.000000e+00 3.378190e-11
#> 102 1.000000e+00 6.094949e-10
#> 103 1.000000e+00 3.903088e-10
#> 104 1.000000e+00 1.463033e-09
#> 105 1.000000e+00 3.266176e-08
#> 106 9.999997e-01 2.691745e-07
#> 107 1.000000e+00 2.165185e-10
#> 108 1.000000e+00 4.417720e-08
#> 109 1.000000e+00 2.613364e-10
#> 110 1.000000e+00 1.855565e-10
#> 111 1.000000e+00 1.247697e-08
#> 112 9.999999e-01 1.177873e-07
#> 113 1.000000e+00 2.975804e-09
#> 114 1.000000e+00 1.558266e-09
#> 115 1.000000e+00 1.849239e-09
#> 116 1.000000e+00 1.031145e-09
#> 117 1.000000e+00 7.985078e-10
#> 118 1.000000e+00 4.550104e-09
#> 119 1.000000e+00 4.156114e-10
#> 120 1.000000e+00 3.206136e-10
#> 121 1.000000e+00 2.233346e-08
#> 122 9.999999e-01 8.120601e-08
#> 123 1.000000e+00 5.954044e-10
#> 124 1.000000e+00 3.026458e-11
#> 125 1.000000e+00 1.424766e-09
#> 126 1.000000e+00 8.130364e-10
#> 127 1.000000e+00 6.150024e-10
#> 128 1.000000e+00 9.444138e-09
#> 129 1.000000e+00 2.328948e-11
#> 130 1.000000e+00 1.563133e-09
#> 131 1.000000e+00 7.070482e-12
#> 132 1.000000e+00 2.430530e-12
#> 133 1.000000e+00 1.825761e-09
#> 134 1.000000e+00 6.650521e-09
#> 135 1.000000e+00 1.370103e-11
#> 136 1.000000e+00 1.025182e-09
#> 137 1.000000e+00 1.227042e-09
#> 138 1.000000e+00 2.044575e-09
#> 139 1.000000e+00 5.253970e-09
#> 140 1.000000e+00 3.989508e-08
#> 141 1.000000e+00 6.667898e-10
#> 142 1.000000e+00 6.031687e-11
#> 143 1.000000e+00 9.281413e-11
#> 144 1.000000e+00 3.580572e-09
#> 145 1.000000e+00 5.328300e-13
#> 146 1.000000e+00 2.029222e-12
#> 147 1.000000e+00 3.769147e-09
#> 148 1.000000e+00 2.288466e-09
#> 149 1.000000e+00 1.052566e-08
#> 150 1.000000e+00 3.274686e-08
#> 151 1.000000e+00 2.471732e-26
#> 152 1.000000e+00 8.469882e-29
#> 153 1.000000e+00 1.695607e-31
#> 154 1.000000e+00 1.193504e-30
#> 155 1.000000e+00 8.066766e-25
#> 156 1.000000e+00 3.073320e-26
#> 157 1.000000e+00 1.101321e-34
#> 158 1.000000e+00 2.275016e-31
#> 159 1.000000e+00 2.911821e-35
#> 160 1.000000e+00 2.330361e-32
#> 161 1.000000e+00 1.275205e-41
#> 162 1.000000e+00 3.527564e-25
#> 163 1.000000e+00 5.453888e-33
#> 164 1.000000e+00 5.219841e-32
#> 165 1.000000e+00 4.904099e-30
#> 166 1.000000e+00 4.439443e-29
#> 167 1.000000e+00 1.565171e-28
#> 168 1.000000e+00 4.165055e-28
#> 169 1.000000e+00 7.260726e-33
#> 170 1.000000e+00 2.191088e-36
#> 171 1.000000e+00 1.604883e-33
#> 172 1.000000e+00 7.948705e-31
#> 173 1.000000e+00 2.416388e-34
#> 174 1.000000e+00 2.302697e-31
#> 175 1.000000e+00 1.701660e-35
#> 176 1.000000e+00 1.088227e-32
#> 177 1.000000e+00 4.202725e-30
#> 178 1.000000e+00 2.132957e-32
#> 179 1.000000e+00 1.985949e-32
#> 180 1.000000e+00 2.624164e-24
#> 181 1.000000e+00 1.952052e-29
#> 182 1.000000e+00 6.747480e-26
#> 183 1.000000e+00 7.691045e-35
#> 184 1.000000e+00 2.337360e-30
#> 185 1.000000e+00 3.671426e-27
#> 186 1.000000e+00 1.975783e-30
#> 187 1.000000e+00 2.035570e-39
#> 188 1.000000e+00 4.969321e-28
#> 189 1.000000e+00 4.456556e-38
#> 190 1.000000e+00 1.971674e-33
#> 191 1.000000e+00 5.329904e-25
#> 192 1.000000e+00 1.312493e-29
#> 193 1.000000e+00 1.176425e-25
#> 194 1.000000e+00 3.285059e-31
#> 195 1.000000e+00 5.007539e-31
#> 196 1.000000e+00 7.281392e-36
#> 197 1.000000e+00 5.466925e-24
#> 198 1.000000e+00 4.488509e-31
#> 199 1.000000e+00 4.130772e-33
#> 200 1.000000e+00 5.307268e-28