Page 1 of 1

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

Posted: 16 Nov 2021, 14:50
by Lucas_W
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

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

Posted: 29 Nov 2021, 13:46
by stephanehess
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