I am generating and analyzing logistic regression models using MATLAB's fitglm. http://www.mathworks.com/help/stats/fitglm.html The fit models can then be visualized using plotSlice(glm). This figure is great, but is hard to customize.

I want to recreate the confidence bounds from plotSlice, but I am unable to. No where in documentation or figure can find the confidence bound data or the equation used to calculate it.

I have tried to recreate the bounds by calculating the variance of the sums of the fit coefficient variance as instructed in "Wiley Series in Probability and Statistics : Applied Logistic Regression (3rd Edition)"

Ex (1 parameter(B1) with intercept(B0)).

Var(g(xi)) = var(B0)+xi^2(var(B1))+2*(covar(B0,B1)) %the variance of the model at xi

where Var(g(xi)) is variance at xi, B0 is the fit intercept, B1 is the fit slope, xi is ith predictor value;

g_CI = +- z*sqrt(Var(g(xi)))% bounds at xi

where g_CI is 95% CI at xi, z is the z score from standard normal dist.


mdlCoeff =  [-1.2631;0.1558];
stats.se = [0.4472;0.0641];
stats.covb = [0.2000,-0.0271;-0.0271,0.0041];
testX = 7;
testp = mdlCoeff(1) + mdlCoeff(2)*testX;
phattest = exp(testp)./(1 + exp(testp));
varXitest = (stats.se(1).^2)+((testX.^2).*stats.se(2).^2)+(2*testX.*stats.covb(3));
phat_bounds3test = [phattest + (normcdf(.975).*(varXitest.^0.5)),
                    phattest - (normcdf(.975).*(varXitest.^0.5))] 

this gives me 95% bounds of 0.5896 and 0.3333.

However, the plotSlice produce figure returns .5467 and .3700. Even when I reduce my z value 0 I don't get this narrow of a bound. Therefore I must be calculating varXitest incorrectly.

What am I missing here?

  • $\begingroup$ Just a very general comment. Systems built for statistics such as R make such tasks far easier. $\endgroup$ Nov 8, 2015 at 17:03
  • $\begingroup$ Thank you for your comment. Unfortunately this regression is part a large, many functioned program and switching to R would require a lot of work. $\endgroup$
    – rconway91
    Nov 8, 2015 at 17:04

1 Answer 1


In your code, you have

testp = the estimated linear combination of X values
phattest = testp transformed to the probability scale by the inverse logit function
varXitest = estimated variance of testp.

You are using varXitest as if it described the variance of phattest. I think you want to compute confidence intervals for testp using varXitest. Then transform both testp and its confidence intervals to the probability scale.

The alternative would be to estimate the variance of phattest using the Jacobian of the inverse logit transformation. This could be used to compute confidence intervals for the predicted probability. But I think you would be better off computing the confidence intervals on the unbounded scale of testp, and transforming them.

  • $\begingroup$ Thank you! You were correct, If I get my linear bounds and then perform the transform I get what the mysterious MATLAB function produced! Thanks $\endgroup$
    – rconway91
    Nov 12, 2015 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.