Asked by Ase U
on 8 Aug 2018

Hi all,

i have a signal so it's just data, that i load on Matlab and I have to plot 95% confidence interval according to student t-distribution of my signal. Exactly like photo, that i added. When i am reading some solutions about that, i am confuse because i am not good about statistics. If you help me, at least how can i start to make something, i would be very appreciated that.

Thank you!

Answer by Star Strider
on 8 Aug 2018

Accepted Answer

In order to calculate the 95% confidence intervals of your signal, you first will need to calculate the mean and *|std| (standard deviation) of your experiments at each value of your independent variable. The standard way to do this is to calculate the standard error of the mean at each value of your independent variable, multiply it by the calculated 95% values of the t-distribution (here), then add and subtract those values from the mean. The plot is then straightforward. (The tinv function is in the Statistics and Machine Learning Toolbox.)

Example —

x = 1:100; % Create Independent Variable

y = randn(50,100); % Create Dependent Variable ‘Experiments’ Data

N = size(y,1); % Number of ‘Experiments’ In Data Set

yMean = mean(y); % Mean Of All Experiments At Each Value Of ‘x’

ySEM = std(y)/sqrt(N); % Compute ‘Standard Error Of The Mean’ Of All Experiments At Each Value Of ‘x’

CI95 = tinv([0.025 0.975], N-1); % Calculate 95% Probability Intervals Of t-Distribution

yCI95 = bsxfun(@times, ySEM, CI95(:)); % Calculate 95% Confidence Intervals Of All Experiments At Each Value Of ‘x’

figure

plot(x, yMean) % Plot Mean Of All Experiments

hold on

plot(x, yCI95+yMean) % Plot 95% Confidence Intervals Of All Experiments

hold off

grid

This should get you started.

Star Strider
on 10 Aug 2018

I do not understand ‘... size of x and y signals is 5001.’

I do not know the dimensions of your vectors and matrices. You would get a scalar (1x1) mean value of a column vector.

Since your data may be column-oriented rather than row-oriented, see if adding a dimension argument and calculating them across the columns (rather than across the rows) as (for example, using some 2D matrix ‘z’):

zmean = mean(z,2);

and

zstd = std(z,[],2);

solves your problem.

If you simply want to expand your scalar mean value (that I call ‘scalarMean’ here) to be the same size as ‘x’, create it as:

meanvec = scalarMean*ones(size(x));

That will work.

Ase U
on 11 Aug 2018

Star Strider
on 11 Aug 2018

Size (5001x1) means 5001 rows and 1 column. Most MATLAB functions will operate column-wise, so the mean function will produce a scalar result for a column vector. If all your signals are vectors, then taking the mean of them will always produce a scalar result.

If all your data are vectors (not matrices of several experiments), they will not have confidence intervals. The only way you can calculate confidence intervals for them is to do curve-fitting and then calculate the confidence intervals on the fit. Use nlinfit and nlpredci in the Statistics and Machine Learning Toolbox for that. Note that you will need a mathematical model of the process that produced your data (the ‘objective function’) to do the regression.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.