Documente Academic
Documente Profesional
Documente Cultură
10/02/10 11:52
Regression
Panel Data Model (pdf)
T-test & ANOVA
Categorical Data (pdf)
Event Count Data (pdf)
Statistics (K300)
T-tests & ANOVA (pdf)
Factor Analysis (SEM)
HLM (Multilevel Model)
Software
SAS (vendor)
Stata (vendor)
M-Plus (vendor)
R (R-project)
Resources
Data Achives
Journals
Home (masil.org)
Korean (Hangeul)
Knowledge Base | KB2
SSCI Journal List
K-E Dic
This page illustrates how to compare group means using T-test, various ANOVA (analysis of
variance) including the repeated measure ANOVA, ANCOVA (analysis of covariance), and MANOVA
(multivariate analysis of variance).
LHS (interval)
Single
Single
Single
Single
Multiple
RHS (categorical)
Single (binary)
Single
Two (multiple)
Multiple
Multiple
Notes
Covariates
Page 1 sur 10
10/02/10 11:52
SAS has the UNIVARIATE, MEANS, and TTEST procedures for t-test, while SAS ANOVA,
GLM, and MIXED procedures conduct ANOVA.
The ANOVA procedure is able to handle balanced data only, but the GLM and MIXED procedures
can deal with both balanced and unbalanced data. The t-test and one-way ANOVA do not matter
whether data are balanced or not.
STATA has the .ttest, and the .ttesti commands for t-test, and the .anova, and .manova commands
conduct ANOVA. Note STATA .glm command is not used for ANOVA.
DATA STRUCTURE
It is useful to read multiple observations in a data line. Note that @@ is a line holder in SAS.
LIBNAME js 'c:\data\sas';
DATA js.data1;
INPUT group block $ response @@;
DATALINES;
1 A 34.5 1 B 54.5 1 B 25.8 3 C 54.8
2 B 54.8 3 A 15.8 2 C 14.5 2 A 15.1
...
RUN;
/* Data read ******************
1 1 A 34.5
2 1 B 54.5
3 1 B 25.8
...
*******************************/
The DO statement allows to read more complicated data. You may list the particular numbers in the DO
http://www.masil.org/method/anova.html
Page 2 sur 10
10/02/10 11:52
statement rather than set a range of values (e.g., DO treatment=1 TO 2;). The @ may not be omitted.
This tip is very useful especially when you type in data for the randomized complete block design (RCB)
and the Latin square design (LSD).
DATA js.data2;
DO block=1 TO 3;
DO treatment=1,5;
INPUT response @;
OUTPUT;
END;
END;
DATALINES;
4.91 4.63 4.76 5.04 5.38 6.21
5.60 5.08 4.91 4.63 4.76 5.04
...
RUN;
/* Data read *********************
1 1 1 4.91
2 1 5 4.63
3 2 1 4.76
4 2 5 5.04
5 3 1 5.38
...
**********************************/
If data are arranged in the long format, you need to rearranged into the wide format.
DATA js.wide1;
SET js.long;
IF period=1;
RENAME response=response1;
PROC SORT DATA=js.wide1;
BY id;
RUN;
...
DATA js.wide;
MERGE js.long1 js.long2 ...;
BY id;
RUN;
STATA has the .pkshape command to transform a data set in the latin square form into the corresponing
data set for analysis.
. list, noobs
+---------------+
|id row c1 c2 c3|
|---------------|
|100 1 74 97 54 |
|101 2 54 84 25 |
|102 3 15 57 64 |
+---------------+
http://www.masil.org/method/anova.html
Page 3 sur 10
10/02/10 11:52
T-TEST
One Sample T-Test
The MU0 option specifies a value of the null hypothesis. The ALPHA option specifies the significance
level. The T option in the MEANS procedure runs the t-test.
PROC UNIVARIATE MU0=0 ALPHA=.01;
VAR response;
RUN;
. ttest response=0, level(99)
PROC UNIVARIATE MU0=10 VARDEF=DF NORMAL ALPHA=.05;
VAR response;
RUN;
. ttest response=10
PROC MEANS T PROBT;
VAR response;
RUN;
. ttest response=0
PROC MEANS MEAN STD STDERR T VARDEF=DF PROBT CLM ALPHA=.01;
VAR response;
RUN;
Paired T-Test
PROC TTEST;
PAIRED pre*post;
RUN;
. ttest pre=post,level(95)
Note that STATA .ttest command does not have the "unpaired" option. SAS PAIRED statement is able
to compare multiple pairs.
PROC TTEST;
PAIRED (a b)*(c d);
RUN;
Two Independent Samples T-Test
The TTEST procedure reports two T statistics: one under the equal variance assumptio and the other for
unequal variance. Users have to check the equal variance test (F test) first. If not rejected, read the T
statistic and its p-value of pooled analysis. If rejected, read the T statistic and its p-value of Satterthwaite
or Cochran/Cox approximation.
http://www.masil.org/method/anova.html
Page 4 sur 10
10/02/10 11:52
ONE-WAY ANOVA
This experimental design is often called completely randomized design (CRD). SAS has the ANOVA,
GLM (Generalized Linear Model), MIXED Procedures for one-way ANOVA. Their usages are identical.
PROC ANOVA;
CLASS treatment;
MODEL response=treatment;
RUN;
STATA has the .anova and .oneway command for one-way ANOVA.
. anova response treatment
. oneway response treatment, tabulate
You may add the MEANS statement in both ANOVA and GLM procedures to compute means of groups
and perform multiple comparison tests such as DUNCAN, TUKEY, DUNNETT, and BON.
PROC GLM;
CLASS treatment;
http://www.masil.org/method/anova.html
Page 5 sur 10
10/02/10 11:52
MODEL response=treatment;
MEANS treatment /T DUNCAN;
RUN;
TWO-WAY ANOVA
Randomized Complete Block (RCB): Treatments are assigned at random within blocks of adjacent
subjects, each treatment once per block. The number of blocks is the number of replications. Any
treatment can be adjacent to any other treatment, but not to the same treatment within the block.
Again, the ANOVA, GLM, and MIXED conduct the two-way ANOVA with the identical usage.
PROC GLM;
CLASS treat1 treat2;
MODEL response=treat1 treat2;
RUN;
In the case of the randomized complete block design, you may have one observation in each cell. So,
including an interaction term is meaningless, producing awkward results. But it is noteworthy that the
sum of squares due to error (SSE) is equivalent to the sum of squares of interaction (SSI).
You may compare group means using the MEANS or the LSMEANS (least squares means) statement.
The LSMEANS statement is not available in the ANOVA procedure.
PROC ANOVA;
CLASS treatment block;
MODEL response=treatment block;
MEANS treatment block /TUKEY;
RUN;
PROC GLM;
CLASS treatment block;
MODEL response=treatment block;
LSMEANS treatment block /ADJUST=TUKEY;
RUN;
If there is subsamples, you need to use nested scheme as follows.
PROC GLM;
CLASS treatment sub;
MODEL response=treatment treatment(sub);
RUN;
. ttest response treatment / sub | treatment /
FACTORIAL DESIGN
If there are subsamples (more than one observation in each cell) in a two-way ANOVA, you may
consider the interaction effects. This is the two-way factorial design on CRD.
Treat1
Block1
54, 67, 87
http://www.masil.org/method/anova.html
block2
57, 67
block3
31, 54, 87, 95
Page 6 sur 10
Treat2
Treat3
35, 67
98, 45, 12, 57, 87
10/02/10 11:52
The interaction is expressed by asterisk (*). The | indicates all possible combinations. Thus, the following
procedures return the same result.
PROC ANOVA;
CLASS treatment block;
MODEL response=treatment | block;
RUN;
PROC GLM;
CLASS treatment block;
MODEL response=treatment block treatment*block;
RUN;
You may compare group means using the MEANS or the LSMEANS (least squares means) statement.
The LSMEANS statement is not available in the ANOVA procedure.
PROC ANOVA;
CLASS treatment block;
MODEL response=treatment | block;
MEANS treatment block treatment*block/TUKEY;
RUN;
PROC GLM;
CLASS treatment block;
MODEL response=treatment | block;
LSMEANS treatment | block /ADJUST=TUKEY;
RUN;
Two-Way Factorial Design on RCB
PROC GLM;
CLASS treat1 treat2 block;
MODEL response=treat1 treat2 block treat1*treat2;
RUN;
. anova response treatment block treatment*block
Three-Way Factorial Design on RCB
PROC GLM;
CLASS treat1 treat2 treat3 block;
MODEL response=treat1 treat2 block treat1*treat2 treat1*treat3 treat2*treat3 treat1*treat2*treat3;
RUN;
SPLIT-PLOT DESIGN
Split-Plot Design on CRD
PROC GLM;
CLASS treat repeat sub;
http://www.masil.org/method/anova.html
Page 7 sur 10
10/02/10 11:52
Page 8 sur 10
10/02/10 11:52
ANCOVA
ANCOVA controls variation in an experiment by measuring an independent factor on each experimental
subject.
PROC GLM;
CLASS treat;
MODEL response=covariate treat /SOLUTION;
LSMEANS treat /STDERR;
RUN;
. anova response treat covariate, continuous(covariate)
MANOVA
The MANOVA statement indicates that this model is the multivariate analysis of variance.
PROC GLM;
CLASS treat1 treat2;
MODEL response1-response3= treat1-treat5/NOUNI;
MANOVA H=treat;
RUN;
. manova response1-response3 = treat1-treat5
REFERENCES
http://www.masil.org/method/anova.html
Page 9 sur 10
10/02/10 11:52
Littell, Ramon C., Walter W. Stroup, and Rudolf J. Freund. 2002. SAS for Linear Models, 4th ed.
Cary, NC: SAS Institute.
Littell, Ramon C., George A. Milliken, Walter W. Stroup, and Russell D. Wolfinge. 2006. SAS
System for Mixed Models. 2nd ed. Cary, NC: SAS Institute.
Stata Press. 2003. Stata Base Reference Manual Release 8. College Station, TX: Stata Press.
http://www.tfrec.wsu.edu/ANOVA/
Indiana University | Korea University | PA Department | IGS Korea | ASPA | KAPA | KAPS
http://www.masil.org/method/anova.html. Last modified on 02/07/2010
Copyright 1999-2010, Jeeshim and KUCC625
http://www.masil.org/method/anova.html
Page 10 sur 10