predict.RprobitB_fit: Predict choices

View source: R/prediction.R

predict.RprobitB_fitR Documentation

Predict choices

Description

Computes occasion-level choice probabilities over the retained posterior draws and predicts the alternative with the largest mean probability.

Usage

## S3 method for class 'RprobitB_fit'
predict(
  object,
  newdata = NULL,
  type = c("population", "conditional"),
  uncertainty = FALSE,
  level = 0.95,
  ghk_draws = 500L,
  progress = interactive(),
  ...
)

Arguments

object

[RprobitB_fit]
Fitted choice model.

newdata

[data.frame | NULL]
Data for prediction. NULL uses the fitted data. A response column is optional. In wide format, missing decider and occasion identifiers make every row a choice occasion of its own decider.

type

[character(1)]
Which coefficients to predict with:

  • "population" integrates over the estimated population distribution of the random coefficients and applies to any decider.

  • "conditional" uses the posterior random coefficients and class allocations of the deciders that were observed when fitting the model, which newdata must then name.

uncertainty

[logical(1)]
Add posterior standard deviations and credible intervals?

level

[numeric(1)]
Probability of the credible intervals.

ghk_draws

[integer(1)]
Number of draws of the GHK simulator for multivariate normal probabilities of more than three dimensions, see oeli::pmvnorm().

progress

[logical(1)]
Show progress?

...

Currently not used.

Details

Conditional prediction is based on the individual-level parameters (Train, 2009, Chapters 11 and 12): the posterior distribution of a decider's coefficients given their observed choices, which the Gibbs sampler provides as draws when the model is fitted with save_individual_draws = TRUE.

Value

A data.frame with one row per choice occasion, identifier columns, .prediction, and one ⁠probability_*⁠ column per alternative. If uncertainty = TRUE, ⁠sd_*⁠, ⁠lower_*⁠, and ⁠upper_*⁠ columns are added.

References

\insertRef

Train2009RprobitB

Examples

set.seed(1)
model <- fit(
  choice ~ x | 0,
  random_effects = "x",
  dgp_parameters = list(beta = c(x = 1), Omega = matrix(0.5)),
  n_deciders = 20,
  iterations = 300,
  warmup = 150,
  chains = 1,
  save_individual_draws = TRUE
)
head(predict(model))
head(predict(model, type = "conditional"))
head(predict(model, uncertainty = TRUE))

### new choice occasions
new_data <- data.frame(deciderID = 21:22, x_A = c(1, -1), x_B = c(0, 0))
predict(model, newdata = new_data)

RprobitB documentation built on Sept. 20, 2026, 9:07 a.m.