Predict either posterior probabilities for each group or latent positions based on new samples

# S3 method for PLNmixturefit
predict(
  object,
  newdata,
  type = c("posterior", "response", "position"),
  prior = matrix(rep(1/object$k, object$k), nrow(newdata), object$k, byrow = TRUE),
  control = PLNmixture_param(),
  ...
)

Arguments

object

an R6 object with class PLNmixturefit

newdata

A data frame in which to look for variables, offsets and counts with which to predict.

type

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.

prior

User-specified prior group probabilities in the new data. The default uses a uniform prior.

control

a list-like structure for controlling the fit. See PLNmixture_param() for details.

...

additional parameters for S3 compatibility. Not used

Value

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").

Examples

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  6.389515e-02 9.341743e-01 2.220446e-16 1.930558e-03 2.220446e-16
#> 2  9.031375e-01 7.466324e-02 2.218086e-02 1.844236e-05 2.220446e-16
#> 3  2.099416e-01 5.783536e-04 7.894801e-01 2.220446e-16 2.220446e-16
#> 4  3.413244e-05 2.220446e-16 9.999659e-01 2.220446e-16 2.220446e-16
#> 5  8.088896e-03 3.756311e-04 9.915355e-01 2.220446e-16 2.220446e-16
#> 6  4.771905e-01 1.685936e-01 3.542053e-01 1.061261e-05 2.220446e-16
#> 7  1.214870e-01 8.719007e-01 3.907303e-03 2.704970e-03 2.220446e-16
#> 8  2.473831e-02 1.906193e-02 9.561983e-01 1.496632e-06 2.220446e-16
#> 9  4.246473e-01 5.630482e-01 1.213833e-02 1.662047e-04 2.220446e-16
#> 10 3.811671e-01 5.880195e-01 2.252869e-02 8.284673e-03 1.413877e-14
#> 11 2.978222e-01 5.629192e-01 1.167296e-01 1.922082e-02 3.308189e-03
#> 12 1.951114e-01 3.449074e-01 3.305686e-01 4.330877e-02 8.610371e-02
#> 13 2.220446e-16 1.000000e+00 2.220446e-16 2.220446e-16 2.220446e-16
#> 14 2.220446e-16 9.999963e-01 2.220446e-16 3.688351e-06 2.220446e-16
#> 15 2.220446e-16 2.220446e-16 1.000000e+00 2.220446e-16 2.220446e-16
#> 16 2.874751e-06 2.220446e-16 9.999971e-01 2.220446e-16 2.220446e-16
#> 17 2.220446e-16 9.999960e-01 2.220446e-16 4.046031e-06 2.220446e-16
#> 18 2.220446e-16 1.000000e+00 2.220446e-16 2.220446e-16 2.220446e-16
#> 19 1.249297e-04 9.998047e-01 7.038822e-05 2.220446e-16 2.220446e-16
#> 20 2.220446e-16 1.000000e+00 2.220446e-16 2.220446e-16 2.220446e-16
#> 21 5.558246e-03 9.943529e-01 8.446806e-05 4.355609e-06 2.220446e-16
#> 22 5.942620e-02 8.716126e-01 3.643774e-04 6.859685e-02 2.220446e-16
#> 23 4.493281e-13 1.855065e-03 2.220446e-16 9.981449e-01 2.220446e-16
#> 24 3.143233e-01 5.677046e-01 8.772767e-02 2.772662e-02 2.517720e-03
#> 25 2.220446e-16 9.776802e-04 2.220446e-16 9.990223e-01 2.220446e-16
#> 26 2.220446e-16 2.220446e-16 2.220446e-16 1.000000e+00 2.220446e-16
#> 27 2.220446e-16 2.220446e-16 2.220446e-16 1.000000e+00 2.220446e-16
#> 28 5.625414e-16 8.871769e-04 2.220446e-16 9.985166e-01 5.962021e-04
#> 29 1.698238e-04 9.024372e-03 1.488401e-04 9.704662e-01 2.019079e-02
#> 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 1.000000e+00 2.220446e-16 2.220446e-16 2.220446e-16 2.220446e-16
#> 33 1.000000e+00 2.220446e-16 2.220446e-16 2.220446e-16 2.220446e-16
#> 34 1.000000e+00 2.220446e-16 2.220446e-16 2.220446e-16 2.220446e-16
#> 35 9.999344e-01 6.557672e-05 2.220446e-16 2.220446e-16 2.220446e-16
#> 36 8.777056e-01 4.441680e-04 1.218503e-01 2.220446e-16 2.220446e-16
#> 37 9.999603e-01 3.971018e-05 2.220446e-16 2.220446e-16 2.220446e-16
#> 38 6.546262e-01 3.430257e-01 2.220446e-16 2.348094e-03 2.220446e-16
#> 39 8.450488e-01 1.543681e-01 4.385669e-05 5.391859e-04 2.220446e-16
#> 40 1.553990e-01 4.829495e-02 7.959461e-01 4.122080e-05 3.186397e-04
#> 41 3.552621e-01 5.248010e-01 1.199369e-01 2.220446e-16 2.220446e-16
#> 42 2.220446e-16 9.956338e-01 2.220446e-16 4.366150e-03 2.220446e-16
#> 43 8.839467e-01 1.137961e-01 2.253701e-03 3.462870e-06 2.220446e-16
#> 44 2.220446e-16 1.000000e+00 2.220446e-16 2.220446e-16 2.220446e-16
#> 45 2.220446e-16 1.000000e+00 2.220446e-16 2.220446e-16 2.220446e-16
#> 46 2.220446e-16 1.000000e+00 2.220446e-16 2.220446e-16 2.220446e-16
#> 47 1.868024e-14 9.960983e-01 3.218078e-03 6.835924e-04 2.220446e-16
#> 48 2.220446e-16 2.122855e-02 2.220446e-16 9.787714e-01 2.220446e-16
#> 49 2.220446e-16 2.220446e-16 2.220446e-16 1.000000e+00 2.220446e-16
predict(myPLN, trichoptera, "position")
#>          [,1]       [,2]      [,3]       [,4]        [,5]      [,6]       [,7]
#> 1   -6.916603  -7.561023 -2.129537  -5.503348 -0.55748382 -3.691839  -5.900209
#> 2  -17.864881 -17.916600 -2.011338  -7.155622 -0.53805026 -3.550764 -17.782793
#> 3  -20.830429 -20.830827 -3.723935 -18.355333 -0.19295059 -3.809734 -20.829804
#> 4  -21.394158 -21.394158 -4.091379 -21.393757 -0.09235429 -3.767729 -21.394158
#> 5  -21.367130 -21.367386 -3.591089 -21.271670 -0.14556744 -3.653283 -21.366734
#> 6  -17.555073 -17.671700 -2.797167 -11.806060 -0.31014049 -3.398001 -17.370327
#> 7   -7.697184  -8.302056 -2.179951  -5.640721 -0.63900233 -3.594075  -6.735350
#> 8  -21.037511 -21.050642 -3.877169 -20.732435 -0.17932286 -3.603321 -21.016838
#> 9  -11.659623 -12.049750 -1.892368  -6.247757 -0.48769776 -3.582978 -11.040170
#> 10 -11.263223 -11.671854 -2.059785  -6.343265 -0.63132698 -3.542611 -10.612768
#> 11 -11.680180 -12.044295 -2.450761  -7.761793 -0.46602127 -3.595560 -11.023422
#> 12 -14.527385 -14.052260 -3.329655 -11.976848 -0.30378944 -3.978865 -13.259682
#> 13  -5.965031  -6.803179 -2.722121  -5.417918 -0.26341472 -3.500752  -5.042567
#> 14  -6.111203  -6.800222 -2.281280  -5.406371 -0.52997064 -3.433237  -4.876818
#> 15 -21.394248 -21.394248 -4.672939 -21.394248 -0.18344179 -3.498400 -21.394248
#> 16 -21.394240 -21.394240 -4.183299 -21.394206 -0.19518873 -3.203148 -21.394240
#> 17  -6.120270  -6.804828 -2.684870  -5.424294 -0.32217257 -3.658382  -5.051658
#> 18  -6.117751  -6.803547 -2.540150  -5.270423 -0.51992644 -3.266602  -5.044601
#> 19  -6.122206  -6.806985 -2.315093  -5.424201 -0.62425729 -3.064592  -5.052513
#> 20  -6.144430  -6.666140 -2.671964  -5.470556 -0.58572831 -3.448010  -4.979639
#> 21  -6.183475  -6.868246 -2.204239  -5.417818 -0.57429624 -3.709255  -5.105737
#> 22  -6.830888  -7.437370 -2.203505  -5.508078 -0.78825821 -3.759458  -5.872377
#> 23  -5.669419  -5.710291 -3.794688  -5.456100 -0.89977454 -5.661622  -5.664159
#> 24 -11.432914 -11.807376 -2.388892  -7.315867 -0.52936008 -3.598270 -10.778537
#> 25  -5.676626  -5.716636 -3.316689  -5.664472 -1.03863004 -5.472177  -5.473475
#> 26  -5.685893  -5.724905 -3.722239  -5.674526 -1.36928135 -5.682715  -5.682715
#> 27  -5.688834  -5.727737 -3.739374  -5.677500 -1.14315583 -5.685666  -5.685666
#> 28  -5.668703  -5.704229 -3.754085  -5.656446 -1.18607259 -5.657610  -5.658343
#> 29  -5.896108  -5.773097 -3.796505  -5.876373 -0.96684439 -5.674655  -5.675332
#> 30 -16.812722  -8.370840 -6.655527 -16.812722 -0.30985256 -7.223395  -6.458305
#> 31 -16.812737  -8.613470 -5.752186 -16.812737 -0.10985394 -7.524125  -6.590181
#> 32 -18.750748 -18.750748 -2.523288  -6.985231 -0.96472936 -3.246687 -18.750748
#> 33 -18.750748 -18.750748 -2.437262  -7.004938 -0.77731884 -2.998631 -18.750748
#> 34 -18.750749 -18.750749 -3.005136  -7.077505 -0.40045744 -2.879903 -18.750749
#> 35 -18.749920 -18.749965 -2.426092  -6.975589 -0.81650262 -2.758958 -18.749850
#> 36 -19.067254 -19.067556 -2.981099  -8.741042 -0.41710056 -3.447083 -19.066788
#> 37 -18.750246 -18.750273 -1.419338  -6.587543 -1.06145581 -3.451047 -18.750204
#> 38 -14.382061 -14.619636 -1.903241  -6.414661 -1.15260597 -3.592244 -14.005417
#> 39 -16.791584 -16.898506 -1.645768  -6.711381 -0.90504544 -3.565400 -16.621976
#> 40 -20.243018 -20.273759 -3.604249 -18.375701 -0.15347634 -3.709903 -20.186889
#> 41 -12.441567 -12.799725 -2.750384  -7.895847 -0.38000599 -3.887104 -11.884728
#> 42  -6.116625  -6.799243 -2.559254  -5.273007 -0.49915370 -3.777360  -5.049446
#> 43 -17.320853 -17.398028 -3.034291  -6.845602 -0.30860431 -3.846394 -17.201817
#> 44  -6.114853  -6.802074 -2.196308  -5.263820 -0.46597746 -3.605149  -4.742361
#> 45  -6.121706  -6.805565 -2.445347  -5.279355 -0.53275632 -3.431340  -4.910886
#> 46  -6.005247  -6.821225 -2.964828  -5.484432 -0.38494210 -3.902789  -5.000938
#> 47  -6.153841  -6.843298 -2.310036  -5.445452 -0.46323350 -3.638626  -5.060864
#> 48  -5.491017  -5.741423 -3.832688  -5.662185 -0.72478007 -5.633948  -5.662164
#> 49  -5.718653  -5.565702 -3.747483  -5.707635 -1.15693643 -5.715572  -5.715572
#>          [,8]       [,9]     [,10]     [,11]     [,12]     [,13]      [,14]
#> 1   -5.621785  -7.548883 -2.875854 -3.465724 -4.790865 -5.248433  -5.371425
#> 2  -17.432365 -17.915632 -3.833930 -5.627699 -3.166278 -3.279336  -7.170230
#> 3   -9.168029 -20.830820 -4.487622 -5.397715 -3.535123 -5.805674 -18.358018
#> 4   -6.673990 -21.394158 -4.708378 -5.438967 -4.339899 -6.519659 -21.393758
#> 5   -6.734311 -21.367381 -4.686103 -5.327449 -4.418548 -6.454073 -21.271786
#> 6  -12.085113 -17.669518 -3.995033 -5.193876 -3.947089 -4.675587 -11.819045
#> 7   -6.410267  -8.290644 -2.717557 -3.511000 -4.835530 -5.074366  -5.672942
#> 8   -6.885645 -21.050396 -4.549822 -5.246145 -4.504787 -6.360929 -20.733518
#> 9  -10.690135 -12.042449 -3.376053 -4.347576 -4.432326 -4.385097  -6.276033
#> 10 -10.093852 -11.663893 -3.288303 -4.219058 -4.449350 -4.407405  -6.356113
#> 11  -9.115971 -12.030880 -3.379134 -4.194104 -4.532911 -4.683355  -7.707280
#> 12  -8.346169 -13.907012 -3.862777 -4.400728 -4.861923 -5.035608 -10.771814
#> 13  -4.608539  -6.790313 -2.971032 -3.395991 -4.900315 -5.405259  -5.457984
#> 14  -4.730762  -6.787318 -2.988559 -3.322347 -5.030485 -5.393558  -5.446871
#> 15  -6.396861 -21.394248 -3.787140 -5.027362 -4.976185 -6.647744 -21.394248
#> 16  -6.667347 -21.394240 -4.355118 -4.858281 -4.452290 -6.512505 -21.394206
#> 17  -4.764527  -6.638825 -2.815464 -3.091679 -5.056061 -5.411701  -5.464113
#> 18  -4.755305  -6.790685 -3.093815 -2.635544 -5.049033 -5.406701  -5.459354
#> 19  -4.763788  -6.794137 -3.010940 -2.869313 -5.053894 -5.410120  -5.464075
#> 20  -4.715381  -6.804625 -3.057424 -2.320399 -5.120400 -5.458508  -5.366752
#> 21  -4.811623  -6.855419 -2.545555 -3.217715 -5.026041 -5.383550  -5.458103
#> 22  -5.554569  -7.423352 -2.760088 -3.374299 -4.975241 -5.038552  -5.411812
#> 23  -4.956531  -5.670678 -3.286834 -3.313908 -5.674456 -2.515290  -3.555105
#> 24  -9.290957 -11.794832 -3.340443 -4.173347 -4.523940 -4.575833  -7.255241
#> 25  -4.971855  -5.677288 -3.525684 -3.050890 -5.682583 -2.633639  -3.434568
#> 26  -4.991037  -5.685893 -3.431344 -3.146384 -5.495909 -2.387169  -3.346044
#> 27  -4.996715  -5.688834 -2.873039 -3.029799 -5.695773 -2.021982  -3.853311
#> 28  -4.743828  -5.663384 -3.410059 -3.246340 -5.669913 -2.375804  -3.499004
#> 29  -5.002685  -5.701678 -3.457281 -3.075245 -5.721052 -2.463311  -3.714698
#> 30  -7.754678  -6.843467 -5.378336 -3.153473 -8.608524 -4.190816  -3.180275
#> 31  -7.857307  -6.910221 -5.918703 -4.072087 -8.477077 -5.166626  -4.018456
#> 32 -18.750748 -18.750748 -4.302557 -5.930470 -3.494336 -1.126492  -6.615420
#> 33 -18.750748 -18.750748 -3.834410 -5.643461 -2.431576 -1.887610  -7.017124
#> 34 -18.750749 -18.750749 -4.512422 -6.144798 -4.016871 -2.530385  -7.088933
#> 35 -18.749831 -18.749964 -3.470959 -5.904834 -3.559754 -2.983826  -6.988116
#> 36 -17.268942 -19.067550 -4.358737 -5.858926 -4.217444 -3.661637  -8.751944
#> 37 -18.750193 -18.750273 -3.676504 -5.536893 -3.539214 -2.646930  -6.986853
#> 38 -13.900263 -14.615101 -2.583030 -4.936733 -4.153390 -3.610042  -6.432591
#> 39 -16.574315 -16.896485 -3.441794 -5.432526 -3.893677 -3.129964  -6.727504
#> 40  -8.410660 -20.272619 -4.387726 -5.245651 -4.154514 -5.885551 -18.375408
#> 41  -9.965607 -12.792998 -3.299108 -4.562790 -4.467674 -4.897298  -7.921028
#> 42  -4.473586  -6.786273 -3.106093 -3.413395 -5.053894 -5.100982  -5.453849
#> 43 -17.137077 -17.396576 -2.524543 -5.343967 -4.284019 -3.412990  -6.860963
#> 44  -4.599292  -6.789193 -2.823127 -3.369553 -4.893272 -5.400909  -5.453849
#> 45  -4.488062  -6.792729 -2.560542 -3.333382 -4.915231 -5.414552  -5.466822
#> 46  -4.871094  -6.808585 -3.380124 -2.895494 -4.873072 -5.472535  -5.243755
#> 47  -4.561356  -6.830376 -2.870837 -3.097555 -5.010954 -5.382296  -5.484977
#> 48  -4.780317  -5.505358 -3.209057 -3.402280 -5.672245 -2.337003  -3.835630
#> 49  -5.052621  -5.718653 -3.638822 -3.153486 -5.725400 -1.055786  -3.994343
#>        [,15]      [,16]     [,17]
#> 1  -4.037832  -5.516546 -2.712142
#> 2  -4.874834  -6.210557 -2.845704
#> 3  -4.944145  -7.061808 -3.248080
#> 4  -4.866878  -7.300342 -3.652214
#> 5  -5.084006  -7.271951 -3.213338
#> 6  -4.926347  -6.474721 -2.961932
#> 7  -4.342858  -5.566220 -2.648458
#> 8  -5.218428  -7.212621 -2.728082
#> 9  -4.558469  -5.799389 -2.747164
#> 10 -4.498498  -5.886715 -2.615568
#> 11 -4.502124  -6.148847 -2.653273
#> 12 -4.429726  -6.984094 -2.967906
#> 13 -4.355047  -5.302237 -2.955497
#> 14 -4.179553  -5.440432 -2.404667
#> 15 -5.405255  -7.153170 -2.544702
#> 16 -5.397568  -7.296917 -2.811933
#> 17 -4.372035  -5.457787 -2.704035
#> 18 -4.358874  -5.452938 -2.559202
#> 19 -4.368463  -5.456599 -2.331701
#> 20 -3.897417  -5.502605 -2.440958
#> 21 -4.331117  -5.446606 -2.423570
#> 22 -3.837359  -6.407630 -2.542788
#> 23 -1.574957 -18.987664 -2.323481
#> 24 -4.461802  -6.221822 -2.622119
#> 25 -1.493211 -18.999589 -2.599831
#> 26 -1.228441 -19.012863 -2.145859
#> 27 -1.551720 -19.012863 -2.404972
#> 28 -1.433414 -18.994125 -2.335796
#> 29 -1.500541 -18.660049 -2.418041
#> 30 -1.964651  -7.754678 -5.123511
#> 31 -2.907161  -7.857307 -6.411268
#> 32 -5.117275  -6.313737 -2.563197
#> 33 -3.979259  -6.349895 -2.983764
#> 34 -4.476149  -6.474243 -2.321795
#> 35 -5.066334  -6.295709 -1.539079
#> 36 -5.144465  -6.432811 -1.611947
#> 37 -5.058988  -6.293222 -1.927663
#> 38 -4.696983  -5.998495 -2.184211
#> 39 -4.819286  -6.129927 -2.341875
#> 40 -5.133451  -7.024039 -3.077145
#> 41 -4.743423  -5.508853 -2.104132
#> 42 -4.354669  -5.513511 -1.992749
#> 43 -5.053657  -6.226277 -2.835784
#> 44 -4.343386  -5.447399 -2.918676
#> 45 -4.379415  -5.312483 -2.729862
#> 46 -4.164898  -5.237870 -2.246238
#> 47 -4.288651  -5.443420 -2.714734
#> 48 -2.340179 -18.724709 -2.027276
#> 49 -1.949105 -19.012863 -2.737713
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 
#>  2  1  3  3  3  1  2  3  2  2  2  2  2  2  3  3  2  2  2  2  2  2  4  2  4  4 
#> 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 
#>  4  4  4  5  5  1  1  1  1  1  1  1  1  3  2  2  1  2  2  2  2  4  4 
#> Levels: 1 2 3 4 5