 Dataplot Vol 1 Vol 2

# T TEST

Name:
T TEST
Type:
Analysis Command
Purpose:
Perform either a one sample t-test, an unpaired two sample t-test, or a paired two sample t-test. Both one-tailed and two-tailed tests are supported.
Description:
There are three distinct tests supported by this command.

1. The test that the mean for a sample is equal to a specified value can be formulated as follows:
 H0: $$\mu$$ = Ha: $$\mu$$ ≠ Test Statistic: $$T = \frac{\bar{x} - \mu} {s/\sqrt{n}}$$ with $$\bar{x}$$, s, n, and $$\mu$$ denoting the sample mean, sample standard deviation, sample size and the hypothesized value, respectively. Significance Level: $$\alpha$$ (typically set to .05) Critical Region: For a two-tailed test $$T < t_{\alpha/2,n-1} \hspace{0.2in} \mbox{or} \hspace{0.2in} T > t_{1 - \alpha/2,n-1}$$ where t is the percent point function of the t distribution. For a lower-tailed test $$T < t_{\alpha,n-1}$$ For an upper-tailed test $$T > t_{1 - \alpha,n-1}$$ Conclusion: Reject null hypothesis if T in critical region

2. The test that the means for two independent samples (i.e., unpaired) are equal can be formulated as follows:
 H0: $$\mu_{1} = \mu_{2}$$ Ha: $$\mu_{1} \ne \mu_{2}$$ Test Statistic (assuming equal population variances): $$T = \frac{\bar{x_1} - \bar{x_2}} {s_{p} \sqrt{\frac{1}{n_1} + \frac{1}{n_{2}}}}$$ where $$\bar{x}_{1}$$, n1, $$\bar{x}_{2}$$, and n2 are the sample one mean and sample size and the sample two mean and sample size, respectively, and where Sp is the pooled standard deviation: $$S_{p} = \sqrt{\frac{(n_1 - 1)s_{1}^2 + (n_2 - 1)s_{2}^2}{n_1 + n_2 -2}}$$ where $$s_{1}^{2}$$ and $$s_{2}^{2}$$ denote the variances of sample 1 and sample 2, respectively. The degrees of freedom equals n1 + n2 - 2. Test Statistic (assuming unequal population variances): $$T = \frac{\bar{x_1} - \bar{x_2}} {\sqrt{\frac{s_{1}^{2}}{n_1} + \frac{s_{2}^{2}}{n_2}}}$$ where $$\bar{x}_{1}$$, $$s_{1}^{2}$$ and n1 are the sample one mean, variance, and sample size and $$\bar{x}_{2}$$, $$s_{2}^{2}$$, and n2 are the sample two mean, variance, and sample size, respectively. The degrees of freedom equals: $$\frac{(\frac{s_1^{2}}{n_1} + \frac{s_2^{2}}{n_2})^2} {\frac{(s_1^{2}/n_1)^2}{n_1 - 1} + \frac{(s_2^{2}/n_2)^2}{n_2 - 1}}$$ Significance Level: $$\alpha$$ (typically set to .05) Critical Region: For a two-tailed test $$T < t_{\alpha/2,df} \hspace{0.2in} \mbox{or} \hspace{0.2in} T > t_{1 - \alpha/2,df}$$ where t is the percent point function of the t distribution and df is as defined above. For a lower-tailed test $$T < t_{\alpha,df}$$ For an upper-tailed test $$T > t_{1 - \alpha,df}$$ Conclusion: Reject null hypothesis if T in critical region

3. The test that the means for two dedependent (i.e., paired) samples are equal can be formulated as follows:
 H0: $$\mu_{1} = \mu_{2}$$ Ha: $$\mu_{1} \ne \mu_{2}$$ Test Statistic: $$T = \frac{\bar{x_1} - \bar{x_2}} {s_{xdel}/\sqrt{n}}$$ where $$\bar{x}_{1}$$ and $$\bar{x}_{2}$$ are the sample one and sample two means, respectively, $$s_{xdel}$$ is the standard deviation of the differences of the paired samples, and n is the number of paired samples. Significance Level: $$\alpha$$ (typically set to .05) Critical Region: For a two-tailed test $$T < t_{\alpha/2,n-1} \hspace{0.2in} \mbox{or} \hspace{0.2in} T > t_{1 - \alpha/2,n-1}$$ where t is the percent point function of the t distribution. For a lower-tailed test $$T < t_{\alpha,n-1}$$ For an upper-tailed test $$T > t_{1 - \alpha,n-1}$$ Conclusion: Reject null hypothesis if T in critical region

