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 do i include an average and 90% confidence in plot?

Subject: How do i include an average and 90% confidence in plot?

From: Robert Smith asdf

Date: 8 Apr, 2010 14:50:10

Message: 1 of 5

i have x-y data as such (i hope that the pic works): http://img175.imageshack.us/i/77916937.jpg/
where there are multiple y values for every x. how do i calculate an average value for each x and how do i make the 90% confidence interval and plot them?

any suggestions?

Subject: How do i include an average and 90% confidence in plot?

From: us

Date: 8 Apr, 2010 14:59:08

Message: 2 of 5

"Robert Smith asdf" <bainit83remove@thisyahoo.com> wrote in message <hpkqf2$k9u$1@fred.mathworks.com>...
> i have x-y data as such (i hope that the pic works): http://img175.imageshack.us/i/77916937.jpg/
> where there are multiple y values for every x. how do i calculate an average value for each x and how do i make the 90% confidence interval and plot them?
>
> any suggestions?

a hint:
- assuming your X-vals are equal for all Y-vals...
- otherwise, use a consolidating algo...

     help mean; % <- all vectorized...
     help var; % <- + with appropriate scaling... or
     help std;

us

Subject: How do i include an average and 90% confidence in plot?

From: Robert Smith asdf

Date: 8 Apr, 2010 18:34:09

Message: 3 of 5

"Robert Smith asdf" <bainit83remove@thisyahoo.com> wrote in message <hpkqf2$k9u$1@fred.mathworks.com>...
> i have x-y data as such (i hope that the pic works): http://img175.imageshack.us/i/77916937.jpg/
> where there are multiple y values for every x. how do i calculate an average value for each x and how do i make the 90% confidence interval and plot them?
>
> any suggestions?
there are multiple y for each x (not the same number also).

Subject: How do i include an average and 90% confidence in plot?

From: Tom Lane

Date: 9 Apr, 2010 17:33:11

Message: 4 of 5

>> i have x-y data as such (i hope that the pic works):
>> http://img175.imageshack.us/i/77916937.jpg/
>> where there are multiple y values for every x. how do i calculate an
>> average value for each x and how do i make the 90% confidence interval
>> and plot them?
>>
>> any suggestions?
> there are multiple y for each x (not the same number also).

Robert, in general the errorbar function is good for plotting averages error
limits. It requires that you calculate those averages and limits separately,
though.

The plot you pointed out looks a lot like x/y data where you could imagine
fitting y=f(x)+error and asking for error limits around that. But I think
you're asking how to compute averages of y values at the distinct x values.
So take a look at this code and see if you can figure out how to adapt it to
your situation (for example to specify the confidence level):

x = randi(20,120,1);
y = x + randn(size(x));
plot(x,y,'bx')
[m,ci,g] = grpstats(y,x,{'mean' 'meanci' 'gname'})
g = str2num(char(g));
line(g,m,'color','r')
line(g,ci,'color','r','linestyle',':')

-- Tom

Subject: How do i include an average and 90% confidence in plot?

From: Rob Campbell

Date: 9 Apr, 2010 17:57:06

Message: 5 of 5

"Tom Lane" <tlane@mathworks.com> wrote in message <hpnocn$bcs$1@fred.mathworks.com>...
> >> i have x-y data as such (i hope that the pic works):
> >> http://img175.imageshack.us/i/77916937.jpg/
> >> where there are multiple y values for every x. how do i calculate an
> >> average value for each x and how do i make the 90% confidence interval
> >> and plot them?
> >>
>
I have a function on the FEX that may do what you want:
http://www.mathworks.com/matlabcentral/fileexchange/26311-shadederrorbar

You can feed it the raw data and can tell it where to draw the line and CI using function handles. To get the SEM you can feed in other one of my functions as a function handle.
http://www.mathworks.com/matlabcentral/fileexchange/26508-notboxplot-alternative-to-box-plots

To plot the mean and a 95% confidence interval for the mean you simply do:
shadedErrorBar(x,y,{@mean,@SEM_calc});

You can easily change the 95% to any other number (see help SEM_calc, SEM_calc is in the second link). You can also remove the shaded error region from the shaded plot if you don't like it: shaded error bar returns all the plot object handles, so apply delete to those you don't want. You can also (obviously) over-plot your raw data onto the shaded area.

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