<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Contrast problem in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Contrast-problem/m-p/15089#M309</link>
    <description>Hello all,&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
The desired contrast is X1-X2 where, &lt;BR /&gt;
X1 = (mean of Line1+mean of Line1*YS) and &lt;BR /&gt;
X2 = (mean of Line2+mean of Line2*YS).&lt;BR /&gt;
&lt;BR /&gt;
I calculated the result manually:&lt;BR /&gt;
 &lt;BR /&gt;
X1 is manually estimated as:&lt;BR /&gt;
Line1 mean = (66/10) = 6.6&lt;BR /&gt;
Mean of Line1*YS1 = (28/5) = 5.60&lt;BR /&gt;
Mean of Line1*YS2 = (30/4) = 7.50&lt;BR /&gt;
Mean of Line1*YS3 = (8/1) = 8.00&lt;BR /&gt;
Then X1 = 6.6 + 5.6 + 7.5 + 8 = 27.70&lt;BR /&gt;
 &lt;BR /&gt;
X2 is manually estimated as:&lt;BR /&gt;
Line2 mean = (48/8) = 6.00&lt;BR /&gt;
Mean of Line2*YS1 = (20/3) = 6.67&lt;BR /&gt;
Mean of Line2*YS2 = (19/3) = 6.33&lt;BR /&gt;
Mean of Line2*YS3 = (9/2) = 4.50&lt;BR /&gt;
Then X2 = 6.00 + 6.67 + 6.33 + 4.50 = 23.5&lt;BR /&gt;
&lt;BR /&gt;
X1-X2 = 27.7-23.5 = 4.2&lt;BR /&gt;
*/&lt;BR /&gt;
------------------------&lt;BR /&gt;
and by SAS as:&lt;BR /&gt;
------------------------ &lt;BR /&gt;
title " means";&lt;BR /&gt;
data test;&lt;BR /&gt;
input Line YS Animal TR @@;&lt;BR /&gt;
cards;&lt;BR /&gt;
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&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
 &lt;BR /&gt;
proc sort data=test; by ys line;&lt;BR /&gt;
proc means noprint data=test;&lt;BR /&gt;
class ys line;&lt;BR /&gt;
var tr ;&lt;BR /&gt;
output out=test2 mean= avg_tr;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print data=test2;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
data line1 line2 ; set test2;&lt;BR /&gt;
if line=1 then output line1;&lt;BR /&gt;
if line=2 then output line2;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
proc means noprint data=line1;&lt;BR /&gt;
var avg_tr; ;&lt;BR /&gt;
output out=test3 sum= X1;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
proc means noprint data=line2;&lt;BR /&gt;
var avg_tr; ;&lt;BR /&gt;
output out=test4 sum= X2;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
data final;&lt;BR /&gt;
merge test3 test4;&lt;BR /&gt;
diff=x1-x2;&lt;BR /&gt;
run;&lt;BR /&gt;
title "The desired contrast X1-X2";&lt;BR /&gt;
proc print data=final;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
-----------------------------------------------------------------------------------------------------------&lt;BR /&gt;
The result is the same by both methods, but have two problems&lt;BR /&gt;
1-I'd like to get the standard error of the difference between the X1 and X2.&lt;BR /&gt;
2-I think that there is a duplicated intercept in the model. How to exclude it?&lt;BR /&gt;
&lt;BR /&gt;
Is there any suggestions?</description>
    <pubDate>Wed, 11 Nov 2009 10:49:02 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-11-11T10:49:02Z</dc:date>
    <item>
      <title>Contrast problem</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Contrast-problem/m-p/15089#M309</link>
      <description>Hello all,&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
The desired contrast is X1-X2 where, &lt;BR /&gt;
X1 = (mean of Line1+mean of Line1*YS) and &lt;BR /&gt;
X2 = (mean of Line2+mean of Line2*YS).&lt;BR /&gt;
&lt;BR /&gt;
I calculated the result manually:&lt;BR /&gt;
 &lt;BR /&gt;
X1 is manually estimated as:&lt;BR /&gt;
Line1 mean = (66/10) = 6.6&lt;BR /&gt;
Mean of Line1*YS1 = (28/5) = 5.60&lt;BR /&gt;
Mean of Line1*YS2 = (30/4) = 7.50&lt;BR /&gt;
Mean of Line1*YS3 = (8/1) = 8.00&lt;BR /&gt;
Then X1 = 6.6 + 5.6 + 7.5 + 8 = 27.70&lt;BR /&gt;
 &lt;BR /&gt;
