How to calculate the confidence interval

1,125 ビュー (過去 30 日間)
Sepp
Sepp 2014 年 10 月 20 日
コメント済み: Star Strider 2023 年 8 月 25 日
Hi
I have a vector x with e.g. 100 data point. I can easy calculate the mean but now I want the 95% confidence interval. I can calculate the 95% confidence interval as follows:
CI = mean(x)+- t * (s / square(n))
where s is the standard deviation and n the sample size (= 100).
Is there a method in matlab where I just can feed in the vector and then I get the confidence interval?
Or I can write my own method but I need at least the value of t (critical value of the t distribution) because it depends on the number of samples and I don't want to lookup it in a table everytime. Is this possible?
Would be very nice if somebody could give an example.
Last but not least, I want 95% confidence in a 5% interval around the mean. For checking that I just have to calculate the 95% confidence interval and then check if the retrieved value is less than 5% of my mean, right?
  4 件のコメント
Jennifer Wade
Jennifer Wade 2022 年 2 月 15 日
I use something like this for a generic data vector, A.....
N = length(A)
STDmean = mean(A)/sqrt(N)
dof = N - 1; %Depends on the problem but this is standard for a CI around a mean.
studentst = tinv([.025 0.975],dof) %tinv is the student's t lookup table for the two-tailed 95% CI ...
CI = studentst*STDmean
I'm looking into bootci now!
Jennifer Wade
Jennifer Wade 2022 年 2 月 15 日
Sorry, just saw the same answer below!

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2014 年 10 月 20 日
This works:
x = randi(50, 1, 100); % Create Data
SEM = std(x)/sqrt(length(x)); % Standard Error
ts = tinv([0.025 0.975],length(x)-1); % T-Score
CI = mean(x) + ts*SEM; % Confidence Intervals
You have to have the Statistics Toolbox to use the tinv function. If you do not have it, I can provide you with a few lines of my code that will calculate the t-probability and its inverse.
  25 件のコメント
Niraj Desai
Niraj Desai 2023 年 8 月 25 日
@Star Strider Thank you so much for your answers (over the course of eight years !!!) I realize this thread started in 2014, but I only found it today. It clarified something that I had been confused about. I'm grateful.
Star Strider
Star Strider 2023 年 8 月 25 日
@Niraj Desai — My pleasure!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by