How to implement tinv manually? Without Statistics and Machine Learning Toolbox
10 ビュー (過去 30 日間)
古いコメントを表示
As an exercise, I am trying to implement ttests manually, without using the Statistics and Machine Learning Toolbox.
To obtain the p-value from the t-value, I have used Star Striders excellent method. http://www.mathworks.com/matlabcentral/answers/20373-how-to-obtain-the-t-value-of-the-students-t-distribution-with-given-alpha-df-and-tail-s
Now, I wish to determine the confidence interval. For this, the critical t-value is needed.
With the toolbox, you just use tinv according to http://www.mathworks.com/matlabcentral/answers/20373-how-to-obtain-the-t-value-of-the-students-t-distribution-with-given-alpha-df-and-tail-s
My question is, is there any way to do this without the Statistics and Machine Learning Toolbox? More exactly, how to implement tinv?
0 件のコメント
回答 (1 件)
Star Strider
2015 年 12 月 16 日
Thank you for the endorsement!
You have to have all these functions in your workspace simultaneously, and with them, you can use fzero to get the critical t-statistic from the probability (alpha) and degrees-of-freedom (v):
% % Variables:
% % t: t-statistic
% % v: degrees of freedom
tdist2T = @(t,v) (1-betainc(v/(v+t^2),v/2,0.5)); % 2-tailed t-distribution
tdist1T = @(t,v) 1-(1-tdist2T(t,v))/2; % 1-tailed t-distribution
t_inv = @(alpha,v) fzero(@(tval) (max(alpha,(1-alpha)) - tdist1T(tval,v)), 5); % T-Statistic Given Probability ‘alpha’ & Degrees-Of-Freedom ‘v’
Example:
alpha = 0.025;
v = 10;
T = t_inv(alpha, v) * [-1 1]
T_STB = tinv(alpha, v) % Statistics Toolbox Function
The Statistics Toolbox uses the one-tailed t-test to calculate the t-statistic, so I used it here as well.
T =
-2.2281 2.2281
T_STB =
-2.2281
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Random Number Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!