How to implement tinv manually? Without Statistics and Machine Learning Toolbox
조회 수: 9 (최근 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!