Welch's t-test: Difference between revisions

Content added Content deleted
(+Stata)
Line 841: Line 841:
=={{header|Stata}}==
=={{header|Stata}}==
Here is a straightforward solution using the '''ttest''' command. If one does not want the output but only the p-value, prepend the command with '''qui''' and use the result r(p) as shown below. The t statistic is r(t). Notice the data are stored in a single variable, using a group variable to distinguish the two series.
Here is a straightforward solution using the '''ttest''' command. If one does not want the output but only the p-value, prepend the command with '''qui''' and use the result r(p) as shown below. The t statistic is r(t). Notice the data are stored in a single variable, using a group variable to distinguish the two series.

Notice that here we use the option '''unequal''' of the '''ttest''' command, and not '''welch''', so that Stata uses the Welch-Satterthwaite approximation.


<lang stata>mat a=(3,4,1,2.1,490.2,340,433.9\1,1,1,1,2,2,2)'
<lang stata>mat a=(3,4,1,2.1,490.2,340,433.9\1,1,1,1,2,2,2)'
Line 846: Line 848:
svmat double a
svmat double a
rename (a1 a2) (x group)
rename (a1 a2) (x group)
ttest x, by(group) welch
ttest x, by(group) unequal


Two-sample t test with unequal variances
Two-sample t test with unequal variances
Line 857: Line 859:
combined | 7 182.0286 86.22435 228.1282 -28.95482 393.012
combined | 7 182.0286 86.22435 228.1282 -28.95482 393.012
---------+--------------------------------------------------------------------
---------+--------------------------------------------------------------------
diff | -418.8417 43.81419 -607.2052 -230.4782
diff | -418.8417 43.81419 -607.282 -230.4014
------------------------------------------------------------------------------
------------------------------------------------------------------------------
diff = mean(1) - mean(2) t = -9.5595
diff = mean(1) - mean(2) t = -9.5595
Ho: diff = 0 Welch's degrees of freedom = 2.0017
Ho: diff = 0 Satterthwaite's degrees of freedom = 2.00085


Ha: diff < 0 Ha: diff != 0 Ha: diff > 0
Ha: diff < 0 Ha: diff != 0 Ha: diff > 0
Pr(T < t) = 0.0054 Pr(|T| > |t|) = 0.0107 Pr(T > t) = 0.9946
Pr(T < t) = 0.0054 Pr(|T| > |t|) = 0.0108 Pr(T > t) = 0.9946


di r(t)
di r(t)
-9.5594977
-9.5594977

di r(p)
di r(p)
.01073671</lang>
.01075156
</lang>


The computation can easily be implemented in Mata. Here is how to compute the t statistic (t), the approximate degrees of freedom (df) and the p-value (p).
The computation can easily be implemented in Mata. Here is how to compute the t statistic (t), the approximate degrees of freedom (df) and the p-value (p).