notes1.pdf

St 711 ( 1 )
Design
ñ Elements
1. Representativeness
2. Randomization
3. Replication
4. Error Control (blocking)
ñ Reducing Unexplained Variation
Better Technique, Replication, Blocking,
Improving Model (transformation,
covariates, etc.)
ñ Random versus Haphazard
ñ No Universal Agreement (sec. 1.5)
%Let seed = 1827655; Options Symbolgen;
Data Sample; Input Units @@; X=ranuni(&seed);
cards;
1 2 3 4 5 6 7 8 9 10 11 12
; Proc Sort; By X; Data Next; Set Sample;
Trt = 1+(_N_>6); Proc Print noobs;
Title "Randomized Using &seed "; run;
St 711 ( 2 )
Randomized Using 1827655
Units
X
Trt
8
4
9
2
5
12
6
7
11
10
1
3
0.03567
0.23122
0.30097
0.49160
0.55945
0.57792
0.59466
0.60070
0.68211
0.69087
0.76555
0.89215
1
1
1
1
1
1
2
2
2
2
2
2
Completely Randomized Design (Ch. 2)
ñ Unequal reps - no problem.
ñ Assume homogeneous experimental units.
Ui =unit i (of n) Tj =Trt j (of t)
Y = Ui +Tj n of these, nt possibilities
4 Units (4 obs.) 2 Trts, 8 possibilities
St 711 ( 3 )
(."" )
.#"
.$"
units:
(.%" )

. ñ"

. ñ" -
.ñ ñ
treatments

."#
. "ñ

(.## )
. #ñ

(.$# )
. $ñ

.%#
. %ñ

. ñ#
.=
.ñ ñ

. 1ñ -
.ñ ñ

. 2ñ -
.ñ ñ

. 3ñ -
.ñ ñ

. -
.
4ñ
ññ

. ñ2 -
.ñ ñ
ñ Using () Units 1, 4 got trt 1, others got trt 2
ñ We assume additivity
.ij = . + [
. iñ -.]+ [
. ñj -.]
(mean + trt effect + unit effect)
ñ We would only see 4 numbers
Y11 = ."" , Y12 = .41
Y21 = .## , Y22 = .3#
ñ In this way of thinking, there is no mention
of larger "population" or fancy model - just
random assignment of treatments and
additivity.
St 711 ( 4 )
ñ Allows "randomization test" (Ch. 4)
ñ Factorial treatments have similar structure.
ñ More like what we're used to
ñ Tables of means
no interaction
10 18 20
14 22 24
9 17 ??
interaction
1
2
4
2
4
8
8 16 32
ñ Table 1
overall mean 17
column (A) effects -6, 2, 4 (sum to 0)
row (B) effects -1, 3, -2 (sum to 0)
Data
10, 12 15, 17
13, 11 24, 22
8, 12 15, 19
21, 25
25, 21
17, 21
Means
11 16 23
12 23 23
10 17 19
ñ SSE = 2+2+8+2+2+8+8+8+8 = 48
St 711 ( 5 )
ñ MSE = 48/9 = 5.333 _

ñ SS(trt) = r!(Yijñ  Yñññ )2 =
i,j
2
2(11-17.111) + â+2(19-17.111)2 =
445.778 = 222 /2+â+382 /2  3082 /18
data a; do a=1 to 3; do b=1 to 3;
trt+1; do rep = 1 to 2; input Y @@;output; end; end; end;
cards;
10 12 15 17 21 25
13 11 24 22 25 21
8 12 15 19 17 21
;
proc print data=a (obs=9); title "Factorial";
proc means noprint mean sum css; by trt; var Y;
output out=out1 mean=mnY css=css sum=sumY ; id A B;
proc print noobs; sum mnY css sumY; run;
proc glm data=a; class trt; model Y= trt;
proc glmmod data=a; class trt; model Y=trt;
run;
Factorial
Obs
1
2
3
4
5
6
7
8
9
a
1
1
1
1
1
1
2
2
2
b
1
1
2
2
3
3
1
1
2
trt
1
1
2
2
3
3
4
4
5
rep
1
2
1
2
1
2
1
2
1
Y
10
12
15
17
21
25
13
11
24
St 711 ( 6 )
trt
1
2
3
4
5
6
7
8
9
a
1
1
1
2
2
2
3
3
3
b
1
2
3
1
2
3
1
2
3
_TYPE_
0
0
0
0
0
0
0
0
0
_FREQ_
2
2
2
2
2
2
2
2
2
mnY
11
16
23
12
23
23
10
17
19
===
154
css
2
2
8
2
2
8
8
8
8
===
48
sumY
22
32
46
24
46
46
20
34
38
====
308
The GLM Procedure
Class Level Information
Class
trt
Levels
9
Values
1 2 3 4 5 6 7 8 9
Number of observations
Dependent Variable: Y
Source
DF
Sum of
Squares
Model
Error
Corrected Total
8
9
17
445.7777778
48.0000000
493.7777778
Source
Model
18
Mean Square
55.7222222
5.3333333
F Value
Pr > F
10.45
0.0010
St 711 ( 7 )
The GLMMOD Procedure
Design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ñ Î 39 Ñ
!Ó
Ð 71 Ó
Ð y1 ñ Ó
Ð "! Ó
=Ð
=Ð
Ð
Ó
Ó
Ó
Ó
y2 ñ
72
9
!
Ï Ò Ï y Ò Ï #! Ò
3ñ
2 Ò 73
( ñ with no bar is total)
St 711 ( 9 )
"Least squares" must reproduce means.
We need
_
_
_
^ +7^ 1 = y = 5 , .
^ +7^ 2 = y = 3 , .
^ +7^ 3 = y = 10
.
1ñ
2ñ
3ñ
Table 1: many solutions !!
^
.
7^ 1
7^ 2
7^ 3
0
10
6
2
-10
5
-5
-1
3
15
3
-7
-3
1
13
10
0
4
8
20
^ +7^ 2 =__
.
7^ 1 + 7^ 2 =__
^ =__
.
7^ 2 =__
7^ 1  7^ 2 =__
ñ Estimable Functions:
Same regardless of solution.
ñ Obviously they are all possibilities for
c1 (.+71 )+c2 (.+72 )+c3 (.+73 )
(c1 +c2 +c3 ). + c1 71 +c2 72 +c3 73
L1 . + L2 71 +L3 72 +(L1  L2  L3 )73
St 711 ( 10 )
DATA EXAMPLE; INPUT TRT Y @@; CARDS;
1 4 1 6
2 5 2 1 2 3
3 8 3 12
PROC GLM; CLASS TRT; MODEL Y=TRT/E;
ESTIMATE "ATTEMPT 1" TRT 1 0 0;
ESTIMATE "ATTEMPT 2" INTERCEPT 1 TRT 1 0 0;
RUN;
The GLM Procedure
General Form of Estimable Functions
Effect
Coefficients
Intercept
L1
TRT
TRT
TRT
1
2
3
L2
L3
L1-L2-L3
Dependent Variable: Y
Source
DF
Model
2
Error
4
Corr.Tot. 6
Parameter
ATTEMPT 2
Sum of
Squares
59.71428571
18.00000000
77.71428571
Estimate
5.00000000
Mean Square
29.85714286
4.50000000
Standard
Error
1.50000000
F Value
6.63
t Value
3.33
Pr > F
0.0536
Pr > |t|
0.0290
St 711 ( 11 )
(FROM THE LOG WINDOW)
32
33
ESTIMATE "ATTEMPT 1" TRT 1 0 0;
ESTIMATE "ATTEMPT 2" INTERCEPT 1 TRT 1 0 0;
NOTE: ATTE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Ï 9 Ò Ï -7 Ò
-1
ñ Advantage: Computational speed
(diagnose singularities left to right in X)
ñ SAS automates
St 711 ( 15 )
SAS makes no assumptions but uses
restriction associated with reference
cell to get a solution if requested:
PROC IML; RESET SPACES=5 FW=3;
X= {1 1 0 0, 1 1 0 0, 1 0 1 0, 1 0 1 0,
1 0 1 0, 1 0 0 1, 1 0 0 1};
Y = {4 6 5 1 3 8 12}`;
XC = X[ ,2:4]; XR = X[ ,1:3];
XE= X[ ,1]||( X[ ,2:3] - X[ ,4]*{1 1} );
** || CONCATENATE HORIZONTALLY
[ ] PICK OUT ROWS OR COLUMNS ;
PRINT X XC XR XE Y;
BE = INV(XE`*XE)*XE`*Y; BC = INV(XC`*XC)*XC`*Y;
BR=INV(XR`*XR)*XR`*Y;
PRINT BE BC BR;
QUIT;
X
1
1
1
1
1
1
1
XC
1
1
0
0
0
0
0
0
0
1
1
1
0
0
0
0
0
0
0
1
1
1
1
0
0
0
0
0
XR
0
0
1
1
1
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
XE
1
1
0
0
0
0
0
0
0
1
1
1
0
0
BE
BC
BR
6
-1
-3
5
3
10
10
-5
-7
1 1 0
1 1 0
1 0 1
1 0 1
1 0 1
1 -1 -1
1 -1 -1
Y
4
6
5
1
3
8
12
St 711 ( 16 )
ñ SAS allows you to specify contrasts
checks estimability
ñ SAS actually uses "generalized inverse"
Î7
Ð 2
Ð
3
Ï2
2
2
!
!
3
!
3
!
2Ñ .
Î Ñ Î yñ ñ Ñ Î 39 Ñ
!Ó
Ð 71 Ó
Ð y Ó
Ð "! Ó
=Ð 1 ñ Ó
=Ð
Ð
Ó
Ó
Ó
y2 ñ
72
9
!
Ï Ò Ï y Ò Ï #! Ò
3ñ
2 Ò 73
7
.
Î
Î Ñ
Ð 2
Ð 71 Ó
=Ð
Ð
Ó
72
3
Ï 73 Ò Ï
2
Î 0.5
Ð -0.5
Ð
Ï 0
-0.5
2
2
!
!
-0.5
1
0.5
-0.5
0.5_
0.833
!
!
3
!
3
!
2 Ñ 39
Î Ñ
!Ó
Ð "! Ó
=
Ð
Ó
Ó
9
!
Ï Ò
2 Ò #!

0 Ñ 39
Î Ñ Î 10 Ñ
!Ó
Ð "! Ó
Ð -5 Ó
=Ð
Ð
Ó
Ó
Ó
9
-7
!
Ï #! Ò Ï ! Ò
Ò
0
ñ SAS tells you this is just one possibility.
St 711 ( 17 )
DATA EXAMPLE; INPUT TRT Y @@; CARDS;
1 4 1 6
2 5 2 1 2 3
3 8 3 12
PROC GLM; CLASS TRT; MODEL Y=TRT/SOLUTION; RUN;
Dependent Variable: Y
Source
Model
Error
Corrected Total
Parameter
Intercept
TRT
1
TRT
2
TRT
3
DF
2
4
6
The GLM Procedure
Sum of
Squares
59.71428571
18.00000000
77.71428571
Estimate
10.00000000
-5.00000000
-7.00000000
0.00000000
B
B
B
B
Mean Square
29.85714286
4.50000000
Standard
Error
t Value
Pr > |t|
1.50000000
2.12132034
1.93649167
.
6.67
-2.36
-3.61
.
0.0026
0.0779
0.0225
.
NOTE: The X'X matrix has been found to be singular, and a
generalized inverse was used to solve the normal
equations. Terms whose estimates are followed by the
letter 'B' are not uniquely estimable.
Random Variables and Expectations:
ñ Discrete (#tosses until heads)
Y
1
2
3
4
...
P(Y) "# ( "# )2 ( "# )3 ( "# )4 ...
E{Y} = mean = weighted average =
1( "# )+2 ( "# )2 +3( "# )3 + ... = 2
St 711 ( 18 )
S=1( "# )+2 ( "# )2 +3( "# )3 + ...
( "# )S = 1( "# )2 +2 ( "# )3 + ...
(1- "# )S = 1( "# )  1( "# )2 +" ( "# )3 + ...=1
S=2
ñ Continuous Pr{A<Y<B} = area
Plot of fy*Y.
Legend: A = 1 obs, B = 2 obs, etc.
fy ‚
1.0 ˆ
AAA
‚
A
A
‚
‚
A
A
‚
‚
A
A
‚
|
‚
A |
A
‚
|
0.5 ˆ
A |
A
‚
|
‚
A
|
A
‚
|
‚
A
|
A
‚
A
|
A
‚
|
|
‚
AA
|
|AA
‚
AA
|
| AA
0.0 ˆ AAAAAAA
|
|
AAAAAAA
Šƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒ
-4
-2
A 0
B 2
4
Y
_
'
ñ E{Y} = mean =.= _ y f(y) dy
ñ Variance: E{(Y-.)2 } = 5Y2
St 711 ( 19 )
ñ Covariance between Y1 and Y2
512 = E{(Y1 -.1 )(Y2 -.2 )}
"uncorrelated": 512 =0
ñ Var(Y1 „ Y2 )= 512 +522 „ 2512
ñ Rule 1: If uncorrelated,
Var(Y1 „ Y2 )= 512 +522
(variance of sum or difference is sum of
variances)
ñ Rule 2: C constant, then Var(CY) = C2 5Y2
ñ Rule 3: For Y~_ (., 5Y2 ) and uncorrelated,
Var(Y)=5Y2 /n
_
[ Y= 1n DYi , Var( DYi ) = n5Y2 (rule 1),
Var( 1n DYi ) = ( 1n )2 n5Y2 (rule 2) = 5Y2 /n]
ñ Nicer with matrices! (appendix 3A in G&G)
Y µ N(., V)
St 711 ( 20 )
2
5
.
Y
1
1
1
Î Ñ ÎÎ Ñ Î
.2 ß 512
Y2 ~
Ï Y3 Ò ÏÏ .3 Ò Ï 5
13
w
512
522
523
513 Ñ
523
532 Ò
Ñ
Ò
Then LY µ N(L., LVL )
ñ Example:
Î Y1 Ñ ÎÎ 12 Ñ Î 6
Y2 ~
16 ß 2
Ï Y3 Ò ÏÏ 6 Ò Ï -1
2
4
1
-1 Ñ
1
8Ò
Find distribution of
Y1 +Y2 -3Y3
proc iml; reset fw=4 spaces=5;
V= {6 2 -1, 2 4 1, -1 1 8};
L = {1 1 -3}; MuY = {12, 16, 6};
LVLP = L*V*L`; MuLY = L*MuY;
print MuY V MuLY LVLP;
MUY
12
16
6
V
6
2
-1
2
4
1
-1
1
8
MULY
10
ñ Regression uses these ideas.
LVLP
86
Ñ
Ò
St 711 ( 21 )
Y=X" +% so Y µ N(X" , I5 2 )
^ =(Xw X)-1 Xw Y, form is LY
"
E{LY} = LX" =(Xw X)-1 Xw X" ="
Var{LY}=LILw 5 2 = (Xw X)-1 5 2
ñ Regression, p parameters in "
^
s )w (Y  X"
s )=
(Y  X"
w
w
w
w s
w
s
s
s=
Y Y  Y X"  " X Y+" Xw X"
w
w
w
w s
w
s
s
Y Y  Y X"  " X Y+" Xw Y =
_2
_2
w
s Xw Y  nY )+0=
(Yw Y  nY )  ("
SS(total)  SS(regression)
SSE(" ) =
ñ ANOVA
Source df
Regn. p-1
Error n-p
Total n-1
SSq
Mn Sq F EMS
SS(reg.) SS/df
SS(err.)
" =MSE
SS(tot.)
ñ Example: 3 uncorrelated means
St 711 ( 22 )
_
no drug: Y
_ 1ñ µ N(10, 9/4),
half dose: Y
_2ñ µ N(16, 9/16),
full dose: Y3ñ µ N(18, 9/5)
C1 = full versus
none
_
_
_
 1Y1ñ + 0Y2ñ + 1Y3ñ
"
C2 = half dose
vs.
_
_ # (full +
_ low)
 1Y1ñ + 2Y2ñ  1Y3ñ
"contrasts" (coefficients sum to 0)
expected value:
 1(.+71 )+0(.+72 )+1(.  73 )=73  71
"orthogonal" (cross products sum to 0)
(-1)(-1)+(2)(0)+(-1)(1) = 0
ñ Find joint distribution of these contrasts
-1
LVLw =Œ
-1
4.05
Œ 0.45
0
2
0.45
6.30 
9/4
0
1 Î
0 9/16
-1 Ï
0
0
0 ÑÎ -1 -1 Ñ
0
0 2 =
9/5 ÒÏ 1 -1 Ò
orthogonal -> uncorrelated
if equal reps (not here)
St 711 ( 23 )
4.05
C"
8
µ
N
,
ŒC 
Œ Œ 4  Œ 0.45
2
0.45
6.30 

Two-way designs Row Column:
Yijk =. + 3i + #j + (3# )ij +%ijk
i=1,...,R j=1,...,C k=1,...,n ex.: R=3, C=n=2
ñ SAS assumes no restrictions!
ñ program shows what is being estimated in
general:
*** Demo 8 2-way model ***;
data a; do rho=1 to 3; do gamma=1 to 2; do rep=1 to
2;
Y=round(5*normal(1827655)+ 8*gamma + 12*rho);
output; end; end; end;
data names; input beta $ @@;
cards;
Mu r1 r2 r3 g1 g2 rg11 rg12 rg21 rg22 rg31 rg32
;
proc glmmod data=a outdesign=Xout;
class rho gamma; model Y=rho|gamma;
data Pg37; merge Xout names;
proc print noobs; title "G & G pg. 37";
St 711 ( 24 )
Y
X
16
20
24
33
29
28
41
46
40
37
53
48
1
1
1
1
1
1
1
1
1
1
1
1
G & G pg. 37
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
0
0
1
1
0
0
1
1
0
0
0
0
1
1
0
0
1
1
0
0
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
BETA
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
1
1
Mu
r1
r2
r3
g1
g2
rg11
rg12
rg21
rg22
rg31
rg32
%macro genname; %do i=1 %to 12; col&i %end;
%mend genname;
proc iml; reset fw=2 spaces=5;
use Pg37; read all var{%genname} into X;
read all var{beta} into beta;
read all var{Y} into Y;
print Y X beta;
XM = X[ ,7:12]; * cell means ;
extractR ={1 2 3 5 7 9}; XR=X[ ,extractR]; *
reference cell;
XE = {1 1 0 1 1 0, 1 1 0 1 1 0, 1 1 0 -1 -1 0, 1 1
0 -1 -1 0, 1 0 1 1 0 1, 1 0 1 1 0 1, 1 0 1 -1 0 -1,
1 0 1 -1 0 -1, 1 -1 -1 1 -1 -1, 1 -1 -1 1 -1 -1, 1
-1 -1 -1 1 1, 1 -1 -1 -1 1 1};
betaM ={"mu11","mu12","mu21","mu22","mu31","mu32"};
betaR = beta[extractR,1]; betaE=betaR;
print "G & G parameters (includes assumptions)";
St 711 ( 25 )
print XM betaM XR betaR; print XE betaE;
realM = inv(XM`*XM)*XM`*X; print realM beta;
realR = inv(XR`*XR)*XR`*X;
realE6 = 6*inv(XE`*XE)*XE`*X; print realR beta;
print realE6 beta;
part of output:
REALR
BETA
1 -0 -0 1 -0 1 -0 0 -0 0 0 1
0 1 0 -1 0 0 0 1 0 0 0 -1
0 -0 1 -1 0 0 0 -0 0 1 -0 -1
0 0 0 0 1 -1 0 -0 0 -0 1 -1
0 0 0 0 0 -0 1 -1 0 0 -1 1
0 0 0 0 0 -0 -0 0 1 -1 -1 1
REALE6
6 2 2 2
0 4 -2 -2
0 -2 4 -2
0 0 0 0
0 0 0 0
0 0 0 0
Mu
r1
r2
r3
g1
g2
rg11
rg12
rg21
rg22
rg31
rg32
BETA
3 3 1 1 1 1
0 0 2 2 -1 -1
0 0 -1 -1 2 2
3 -3 1 -1 1 -1
0 0 2 -2 -1 1
0 0 -1 1 2 -2
1 1
-1 -1
-1 -1
1 -1
-1 1
-1 1
Mu
r1
r2
r3
g1
g2
rg11
rg12
rg21
rg22
rg31
rg32
St 711 ( 26 )
proc glm data=a; class rho gamma;
model Y=rho|gamma/solution;
Parameter
Estimate
Intercept
rho
1
rho
2
rho
3
gamma
1
gamma
2
rho*gamma
rho*gamma
rho*gamma
rho*gamma
rho*gamma
rho*gamma
50.50000
-22.00000
-7.00000
0.00000
-12.00000
0.00000
1 1.50000
2 0.00000
1 -3.00000
2 0.00000
1 0.00000
2 0.00000
1
1
2
2
3
3
Standard
Error t Value
B
B
B
B
B
B
B
B
B
B
B
B
2.55766821
3.61708907
3.61708907
.
3.61708907
.
5.11533642
.
5.11533642
.
.
.
19.74
-6.08
-1.94
.
-3.32
.
0.29
.
-0.59
.
.
.
Pr > |t|
<.0001
0.0009
0.1011
.
0.0161
.
0.7792
.
0.5789
.
.
.
NOTE: The X'X matrix has been found to be singular, and a generalized
inverse was used to solve the normal equations. Terms whose
estimates are followed by the letter 'B' are not uniquely
estimable.
Coefficients for "31 " in
effects coding:
(3# )11 (3# )12 31
2/6 2/6 [4/6]
-1/6 -1/6 [-2/6]
(3# )21 (3# )22 32
-1/6 -1/6 [-2/6]
(3# )31 (3# )32 33
[0] [0] [0]
#1
#2
.
estimable if entries sum to [ ]
Model parameters
St 711 ( 27 )
ñ 31 in G&G effects coding really means
(6/6) 31 -(2/6)D3i + (3/6)D(3# )1j  (1/6)D(3# )ij
i
j
ij
which is 31 only if all D are 0 (coding assumption)
0
0
0
[0]
1
0
-1
[0]
[1]
[0]
[-1]
[0]
<-- Reference cell coding
ñ 31 in G&G reference cell coding really
means
31 -33 + (3# )1#  (3# )$#
which is 31 only if last levels all are 0
(reference cell coding assumption)
ñ Estimate of 31 in G&G can be different
depending on coding. Is 31 estimable
(without arbitrary assumptions)??
reset fw=5;b_hat_E = inv(XE`*XE)*XE`*Y;
b_hat_R=inv(XR`*XR)*XR`*Y;
print b_hat_E b_hat_R betaR ;
St 711 ( 28 )
B_HAT_E
B_HAT_R
34.58
-11.3
1.417
-6.25
1
-1.25
50.5
-22
-7
-12
1.5
-3
BETAR
Mu
r1
r2
g1
rg11
rg21
-11.3 ??(yes under effects coding)
3^ 1 =
-22 ?? (yes under ref. cell coding)
Note:31 -(2/6)D3i + (3/6)D(3# )1j -(1/6)D(3# )ij
i
j
ij
estimable! Estimate is -11.3 for effect coding.
For reference cell coding:
-22 -(-22-7+0)/3 + (1.5+0)/2 -(1.5-3+4(0))/6
= -22 +29/3+.75+1.5/6 = -11.3333
Why same? Estimable function!!
ñ SAS: no arbitrary assumptions, you must
fully specify contrasts.
proc glm data=a;
class rho gamma; model Y=rho gamma rho*gamma;
estimate "like effects" rho 4 -2 -2 gamma 0 0
rho*gamma 2 2 -1 -1 -1 -1/divisor=6;
estimate "like ref cell" rho 1 0 -1 gamma 0 0
rho*gamma 0 1 0 0 0 -1;
run;
St 711 ( 29 )
Parameter
like effects
like ref cell
Estimate
Standard
Error
t Value
-11.3333333
-22.0000000
1.47667043
3.61708907
-7.67
-6.08
Chapter 4
ñ Full versus reduced model F test
Yi ="0 +"1 X1i +â+"k Xki +% i % i µ N(0,5 2 )
H0 : "k-m+1 =â="k =0
SS(H0 :)=R("k-m+1 ,â,"k |"0 ,"1 ,â,"k-m )
=SSE(model without Xk-m+1 ,â,Xk ) 
SSE(full model) <= has m d.f.
Fm
n-k-1 = MS(H0 :)/MSE(full)
* Example (demo 9);
data a; input X1 X2
37 5 7 25.0
30
15 35 59 16.1
11
5 53 87 10.4
5
8 58 88 14.1
11
24 50 65 31.1
30
;
X3
14
41
55
57
46
Y @@; cards;
25 25.9
24
71 13.4
8
91 7.2
5
87 26.2
15
57 28.2
37
proc reg; model Y=X1 X2 X3/ss1;
omit2: test X2=0, X3=0;
proc reg; model Y=X1; run;
22
46
57
55
41
37
77
91
79
43
18.4
16.8
15.8
10.7
25.0
19
6
6
19
45
29
50
58
53
35
51
85
93
75
31
25.7
21.3
11.3
16.6
28.3
St 711 ( 30 )
The REG Procedure
Model: MODEL1
Dependent Variable: Y
Analysis of Variance
Source
Model
Error
Corrected Total
Variable
DF
Intercept
X1
X2
X3
Sum of
Squares
520.08339
442.63411
962.71750
DF
3
16
19
Parameter
Estimate
1 -23.96963
1
1.29727
1 -0.85018
1
0.87069
Mean
Square F Value
173.36113
6.27
27.66463
Standard
Error t Value
44.04222
1.09895
1.11119
1.10098
Pr > F
0.0051
Pr > |t|
Type I SS
0.5938
0.2551
0.4553
0.4406
7507.81250
501.21490
1.56642
17.30208
-0.54
1.18
-0.77
0.79
Test omit2 Results for Dependent Variable Y
Source
Numerator
Denominator
DF
2
16
Mean
Square
9.43425
27.66463
F Value
0.34
Pr > F
0.7161
Dependent Variable: Y
Analysis of Variance
Source
DF
Model
1
Error
18
Corrected Total 19
Variable DF
Intercept 1
X1
1
Sum of
Squares
501.21490
461.50260
962.71750
Parameter
Estimate
11.92261
0.41402
Mean
Square
501.21490
25.63903
Standard
Error
2.03050
0.09364
t Value
5.87
4.42
F Value
19.55
Pr > F
0.0003
Pr > |t|
<.0001
0.0003
St 711 ( 31 )
ñ Another way: H0 :L" =m0 (often 0)
In example
!
L=Œ
!
!
!
1
!
!
1
w
^
^ -m )
SS(H0 )= (L" -m0 ) (L(Xw X)-1 Lw Ñ-1 (L"
!
F=MS(H0 )/MSE as before.
E{MSE} = 5 2 always
E{MS(H0 )} = 5 2 if H0 true, >5 2 if not.
Big F ratio implies H0 unlikely.
ñ Under H0 , F has central F distribution.
ñ Under H1 , F has noncentral F distribution.
(graph G&G Fig. 4.1)
St 711 ( 32 )
C is F with 5 and 20 df
N is Noncentral F (noncentrality 5)
F ‚
‚
0.04 ˆ
‚
‚
c
‚
‚
cccc
‚
‚
c
c
‚
‚
c
c
‚
‚
cc
‚
‚
c
c
‚
0.02 ˆ c
nnncnn
‚
‚
nn
cnnn
‚
‚ c n
cc nn
‚
‚
nn
cc nnn‚
‚ cnn
cc
nnnn
‚
n
ccc ‚ nnnnnn
‚ n
cccccc nnnnnnnnnn
0.00 ˆ c
‚
cccccccccccccccccccc
Šƒˆƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒ
0
2
4
6
x
ñ Example 1-way ANOVA, t trts., ri reps
E{MS(trt)} =
-=
t
_
D ri (7i -7 )2
i=1
52
t
_2
D
r
(
7
7
2 i=1 i i )
5 + t-1
_
is "noncentrality": 7 =
t
D ri 7i
i=1
t
D ri
i=1
ñ Notes:
Z21 +Z22 +â+Zk2 µ ;2k (central) [Z iid N(0,1)]
(Z1 +È-)2 +Z22 +â+Z2k µ ;2k (-="noncentrality")
St 711 ( 33 )
E{SS(trt)/5 2 } µ ;2k (central) if all 7 's are 0
2
E{SS(trt)/5 } µ
;2k
(
t
_
D ri (7i -7 )2
i=1
52
)
ñ Example: t=3 treatments, 10 reps.
Test H0 : no trt effect.
guess: 5 2 about 30
want to reject if 71 =6, 72 =-3, 73 =-3
- = 540/30=18
data prej; do lamb=0 to 20; crit = finv(0.95,2,27);
Power = 1- probf(crit,2,27,lamb); output; end;
proc plot; plot power*lamb/vpos=12 hpos=50 href=18; run;
Plot of Power*lamb.
Legend: A = 1 obs, B = 2 obs, etc.
Power ‚
‚
1.0 ˆ
A A A
‚
A A A A A ‚
‚
A A A
‚
‚
A A
‚
‚
A
‚
0.5 ˆ
A A
‚
‚
A
‚
‚
A
‚
‚
A
‚
‚ A A
‚
0.0 ˆ
Šƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒ
0
5
10
15
20
lamb
St 711 ( 34 )
ñ General case (regression)
H0 :L" =m0
w
-= (mA -m0 ) (L(Xw X)-1 Lw 5 2 Ñ-1 (mA -m0 )
where mA is the alternative (true) L" that
you want to detect.
ñ Example:
Fertilizer at levels 10, 12, 14, 16, 18
Linear regression, Yield on fertilizer.
H0 : No fertilizer effect (slope=0)
How many reps per level to get power
up to 0.80 when slope is really 0.5?
Past studies show cv about 10%, average
yield about 250.
(5 /.)=.10 implies 5 = 25, 5 2 = 625
St 711 ( 35 )
%let V=625; options symbolgen;
proc iml;
X = {1 10, 1 12, 1 14, 1 16, 1 18};
V=inv(X`*X); L={0 1}; Lbeta={.5};
lambda =
Lbeta`*inv(L*inv(X`*X)*L`*&V)*Lbeta;
results = {0 0};
do r=100 to 1000 by 100;
noncent=r*lambda;
ndf = 1; ddf=r*5-2; crit = Finv(0.95,ndf,ddf);
power = 1-ProbF(crit,ndf,ddf,noncent);
results = results//(r||power);
end;
clab = {"r" "Power"};
print results [colname=clab];
RESULTS
r
Power
100 0.2433831
200 0.4314816
(more lines)
700 0.9170895
800 0.9470485
1000 0.9792883
(i.e. impossible to achieve with reasonable r)
ñ Example: Computer Mouse Study G&G
St 711 ( 36 )
ñ Example: Computer Mouse Study G&G
yijk =time difference in milliseconds
(drag&drop vs. pt.&click)
yijk =.+Si +Aj +(AS)ij +%ijk % µ N(0,45000)
i=1,2 sex
assume:
Aj age 9,10,11,12,13
linear decrease in difference,
no interaction (same slope)
H0 : difference 0ms at age 11
HA : difference 50 at age 11
Want power 80% to detect alternative.
Linear decrease Ä
mean of all ages = mean at 11
Use two-sided t. For t, noncentrality is
( n kids, 2 sexes, 5 ages so 10n total)
A -m0
9= ÈmVar(
=
50/È45000/(10n) =0.75Èn
^
.)
(^--- defines noncentrality for t)
St 711 ( 37 )
data a; do n=2 to 20;
dfe=10*(n-1); phi=50/sqrt(45000/(10*n));
critR = tinv(0.975,dfe); critL=-1*critR;
power = probt(critL,dfe,phi)+1-probt(critR,dfe,phi);
output; end;
proc print noobs; var n dfe phi power;
where .7<power<1; run;
n dfe
phi
12
13
14
15
16
17
18
19
20
2.58199
2.68742
2.78887
2.88675
2.98142
3.07318
3.16228
3.24893
3.33333
110
120
130
140
150
160
170
180
190
power
0.72556
0.75987
0.79053
0.81778
0.84191
0.86318
0.88187
0.89824
0.91253
ñ Last example:
data a;
put _all_;
n = 12; do truediff = -20 to 80 by 5;
dfe=10*(n-1); phi=truediff/sqrt(45000/(10*n));
critR = tinv(0.975,dfe); critL=-1*critR;
power = probt(critL,dfe,phi)+1-probt(critR,dfe,phi);
put "PDV at end " _all_ //;
output; end;
proc plot; plot power*truediff/vref=0.05 hpos=60 vpos=25;
run;
St 711 ( 38 )
Plot of power*truediff. Legend: A = 1 obs, B = 2 obs, etc.
1.00 ˆ
A
‚
A A
‚
A
‚
A
‚
‚
A
0.75 ˆ
‚
A
‚
power‚
A
‚
‚
A
0.50 ˆ
‚
‚
A
‚
‚
A
‚
0.25 ˆ
A
‚
‚
A
A
‚
A
A
‚
A
A
‚ƒƒƒƒƒƒƒƒƒAƒAƒAƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
0.00 ˆ
Šƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒ
-25
0
25
50
75
100
truediff
(from log window)
n=. truediff=. dfe=. phi=. critR=. critL=.
power=. _ERROR_=0 _N_=1
PDV at end n=12 truediff=-20 dfe=110 phi=-1.032795559
critR=1.9817652821 critL=-1.981765282
power=0.1760169031 _ERROR_=0 _N_=1
ñ G&G also show binomial sample size
computations. Main idea is that if p is
sample binomial proportion from bin(r,p0 )
St 711 ( 39 )
then arcsin(Èp) is approximately normal
with mean arcsin(Èp0 ) and variance 1/(4r).
ñ Nonparametric tests:
(1) Kruskal - Wallis
Variety A
10
29 30
80 100
Variety B 2 3
12
32 35
Variety C
568
13 24
ranks (sij ) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
2
t (!sij )
A: 56
12 ! j=1
H = n(n+1)
- 3(n+1), !sij = B: 35
ri
i=1
j=1
C: 29
2
2
2
12
H = 15x16
[ 565 + 355 + 295 ] - 48 = 4.02
ri
ri
(G&G show adjustment for ties)
Compare to ;2t-1 =;22
( ;22 (0.05)= 5.99 )
In SAS: PROC NPAR1WAY
Data A; input Variety $ @;
do rep = 1 to 5; input Y @; output; end;
cards;
A
10
29 30
B
2 3
12
32 35
C
5 6 8
13
24
80
100
St 711 ( 40 )
;
proc npar1way; class variety; var Y; run;
The NPAR1WAY Procedure
Analysis of Variance for Variable Y
Classified by Variable Variety
Variety
N
Mean
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
A
5
49.80
B
5
16.80
C
5
11.20
Source DF Sum of Squares Mean Square
F Value
Pr > F
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
Among
2
4350.533333 2175.266667
3.6877
0.0564
Within 12
7078.400000
589.866667
Wilcoxon Scores (Rank Sums) for Variable Y
Classified by Variable Variety
Sum of
Expected
Std Dev
Mean
Variety N
Scores
Under H0
Under H0
Score
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
A
5
56.0
40.0
8.164966
11.20
B
5
35.0
40.0
8.164966
7.00
C
5
29.0
40.0
8.164966
5.80
Kruskal-Wallis Test
Chi-Square
4.0200
DF
2
Pr > Chi-Square
0.1340
St 711 ( 41 )
(2) Randomization Test
ñ Assumes a proper randomization
ñ Idea: Take all possible divisions of the
data into t groups of r (t trts, r reps) and
compute F for each.
Under H0 :no trt effect, the F test for the
split actually used is just a random selection
from this list and the number of Fs at or
exceding this serves as a P-value.
ñ Example: t=2 varieties, r=4 replicates
Difference of means instead of F.
*See Demo 15 - creates dataset next with all possible
permutations of -1 -1 -1 -1 1 1 1 1 then ....;
Data rantest; set next;
diffmean =
(1*X1+4*X2+3*X3+10*X4+5*X5+15*X6+18*X7+30*X8)/4;
* variety A: 1 4 3 10, variety B: B 5 15 18 30;
St 711 ( 42 )
proc rank data=rantest out=out1;
ranks rank; var diffmean;
proc print data=out1(obs=5); run;
Obs
X1
X2
X3
1
2
3
4
5
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
X4
1
-1
-1
-1
-1
X5
X6
X7
X8
diffmean
rank
-1
1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
1
-12.5
-15.0
-10.0
-8.5
-2.5
2.0
1.0
6.0
9.0
27.5
(observed is obs. #1 so rank=2,
P-value is 2/70 = 0.029)