Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to calculate confidence intervals (bounds) of NORMCDF using MATLAB

1,339 views
Skip to first unread message

david

unread,
Mar 29, 2011, 9:54:03 AM3/29/11
to
Dear guys,

Could anyone tell me how to calculate confidence intervals (bounds) of cumulative normal distribution usign matlab. The matlab code is shown below:


x=0:0.01:0.5;

y = cdf('Normal',x,0.2,0.025);

figure(2);plot(x,y);

Let's start from 95% one-sided confidence intervals.

Thank you very much!

Dawei

Frank

unread,
Mar 29, 2011, 10:31:35 AM3/29/11
to
If you are using the cdf function, then I assume you have the stats
toolbox. If so, use the normcdf function instead. If will give you
confidence bounds on probability for any confidence level you desire.
Also, see the function normlike to get the covariance matrix of the
estimated parameters, which you need in the call for normcdf.

Frank

david

unread,
Apr 4, 2011, 9:40:05 AM4/4/11
to
Frank <fbl...@yahoo.com> wrote in message <dc3eba23-efe6-4980...@i4g2000pro.googlegroups.com>...

Hi Frank,

Thank you very much for your reply which is really helpful. Also I have some more questions, hope you could give me some advices:

1. I have done some codes and could you help me to check whether the code is following what you said.

x=0:0.01:0.5;
mu=0.12;
sigma=0.025;
alpha=0.05;
[a,pcov] = normlike([mu,sigma], x);
[y,yl,yu] = normcdf(x,mu,sigma,pcov,alpha);
figure(2);plot(x,y,'b',x,yl,'r',x,yu,'r');hold on;

2. Could you tell me the value of alpha is for one-sided or two-sided?

3. Do you know how to calculate confidence intervals for other function other than normal cumulative function, e.g. y = exp(z) / (1+exp(z)), where z=a+b*x. This function can be considered as an inverse log-odss function.

Thank you and look forward to your reply.

David

Frank

unread,
Apr 5, 2011, 9:58:47 AM4/5/11
to
> 1. I  have done some codes and could you help me to check whether the code is following what you said.
>
> x=0:0.01:0.5;
> mu=0.12;
> sigma=0.025;
> alpha=0.05;
> [a,pcov] = normlike([mu,sigma], x);
> [y,yl,yu] = normcdf(x,mu,sigma,pcov,alpha);
> figure(2);plot(x,y,'b',x,yl,'r',x,yu,'r');hold on;
>

Yes....that looks to be correct.

> 2. Could you tell me the value of alpha is for one-sided or two-sided?
>

alpha is two-sided, meaning if you use alpha = 0.05, this will give
the 95% two-sided confidence intervals

> 3. Do you know how to calculate confidence intervals for other function other than normal cumulative function, e.g. y = exp(z) / (1+exp(z)), where z=a+b*x. This function can be considered as an inverse log-odss function.
>

It should be just a simple transformation. Meaning, if you know the
confidence intervals on x, then the confidence intervals on z should
be a+b*yu and a+b*yl. Of course, I haven't checked this.

Frank

david

unread,
Apr 18, 2011, 7:08:04 AM4/18/11
to
Frank <fbl...@yahoo.com> wrote in message <a520ef7f-c8a7-49d9...@f18g2000yqd.googlegroups.com>...

>
> > 3. Do you know how to calculate confidence intervals for other function other than normal cumulative function, e.g. y = exp(z) / (1+exp(z)), where z=a+b*x. This function can be considered as an inverse log-odss function.
> >
>
> It should be just a simple transformation. Meaning, if you know the
> confidence intervals on x, then the confidence intervals on z should
> be a+b*yu and a+b*yl. Of course, I haven't checked this.
>
> Frank


Hi Frank,

Thank you very much for your help! BTW sorry for late reply.

With regards to my third question, I realized the funciton is called Logistic function which is defined as : y = exp(z) / (1+exp(z)).
What I want is to calculate confidence intervals for y. Also z = a+b*x

For the convenience I provide the code:
a=-5;
b=38;
x=0.01:0.01:0.5;
z=a+b.*x;
y = exp(z)./(1+exp(z));
figure(2);plot(x,y);hold on;

My question is Could you tell me how to calculate confidence intervals for y in the plot of x&y.

david

