IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
confint.m
Go to the documentation of this file.
1 %> @brief Calculates confidence interval
2 %> @ingroup maths
3 %> @file
4 %>
5 %> @brief Calculates confidence interval of an input vector
6 %
7 %> @param x Input vector
8 %> @param perc =.95 The percentual confidence
9 %> @return a 2-element vector with the confidence interval boundaries
10 function y = confint(x, perc)
11 
12 if nargin < 2 || isempty(perc)
13  perc = .95;
14 end;
15 
16 me = mean(x);
17 st = std(x);
18 n = numel(x);
19 
20 perc2 = 1-(1-perc)/2; % Adujsts to single-tail
21 
22 
23 no_stds = tinv(perc2, n-1);
24 mean_std = st/sqrt(n);
25 n1 = me-mean_std*no_stds;
26 n2 = me+mean_std*no_stds;
27 
28 y = [n1, n2];
function confint(in x, in perc)