Go Back   Rhinocerus > Newsgroup > Newsgroup comp.soft-sys.sas

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 05-19-2005, 03:35 PM
baogong jiang
Guest
 
Posts: n/a
Default Re: Type I-IV Sum of squares with empty cells

hi, Isaac:

You can bulid the IV type SS tests in SAS. For example. If you want to
bulid a type III test contrast for the 'a' effect; with the following
statement:

proc mixed data=test method=type3;
class a b;
model y=a b a*b/e3; /* get the type 3 coefficients for a */
run;

from the output, you will find this parts for the a effect:

Type 3 Coefficients for a

Effect a b Row1 Row2 Row3

Intercept
a 1 1
a 2 1
a 3 1
a 4 -1 -1 -1
b 1
b 2
a*b 1 1 0.25 -0.5 -0.25
a*b 1 2 0.75 0.5 0.25
a*b 2 1 1
a*b 3 1 -0.25 -0.5 0.25
a*b 3 2 0.25 0.5 0.75
a*b 4 2 -1 -1 -1


the row1 row2 and row3 are the contrast for test a effect, in this
sample, the contrast is:
intercept 0 a 1 0 0 -1 b 0 0 a*b .25 .75 0 -.25 .25 -1,
intercept 0 a 0 1 0 -1 b 0 0 a*b -.5 .5 1 -.5 .5 -1,
intercept 0 a 0 0 1 -1 b 0 0 a*b -.25 .25 0 .25 .75 -1;

the result as :


Type 3 Tests of Fixed Effects

Num Den
Effect DF DF F Value Pr > F

a 3 2 48.40 0.0203
b 1 2 16.33 0.0561
a*b 1 2 3.00 0.2254


Contrast

Num Den
Label DF DF F Value Pr > F

type III test 3 2 48.40 0.0203


you can bulid type I , II, III and IV SS test by using this method.


Baogong



On 5/18/05, Isaac Neuhaus <isaac.neuhaus@bms.com> wrote:
> Thank you. How do you build the contrasts?
> Isaac
>
>
> baogong jiang wrote:
> Hi, Isaac,


The SAS type I-IV SS test is very useful in a balanced design
> without

missing cells. If your data have missing cells, then depends on
> what

hypotheses you want to test, maybe none of the 4 type SS test
> is

right.

in proc mixed or proc glm, with the e or e1 e2 e3 e4 options in
> the

model statement, it's every easy to find out what hypothese the 4
> type

SS test are testing.

proc mixed method=type3;
class a b;
model y=a b
> a*b/e3;

run;


here is a program i wrote to compare the 4 type SS test. also
> I wrote

a macro PMMixed to calculate population marginal means when
> data

have missing cells. (SAS lsmeans will give out no-est. results.),
> if

you want the macro, just let me know!

data one;
do a=1 to 2;
do b=1 to
> 3;

do c=1 to 2;
do d=1 to 3;
do e=1 to
> 5;

score=10+30*abs(rannor(234323));
output;
end;end;end;end;end;
run;
data
> two;

set one;
if a=1 and b=2 then delete;
if b=2 and c=1 then
> delete;

run;

data three;
set two;
if a=1 and b=3 and d>2 then delete;
if
> a=2 and b=1 and d=5 then delete;

run;

proc tabulate data=three;
class a b c
> d;

var score;
table a,b;run;

proc mixed data=three;
class a b c d;
model
> score=a|b/solution ddfm=satterthwaite;

lsmeans a|b/e;
run;
proc glm
> data=three;

class a b c d;
model score=a|b/solution e1 e2 e3 e4;
contrast
> 'type 1 test for a effect' a 10 -10 b 2 -2 0

a*b 6 4 -4 -2 -4/e;
contrast
> 'type 2 test for a effect' a 1 -1 b 0 0 0

a*b .5556 .4444 -.5556 0
> -.4444/e;

contrast 'type 3 & 4 test for a effect' a 1 -1 b 0 0 0
a*b .5 .5
> -.5 0 -.5/e;

/* contrast LSmeans test is not estimable */;
contrast '
> LSmeans test ' a 6 -6 b 0 0 0 a*b 3 3 -2 -2 -2/e;

contrast 'type 1 & 2 test
> for b effect' b 1 0 -1 a*b .4444 -.4444

..5556 0 -.5556,
b 0 1 -1 a*b .2222
> -.2222

-.2222 1 -.7778/e ;

contrast 'type 3 test for b effect' b 1 0 -1
> a*b .5 -.5 .5 0 -.5,

b 0 1 -1 a*b .25 -.25 -.25 1 -.75/e ;
contrast 'type 4
> test for b effect' b 1 0 -1 a*b .5 -.5 .5 0 -.5,

b 0 1 -1 a*b 0 0 0 1 -1/e
> ;


