Introduction
Contrast coefficients for Trend Analysis
(Valid when X levels are equally spaced & N's are
equal)
Coefficients, c(i)
r
Trend
X=1
2
3
4
5
6
7
sum c(i)**2
---------------------------------------------------------
3
Linear
-1
0
1
2
Quad
1 -2
1
6
--------------------------------------------------
4
Linear
-3 -1
1
3
20
Quad
1 -1 -1
1
4
Cubic
-1
3 -3
1
20
--------------------------------------------------
5
Linear
-2 -1
0
1
2
10
Quad
2 -1 -2 -1
2
14
Cubic
-1
2
0 -2
1
10
Quartic
1 -4
6 -4
1
70
--------------------------------------------------
6
Linear
-5 -3 -1
1
3
5
70
Quad
5 -1 -4 -4 -1
5
84
Cubic
-5
7
4 -4 -7
5
180
Quartic
1 -3
2
2 -3
1
28
--------------------------------------------------
7
Linear
-3 -2 -1
0
1
2
3
28
Quad
5
0 -3 -4 -3
0
5
84
Cubic
-1
1
1
0 -1 -1
1
6
Quartic
3 -7
1
6
1 -7
3
154
--------------------------------------------------
8
Linear
-7 -5 -3 -1
1
3
5 7
168
Quad
7
1 -3 -5 -5 -3
1 7
168
Cubic
-7
5
7
3 -3 -7 -5 7
264
Quartic 7
-13 -3
9
9 -3 -13 7
616
--------------------------------------------------
9
Linear
-4 -3 -2 -1
0
1
2
3
4
60
Quad
28
7 -8 -17 -20
-17 -8
7 28
2772
Cubic
-14
7 13
9
0 -9 -13 -7 14
990
Quartic 14 -21
-11
9 18 9
-11 -21 14
2002
--------------------------------------------------
http://www.ats.ucla.edu/stat/sas/library/SASAnova_mf.htm
Program
data
have;
infile
datalines
missover;
input
group @;
do
i =1
to
10;
input
y @;
output;
end;
datalines;
1 260 200 240 170 270
205 190 200 250 200
2 310 310 190 225 170
210 280 210 280 240
3 320 260 360 310 270
380 240 295 260 250
;
proc
glm
data
=have;
class
group;
model
y =group;
contrast
'linear trend'
group -1
0
1;
run;
quit;
#R
code
#input and formulate data
BLP.Grp1 <-
c(260,200,240,170,270,205,190,200,250,200)
BLP.Grp2 <-
c(310,310,190,225,170,210,280,210,280,240)
BLP.Grp3 <-
c(320,260,360,310,270,380,240,295,260,250)
#Response and Factor(group)
BLP.Grps <-
c(BLP.Grp1, BLP.Grp2, BLP.Grp3)
Group
<- rep(1:3, times =1, each =10)
BLP
<- transform(cbind(Group,BLP.Grps), Group
=as.factor(Group))
#Construct Contrasts
contrasts(BLP$Group)=contr.poly(levels(BLP$Group))
#Fit and printout model
summary(lm(formula=BLP.Grps~Group,
data =BLP))
Results
SAS
Contrast
|
DF
|
Contrast SS
|
Mean
Square
|
F
Value
|
Pr > F
|
linear trend
|
1
|
28880.00000
|
28880.00000
|
14.72
|
0.0007
|
Figure 1: Boxplot for
group variable.
http://s2/mw690/002ZOYCigy6FCdOJv5T01&690Trend Test in R/SAS" TITLE="262.Linear Trend Test in R/SAS" />
R
Call:
lm(formula
= BLP.Grps ~ Group, data = BLP)
Residuals:
Min
1Q Median
3Q
Max
-72.5 -32.5 -15.5
36.0
85.5
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)
251.833
8.088
31.136
< 2e-16 ***
Group.L
53.740
14.009
3.836 0.000682 *** <<Linear
test |
Group.Q
11.431
14.009
0.816 0.421654
---
Signif.
codes: 0 ‘***’ 0.001 ‘**’
0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual
standard error: 44.3 on 27 degrees of freedom
Multiple
R-squared: 0.3629,
Adjusted R-squared:
0.3157
F-statistic:
7.691 on 2 and 27 DF, p-value:
0.002272 #############################################################
Notice that the results
from R and SAS are identical, i.e.,
t^2 (R) = F, 3.836^2
=14.72(SAS).
加载中,请稍候......