Syntax 1:
<LOWER TAILED/UPPER TAILED> T TEST <y> <mu>
<SUBSET/EXCEPT/FOR qualification>
where <LOWER TAILED/UPPER TAILED> is an optional keyword that specifies either a lower tailed or an upper tailed test;
<y> is a response variable;
<mu> is a parameter or number;
and where the <SUBSET/EXCEPT/FOR qualification> is optional.

This syntax performs a one sample t-test that the mean is equal to <mu> If <mu> is omitted, it is assumed to be zero.

The response variable can be a matrix.

If neither LOWER TAILED or UPPER TAILED is specified, the t test will return the results for the two-tailed case, the lower tailed case, and the upper tailed case. If LOWER TAILED is specified, then only the results for the lower tailed case will be printed. If UPPER TAILED is specified, then only the results for the upper tailed case will be printed.

Syntax 2:
MULTIPLE <LOWER TAILED/UPPER TAILED> ONE SAMPLE T TEST <y1> ... <yk> <mu>
<SUBSET/EXCEPT/FOR qualification>
where <LOWER TAILED/UPPER TAILED> is an optional keyword that specifies either a lower tailed or an upper tailed test;
<y1> ... <yk> is a list of one to 30 response variables;
<mu> is a parameter or number;
and where the <SUBSET/EXCEPT/FOR qualification> is optional.

This syntax performs a one sample t-test that the mean is equal to <mu> for each of the response variables. If <mu> is omitted, it is assumed to be zero.

The response variables can be matrices.

If neither LOWER TAILED or UPPER TAILED is specified, the t test will return the results for the two-tailed case, the lower tailed case, and the upper tailed case. If LOWER TAILED is specified, then only the results for the lower tailed case will be printed. If UPPER TAILED is specified, then only the results for the upper tailed case will be printed.

Syntax 3:
<LOWER TAILED/UPPER TAILED> <PAIRED> T TEST <y1> <y2>
<SUBSET/EXCEPT/FOR qualification>
where <LOWER TAILED/UPPER TAILED> is an optional keyword that specifies either a lower tailed or an upper tailed test;
<PAIRED> is an optional keyword that specifies whether a paired or unpaired t test is performed;
<y1> is the first response variable;
<y2> is the second response variable;
and where the <SUBSET/EXCEPT/FOR qualification> is optional.

This syntax performs a two sample t-test. If the keyword PAIRED is given, a paired t test is performed. Otherwise an unpaired t test is performed.

The response variables can be matrices.

If neither LOWER TAILED or UPPER TAILED is specified, the t test will return the results for the two-tailed case, the lower tailed case, and the upper tailed case. If LOWER TAILED is specified, then only the results for the lower tailed case will be printed. If UPPER will be printed.

Syntax 4:
MULTIPLE <LOWER TAILED/UPPER TAILED> <PAIRED> T TEST <y1> ... <yk>
<SUBSET/EXCEPT/FOR qualification>
where <LOWER TAILED/UPPER TAILED> is an optional keyword that specifies either a lower tailed or an upper tailed test;
<PAIRED> is an optional keyword that specifies whether a paired or unpaired t test is performed;
<y1> ... <yk> is a list of 1 to 30 response variables;
<y2> is the second response variable;
and where the <SUBSET/EXCEPT/FOR qualification> is optional.

This syntax performs all the pairwise t tests for the listed response variables.

If the keyword PAIRED is given, a paired t test is performed. Otherwise an unpaired t test is performed.

The response variables can be matrices.

If neither LOWER TAILED or UPPER TAILED is specified, the t test will return the results for the two-tailed case, the lower tailed case, and the upper tailed case. If LOWER TAILED is specified, then only the results for the lower tailed case will be printed. If UPPER TAILED is specified, then only the results for the upper tailed case will be printed.

