I am writing a program in C# that requires me to use the Ttest formula. I have to effectively interpret the Excel formula:
=TTEST(range1,range2,1,3)
I am using the formula given here
and have interpreted into code as such:
double TStatistic = (mean1 - mean2) / Math.Sqrt((Math.Pow(variance1, 2) / count1) + (Math.Pow(variance2, 2) / count2));
However, I don't fully understand t-test and the values I am getting are completely different than those calculated within Excel.
I have been using the following ranges:
R1: 91.17462277, 118.3936425, 96.6746393, 102.488785, 91.26831043 R2: 17.20546254, 19.56969811, 19.2831241, 13.03360631, 13.86577314
The value I am getting using my attempt is 1.8248, however that from Excel is 1.74463E-05. Could somebody please point me in the right direction?
Contents
hide
Best Answer
There are at least two problems with what you have done.
- You have misinterpreted the formula $$t = frac{bar{x}_1-bar{x}_2}{sqrt{s_1^2 / n_1 + s_2^2 / n_2}}$$ since $s^2$ is already a variance (square of standard deviation) and does not need to be squared again.
- You are comparing eggs and omelettes: you need compare your "calculated $t$-value, with $k$ degrees of freedom … to the $t$ distribution table". Excel has already done this with
TTEST()
.
There are other possible issues such as using a population variance or sample variance formula.
Similar Posts:
- Solved – the probability (area) of overlap of two normal distributions having EQUAL variance
- Solved – Byar’s Confidence Interval Calculation
- Solved – T-test – Difference between p-Values of `stats.ttest_1samp`, `stats.ttest_rel` and `stats.ttest_ind`
- Solved – For a T-test, what would happen if one of the samples was made up of only one observation?
- Solved – the expected value for the Pearson correlation coefficient