unread,
May 27, 2011, 3:59:05 AM5/27/11
to
> > It should be just a simple transformation. Meaning, if you know the
> > confidence intervals on x, then the confidence intervals on z should
> > be a+b*yu and a+b*yl. Of course, I haven't checked this.
> >
> > Frank
>
>
> Hi Frank,
>
> Thank you very much for your help! BTW sorry for late reply.
>
> With regards to my third question, I realized the funciton is called Logistic function which is defined as : y = exp(z) / (1+exp(z)).
> What I want is to calculate confidence intervals for y. Also z = a+b*x

Could someone help me?

Tom Lane

unread,
May 27, 2011, 12:12:12 PM5/27/11
to
>> With regards to my third question, I realized the funciton is called
>> Logistic function which is defined as : y = exp(z) / (1+exp(z)).
>> What I want is to calculate confidence intervals for y. Also z = a+b*x
>
> Could someone help me?

David, I have not been able to follow what you are trying to do.

In your original note you seem to have specified a grid of x values and a
fixed value for mu and sigma, then asked for confidence intervals. Usually
confidence intervals are around an estimate of something. What is being
estimated here?

You are correct that you can get a parameter covariance matrix from normlike
and pass it into normcdf. But for that to be sensible, the parameters you
input to normlike would have to be estimated from the data that you also
pass in. You don't want to pass in just a grid of data values and some
constant parameter values.

-- Tom

david

unread,
Jun 1, 2011, 4:32:04 AM6/1/11
to
"Tom Lane" <tl...@mathworks.nospam.com> wrote in message <iroiia$n5g$1...@newscl01ah.mathworks.com>...

Hi Tom,

Thanks for your reply.

1. I think I understand what you mean. Actually sigma and mu are estimated from raw data and x is not even distributed. In my code x = 0:0.01:0.5, but in the raw data, x is between 0 and 0.5 and not even distributed.

Please tell me I understand your comment.

2. Could you tell me how to calcualte confidence intervals for Logistic function ? So plot confidence intervals in the xy plot.

a=-5; b=38;

x=0.01:0.01:0.5;

z=a+b.*x;

y = exp(z)./(1+exp(z));

figure(2);plot(x,y);hold on;

Thank you.

Dawei

Tom Lane

unread,
Jun 2, 2011, 1:13:44 PM6/2/11
to
> 1. I think I understand what you mean. Actually sigma and mu are estimated
> from raw data and x is not even distributed. In my code x = 0:0.01:0.5,
> but in the raw data, x is between 0 and 0.5 and not even distributed.
> Please tell me I understand your comment.
>
> 2. Could you tell me how to calcualte confidence intervals for Logistic
> function ? So plot confidence intervals in the xy plot.

Dawei, I don't think anyone can tell you how to calculate confidence
intervals for a=-5 and b=38. All we can tell is how to compute confidence
intervals for parameters that are estimated from data.

Sometimes I like to suggest and answer questions different from the ones
posed. Here are two:

1. How can I calculate intervals such that 95% of the probability
distribution falls in the interval?

Tom Lane

unread,
Jun 2, 2011, 1:24:29 PM6/2/11
to
Sorry, continuing incomplete message ...

"Tom Lane" <tl...@mathworks.nospam.com> wrote in message

news:is8gdd$cs1$1...@newscl01ah.mathworks.com...

>> mu = 5; sigma = 2;
>> norminv([.025 .975],mu,sigma)
ans =
1.0801 8.9199

2. How can I compute confidence intervals for the cdf given the data x from
which I estimated the parameters?

>> x = normrnd(10,2,100,1);
>> [m,s] = normfit(x);
>> [~,pcov] = normlike([m s],x);
>> [p,plo,pup] = normcdf(11.1,m,s,pcov)
p =
0.6433
plo =
0.5654
pup =
0.7156

The Statistics Toolbox doesn't have this set of functions for the logistic
distribution, so you can't use the same approach for that distribution.

-- Tom

Frank

unread,
Jun 28, 2011, 5:33:54 PM6/28/11
to
Sorry I didn't reply earlier. Doing confidence intervals (really, it's
the confidence bounds) for the logistic distribution is trickier,
since matlab doesn't have a built-in function like the normcdf to give
you those bounds. Since the normal and logistic distributions are
similar, you can theoretically transform a normal distribution to a
logistic by applying the transform data * sqrt(3)/pi. Give that a try,
and if it doesn't give you what you are looking for, let me know and
I'll try to post some code which will do it the brute force way.

hth,
Frank

0 new messages