Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

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

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

From: david

Date: 29 Mar, 2011 13:54:03

Message: 1 of 11

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

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

From: Frank

Date: 29 Mar, 2011 14:31:35

Message: 2 of 11

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

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

From: david

Date: 4 Apr, 2011 13:40:05

Message: 3 of 11

Frank <fbleahy@yahoo.com> wrote in message <dc3eba23-efe6-4980-b610-8da0a3369cd0@i4g2000pro.googlegroups.com>...
> 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

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

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

From: Frank

Date: 5 Apr, 2011 13:58:47

Message: 4 of 11

> 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

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

From: david

Date: 18 Apr, 2011 11:08:04

Message: 5 of 11

Frank <fbleahy@yahoo.com> wrote in message <a520ef7f-c8a7-49d9-b16e-e9fdde35171a@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.

Thank you and look forward to your reply.

David

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

From: david

Date: 27 May, 2011 07:59:05

Message: 6 of 11

> > 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?

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

From: Tom Lane

Date: 27 May, 2011 16:12:12

Message: 7 of 11

>> 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

 

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

From: david

Date: 1 Jun, 2011 08:32:04

Message: 8 of 11

"Tom Lane" <tlane@mathworks.nospam.com> wrote in message <iroiia$n5g$1@newscl01ah.mathworks.com>...
> >> 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
>
>

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

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

From: Tom Lane

Date: 2 Jun, 2011 17:13:44

Message: 9 of 11

> 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?
 

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

From: Tom Lane

Date: 2 Jun, 2011 17:24:29

Message: 10 of 11

Sorry, continuing incomplete message ...

"Tom Lane" <tlane@mathworks.nospam.com> wrote in message
news:is8gdd$cs1$1@newscl01ah.mathworks.com...
>> 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?

>> 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

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

From: Frank

Date: 28 Jun, 2011 21:33:54

Message: 11 of 11

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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us