Back to Code

teg_ttest

One-sample t-test.

function [p, t, df] = teg_ttest(vec)

% function [p, t, df] = teg_ttest(vec)
t = sqrt(length(vec)) * mean(vec) / sqrt(var(vec));
df = length(vec) - 1;

x = (t + sqrt(t.^2 + df)) / (2 * sqrt(t.^2 + df));
z = df / 2;
w = df / 2;
tcdf00 = betainc(x, z, w);
p = 1 - tcdf00;
if p > 0.5,
    p = 1 - p;
end;