Examples:
T TEST Y
T TEST Y MU
LOWER TAILED T TEST Y MU
MULTIPLE ONE SAMPLE T TEST Y1 TO Y5 MU
T TEST Y1 Y2
T TEST Y1 Y2 SUBSET TAG > 2
UPPER TAILED PAIRED T TEST Y1 Y2
MULTIPLE T TEST Y1 TO Y10
Note:
Sample sizes do not need to be equal unless paired t tests are specified.
Note:
By default, Dataplot prints the test statistic for both the equal and unequal population variances assumptions for the two sample test. The following command can be used to specify this:

SET T TEST VARIANCE EQUAL
SET T TEST VARIANCE UNEQUAL
SET T TEST VARIANCE BOTH

The EQUAL keyword specifies that only the equal variance case will be printed, UNEQUAL specifies that only the unequal variances case will be printed, and BOTH resets the default that both the equal and unequal variance cases will be printed.

Note:
Dataplot saves the following internal parameters after a t test:

 STATVAL: the value of the test statistic STATCDF: the CDF of the test statistic PVALUE: the p-value for the two-sided test PVALUELT: the p-value for the lower tailed test PVALUEUT: the p-value for the upper tailed test CUTLOW50: the 50% lower tailed critical value CUTUPP50: the 50% upper tailed critical value CUTLOW80: the 80% lower tailed critical value CUTUPP80: the 80% upper tailed critical value CUTLOW90: the 90% lower tailed critical value CUTUPP90: the 90% upper tailed critical value CUTLOW95: the 95% lower tailed critical value CUTUPP95: the 95% upper tailed critical value CUTLOW99: the 99% lower tailed critical value CUTUPP99: the 99% upper tailed critical value CUTLO999: the 99.9% lower tailed critical value CUTUP999: the 99.9% upper tailed critical value
Note:
The following statistics are also supported:

LET A = ONE SAMPLE T TEST Y MU
LET A = ONE SAMPLE T TEST CDF Y MU
LET A = ONE SAMPLE T TEST PVALUE Y MU
LET A = ONE SAMPLE T TEST LOWER TAIL PVALUE Y MU
LET A = ONE SAMPLE T TEST UPPER TAIL PVALUE Y MU

If MU is omitted in the above commands, it is assumed to be zero.

LET A = TWO SAMPLE T TEST Y1 Y2
LET A = TWO SAMPLE T TEST CDF Y1 Y2
LET A = TWO SAMPLE T TEST PVALUE Y1 Y2
LET A = TWO SAMPLE T TEST LOWER TAIL PVALUE Y1 Y2
LET A = TWO SAMPLE T TEST UPPER TAIL PVALUE Y1 Y2

LET A = TWO SAMPLE PAIRED T TEST Y1 Y2
LET A = TWO SAMPLE PAIRED T TEST CDF Y1 Y2
LET A = TWO SAMPLE PAIRED T TEST PVALUE Y1 Y2
LET A = TWO SAMPLE PAIRED T TEST LOWER TAIL PVALUE Y1 Y2
LET A = TWO SAMPLE PAIRED T TEST UPPER TAIL PVALUE Y1 Y2

Enter HELP STATISTICS to see what commands can use these statistics.

Default:
Two-tailed tests will be performed unless the LOWER TAILED or UPPER TAILED keywords are specified. For the two sample test, an unpaired test will be assumed unless the PAIRED keyword is specified.
Synonyms:
TTEST is a synonym for T TEST.
1 SAMPLE is a synonym for ONE SAMPLE.
Related Commands:
 CONFIDENCE LIMITS = Compute the confidence limits for the mean of a sample. BIHISTOGRAM = Generates a bihistogram. QUANTILE QUANTILE PLOT = Generates a quantile qauntile plot. BOX PLOT = Generates a box plot.
Reference:
T tests are discussed in most introductory statistics books.
Applications:
Confirmatory Data Analysis
Implementation Date:
Pre-1987
2011/3: Added support for paired t test
2011/3: Reformatted output for greater clarity
2011/3: Support for one-tailed tests
Program 1:

SKIP 25
T TEST Y1 Y2

The following output is generated.
            Two Sample t-Test for Equal Means

First Response Variable:  Y1
Second Response Variable: Y2

H0: Population Means Are Equal
Ha: Population Means Are Not Equal

Sample One Summary Statistics:
Number of Observations:                             249
Sample Mean:                                   20.14457
Sample Standard Deviation:                      6.41469
Sample Standard Deviation of the Mean:          0.40651