X2 is manually estimated as:&lt;BR /&gt;
Line2 mean = (48/8) = 6.00&lt;BR /&gt;
Mean of Line2*YS1 = (20/3) = 6.67&lt;BR /&gt;
Mean of Line2*YS2 = (19/3) = 6.33&lt;BR /&gt;
Mean of Line2*YS3 = (9/2) = 4.50&lt;BR /&gt;
Then X2 = 6.00 + 6.67 + 6.33 + 4.50 = 23.5&lt;BR /&gt;
&lt;BR /&gt;
X1-X2 = 27.7-23.5 = 4.2&lt;BR /&gt;
*/&lt;BR /&gt;
------------------------&lt;BR /&gt;
and by SAS as:&lt;BR /&gt;
------------------------ &lt;BR /&gt;
title " means";&lt;BR /&gt;
data test;&lt;BR /&gt;
input Line YS Animal TR @@;&lt;BR /&gt;
cards;&lt;BR /&gt;
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&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
 &lt;BR /&gt;
proc sort data=test; by ys line;&lt;BR /&gt;
proc means noprint data=test;&lt;BR /&gt;
class ys line;&lt;BR /&gt;
var tr ;&lt;BR /&gt;
output out=test2 mean= avg_tr;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print data=test2;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
data line1 line2 ; set test2;&lt;BR /&gt;
if line=1 then output line1;&lt;BR /&gt;
if line=2 then output line2;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
proc means noprint data=line1;&lt;BR /&gt;
var avg_tr; ;&lt;BR /&gt;
output out=test3 sum= X1;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
proc means noprint data=line2;&lt;BR /&gt;
var avg_tr; ;&lt;BR /&gt;
output out=test4 sum= X2;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
data final;&lt;BR /&gt;
merge test3 test4;&lt;BR /&gt;
diff=x1-x2;&lt;BR /&gt;
run;&lt;BR /&gt;
title "The desired contrast X1-X2";&lt;BR /&gt;
proc print data=final;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
-----------------------------------------------------------------------------------------------------------&lt;BR /&gt;
The result is the same by both methods, but have two problems&lt;BR /&gt;
1-I'd like to get the standard error of the difference between the X1 and X2.&lt;BR /&gt;
2-I think that there is a duplicated intercept in the model. How to exclude it?&lt;BR /&gt;
&lt;BR /&gt;
Is there any suggestions?</description>
      <pubDate>Wed, 11 Nov 2009 10:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Contrast-problem/m-p/15089#M309</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-11-11T10:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Contrast problem</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Contrast-problem/m-p/15090#M310</link>
      <description>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.  &lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data test;&lt;BR /&gt;
   input Line YS Animal TR @@;&lt;BR /&gt;
   cards;&lt;BR /&gt;
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 &lt;BR /&gt;
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&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
proc mixed data=test;&lt;BR /&gt;
   class line ys;&lt;BR /&gt;
   model tr = line|ys;&lt;BR /&gt;
   lsmeans ys|line / e;&lt;BR /&gt;
   estimate 'Line 1 Mean' intercept  3 line  3   0 ys 1 1 1 line*ys 1 1 1  0  0  0 / divisor=3; &lt;BR /&gt;
   estimate 'Line 1*ys 1' intercept  3 line  3   0 ys 3 0 0 line*ys 3 0 0  0  0  0 / divisor=3; &lt;BR /&gt;
   estimate 'Line 1*ys 2' intercept  3 line  3   0 ys 0 3 0 line*ys 0 3 0  0  0  0 / divisor=3; &lt;BR /&gt;
   estimate 'Line 1*ys 3' intercept  3 line  3   0 ys 0 0 3 line*ys 0 0 3  0  0  0 / divisor=3; &lt;BR /&gt;
   Estimate 'x1'          intercept 12 line 12   0 ys 4 4 4 line*ys 4 4 4  0  0  0 / divisor=3;&lt;BR /&gt;
   Estimate 'x2'          intercept 12 line  0  12 ys 4 4 4 line*ys 0 0 0  4  4  4 / divisor=3;&lt;BR /&gt;
   Estimate 'x1-x2'       intercept  0 line 12 -12 ys 0 0 0 line*ys 4 4 4 -4 -4 -4 / divisor=3;&lt;BR /&gt;
   run;&lt;BR /&gt;
   quit;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 11 Nov 2009 12:56:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Contrast-problem/m-p/15090#M310</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-11-11T12:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: Contrast problem</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Contrast-problem/m-p/15091#M311</link>
      <description>data_null_;&lt;BR /&gt;
