BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello all,

I have a problem in estimating a contrast in a data set where there are 2 lines, 6 year-seasons (YS), 10 animals and 1 trait (TR) in 18 observations.

The desired contrast is X1-X2 where,
X1 = (mean of Line1+mean of Line1*YS) and
X2 = (mean of Line2+mean of Line2*YS).

I calculated the result manually:

X1 is manually estimated as:
Line1 mean = (66/10) = 6.6
Mean of Line1*YS1 = (28/5) = 5.60
Mean of Line1*YS2 = (30/4) = 7.50
Mean of Line1*YS3 = (8/1) = 8.00
Then X1 = 6.6 + 5.6 + 7.5 + 8 = 27.70

X2 is manually estimated as:
Line2 mean = (48/8) = 6.00
Mean of Line2*YS1 = (20/3) = 6.67
Mean of Line2*YS2 = (19/3) = 6.33
Mean of Line2*YS3 = (9/2) = 4.50
Then X2 = 6.00 + 6.67 + 6.33 + 4.50 = 23.5

X1-X2 = 27.7-23.5 = 4.2
*/
------------------------
and by SAS as:
------------------------
title " means";
data test;
input Line YS Animal TR @@;
cards;
1 1 1 5 1 1 1 6 1 1 2 5 1 2 2 8 1 2 3 7 1 2 3 9 1 3 3 8 1 1 4 7 1 2 4 6 1 1 5 5 2 1 6 6 2 2 6 5 2 3 7 4 2 1 7 9 2 2 8 8 2 1 8 5 2 2 9 6 2 3 10 5
;
run;


proc sort data=test; by ys line;
proc means noprint data=test;
class ys line;
var tr ;
output out=test2 mean= avg_tr;
run;
proc print data=test2;
run;

data line1 line2 ; set test2;
if line=1 then output line1;
if line=2 then output line2;
run;

proc means noprint data=line1;
var avg_tr; ;
output out=test3 sum= X1;
run;

proc means noprint data=line2;
var avg_tr; ;
output out=test4 sum= X2;
run;

data final;
merge test3 test4;
diff=x1-x2;
run;
title "The desired contrast X1-X2";
proc print data=final;
run;

-----------------------------------------------------------------------------------------------------------
The result is the same by both methods, but have two problems
1-I'd like to get the standard error of the difference between the X1 and X2.
2-I think that there is a duplicated intercept in the model. How to exclude it?

Is there any suggestions?
4 REPLIES 4
data_null__
Jade | Level 19
Using the estimateable functions for the LS means I came up with this. Notice that the LSmeans for LINE are different from the means give by PROC MEANS.

[pre]
data test;
input Line YS Animal TR @@;
cards;
1 1 1 5 1 1 1 6 1 1 2 5 1 2 2 8 1 2 3 7 1 2 3 9 1 3 3 8 1 1 4 7 1 2 4 6 1 1 5 5
2 1 6 6 2 2 6 5 2 3 7 4 2 1 7 9 2 2 8 8 2 1 8 5 2 2 9 6 2 3 10 5
;;;;
run;
proc print;
run;

proc mixed data=test;
class line ys;
model tr = line|ys;
lsmeans ys|line / e;
estimate 'Line 1 Mean' intercept 3 line 3 0 ys 1 1 1 line*ys 1 1 1 0 0 0 / divisor=3;
estimate 'Line 1*ys 1' intercept 3 line 3 0 ys 3 0 0 line*ys 3 0 0 0 0 0 / divisor=3;
estimate 'Line 1*ys 2' intercept 3 line 3 0 ys 0 3 0 line*ys 0 3 0 0 0 0 / divisor=3;
estimate 'Line 1*ys 3' intercept 3 line 3 0 ys 0 0 3 line*ys 0 0 3 0 0 0 / divisor=3;
Estimate 'x1' intercept 12 line 12 0 ys 4 4 4 line*ys 4 4 4 0 0 0 / divisor=3;
Estimate 'x2' intercept 12 line 0 12 ys 4 4 4 line*ys 0 0 0 4 4 4 / divisor=3;
Estimate 'x1-x2' intercept 0 line 12 -12 ys 0 0 0 line*ys 4 4 4 -4 -4 -4 / divisor=3;
run;
quit;
[/pre]
deleted_user
Not applicable
data_null_;
Thanks for reply.
The final result is different from the manual one (4.8 vs 4.2). I think that it is due to different procs. LSmeans vs means.

Important!!
This data set is a small example. How to construct such contrasts in larger data set (say 200 levels of year-season and 400 interactions)?
I'm looking for a general and simpler way.
data_null__
Jade | Level 19
> data_null_;
> Thanks for reply.
> The final result is different from the manual one
> (4.8 vs 4.2). I think that it is due to different
> procs. LSmeans vs means.
Yes, the result is different if you had complete balance they would be the same. I would use the lsmeans.

> Important!!
> This data set is a small example. How to construct
> such contrasts in larger data set (say 200 levels of
> year-season and 400 interactions)?
> I'm looking for a general and simpler way.

Do you mean more levels or more factors?

I don't know enough to know the "proper" way to do this. Here is the brute force method. You should be able to generalize this to suite your actual data.

[pre]
data test;
input Line YS Animal TR @@;
cards;
1 1 1 5 1 1 1 6 1 1 2 5 1 2 2 8 1 2 3 7 1 2 3 9 1 3 3 8 1 1 4 7 1 2 4 6 1 1 5 5
2 1 6 6 2 2 6 5 2 3 7 4 2 1 7 9 2 2 8 8 2 1 8 5 2 2 9 6 2 3 10 5
;;;;
run;
proc print;
run;
ods listing close;
ods trace on;
proc mixed data=test;
class line ys;
model tr = line|ys;
lsmeans line line*ys / e;
ods output coef=Coef;
run;
quit;
ods trace off;
ods listing;
proc contents data=Coef varnum;
run;
proc print data=coef;
run;

filename FT55F001 temp;
data coef2;
set coef(where=(lmatrix eq 1) drop=row3-row6 rename=(Row1-Row2=L1-L2)) end=eof;
by notsorted Effect Line YS;
set coef(where=(lmatrix eq 2));
by notsorted Effect Line YS;
x1 = sum(of L1 Row1-Row3);
x2 = sum(of L2 Row4-Row6);
dif = x1-x2;

file FT55F001;
if _n_ eq 1 then put +3 'Estimate "x1-x2"';
if first.effect then put +6 effect @;
put dif @;
if last.effect then put;
if eof then put +6 ';';
format dif best32.;
run;
proc print;
run;
proc mixed data=test;
class line ys;
model tr = line|ys;
*lsmeans line line*ys;
%inc FT55F001 / source2;
run;
quit;
[/pre]
deleted_user
Not applicable
Hi data_null_;
I meant levels not factors.
However, the code solved the problem as the previous one. I'll try to generalise for the actual data.

Thanks for kind help

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1273 views
  • 0 likes
  • 2 in conversation