Sample Two Summary Statistics:
Number of Observations:                             249
Sample Mean:                                 -672.37751
Sample Standard Deviation:                    480.11125
Sample Standard Deviation of the Mean:         30.42581

Test When Assume Equal Variances:
Pooled Standard Deviation:                    339.52022
Difference (Delta) in Means:                  692.52208
Standard Deviation of Delta:                   30.42853
t-Test Statistic Value:                        22.75897
Degrees of Freedom:                                 496
CDF Value:                                      0.99999
P-Value (2-tailed test):                        0.00000
P-Value (lower-tailed test):                    0.99999
P-Value (upper-tailed test):                    0.00000

Test When Assume Unequal Variances:
Bartlett CDF Value:                             1.00000
Difference (Delta) in Means:                  692.52208
Standard Deviation of Delta:                   30.42853
t-Test Statistic Value:                        22.75897
Degrees of Freedom:                                 248
CDF Value:                                      1.00000
P-Value (2-tailed test):                        0.00000
P-Value (lower-tailed test):                    1.00000
P-Value (upper-tailed test):                    0.00000

Two-Tailed Test (Assume Equal Variances)

H0: u1 = u2; Ha: u1 <> u2
------------------------------------------------------------
Null
Significance           Test       Critical     Hypothesis
Level      Statistic    Value (+/-)     Conclusion
------------------------------------------------------------
50.0%       22.75897        0.67498         REJECT
80.0%       22.75897        1.28326         REJECT
90.0%       22.75897        1.64793         REJECT
95.0%       22.75897        1.96475         REJECT
99.0%       22.75897        2.58577         REJECT
99.9%       22.75897        3.31024         REJECT

Lower One-Tailed Test (Assume Equal Variances)

H0: u1 = u2; Ha: u1 < u2
------------------------------------------------------------
Null
Significance           Test       Critical     Hypothesis
Level      Statistic      Value (<)     Conclusion
------------------------------------------------------------
50.0%       22.75897        0.00000         ACCEPT
80.0%       22.75897       -0.84234         ACCEPT
90.0%       22.75897       -1.28326         ACCEPT
95.0%       22.75897       -1.64793         ACCEPT
99.0%       22.75897       -2.33388         ACCEPT
99.9%       22.75897       -3.10674         ACCEPT

Upper One-Tailed Test (Assume Equal Variances)

H0: u1 = u2; Ha: u1 > u2
------------------------------------------------------------
Null
Significance           Test       Critical     Hypothesis
Level      Statistic      Value (>)     Conclusion
------------------------------------------------------------
50.0%       22.75897        0.00000         REJECT
80.0%       22.75897        0.84234         REJECT
90.0%       22.75897        1.28326         REJECT
95.0%       22.75897        1.64793         REJECT
99.0%       22.75897        2.33388         REJECT
99.9%       22.75897        3.10674         REJECT

Two-Tailed Test (Assume Unequal Variances)

H0: u1 = u2; Ha: u1 <> u2
------------------------------------------------------------
Null
Significance           Test       Critical     Hypothesis
Level      Statistic    Value (+/-)     Conclusion
------------------------------------------------------------
50.0%       22.75897        0.67547         REJECT
80.0%       22.75897        1.28497         REJECT
90.0%       22.75897        1.65101         REJECT
95.0%       22.75897        1.96957         REJECT
99.0%       22.75897        2.59579         REJECT
99.9%       22.75897        3.33017         REJECT

Lower One-Tailed Test (Assume Unequal Variances)

H0: u1 = u2; Ha: u1 < u2
------------------------------------------------------------
Null
Significance           Test       Critical     Hypothesis
Level      Statistic      Value (<)     Conclusion
------------------------------------------------------------
50.0%       22.75897        0.00000         ACCEPT
80.0%       22.75897       -0.84307         ACCEPT
90.0%       22.75897       -1.28497         ACCEPT
95.0%       22.75897       -1.65101         ACCEPT
99.0%       22.75897       -2.34147         ACCEPT
99.9%       22.75897       -3.12340         ACCEPT

Upper One-Tailed Test (Assume Unequal Variances)

