Predict either posterior probabilities for each group or latent positions based on new samples
an R6 object with class PLNmixturefit
A data frame in which to look for variables, offsets and counts with which to predict.
The type of prediction required. The default posterior
are posterior probabilities for each group ,
response
is the group with maximal posterior probability and latent
is the averaged latent in the latent space,
with weights equal to the posterior probabilities.
User-specified prior group probabilities in the new data. The default uses a uniform prior.
a list-like structure for controlling the fit. See PLNmixture_param()
for details.
additional parameters for S3 compatibility. Not used
A matrix of posterior probabilities for each group (if type = "posterior"), a matrix of (average) position in the latent space (if type = "position") or a vector of predicted groups (if type = "response").
data(trichoptera)
trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate)
myPLN <- PLNmixture(Abundance ~ 1 + offset(log(Offset)),
data = trichoptera, control = PLNmixture_param(smoothing = "none")) %>% getBestModel()
#>
#> Initialization...
#>
#> Adjusting 5 PLN mixture models.
#> number of cluster = 1
number of cluster = 2
number of cluster = 3
number of cluster = 4
number of cluster = 5
#> Post-treatments
#> DONE!
predict(myPLN, trichoptera, "posterior")
#> [,1] [,2] [,3] [,4] [,5]
#> 1 2.220446e-16 7.924865e-12 2.082381e-12 1.000000e+00 2.220446e-16
#> 2 7.973393e-11 1.000000e+00 1.082301e-13 1.966364e-08 2.220446e-16
#> 3 1.000000e+00 1.178320e-12 2.220446e-16 1.048401e-11 2.220446e-16
#> 4 1.000000e+00 2.220446e-16 2.220446e-16 2.220446e-16 2.220446e-16
#> 5 1.000000e+00 1.351445e-15 2.220446e-16 2.990806e-13 2.220446e-16
#> 6 8.548744e-09 9.999999e-01 2.809572e-14 9.544065e-08 2.041723e-14
#> 7 1.642290e-11 1.392001e-11 4.954814e-11 1.000000e+00 1.437571e-14
#> 8 1.000000e+00 1.278590e-12 2.220446e-16 1.769312e-09 3.855183e-15
#> 9 7.411110e-11 9.999997e-01 1.518001e-12 2.902536e-07 6.872657e-15
#> 10 2.157595e-10 7.024307e-11 2.908832e-10 1.000000e+00 2.011717e-12
#> 11 3.679672e-09 9.999995e-01 1.555983e-09 5.120229e-07 3.048658e-10
#> 12 1.673214e-08 9.999995e-01 5.004694e-09 4.347224e-07 1.269617e-08
#> 13 4.995946e-14 2.220446e-16 2.220446e-16 1.000000e+00 2.220446e-16
#> 14 2.220446e-16 2.220446e-16 1.633067e-15 1.000000e+00 2.220446e-16
#> 15 1.000000e+00 2.220446e-16 2.220446e-16 2.220446e-16 2.220446e-16
#> 16 1.000000e+00 2.220446e-16 2.220446e-16 2.220446e-16 2.220446e-16
#> 17 2.388666e-16 2.220446e-16 2.220446e-16 1.000000e+00 2.220446e-16
#> 18 2.220446e-16 2.220446e-16 2.220446e-16 1.000000e+00 2.220446e-16
#> 19 2.220446e-16 2.220446e-16 2.220446e-16 1.000000e+00 2.220446e-16
#> 20 2.220446e-16 2.220446e-16 2.220446e-16 1.000000e+00 2.220446e-16
#> 21 6.709446e-15 2.024251e-13 4.291392e-16 1.000000e+00 2.220446e-16
#> 22 3.114749e-13 3.518153e-12 1.533321e-09 1.000000e+00 4.046580e-16
#> 23 2.220446e-16 2.220446e-16 1.000000e+00 2.023618e-10 2.220446e-16
#> 24 1.284189e-09 7.666062e-11 1.224638e-09 1.000000e+00 1.096598e-10
#> 25 2.220446e-16 2.220446e-16 1.000000e+00 7.829412e-12 8.729030e-15
#> 26 2.220446e-16 2.220446e-16 1.000000e+00 2.220446e-16 2.220446e-16
#> 27 2.220446e-16 2.220446e-16 1.000000e+00 2.220446e-16 2.220446e-16
#> 28 2.220446e-16 2.220446e-16 1.000000e+00 9.392513e-11 3.963488e-12
#> 29 3.467405e-13 5.786016e-15 1.000000e+00 1.528010e-09 2.816889e-10
#> 30 2.220446e-16 2.220446e-16 2.220446e-16 2.220446e-16 1.000000e+00
#> 31 2.220446e-16 2.220446e-16 2.220446e-16 2.220446e-16 1.000000e+00
#> 32 2.220446e-16 1.000000e+00 2.220446e-16 2.220446e-16 2.220446e-16
#> 33 2.220446e-16 1.000000e+00 2.220446e-16 2.220446e-16 2.220446e-16
#> 34 2.220446e-16 1.000000e+00 2.220446e-16 2.220446e-16 2.220446e-16
#> 35 2.220446e-16 1.000000e+00 2.220446e-16 3.376592e-14 2.220446e-16
#> 36 1.000000e+00 6.611212e-13 2.220446e-16 6.070399e-13 2.220446e-16
#> 37 2.220446e-16 1.000000e+00 2.220446e-16 7.168398e-16 2.220446e-16
#> 38 2.220446e-16 6.212722e-12 1.477633e-11 1.000000e+00 2.220446e-16
#> 39 5.738819e-14 2.713298e-10 1.550747e-11 1.000000e+00 2.220446e-16
#> 40 1.000000e+00 1.322935e-11 9.618763e-15 7.331077e-09 1.244363e-11
#> 41 1.050662e-10 9.999999e-01 2.220446e-16 1.023028e-07 2.220446e-16
#> 42 2.220446e-16 2.220446e-16 1.124848e-14 1.000000e+00 2.220446e-16
#> 43 1.156356e-14 1.000000e+00 2.220446e-16 7.416629e-10 2.220446e-16
#> 44 2.220446e-16 2.220446e-16 2.220446e-16 1.000000e+00 2.220446e-16
#> 45 2.220446e-16 2.220446e-16 2.220446e-16 1.000000e+00 2.220446e-16
#> 46 2.220446e-16 2.220446e-16 2.220446e-16 1.000000e+00 2.220446e-16
#> 47 2.298262e-11 2.220446e-16 3.281525e-12 1.000000e+00 7.761288e-14
#> 48 2.220446e-16 2.220446e-16 1.000000e+00 2.032760e-09 2.220446e-16
#> 49 2.220446e-16 2.220446e-16 1.000000e+00 2.220446e-16 2.220446e-16
predict(myPLN, trichoptera, "position")
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> 1 -6.109820 -6.799549 -2.135458 -5.402835 -0.55699291 -3.687283 -5.021782
#> 2 -19.367106 -19.367106 -1.967716 -6.950943 -0.54057406 -3.538023 -19.367106
#> 3 -20.034904 -20.034904 -3.946852 -20.034904 -0.18557740 -3.821748 -20.034904
#> 4 -20.034894 -20.034894 -4.092257 -20.034894 -0.09224198 -3.767980 -20.034894
#> 5 -20.034904 -20.034904 -3.597625 -20.034904 -0.14481261 -3.654124 -20.034904
#> 6 -19.367105 -19.367106 -2.334657 -6.953245 -0.32661958 -3.276458 -19.367105
#> 7 -6.102037 -6.795636 -2.190567 -5.387118 -0.63155429 -3.603052 -4.998861
#> 8 -20.034904 -20.034904 -3.930030 -20.034904 -0.17550046 -3.607700 -20.034904
#> 9 -19.367103 -19.367103 -1.714437 -6.950481 -0.48043451 -3.526498 -19.367103
#> 10 -6.100540 -6.794887 -2.121805 -5.384063 -0.60847761 -3.585199 -4.994366
#> 11 -19.367100 -19.367100 -2.170492 -6.946767 -0.46739668 -3.422477 -19.367099
#> 12 -19.367101 -19.367101 -2.474756 -6.946301 -0.32530760 -3.407630 -19.367100
#> 13 -5.965062 -6.803245 -2.722358 -5.417332 -0.26339266 -3.500577 -5.042627
#> 14 -6.111288 -6.800291 -2.281424 -5.405770 -0.52993171 -3.433029 -4.876796
#> 15 -20.034872 -20.034872 -4.674798 -20.034872 -0.18351822 -3.498762 -20.034872
#> 16 -20.034904 -20.034904 -4.184497 -20.034904 -0.19495046 -3.202395 -20.034904
#> 17 -6.120362 -6.804899 -2.685078 -5.423704 -0.32216143 -3.658254 -5.051707
#> 18 -6.117839 -6.803613 -2.540355 -5.269783 -0.51989770 -3.266379 -5.044663
#> 19 -6.119642 -6.804532 -2.315166 -5.422294 -0.62423455 -3.064401 -5.049702
#> 20 -6.144519 -6.666131 -2.672149 -5.470072 -0.58575672 -3.447860 -4.979640
#> 21 -6.112020 -6.800661 -2.204644 -5.407231 -0.57423458 -3.708936 -5.028136
#> 22 -6.103902 -6.796571 -2.139507 -5.390908 -0.76315545 -3.624467 -5.004421
#> 23 -5.668469 -5.708076 -3.796849 -5.456532 -0.90021126 -5.665242 -5.665242
#> 24 -6.100165 -6.794700 -2.249864 -5.383296 -0.53923283 -3.580628 -4.993235
#> 25 -5.676059 -5.715378 -3.317705 -5.664613 -1.03881425 -5.474068 -5.474068
#> 26 -5.685742 -5.724700 -3.722190 -5.674404 -1.36919471 -5.682569 -5.682569
#> 27 -5.688683 -5.727549 -3.739297 -5.677376 -1.14313057 -5.685518 -5.685518
#> 28 -5.661530 -5.701404 -3.753676 -5.649918 -1.18662404 -5.658280 -5.658280
#> 29 -5.662306 -5.702150 -3.758667 -5.650703 -0.97867548 -5.659059 -5.659059
#> 30 -16.848772 -8.370860 -6.654430 -16.848772 -0.30984634 -7.223777 -6.458345
#> 31 -16.848642 -8.612756 -5.752849 -16.848642 -0.10981096 -7.523556 -6.590010
#> 32 -19.367107 -19.367107 -2.523087 -6.984229 -0.96476148 -3.245668 -19.367107
#> 33 -19.367107 -19.367107 -2.437203 -7.003830 -0.77749315 -2.998293 -19.367107
#> 34 -19.367107 -19.367107 -3.004731 -7.076147 -0.40103315 -2.879838 -19.367107
#> 35 -19.367107 -19.367107 -2.425991 -6.974730 -0.81656821 -2.758857 -19.367107
#> 36 -20.034904 -20.034904 -3.644457 -20.034904 -0.39842193 -3.550821 -20.034904
#> 37 -19.367107 -19.367107 -1.419956 -6.588399 -1.06135725 -3.449184 -19.367107
#> 38 -6.104646 -6.796944 -2.049707 -5.392415 -0.99331317 -3.632773 -5.006626
#> 39 -6.104274 -6.796758 -1.915725 -5.391662 -0.79976348 -3.628637 -5.005525
#> 40 -20.034904 -20.034904 -3.865489 -20.034904 -0.13898780 -3.730665 -20.034904
#> 41 -19.367105 -19.367106 -2.721979 -6.976472 -0.37633271 -3.961049 -19.367105
#> 42 -6.118561 -6.803981 -2.555490 -5.271421 -0.49883996 -3.768858 -5.046678
#> 43 -19.367107 -19.367107 -3.059967 -6.987208 -0.30768641 -3.853184 -19.367107
#> 44 -6.114939 -6.802139 -2.196400 -5.263173 -0.46593582 -3.605019 -4.742311
#> 45 -6.121811 -6.805632 -2.445508 -5.278724 -0.53274111 -3.431170 -4.910835
#> 46 -6.005270 -6.821298 -2.965109 -5.483967 -0.38498548 -3.902830 -5.000977
#> 47 -6.105018 -6.797131 -2.305180 -5.393169 -0.46342545 -3.636873 -5.007727
#> 48 -5.480897 -5.718266 -3.857241 -5.667648 -0.72743419 -5.675866 -5.675866
#> 49 -5.718482 -5.565614 -3.747419 -5.707492 -1.15691818 -5.715406 -5.715406
#> [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> 1 -4.725238 -6.786357 -2.839132 -3.301980 -4.876376 -5.390145 -5.292548
#> 2 -19.367106 -19.367106 -3.885445 -5.835858 -3.019640 -3.022277 -6.963588
#> 3 -6.623986 -20.034904 -4.600575 -5.273548 -3.707091 -6.460953 -20.034904
#> 4 -6.674712 -20.034894 -4.708246 -5.439446 -4.339477 -6.520083 -20.034894
#> 5 -6.638046 -20.034904 -4.689873 -5.323558 -4.422668 -6.477412 -20.034904
#> 6 -19.367105 -19.367106 -3.926198 -5.842724 -3.402121 -3.101166 -6.965861
#> 7 -4.694533 -6.782393 -2.653436 -3.180685 -5.003461 -5.374228 -5.429055
#> 8 -6.622591 -20.034904 -4.590924 -5.268369 -4.511266 -6.459314 -20.034904
#> 9 -19.367102 -19.367103 -3.876855 -5.834471 -3.666803 -3.004974 -6.963131
#> 10 -4.688450 -6.781634 -2.906441 -3.153760 -4.998986 -5.371134 -5.426125
#> 11 -19.367099 -19.367100 -3.801613 -5.823210 -3.575347 -2.839635 -6.959464
#> 12 -19.367100 -19.367101 -3.791245 -5.821782 -3.562491 -2.814299 -6.959003
#> 13 -4.608537 -6.790102 -2.971086 -3.395765 -4.900285 -5.404819 -5.458077
#> 14 -4.730868 -6.787109 -2.988638 -3.322130 -5.030504 -5.393119 -5.446961
#> 15 -6.396871 -20.034872 -3.785814 -5.026841 -4.977838 -6.648382 -20.034872
#> 16 -6.668429 -20.034904 -4.354096 -4.857052 -4.452271 -6.512817 -20.034904
#> 17 -4.764628 -6.638564 -2.815448 -3.091377 -5.056080 -5.411268 -5.464208
#> 18 -4.755406 -6.790475 -3.093888 -2.635221 -5.049064 -5.406262 -5.459448
#> 19 -4.762011 -6.791405 -3.010837 -2.868760 -5.054083 -5.409850 -5.462858
#> 20 -4.715456 -6.804421 -3.057465 -2.320130 -5.120523 -5.458164 -5.366790
#> 21 -4.733659 -6.787484 -2.544156 -3.204608 -5.032602 -5.394598 -5.448364
#> 22 -4.702027 -6.783340 -2.704184 -3.212357 -5.008995 -5.378067 -5.432691
#> 23 -4.956899 -5.668469 -3.287528 -3.313880 -5.675537 -2.509501 -3.551932
#> 24 -4.686918 -6.781444 -2.897573 -3.146787 -4.997860 -5.370357 -5.425390
#> 25 -4.971994 -5.676059 -3.525964 -3.050911 -5.683075 -2.630455 -3.432928
#> 26 -4.990920 -5.685742 -3.431208 -3.146303 -5.495889 -2.386789 -3.346190
#> 27 -4.996623 -5.688683 -2.873203 -3.029819 -5.695613 -2.021805 -3.853231
#> 28 -4.742361 -5.661530 -3.408986 -3.246020 -5.668646 -2.371278 -3.497534
#> 29 -4.944459 -5.662306 -3.415890 -3.066573 -5.669417 -2.388563 -3.696676
#> 30 -7.754605 -6.843484 -5.378608 -3.153921 -8.608318 -4.191009 -3.180111
#> 31 -7.856946 -6.910185 -5.918497 -4.071927 -8.477000 -5.165918 -4.018249
#> 32 -19.367107 -19.367107 -4.299796 -5.929043 -3.493901 -1.126643 -6.615970
#> 33 -19.367107 -19.367107 -3.833506 -5.643232 -2.432327 -1.887412 -7.015853
#> 34 -19.367107 -19.367107 -4.510296 -6.142748 -4.015864 -2.529957 -7.087424
#> 35 -19.367107 -19.367107 -3.470856 -5.903676 -3.558981 -2.980644 -6.987086
#> 36 -6.641745 -20.034904 -4.711361 -5.336132 -4.639797 -6.028847 -20.034904
#> 37 -19.367107 -19.367107 -3.675800 -5.537227 -3.538532 -2.644896 -6.985790
#> 38 -4.704991 -6.783718 -2.461336 -3.224475 -5.011193 -5.226490 -5.434138
#> 39 -4.703511 -6.783529 -2.849364 -3.218453 -5.010096 -5.225603 -5.433415
#> 40 -6.617673 -20.034904 -4.555530 -5.249784 -4.251069 -6.453534 -20.034904
#> 41 -19.367105 -19.367106 -3.498354 -5.908381 -3.814599 -3.587124 -6.988808
#> 42 -4.472728 -6.790847 -3.104447 -3.412706 -5.051071 -5.111302 -5.460815
#> 43 -19.367107 -19.367107 -2.532273 -5.587229 -4.176555 -3.198207 -6.999418
#> 44 -4.599279 -6.788982 -2.823135 -3.369314 -4.893240 -5.400464 -5.453936
#> 45 -4.488076 -6.792520 -2.560430 -3.333189 -4.915216 -5.414110 -5.466911
#> 46 -4.871332 -6.808386 -3.380289 -2.894917 -4.873022 -5.472135 -5.243644
#> 47 -4.555382 -6.783907 -2.865915 -3.090975 -5.012287 -5.380356 -5.434860
#> 48 -4.784682 -5.480897 -3.216743 -3.404086 -5.686055 -2.280214 -3.800644
#> 49 -5.052545 -5.718482 -3.638580 -3.153439 -5.725221 -1.055747 -3.994114
#> [,15] [,16] [,17]
#> 1 -4.026343 -5.437642 -2.702539
#> 2 -4.912925 -6.247696 -2.852484
#> 3 -5.023870 -7.273540 -3.264639
#> 4 -4.865810 -7.301017 -3.655855
#> 5 -5.086168 -7.280995 -3.216807
#> 6 -4.929407 -6.252295 -2.941046
#> 7 -4.268973 -5.422455 -2.633563
#> 8 -5.242237 -7.272806 -2.738916
#> 9 -4.909553 -6.246770 -2.832886
#> 10 -4.259701 -5.419506 -2.588134
#> 11 -4.881586 -6.239289 -2.641455
#> 12 -4.877958 -6.238345 -2.611256
#> 13 -4.354888 -5.302283 -2.955505
#> 14 -4.179342 -5.440476 -2.404558
#> 15 -5.405756 -7.153152 -2.543837
#> 16 -5.397987 -7.297465 -2.812675
#> 17 -4.371891 -5.457831 -2.703997
#> 18 -4.358717 -5.453042 -2.559123
#> 19 -4.368162 -5.456473 -2.331562
#> 20 -3.897190 -5.502709 -2.440872
#> 21 -4.327238 -5.441889 -2.423851
#> 22 -3.980751 -5.426115 -2.550925
#> 23 -1.571046 -18.284515 -2.323235
#> 24 -4.257354 -5.418766 -2.576078
#> 25 -1.491436 -18.284515 -2.599628
#> 26 -1.228508 -18.284515 -2.145915
#> 27 -1.551730 -18.284515 -2.404938
#> 28 -1.431072 -18.284515 -2.333783
#> 29 -1.466265 -18.284515 -2.351601
#> 30 -1.964561 -7.754605 -5.122116
#> 31 -2.907274 -7.856946 -6.408932
#> 32 -5.114061 -6.312018 -2.562772
#> 33 -3.979912 -6.348052 -2.982959
#> 34 -4.475740 -6.472049 -2.321721
#> 35 -5.063257 -6.294109 -1.539623
#> 36 -5.311660 -7.282975 -1.741378
#> 37 -5.055908 -6.291610 -1.928089
#> 38 -4.284774 -5.427571 -2.316867
#> 39 -4.282552 -5.426844 -2.431400
#> 40 -5.223250 -7.270228 -3.119777
#> 41 -5.072888 -5.566144 -2.010999
#> 42 -4.362517 -5.454417 -1.993091
#> 43 -5.129208 -6.317570 -2.846353
#> 44 -4.343238 -5.447496 -2.918692
#> 45 -4.379267 -5.312506 -2.729829
#> 46 -4.164725 -5.237771 -2.246145
#> 47 -4.286983 -5.428298 -2.713610
#> 48 -2.296951 -18.284515 -2.024087
#> 49 -1.948986 -18.284515 -2.737562
predict(myPLN, trichoptera, "response")
#> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#> 4 2 1 1 1 2 4 1 2 4 2 2 4 4 1 1 4 4 4 4 4 4 3 4 3 3
#> 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#> 3 3 3 5 5 2 2 2 2 1 2 4 4 1 2 4 2 4 4 4 4 3 3
#> Levels: 1 2 3 4 5