Skip to contents

This function predicts the discrete choice behavior

Usage

# S3 method for RprobitB_fit
predict(object, data = NULL, overview = TRUE, digits = 2, ...)

Arguments

object

An object of class RprobitB_fit.

data

Either

  • NULL, using the data in object,

  • an object of class RprobitB_data, for example the test part generated by train_test,

  • or a data frame of custom choice characteristics. It must have the same structure as choice_data used in prepare_data. Missing columns or NA values are set to 0.

overview

If TRUE, returns a confusion matrix.

digits

The number of digits of the returned choice probabilities. digits = 2 per default.

...

Ignored.

Value

Either a table if overview = TRUE or a data frame otherwise.

Details

Predictions are made based on the maximum predicted probability for each choice alternative. See the vignette on choice prediction for a demonstration on how to visualize the model's sensitivity and specificity by means of a receiver operating characteristic (ROC) curve.

Examples

data <- simulate_choices(
  form = choice ~ cov, N = 10, T = 10, J = 2, seed = 1
)
data <- train_test(data, test_proportion = 0.5)
model <- fit_model(data$train)
#> Computing sufficient statistics - 0 of 4  

#> Computing sufficient statistics - 1 of 4  

#> Computing sufficient statistics - 2 of 4  

#> Computing sufficient statistics - 3 of 4  

#> Computing sufficient statistics - 4 of 4  

#> MCMC iteration - 1 of 1000  

#> MCMC iteration - 10 of 1000  

#> MCMC iteration - 20 of 1000  

#> MCMC iteration - 30 of 1000  

#> MCMC iteration - 40 of 1000  

#> MCMC iteration - 50 of 1000  

#> MCMC iteration - 60 of 1000  

#> MCMC iteration - 70 of 1000  

#> MCMC iteration - 80 of 1000  

#> MCMC iteration - 90 of 1000  

#> MCMC iteration - 100 of 1000  

#> MCMC iteration - 110 of 1000  

#> MCMC iteration - 120 of 1000  

#> MCMC iteration - 130 of 1000  

#> MCMC iteration - 140 of 1000  

#> MCMC iteration - 150 of 1000  

#> MCMC iteration - 160 of 1000  

#> MCMC iteration - 170 of 1000  

#> MCMC iteration - 180 of 1000  

#> MCMC iteration - 190 of 1000  

#> MCMC iteration - 200 of 1000  

#> MCMC iteration - 210 of 1000  

#> MCMC iteration - 220 of 1000  

#> MCMC iteration - 230 of 1000  

#> MCMC iteration - 240 of 1000  

#> MCMC iteration - 250 of 1000  

#> MCMC iteration - 260 of 1000  

#> MCMC iteration - 270 of 1000  

#> MCMC iteration - 280 of 1000  

#> MCMC iteration - 290 of 1000  

#> MCMC iteration - 300 of 1000  

#> MCMC iteration - 310 of 1000  

#> MCMC iteration - 320 of 1000  

#> MCMC iteration - 330 of 1000  

#> MCMC iteration - 340 of 1000  

#> MCMC iteration - 350 of 1000  

#> MCMC iteration - 360 of 1000  

#> MCMC iteration - 370 of 1000  

#> MCMC iteration - 380 of 1000  

#> MCMC iteration - 390 of 1000  

#> MCMC iteration - 400 of 1000  

#> MCMC iteration - 410 of 1000  

#> MCMC iteration - 420 of 1000  

#> MCMC iteration - 430 of 1000  

#> MCMC iteration - 440 of 1000  

#> MCMC iteration - 450 of 1000  

#> MCMC iteration - 460 of 1000  

#> MCMC iteration - 470 of 1000  

#> MCMC iteration - 480 of 1000  

#> MCMC iteration - 490 of 1000  

#> MCMC iteration - 500 of 1000  

#> MCMC iteration - 510 of 1000  

#> MCMC iteration - 520 of 1000  

#> MCMC iteration - 530 of 1000  

#> MCMC iteration - 540 of 1000  

#> MCMC iteration - 550 of 1000  

#> MCMC iteration - 560 of 1000  

#> MCMC iteration - 570 of 1000  

#> MCMC iteration - 580 of 1000  

#> MCMC iteration - 590 of 1000  

#> MCMC iteration - 600 of 1000  

#> MCMC iteration - 610 of 1000  

#> MCMC iteration - 620 of 1000  

#> MCMC iteration - 630 of 1000  

#> MCMC iteration - 640 of 1000  

#> MCMC iteration - 650 of 1000  

#> MCMC iteration - 660 of 1000  

#> MCMC iteration - 670 of 1000  

#> MCMC iteration - 680 of 1000  

#> MCMC iteration - 690 of 1000  

#> MCMC iteration - 700 of 1000  

#> MCMC iteration - 710 of 1000  

#> MCMC iteration - 720 of 1000  

#> MCMC iteration - 730 of 1000  

#> MCMC iteration - 740 of 1000  

#> MCMC iteration - 750 of 1000  

#> MCMC iteration - 760 of 1000  

#> MCMC iteration - 770 of 1000  

