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. In addition, help files are available for all functions, using e.g. ?apollo_mnl
  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.

confidence intervals

Ask questions about post-estimation functions (e.g. prediction, conditionals, etc) or other processing of results.
Post Reply
maa033
Posts: 35
Joined: 23 Jul 2020, 14:00

confidence intervals

Post by maa033 »

Hi

I am using the following code to calculate confidence intervals for estimated coefficients:

s.e. = sqrt(vcov(model)[11,11])

ci95 = function(coef_bunn_T) {
t.value = 1.96
standard.error = s.e.
ci = t.value*standard.error
cat("95% Confidence Interval =", mean(coef_bunn_T) - ci, "to ", mean(coef_bunn_T) + ci, "\n")}

ci95(coef_bunn_T)

the parameter "bunn_T" is the 11th parameter in the beta vector.

The problem is that the s.e. is NOT the robust s.e. from the estimated model, but the "ordinary" s.e.
Is there a way to change the reference to the the standard error (s.e.) so that the function uses the robust instead of the ordinary standard error??

I also tried to calculate CIs using the delta method, but I was unable to do it correctly. Is there a simple delta method code for the confidence interval?

thank you for your answer.

best regards,
Margrethe
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: confidence intervals

Post by dpalma »

Hi Margrethe,

You can access the robust standard error through model$robse. So in your case, you could do:

Code: Select all

s.e. = sqrt( model$robse["bunn_T"] )
Alternatively, below is a function that allows calculating 95% C.I. for both a single parameters and functions of them:

Code: Select all

ci95 = function(expr, model) {
  M  = apollo_deltaMethod(model, list(expression=expr))
  ci = 1.96*M[1, "Robust s.e."]
  cat("95% Confidence Interval =", M[1,"Value"] - ci, "to ", M[1,"Value"] + ci, "\n")
}

ci95("bTT", model) # This assumes bTT is a parameter in your model
# Running Delta method computation for user-defined function:
#   
#   Expression   Value Robust s.e. Rob t-ratio (0)
#          bTT -0.0613      0.0067           -9.21
# 95% Confidence Interval = -0.074432 to  -0.048168 
Best wishes
David
maa033
Posts: 35
Joined: 23 Jul 2020, 14:00

Re: confidence intervals

Post by maa033 »

Thanks a lot.
Very useful to have this CI code!!

best regards,
Margrethe
maa033
Posts: 35
Joined: 23 Jul 2020, 14:00

Re: confidence intervals

Post by maa033 »

Hi again David

I have a question related to that of the CIs.

I am running a Poe test to find out whether two coefficients are equal or not.
I use the mded package, and this code:

coef_land_T <- rnorm(1000, coef(model)[12], sqrt(vcov(model)[12,12]))
coef_land_B <- rnorm(1000, coef(model)[7], sqrt(vcov(model)[7,7]))

mded(coef_land_T, coef_land_B, detail=TRUE, independent=TRUE)

While this works for results from the MXL-model, it does not work for results from the MNL model, giving this error message:

Error in varcovar[activePar, activePar] <- solve(-hessian(object)[activePar, :
number of items to replace is not a multiple of replacement length
>

Although this is not directly relevant for the apollo package, maybe you are able to see why this code is not applicable to results from the estimation of an MNL-model in apollo?

thank you in advance.

Best regards,
Margrethe
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: confidence intervals

Post by dpalma »

Hi Margrethe,

I am not familiar with the Poe test nor the mded package, so I am not sure how much I can help. But as a general recommendation, I would advise you to access the coefficients and variance-coviariance values of a model using the "$" operator, as opposed to the "coef" and "vcov" functions. And using the robust covariance matrix might be better than the classical one. Also, it might be that your MNL model has fixed parameters, which appear among the estimates, but not in the variance-covariance matrix.

In particular, I would change your code as follows:

Code: Select all

b = model$estimate[!(names(model$estimate) %in% model$apollo_fixed)] # coefficients excluding fixed ones
s = model$robvarcov # robust covariance matrix
coef_land_T <- rnorm(1000, b[12], sqrt(s[12,12])) # double check the index as it may have changed after removing the fixed parameters
coef_land_B <- rnorm(1000, b[7], sqrt(s[7,7])) # double check the index as it may have changed after removing the fixed parameters
mded(coef_land_T, coef_land_B, detail=TRUE, independent=TRUE)
Finally, while I am not familiar with the Poe test, I can tell you that both coefficients are not really independent, as the (rob)covar matrix will most likely indicate a non-zero covariance between the two parameters.

Best wishes
David
Post Reply