Thanks for reply. &lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
Important!! &lt;BR /&gt;
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)? &lt;BR /&gt;
I'm looking for a general and simpler way.</description>
      <pubDate>Wed, 11 Nov 2009 14:56:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Contrast-problem/m-p/15091#M311</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-11-11T14:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: Contrast problem</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Contrast-problem/m-p/15092#M312</link>
      <description>&amp;gt; data_null_;&lt;BR /&gt;
&amp;gt; Thanks for reply. &lt;BR /&gt;
&amp;gt; The final result is different from the manual one&lt;BR /&gt;
&amp;gt; (4.8 vs 4.2). I think that it is due to different&lt;BR /&gt;
&amp;gt; procs. LSmeans vs means.&lt;BR /&gt;
Yes, the result is different if you had complete balance they would be the same.  I would use the lsmeans.&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; Important!! &lt;BR /&gt;
&amp;gt; This data set is a small example. How to construct&lt;BR /&gt;
&amp;gt; such contrasts in larger data set (say 200 levels of&lt;BR /&gt;
&amp;gt; year-season and 400 interactions)? &lt;BR /&gt;
&amp;gt; I'm looking for a general and simpler way.&lt;BR /&gt;
&lt;BR /&gt;
Do you mean more levels or more factors?&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data test;&lt;BR /&gt;
   input Line YS Animal TR @@;&lt;BR /&gt;
   cards;&lt;BR /&gt;
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 &lt;BR /&gt;
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&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
ods listing close;&lt;BR /&gt;
ods trace on;&lt;BR /&gt;
proc mixed data=test;&lt;BR /&gt;
   class line ys;&lt;BR /&gt;
   model tr = line|ys;&lt;BR /&gt;
   lsmeans line line*ys / e;&lt;BR /&gt;
   ods output coef=Coef;&lt;BR /&gt;
   run;&lt;BR /&gt;
   quit;&lt;BR /&gt;
ods trace off;&lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc contents data=Coef varnum;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print data=coef;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
filename FT55F001 temp;&lt;BR /&gt;
data coef2;&lt;BR /&gt;
   set coef(where=(lmatrix eq 1) drop=row3-row6 rename=(Row1-Row2=L1-L2)) end=eof;&lt;BR /&gt;
   by notsorted Effect Line YS;&lt;BR /&gt;
   set coef(where=(lmatrix eq 2));&lt;BR /&gt;
   by notsorted Effect Line YS;&lt;BR /&gt;
   x1 = sum(of L1 Row1-Row3);&lt;BR /&gt;
   x2 = sum(of L2 Row4-Row6);&lt;BR /&gt;
   dif = x1-x2;&lt;BR /&gt;
&lt;BR /&gt;
   file FT55F001;&lt;BR /&gt;
   if _n_ eq 1 then put +3 'Estimate "x1-x2"';&lt;BR /&gt;
   if first.effect then put +6 effect @;&lt;BR /&gt;
   put dif @;&lt;BR /&gt;
   if last.effect then put;&lt;BR /&gt;
   if eof then put +6 ';';&lt;BR /&gt;
   format dif best32.;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc mixed data=test;&lt;BR /&gt;
   class line ys;&lt;BR /&gt;
   model tr = line|ys;&lt;BR /&gt;
   *lsmeans line line*ys;&lt;BR /&gt;
   %inc FT55F001 / source2;&lt;BR /&gt;
   run;&lt;BR /&gt;
   quit;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 11 Nov 2009 16:45:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Contrast-problem/m-p/15092#M312</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-11-11T16:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: Contrast problem</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Contrast-problem/m-p/15093#M313</link>
      <description>Hi data_null_;&lt;BR /&gt;
I meant levels not factors.&lt;BR /&gt;
However, the code solved the problem as the previous one. I'll try to generalise for the actual data.&lt;BR /&gt;
&lt;BR /&gt;
Thanks for kind help</description>
      <pubDate>Wed, 11 Nov 2009 18:39:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Contrast-problem/m-p/15093#M313</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-11-11T18:39:52Z</dc:date>
    </item>
  </channel>
</rss>