lsmeans a|b/e;
run;
%pmmmixed( data=three, stmts=%str(
Class a b c
> d;

Model Score = a| b /solution e ddfm=Satterthwaite;
Lsmeans a| b / e
> );

run;
/* test macro result */;
proc mixed data=three;
class a b c
> d;

model score=a*b/e1 e2 e3;
contrast 'macro a effect' a*b 3 3 -2 -2
> -2/e;

contrast 'macro b effect' a*b .5 0 .5 -1 0,
a*b .5 -.5 .5 0
> -.5/e;

run;
/*

The GLM Procedure

Dependent Variable: score

Sum of
> Source DF Squares Mean Square

F Value Pr > F

Model 4 1649.69294
> 412.42324

1.34 0.2606

Error 120 37047.30146 308.72751

Corrected Total
> 124 38696.99440



R-Square Coeff Var Root MSE score Mean

0.042631
> 52.46313 17.57064 33.49141



Source DF Type I SS Mean Square
F Value Pr >
> F


a 1 576.6347140 576.6347140
1.87 0.1743
b 2 459.3012397 229.6506198
> 0.74 0.4775

a*b 1 613.7569905 613.7569905
1.99 0.1611


Source DF Type II
> SS Mean Square

F Value Pr > F

a 1 696.5114296 696.5114296
2.26 0.1357
b
> 2 459.3012397 229.6506198

0.74 0.4775
a*b 1 613.7569905 613.7569905
1.99
> 0.1611



Source DF Type III SS Mean Square
F Value Pr > F

a 1
> 551.0947151 551.0947151

1.79 0.1841
b 2 538.9807615 269.4903808
0.87
> 0.4204

a*b 1 613.7569905 613.7569905
1.99 0.1611


Source DF Type IV SS
> Mean

Square F Value Pr > F

a 1* 551.0947151
551.0947151 1.79 0.1841
b 2*
> 335.2225480

167.6112740 0.54 0.5825
a*b 1 613.7569905
613.7569905 1.99
> 0.1611


* NOTE: Other Type IV Testable Hypotheses exist which may yield
> different SS.


Contrast DF Contrast SS Mean
Square F Value Pr > F
type 1
> test for a effect 1 576.6347140

576.6347140 1.87 0.1743
type 2 test for a
> effect 1 696.6283890

696.6283890 2.26 0.1357
type 3 & 4 test for a effect
> 1 551.0947151

551.0947151 1.79 0.1841
type 1 & 2 test for b effect 2
> 459.2409919

229.6204960 0.74 0.4775
type 3 test for b effect 2 538.9807615
>

269.4903808 0.87 0.4204
type 4 test for b effect 2 335.2225480
>

167.6112740 0.54 0.5825

Num Den
Label DF DF F Value Pr > F

macro a
> effect 1 120 0.79 0.3754

macro b effect 2 120 0.54 0.5815

*/;





On
> 5/17/05, isaac.neuhaus@bms.com <isaac.neuhaus@bms.com> wrote:


> Robin High wrote:


> On Tue, 17 May 2005 isaac.neuhaus@BMS.COM wrote:



> I am trying to understand how the different types of sum of squares


> are


>
> calculated and I haven't been able to understand how SAS calculates


> the


>
> type III sum of squares when there are empty cells in the design. I

looked
> at Donald Macnaughton SS.sas code which has been an


> excellent


>
> teaching resource but when it comes to a design with empty cells


> the


>
> type III sum of squares (HTI) do not agree with those produced by


> proc


>
> glm in SAS. Can anybody point to where I can learn how to manually

calculate
> them or even better explain how?


> Isaac,


First, you should read Chapters 13-15 of Milliken and Johnson,

> "Analysis


> of Messy Data", Vol 1. They provide more detail and information than


> I


> could hope to in this short note.


Here is a brief GLM analysis (though one
> could perhaps do even better


> with


> MIXED) that is based on the approach from the above reference:


Proc
> tabulate shows the nature of the empty
> cells:


----------------------------
| | b |
| |-------------------|
| | 1 |
> 2 |

| |---------+---------|
| | N |Mean | N |Mean
> |

|------+---+-----+---+-----|
|a | | | | |
|1 | 1| 7.0| 2| 9.5|
|2 | 1|
> 1.0| .| .|

|3 | 1| 4.0| 2| 5.0|
|4 | .| .| 1|
> 5.0|

----------------------------

I've recoded A and B into one variable
> called lvl which is


lvl = 10*a + b;

so the cell means layout is
> now:


------------------
| | N |Mean |
|------+---+-----|
|lvl i | | |
|11 1
> | 1| 7.0|

|12 2 | 2| 9.5|
|21 3 | 1| 1.0|
|31 4 | 1| 4.0|
|32 5 | 2|
> 5.0|

|42 6 | 1| 5.0|
------------------

The variable i is the index found
> in the ESTIMATE and CONTRAST


> statements


> in the second GLM step:


With empty cells compare the TYPE III and TYPE IV
> sums of Squares:


proc glm data=one;
class a b;
model y = a b a*b / ss3
> ss4;

run; quit;

Source DF Squares Mean Square F Value Pr
F

Model 5
> 57.00000000 11.40000000 45.60


> 0.0216


> Error 2 0.50000000 0.25000000

Corrected Total 7 57.50000000


Source DF Type
> III SS Mean Square F Value Pr > F


a 3 36.30000000 12.10000000 48.40
> 0.0203

b 1 4.08333333 4.08333333 16.33 0.0561
a*b 1 0.75000000 0.75000000
> 3.00 0.2254


Source DF Type IV SS Mean Square F Value Pr > F

a 3*
> 28.80000000 9.60000000 38.40 0.0255

b 1* 4.08333333 4.08333333 16.33
> 0.0561

a*b 1 0.75000000 0.75000000 3.00 0.2254

* NOTE: Other Type IV
> Testable Hypotheses exist which may yield


> different SS.


> Now how does one reproduce these Type IV SS?


Use the cell means model with
> GLM:


proc glm data=one;
class lvl;

model y = lvl / ss4;

/* Sums of
> Squares for A: assume the following contrasts

A 1 vs 2 in b=1
A 1 vs 3 in
> b=1,2

A 3 vs 4 in b=2
*/
contrast 'A' lvl 1 0 0 -1 0 0,
lvl 1 1 0 -1 -1
> 0,

lvl 0 0 0 0 1 -1;
ESTIMATE 'A 1 vs 2 in B=1' lvl 1 0 0 -1 0 0;
ESTIMATE
> 'A 1 vs 3 in B=1,2' lvl 1 1 0 -1 -1 0 / DIVISOR=2;

ESTIMATE 'A 3 vs 4 in
> B=2' lvl 0 0 0 0 1 -1;


/* one contrast for B= 1 vs 2 in A=1,3 */

CONTRAST
> 'B' lvl 1 -1 0 1 -1 0 ;

ESTIMATE 'B' lvl 1 -1 0 1 -1 0 /DIVISOR=2;

/*
> Interaction comes from A=1,3 in B=1,2 */


contrast 'AB' lvl 1 -1 0 -1 1
> 0;

ESTIMATE 'AB' lvl 1 -1 0 -1 1 0 /DIVISOR=2;

run; quit;

< edited output
> >


The GLM Procedure

Class Level Information

Class Levels Values
lvl 6 11
> 12 21 31 32 42



Dependent Variable: y

Sum of
Source DF Squares Mean
> Square F Value Pr >


> F


> Model 5 57.00000000 11.40000000 45.60


> 0.0216


> Error 2 0.50000000 0.25000000

Corrected Total 7 57.50000000

Source DF Type
> IV SS Mean Square F Value Pr

F
lvl 5 57.00000000 11.40000000 45.60

> 0.0216


> Contrast DF Contrast SS Mean Square F Value Pr

F

A 3 28.80000000 9.60000000
> 38.40


> 0.0255


> B 1 4.08333333 4.08333333 16.33


> 0.0561


> AB 1 0.75000000 0.75000000 3.00


> 0.2254


> NOTE: the contrast results are the same as the TYPE IV when the model

y = a
> + b + ab was entered in the first GLM step


You can also compute estimates
> from the above contrasts:


Standard
Parameter Estimate Error t Value Pr >

> |t|


> A 1 vs 2 in B=1 3.00000000 0.70710678 4.24


> 0.0513


> A 1 vs 3 in B=1,2 3.75000000 0.43301270 8.66


> 0.0131


> A 3 vs 4 in B=2 -0.00000000 0.61237244 -0.00


> 1.0000


> B -1.75000000 0.43301270 -4.04


> 0.0561


> AB -0.75000000 0.43301270 -1.73 0.225



Robin High ("sometimes known to also
> have missing cells")

Univ. of Oregon

> Thank you for the explanation. Is there a typo in the
> following

contrast?

/* Sums of Squares for A: assume the following
> contrasts

A 1 vs 2 in b=1
A 1 vs 3 in b=1,2
A 3 vs 4 in b=2
/
contrast 'A'
> lvl 1 0 0 -1 0 0,

lvl 1 1 0 -1 -1 0,
lvl 0 0 0 0 1 -1;

Shouldn't it
> be:


contrast 'A' lvl 1 0 -1 0 0 0,
lvl 1 1 0 -1 -1 0,
lvl 0 0 0 0 1
> -1;


Do you also have an executive summary like this one for the type
> III

sum of squares?

Thanks again,

Isaac


>


>



--
Baoogng Jiang
Department of Agronomy
Lousisana State University
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: when should I use Type I SS and Type III SS in glm/mixed? Nordlund, Dan Newsgroup comp.soft-sys.sas 0 02-24-2009 06:55 PM
Re: help reading data from Excel (pivot table) with empty cells! Wilson, Nancy Newsgroup comp.soft-sys.sas 0 07-24-2008 08:20 PM
Re: Type III Sum of Squares David L Cassell Newsgroup comp.soft-sys.sas 0 08-18-2005 09:50 PM
Re: Type I-IV Sum of squares with empty cells Robin High Newsgroup comp.soft-sys.sas 1 05-18-2005 03:56 AM
Type I-IV Sum of squares with empty cells isaac.neuhaus@bms.com Newsgroup comp.soft-sys.sas 0 05-17-2005 07:49 PM



All times are GMT. The time now is 06:48 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.