Schematic of CR-4 with Example Data
Consider again the following Completely Randomized 4 group design:
Level a1
a2 a3 a4 Total
3
6
3
3
1
2
2
2
4
5
4
3
2
3
4
3
7
8
7
6
5
6
5
6
7
8
9
8
10
10
9
11
Mean 2.75
3.5 6.25 9.0 5.375
Plot of the Group Means
Inspection of the plot of group means suggests, that although it is possible to fit a straight line through the points, there also seems to be a little bit of curvalinearnity present.
Trend analysis partitions the sum of squares for the model into portions due to linear trend, quadratic trend, cubic trend, etc. If there are k groups it is possible to look at up to k - 1 trends, although often researchers combine together all trends above quadratic or cubic.
Coefficients of Orthogonal Polynomials
Trend analysis is performed using coefficients of orthogonal polynomials. For the four group design the coefficients are:
Group -> 1 2 3 4 Linear -3 -1 1 3 Quadratic 1 -1 -1 1 Cubic -1 3 -3 1
Here is a table with more coefficients of orthogonal polynomials.
Plotting Coefficients of Orthogonal Polynomials
Plot of Linear Trend
Plot of Quadratic Trend
Plot of Cubic Trend
Using the Coefficients of Orthogonal Polynomials
One way to perform trend analysis is to use the coefficients of orthogonal polynomials to weight the group sums to compute sums of squares for each of the trends in a manner very similar to computing planned orthogonal comparisons. Using the coefficients in this manner yields the following ANOVA Summary Table:
Source | SS | df | MS | F | |
Between Groups | 194.5 | 3 | 64.833 | 44.28 | |
Linear Trend | 184.9 | 1 | 184.900 | 126.30 | |
Non-Linear | 9.6 | 2 | 4.800 | 3.28 | |
Quadratic Trend | 8.0 | 1 | 8.000 | 5.46 | |
Cubic Trend | 1.6 | 1 | 1.600 | 1.09 | |
Within Groups | 41.0 | 28 | 1.464 | ||
Total | 235.5 | 31 |
Stata Example
An alternative is to apply the coefficients of orthogonal polynomials directly to the observations and to analyze using regression.
input y grp o1 o2 o3 3 1 -3 1 -1 6 1 -3 1 -1 3 1 -3 1 -1 3 1 -3 1 -1 1 1 -3 1 -1 2 1 -3 1 -1 2 1 -3 1 -1 2 1 -3 1 -1 4 2 -1 -1 3 5 2 -1 -1 3 4 2 -1 -1 3 3 2 -1 -1 3 2 2 -1 -1 3 3 2 -1 -1 3 4 2 -1 -1 3 3 2 -1 -1 3 7 3 1 -1 -3 8 3 1 -1 -3 7 3 1 -1 -3 6 3 1 -1 -3 5 3 1 -1 -3 6 3 1 -1 -3 5 3 1 -1 -3 6 3 1 -1 -3 7 4 3 1 1 8 4 3 1 1 9 4 3 1 1 8 4 3 1 1 10 4 3 1 1 10 4 3 1 1 9 4 3 1 1 11 4 3 1 1 end anova y grp Number of obs = 32 R-squared = 0.8259 Root MSE = 1.21008 Adj R-squared = 0.8072 Source | Partial SS df MS F Prob > F -----------+---------------------------------------------------- Model | 194.50 3 64.8333333 44.28 0.0000 | grp | 194.50 3 64.8333333 44.28 0.0000 | Residual | 41.00 28 1.46428571 -----------+---------------------------------------------------- Total | 235.50 31 7.59677419 anovacontrast grp, values(-3 -1 1 3) title(linear) linear Contrast variable grp (-3 -1 1 3) source SS df MS Dep Var = y ---------+--------------------------------- N of obs = 32 contrast | 184.9 1 184.9000 F = 126.27 error | 41 28 1.4643 Prob > F = 0.0000 ---------+--------------------------------- anovacontrast grp, values(1 -1 -1 1) title(quadratic) quadratic Contrast variable grp (1 -1 -1 1) source SS df MS Dep Var = y ---------+--------------------------------- N of obs = 32 contrast | 8 1 8.0000 F = 5.46 error | 41 28 1.4643 Prob > F = 0.0268 ---------+--------------------------------- anovacontrast grp, values(-1 3 -3 1) title(cubic) cubic Contrast variable grp (-1 3 -3 1) source SS df MS Dep Var = y ---------+--------------------------------- N of obs = 32 contrast | 1.6 1 1.6000 F = 1.09 error | 41 28 1.4643 Prob > F = 0.3048 ---------+--------------------------------- regress y o1 o2 o3 Source | SS df MS Number of obs = 32 -------------+------------------------------ F( 3, 28) = 44.28 Model | 194.50 3 64.8333333 Prob > F = 0.0000 Residual | 41.00 28 1.46428571 R-squared = 0.8259 -------------+------------------------------ Adj R-squared = 0.8072 Total | 235.50 31 7.59677419 Root MSE = 1.2101 ------------------------------------------------------------------------------ y | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- o1 | 1.075 .095665 11.24 0.000 .8790392 1.270961 o2 | .5 .2139134 2.34 0.027 .0618183 .9381817 o3 | -.1 .095665 -1.05 0.305 -.2959608 .0959608 _cons | 5.375 .2139134 25.13 0.000 4.936818 5.813182 ------------------------------------------------------------------------------ test o1 /* linear */ ( 1) o1 = 0.0 F( 1, 28) = 126.27 Prob > F = 0.0000 test o2 /* quadratic */ ( 1) o2 = 0.0 F( 1, 28) = 5.46 Prob > F = 0.0268 test o3 /* cubic */ ( 1) o3 = 0.0 F( 1, 28) = 1.09 Prob > F = 0.3048 test o2 o3 /* nonlinear */ ( 1) o2 = 0.0 ( 2) o3 = 0.0 F( 2, 28) = 3.28 Prob > F = 0.0526
Using anovalator
This time we will use the user written program anovalator with coefficients of orthogonal polynomials to perform the trend analsis. We can run either regress or anova so we will use the former. The z-vaalue from anovalator will be the same as the t-tvaues from the regression above.
regress y i.grp regress y i.grp Source | SS df MS Number of obs = 32 -------------+------------------------------ F( 3, 28) = 44.28 Model | 194.5 3 64.8333333 Prob > F = 0.0000 Residual | 41 28 1.46428571 R-squared = 0.8259 -------------+------------------------------ Adj R-squared = 0.8072 Total | 235.5 31 7.59677419 Root MSE = 1.2101 ------------------------------------------------------------------------------ y | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- grp | 2 | .75 .6050384 1.24 0.225 -.4893649 1.989365 3 | 3.5 .6050384 5.78 0.000 2.260635 4.739365 4 | 6.25 .6050384 10.33 0.000 5.010635 7.489365 | _cons | 2.75 .4278267 6.43 0.000 1.873637 3.626363 ------------------------------------------------------------------------------ /* linear trend */ anovalator grp, wgt(-3 -1 1 3) quietly anovalator contrast for grp ( 1) - 3*1bn.grp - 2.grp + 3.grp + 3*4.grp = 0 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- (1) | 21.5 1.913299 11.24 0.000 17.75 25.25 ------------------------------------------------------------------------------ /* quadratic trend */ anovalator grp, wgt(1 -1 -1 1) quietly anovalator contrast for grp ( 1) 1bn.grp - 2.grp - 3.grp + 4.grp = 0 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- (1) | 2 .8556535 2.34 0.019 .32295 3.67705 ------------------------------------------------------------------------------ /* cubic trend */ anovalator grp, wgt(-1 3 -3 1) quietly anovalator contrast for grp ( 1) - 1bn.grp + 3*2.grp - 3*3.grp + 4.grp = 0 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- (1) | -2 1.913299 -1.05 0.296 -5.749998 1.749998 ------------------------------------------------------------------------------Using orthpoly
One more try, this time using the orthpoly command.
orthpoly grp, gen(p*) deg(3) tab1 p* -> tabulation of p1 deg=1 orth. | poly. for | grp | Freq. Percent Cum. ------------+----------------------------------- -1.341641 | 8 25.00 25.00 -.4472136 | 8 25.00 50.00 .4472136 | 8 25.00 75.00 1.341641 | 8 25.00 100.00 ------------+----------------------------------- Total | 32 100.00 -> tabulation of p2 deg=2 orth. | poly. for | grp | Freq. Percent Cum. ------------+----------------------------------- -1 | 8 25.00 25.00 -1 | 8 25.00 50.00 1 | 8 25.00 75.00 1 | 8 25.00 100.00 ------------+----------------------------------- Total | 32 100.00 -> tabulation of p3 deg=3 orth. | poly. for | grp | Freq. Percent Cum. ------------+----------------------------------- -1.341641 | 8 25.00 25.00 -.4472136 | 8 25.00 50.00 .4472136 | 8 25.00 75.00 1.341641 | 8 25.00 100.00 ------------+----------------------------------- Total | 32 100.00 regress y p* Source | SS df MS Number of obs = 32 -------------+------------------------------ F( 3, 28) = 44.28 Model | 194.5 3 64.8333333 Prob > F = 0.0000 Residual | 41 28 1.46428571 R-squared = 0.8259 -------------+------------------------------ Adj R-squared = 0.8072 Total | 235.5 31 7.59677419 Root MSE = 1.2101 ------------------------------------------------------------------------------ y | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- p1 | 2.403773 .2139134 11.24 0.000 1.965591 2.841955 p2 | .5 .2139134 2.34 0.027 .0618183 .9381817 p3 | -.2236068 .2139134 -1.05 0.305 -.6617885 .2145749 _cons | 5.375 .2139134 25.13 0.000 4.936818 5.813182 ------------------------------------------------------------------------------
Linear Statistical Models Course
Phil Ender, 17sep10, 12Feb98