Page 1 of 1

confidence intervals

Posted: 30 Jun 2022, 14:06
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

Re: confidence intervals

Posted: 07 Jul 2022, 16:44
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

Re: confidence intervals

Posted: 15 Jul 2022, 09:01
by maa033
Thanks a lot.
Very useful to have this CI code!!

best regards,
Margrethe

Re: confidence intervals

Posted: 15 Jul 2022, 15:28
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

Re: confidence intervals

Posted: 19 Jul 2022, 10:32
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