PROC TTEST can compare group means for two independent samples using a t test. Suppose you have more than two groups and would like to run several t tests for each pair of groups.
The example titled "Testing for Equal Group Variances" in the Examples section of the GLM documentation describes a study to explore how age is related to the sense of smell. The following subset of the data contains three age groups with an olfactory index for each subject.
data upsit; input agegroup smell @@; datalines; 1 1.381 1 1.322 1 1.162 1 1.275 1 1.381 1 1.275 1 1.322 1 1.492 1 1.322 1 1.381 1 1.162 1 1.013 1 1.322 1 1.322 1 1.275 1 1.492 1 1.322 1 1.322 1 1.492 1 1.322 1 1.381 1 1.234 1 1.162 1 1.381 1 1.381 1 1.381 1 1.322 1 1.381 1 1.322 1 1.381 1 1.275 1 1.492 1 1.275 1 1.322 1 1.275 1 1.381 1 1.234 1 1.105 2 1.234 2 1.234 2 1.381 2 1.322 2 1.492 2 1.234 2 1.381 2 1.381 2 1.492 2 1.492 2 1.275 2 1.492 2 1.381 2 1.492 2 1.322 2 1.275 2 1.275 2 1.275 2 1.322 2 1.492 2 1.381 2 1.322 2 1.492 2 1.196 2 1.322 2 1.275 2 1.234 2 1.322 2 1.098 2 1.322 2 1.381 2 1.275 2 1.492 2 1.492 2 1.381 2 1.196 3 1.381 3 1.381 3 1.492 3 1.492 3 1.492 3 1.098 3 1.492 3 1.381 3 1.234 3 1.234 3 1.129 3 1.069 3 1.234 3 1.322 3 1.275 3 1.230 3 1.234 3 1.234 3 1.322 3 1.322 3 1.381 ;
These statements compute a t test to compare the means in each pair of groups. The WHERE statement in each PROC TTEST step selects only the observations from the selected pair for the analysis. Each PROC TTEST step computes two t tests — one assuming equal variances (pooling the variances across the two selected groups), and one assuming unequal variances (estimating the variances separately for each selected group).
proc ttest data=upsit; where agegroup in (1,2); class agegroup; var smell; run; proc ttest data=upsit; where agegroup in (1,3); class agegroup; var smell; run; proc ttest data=upsit; where agegroup in (2,3); class agegroup; var smell; run;Note that the LSMEANS statement with the PDIFF option in the following single PROC GLM step can be used to make all pairwise comparisons, but the data that is used and the variance assumption differ from the PROC TTEST approach.
proc glm data=upsit; class agegroup; model smell=agegroup; lsmeans agegroup / pdiff; run;
In making the comparisons, PROC GLM uses the data from all three groups. It assumes equal variances across all three groups and pools their variances. The pooled variance is used in all pairwise comparisons. In contrast, each PROC TTEST step above uses data from only two of the three groups and pools those two variances for each t test that assumes equal variances. Consequently, the TTEST and GLM results will not generally match.
While it may not be possible to say that the GLM or the TTEST approach is always best, note that if all group variances can be assumed equal, the GLM approach makes use of all of the data in estimating the common variance. The PROC TTEST approach will produce multiple estimates of the common variance.
PROC GLM does not have an option for estimating the variances separately. PROC MIXED does, however, as illustrated in this note.
Neither PROC GLM nor PROC MIXED can match the equal variance tests from the multiple PROC TTEST approach since the variances cannot be pooled across pairwise subsets of the groups as is done when subsetting the data for PROC TTEST.
Product Family | Product | System | SAS Release | |
Reported | Fixed* | |||
SAS System | SAS/STAT | z/OS | ||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2003 for x64 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 for x64 | ||||
Microsoft Windows XP Professional | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
Windows 7 Professional x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Ultimate x64 | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
Windows Vista for x64 | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |
Type: | Usage Note |
Priority: | |
Topic: | Analytics ==> Analysis of Means SAS Reference ==> Procedures ==> TTEST |
Date Modified: | 2012-02-14 16:15:48 |
Date Created: | 2012-01-19 09:52:17 |