📄 ttestp.m
字号:
function y = ttestp(x,a,z)
%TTESTP Evaluates t-distribution and its inverse
% The function will return either the probabilities given
% the t statistic and the degrees of freedom or the
% t statistic given the probability and degrees of freedom.
%
% The I/O format is: y = ttestp(x,a,z)
%
% where
% x = either the statistic (t) or the probability at which
% the function is to be evaluated.
% a = degrees of freedom
% z = flag for determining how the function is evaluated
% = 1 percentage from t-test, given t statistic and D.F.
% = 2 t from inverse t-test given probability and D.F.
% Based on a public domain stats toolbox
% Modified by B.M. Wise December 1994
aa = a * 0.5;
if z == 1
xx = a / (a + x^2);
bb = 0.50;
tmp = beta(xx,aa,bb);
y = tmp * 0.50;
elseif z == 2
ic = 1;
xl = 0.0;
xr = 1.0;
fxl = -x*2;
fxr = 1.0 - (x*2);
if fxl * fxr > 0
error('probability not in the range(0,1) ')
else
while ic < 30
xx = (xl + xr) * 0.5;
p1 = beta(xx,aa,0.5);
fcs = p1 - (x*2);
if fcs * fxl > 0
xl = xx;
fxl = fcs;
else
xr = xx;
fxr = fcs;
end
xrmxl = xr - xl;
if xrmxl <= 0.0001 | abs(fcs) <= 1E-4
break
else
ic = ic + 1;
end
end
end
if ic == 30
error(' failed to converge ')
end
tmp = xx;
y = sqrt((a - a * tmp) / tmp);
else
error('z must be 1 or 2')
return
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -