Important: Read this before posting to this forum

  1. This forum is for questions related to the use of Apollo. We will answer some general choice modelling questions too, where appropriate, and time permitting. We cannot answer questions about how to estimate choice models with other software packages.
  2. There is a very detailed manual for Apollo available at http://www.ApolloChoiceModelling.com/manual.html. This contains detailed descriptions of the various Apollo functions, and numerous examples are available at http://www.ApolloChoiceModelling.com/examples.html.
  3. Before asking a question on the forum, users are kindly requested to follow these steps:
    1. Check that the same issue has not already been addressed in the forum - there is a search tool.
    2. Ensure that the correct syntax has been used. For any function, detailed instructions are available directly in Apollo, e.g. by using ?apollo_mnl for apollo_mnl
    3. Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
    4. Make sure that R is using the latest official release of Apollo.
  4. If the above steps do not resolve the issue, then users should follow these steps when posting a question:
    1. provide full details on the issue, including the entire code and output, including any error messages
    2. posts will not immediately appear on the forum, but will be checked by a moderator first. This may take a day or two at busy times. There is no need to submit the post multiple times.

How to access/compute the prediction intervals printed out by apollo_prediction()?

Ask questions about post-estimation functions (e.g. prediction, conditionals, etc) or other processing of results.
Post Reply
Lucas_W
Posts: 1
Joined: 16 Nov 2021, 14:01

How to access/compute the prediction intervals printed out by apollo_prediction()?

Post by Lucas_W » 16 Nov 2021, 14:50

Hi David and Stephane,

I did a scenario-analysis with a simple ordered logit modle using apollo_prediction():

Code: Select all

pred <- apollo_prediction(Model.3,apollo_probabilities,apollo_inputs,prediction_settings = list(runs=100))
The 95% prediction/confidence intervals of the market shares are printed to the console but I'm rather interested in either finding a way to save them as objects or alternatively to compute them "by hand" using the output in pred$draws. Searching through your manual and academic paper I couldn't find how exactly they are computed.

The issue is that I'm applying a bootstrap-like procedure like so:

Code: Select all

MS.save <- list()
for(j in 1:500){
	wt.new <- manipulate_wt(wt.original,new.wt.distribution) # randomly assigns WaitingTime intervals to the observations according to new.wt.distribution using sample()
	database$WaitingTime <- wt.new
	apollo_inputs <- apollo_validateInputs()
	pred <- apollo_prediction(Model.3,apollo_probabilities,apollo_inputs,prediction_settings = list(runs=100))
	MS.save[[j]] <- colMeans(pred$at_estimates[,3:5]) # save market shares for each j
}
Now I'd like to not only save the point estimates at each iteration but also the prediction intervals for each j. Is there any (painless) way to do this?

Best,
Lucas

stephanehess
Site Admin
Posts: 440
Joined: 24 Apr 2020, 16:29

Re: How to access/compute the prediction intervals printed out by apollo_prediction()?

Post by stephanehess » 29 Nov 2021, 13:46

Lucas

the object returned in pred$draws is a cube, with observations in the first dimension (rows), alternatives in the second (columns), and replications in the third dimension.

From this, you can obtain the CIs as:

agg <- apply(pred$draws, MARGIN=c(2,3), sum, na.rm=TRUE)
lower_CI <- apply(agg, MARGIN=1, quantile, probs=0.025)
upper_CI <- apply(agg, MARGIN=1, quantile, probs=0.975)

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk

Post Reply