H0: u1 = u2; Ha: u1 > u2
------------------------------------------------------------
Null
Significance           Test       Critical     Hypothesis
Level      Statistic      Value (>)     Conclusion
------------------------------------------------------------
50.0%       22.75897        0.00000         REJECT
80.0%       22.75897        0.84307         REJECT
90.0%       22.75897        1.28497         REJECT
95.0%       22.75897        1.65101         REJECT
99.0%       22.75897        2.34147         REJECT
99.9%       22.75897        3.12340         REJECT

Program 2:

let z = normal rand numb for i = 1 1 50
let mu0 = 0.3
set write decimals 5
.
t test z mu0
lower tailed t test z mu0
upper tailed t test z mu0

The following output is generated.
            One Sample t-Test for the Mean

Response Variable: Z

H0: Mean Equal                                  0.30000
Ha: Mean Not Equal                              0.30000

Summary Statistics:
Number of Observations:                              50
Sample Mean:                                   -0.00822
Sample Standard Deviation:                      0.71196
Sample Standard Deviation of the Mean:          0.10068

Test:
Mean - Mu0:                                    -0.30822
t-Test Statistic Value:                        -3.06121
Degrees of Freedom:                                  49
CDF Value:                                      0.00178
P-Value (2-tailed test):                        0.00357
P-Value (lower-tailed test):                    0.00178
P-Value (upper-tailed test):                    0.99821

Two-Tailed Test

H0: u = m0; Ha: u <> m0
------------------------------------------------------------
Null
Significance           Test       Critical     Hypothesis
Level      Statistic    Value (+/-)     Conclusion
------------------------------------------------------------
50.0%       -3.06121        0.67952         REJECT
80.0%       -3.06121        1.29906         REJECT
90.0%       -3.06121        1.67655         REJECT
95.0%       -3.06121        2.00957         REJECT
99.0%       -3.06121        2.67995         REJECT
99.9%       -3.06121        3.50044         ACCEPT

Lower One-Tailed Test

H0: u = m0; Ha: u < m0
------------------------------------------------------------
Null
Significance           Test       Critical     Hypothesis
Level      Statistic      Value (<)     Conclusion
------------------------------------------------------------
50.0%       -3.06121        0.00000         REJECT
80.0%       -3.06121       -0.84901         REJECT
90.0%       -3.06121       -1.29906         REJECT
95.0%       -3.06121       -1.67655         REJECT
99.0%       -3.06121       -2.40489         REJECT
99.9%       -3.06121       -3.26507         ACCEPT

Upper One-Tailed Test

H0: u = m0; Ha: u > m0
------------------------------------------------------------
Null
Significance           Test       Critical     Hypothesis
Level      Statistic      Value (>)     Conclusion
------------------------------------------------------------
50.0%       -3.06121        0.00000         ACCEPT
80.0%       -3.06121        0.84901         ACCEPT
90.0%       -3.06121        1.29906         ACCEPT
95.0%       -3.06121        1.67655         ACCEPT
99.0%       -3.06121        2.40489         ACCEPT
99.9%       -3.06121        3.26507         ACCEPT

One Sample t-Test for the Mean

Response Variable: Z

H0: Mean Equal                                  0.30000
Ha: Mean Not Equal                              0.30000

Summary Statistics:
Number of Observations:                              50
Sample Mean:                                   -0.00822
Sample Standard Deviation:                      0.71196
Sample Standard Deviation of the Mean:          0.10068

Test:
Mean - Mu0:                                    -0.30822
t-Test Statistic Value:                        -3.06121
Degrees of Freedom:                                  49
CDF Value:                                      0.00178
P-Value (2-tailed test):                        0.00357
P-Value (lower-tailed test):                    0.00178
P-Value (upper-tailed test):                    0.99821

Lower One-Tailed Test

H0: u = m0; Ha: u < m0
------------------------------------------------------------
Null
Significance           Test       Critical     Hypothesis
Level      Statistic      Value (<)     Conclusion
------------------------------------------------------------
50.0%       -3.06121        0.00000         REJECT
80.0%       -3.06121       -0.84901         REJECT
90.0%       -3.06121       -1.29906         REJECT
95.0%       -3.06121       -1.67655         REJECT
99.0%       -3.06121       -2.40489         REJECT
99.9%       -3.06121       -3.26507         ACCEPT

One Sample t-Test for the Mean

Response Variable: Z