#> MCMC iteration - 780 of 1000  

#> MCMC iteration - 790 of 1000  

#> MCMC iteration - 800 of 1000  

#> MCMC iteration - 810 of 1000  

#> MCMC iteration - 820 of 1000  

#> MCMC iteration - 830 of 1000  

#> MCMC iteration - 840 of 1000  

#> MCMC iteration - 850 of 1000  

#> MCMC iteration - 860 of 1000  

#> MCMC iteration - 870 of 1000  

#> MCMC iteration - 880 of 1000  

#> MCMC iteration - 890 of 1000  

#> MCMC iteration - 900 of 1000  

#> MCMC iteration - 910 of 1000  

#> MCMC iteration - 920 of 1000  

#> MCMC iteration - 930 of 1000  

#> MCMC iteration - 940 of 1000  

#> MCMC iteration - 950 of 1000  

#> MCMC iteration - 960 of 1000  

#> MCMC iteration - 970 of 1000  

#> MCMC iteration - 980 of 1000  

#> MCMC iteration - 990 of 1000  

#> MCMC iteration - 1000 of 1000  

#> Computing log-likelihood

predict(model)
#>     predicted
#> true  A  B
#>    A 11  2
#>    B  0 37
predict(model, overview = FALSE)
#>    id idc    A    B true predicted correct
#> 1   1   1 0.18 0.82    B         B    TRUE
#> 2   1   2 0.10 0.90    B         B    TRUE
#> 3   1   3 0.13 0.87    B         B    TRUE
#> 4   1   4 0.00 1.00    B         B    TRUE
#> 5   1   5 0.00 1.00    B         B    TRUE
#> 6   1   6 1.00 0.00    A         A    TRUE
#> 7   1   7 0.37 0.63    B         B    TRUE
#> 8   1   8 0.31 0.69    B         B    TRUE
#> 9   1   9 0.08 0.92    B         B    TRUE
#> 10  1  10 1.00 0.00    A         A    TRUE
#> 11  2   1 0.00 1.00    B         B    TRUE
#> 12  2   2 0.00 1.00    B         B    TRUE
#> 13  2   3 1.00 0.00    A         A    TRUE
#> 14  2   4 1.00 0.00    A         A    TRUE
#> 15  2   5 0.00 1.00    B         B    TRUE
#> 16  2   6 0.03 0.97    B         B    TRUE
#> 17  2   7 0.04 0.96    B         B    TRUE
#> 18  2   8 0.00 1.00    B         B    TRUE
#> 19  2   9 0.04 0.96    B         B    TRUE
#> 20  2  10 0.00 1.00    B         B    TRUE
#> 21  3   1 0.00 1.00    B         B    TRUE
#> 22  3   2 0.70 0.30    A         A    TRUE
#> 23  3   3 0.05 0.95    B         B    TRUE
#> 24  3   4 1.00 0.00    A         A    TRUE
#> 25  3   5 0.00 1.00    B         B    TRUE
#> 26  3   6 0.85 0.15    A         A    TRUE
#> 27  3   7 0.24 0.76    B         B    TRUE
#> 28  3   8 1.00 0.00    A         A    TRUE
#> 29  3   9 0.07 0.93    B         B    TRUE
#> 30  3  10 0.00 1.00    B         B    TRUE
#> 31  4   1 0.00 1.00    B         B    TRUE
#> 32  4   2 0.02 0.98    B         B    TRUE
#> 33  4   3 0.29 0.71    A         B   FALSE
#> 34  4   4 0.00 1.00    B         B    TRUE
#> 35  4   5 1.00 0.00    A         A    TRUE
#> 36  4   6 0.00 1.00    B         B    TRUE
#> 37  4   7 0.25 0.75    B         B    TRUE
#> 38  4   8 0.02 0.98    B         B    TRUE
#> 39  4   9 0.00 1.00    B         B    TRUE
#> 40  4  10 0.00 1.00    B         B    TRUE
#> 41  5   1 0.00 1.00    B         B    TRUE
#> 42  5   2 1.00 0.00    A         A    TRUE
#> 43  5   3 0.00 1.00    B         B    TRUE
#> 44  5   4 0.00 1.00    B         B    TRUE
#> 45  5   5 0.02 0.98    B         B    TRUE
#> 46  5   6 0.15 0.85    A         B   FALSE
#> 47  5   7 1.00 0.00    A         A    TRUE
#> 48  5   8 0.00 1.00    B         B    TRUE
#> 49  5   9 0.00 1.00    B         B    TRUE
#> 50  5  10 0.00 1.00    B         B    TRUE
predict(model, data = data$test)
#>     predicted
#> true  A  B
#>    A 15  3
#>    B  6 26
predict(
  model,
  data = data.frame("cov_A" = c(1,1,NA,NA), "cov_B" = c(1,NA,1,NA)),
  overview = FALSE
)
#> Checking for missing covariates
#>   id idc    A    B prediction
#> 1  1   1 0.18 0.82          B
#> 2  2   1 0.00 1.00          B
#> 3  3   1 0.95 0.05          A
#> 4  4   1 0.18 0.82          B