T Tests Task: Two-Sample t Test

About the Two-Sample t Test Task

A two-sample t test compares the mean of the first sample minus the mean of the second sample to a given number, the null hypothesis difference.
To compare means from two independent samples with n1 and n2 observations to a value m, use t equals . fraction open , modified x sub 1 with macron above , minus , x with macron above sub 2 , close minus m , over s . square root of fraction 1 , over n sub 1 end fraction , plus , fraction 1 , over n sub 2 end fraction , end root end fraction. Click image for alternative formats.. In this example, s2 is the pooled variance s squared , equals . fraction open , n sub 1 , minus 1 close , s sub 1 and super 2 , plus open , n sub 1 , minus 1 close , s sub 2 and super 2 , , over n sub 1 , plus , n sub 2 , minus 2 end fraction. Click image for alternative formats., and s21 and s22 are the sample variances of the two groups. The use of this t statistic depends on the assumption that sigma sub 1 and super 2 , equals , sigma sub 2 and super 2. Click image for alternative formats., where sigma sub 1 and super 2. Click image for alternative formats. and sigma sub 2 and super 2. Click image for alternative formats. are the population variances of the two groups.
To run a two-sample t test, open the T Tests task. From the T test drop-down list, select Two-sample test.
Note: You must have SAS/STAT to use this task.

Example: Two-Sample t Test

In this example, you want to analyze the height values for males and females in your class.
To create this example:
  1. In the Tasks section, expand the Statistics folder and double-click T Tests. The user interface for the T Tests task opens.
  2. On the Data tab, select the SASHELP.CLASS data set.
  3. From the T test drop-down list, select Two-sample test.
  4. Assign columns to these roles:
    Role
    Column Name
    Analysis variable
    Height
    Groups variable
    Sex
  5. To run the task, click Submit SAS Code.
Here is a subset of the results:
Statistics for Two-Sample t Test
Distribution of Height for Males and Females

Assigning Data to Roles

To run a two-sample t test, select Two-sample test from the T test drop-down list. Assign a column to each of these roles:
Role
Description
Analysis variable
specifies the column to use in the analysis.
Groups variable
specifies the column to use for grouping. This column must have only two levels.

Setting Options

Option Name
Description
Tests
Tails
specifies the number of sides (or tails) and direction of the statistical tests and test-based confidence intervals. You can choose from these options:
  • Two-tailed test specifies two-sided tests and confidence intervals for means.
  • Upper one-tailed test specifies upper one-sided tests in which the alternative hypothesis indicates a mean greater than the null value, and upper one-sided confidence intervals between the lower confidence limit and infinity.
  • Lower one-tailed test specifies lower one-sided tests in which the alternative hypothesis indicates a mean less than the null value, and lower one-sided confidence intervals between minus infinity and the upper confidence limit.
Alternative hypothesis
specifies the value of the null hypothesis.
Cox and Cochran probability approximation for unequal variances
calculates the Cochran and Cox approximation. This approximation of the p-value of the tu is the value of p such that t sub u , equals . fraction open . fraction s sub 1 and super 2 , over sum , from , i equals 1 , to , n with subscript 1 , and with superscript times , end sub-superscript , of . f sub 1 i end sub . w sub 1 i end sub end fraction . close , t sub 1 , plus open . fraction s sub 2 and super 2 , over sum , from , i equals 1 , to , n with subscript 2 , and with superscript times , end sub-superscript , of . f sub 2 i end sub . w sub 2 i end sub end fraction . close , t sub 2 , over open . fraction s sub 1 and super 2 , over sum , from , i equals 1 , to , n with subscript 1 , and with superscript times , end sub-superscript , of . f sub 1 i end sub . w sub 1 i end sub end fraction . close plus open . fraction s sub 2 and super 2 , over sum , from , i equals 1 , to , n with subscript 2 , and with superscript times , end sub-superscript , of . f sub 2 i end sub . w sub 2 i end sub end fraction . close end fraction. Click image for alternative formats.. In this example, t1 and t2 are the critical values of the t distribution corresponding to a significance level of p and sample sizes n1 and n2, respectively. The degrees of freedom is undefined when n sub 1 , not equal to , n sub 2. Click image for alternative formats.. (Cochran and Cox 1950).
Normality Assumption
Tests for normality
runs tests for normality that include a series of goodness-of-fit tests based on the empirical distribution function. The table provides test statistics and p-values for the Shapiro-Wilk test (provided the sample size is less than or equal to 2000), the Kolmogorov-Smirnov test, the Anderson-Darling test, and the Cramér-von Mises test.
Nonparametric Tests
Note: This option is available only for a two-tailed test when the alternative hypothesis equals 0.
Wilcoxon rank-sum test
generates an analysis of Wilcoxon scores. When there are two classification levels (samples), this option produces the Wilcoxon rank-sum test.
Plots
Histogram and box plot
creates a histogram and box plot together in a single panel, sharing common X axes.
Normality plot
creates a normal quantile-quantile (Q-Q) plot.
Confidence interval plot
creates plots of the confidence interval for means. This plot is not created by default.
Wilcoxon box plot
creates a box plot of Wilcoxon scores. This plot is associated with the Wilcoxon analysis. This plot is not created by default.
Note: This plot is available only for a two-tailed test when the alternative hypothesis equals 0.