H0: Mean Equal                                  0.30000
Ha: Mean Not Equal                              0.30000

Summary Statistics:
Number of Observations:                              50
Sample Mean:                                   -0.00822
Sample Standard Deviation:                      0.71196
Sample Standard Deviation of the Mean:          0.10068

Test:
Mean - Mu0:                                    -0.30822
t-Test Statistic Value:                        -3.06121
Degrees of Freedom:                                  49
CDF Value:                                      0.00178
P-Value (2-tailed test):                        0.00357
P-Value (lower-tailed test):                    0.00178
P-Value (upper-tailed test):                    0.99821

Upper One-Tailed Test

H0: u = m0; Ha: u > m0
------------------------------------------------------------
Null
Significance           Test       Critical     Hypothesis
Level      Statistic      Value (>)     Conclusion
------------------------------------------------------------
50.0%       -3.06121        0.00000         ACCEPT
80.0%       -3.06121        0.84901         ACCEPT
90.0%       -3.06121        1.29906         ACCEPT
95.0%       -3.06121        1.67655         ACCEPT
99.0%       -3.06121        2.40489         ACCEPT
99.9%       -3.06121        3.26507         ACCEPT

Program 3:

.  Example of paired t-test from p. 178 of Bowker and Lieberman
73  51
43  41
47  43
53  41
58  47
47  32
52  24
38  43
61  53
56  52
56  57
34  44
55  57
65  40
75  68
end of data
set write decimals 5
paired t test w1 w2

The following output is generated.
            Two Sample Paired t-Test for Equal Means

First Response Variable:  W1
Second Response Variable: W2

H0: Population Means Are Equal
Ha: Population Means Are Not Equal

Sample One Summary Statistics:
Number of Observations:                              15
Sample Mean:                                   54.20000
Sample Standard Deviation:                     11.57707

Sample Two Summary Statistics:
Number of Observations:                              15
Sample Mean:                                   46.20000
Sample Standard Deviation:                     10.77165

Summary Statistics of Paired Data:
Number of Observations:                              15
Sample Mean:                                    8.00000
Sample Standard Deviation:                     11.02594
Sample Standard Deviation of the Mean:          2.84688

Test:
Difference (Delta) in Means:                    8.00000
t-Test Statistic Value:                         2.81008
Degrees of Freedom:                                  14
CDF Value:                                      0.99304
P-Value (2-tailed test):                        0.01390
P-Value (lower-tailed test):                    0.99304
P-Value (upper-tailed test):                    0.00695

Two-Tailed Test

H0: u1 = u2; Ha: u1 <> u2
------------------------------------------------------------
Null
Significance           Test       Critical     Hypothesis
Level      Statistic    Value (+/-)     Conclusion
------------------------------------------------------------
50.0%        2.81008        0.69241         REJECT
80.0%        2.81008        1.34503         REJECT
90.0%        2.81008        1.76130         REJECT
95.0%        2.81008        2.14478         REJECT
99.0%        2.81008        2.97682         ACCEPT
99.9%        2.81008        4.14028         ACCEPT

Lower One-Tailed Test

H0: u1 = u2; Ha: u1 < u2
------------------------------------------------------------
Null
Significance           Test       Critical     Hypothesis
Level      Statistic      Value (<)     Conclusion
------------------------------------------------------------
50.0%        2.81008        0.00000         ACCEPT
80.0%        2.81008       -0.86805         ACCEPT
90.0%        2.81008       -1.34503         ACCEPT
95.0%        2.81008       -1.76130         ACCEPT
99.0%        2.81008       -2.62448         ACCEPT
99.9%        2.81008       -3.78729         ACCEPT

Upper One-Tailed Test

H0: u1 = u2; Ha: u1 > u2
------------------------------------------------------------
Null
Significance           Test       Critical     Hypothesis
Level      Statistic      Value (>)     Conclusion
------------------------------------------------------------
50.0%        2.81008        0.00000         REJECT
80.0%        2.81008        0.86805         REJECT
90.0%        2.81008        1.34503         REJECT
95.0%        2.81008        1.76130         REJECT
99.0%        2.81008        2.62448         REJECT
99.9%        2.81008        3.78729         ACCEPT


NIST is an agency of the U.S. Commerce Department.

Date created: 09/22/2011
Last updated: 06/28/2021