. * do-file for lecture 8 of VHM 802 . version 14 /* works also with version 13 */ . set more off . cd "h:\vhm\vhm802\data_csv" h:\vhm\vhm802\data_csv . . * Example 13.1 . import delimited ch13ta1.csv, clear (4 vars, 15 obs) . anova change tx plant Number of obs = 15 R-squared = 0.8875 Root MSE = 4.21011 Adj R-squared = 0.8031 Source | Partial SS df MS F Prob>F -----------+---------------------------------------------------- Model | 1118.4333 6 186.40556 10.52 0.0020 | tx | 432.03333 2 216.01667 12.19 0.0037 plant | 686.4 4 171.6 9.68 0.0037 | Residual | 141.8 8 17.725 -----------+---------------------------------------------------- Total | 1260.2333 14 90.016667 . margins tx Predictive margins Number of obs = 15 Expression : Linear prediction, predict() ------------------------------------------------------------------------------ | Delta-method | Margin Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- tx | 1 | 4.3 1.882817 2.28 0.052 -.0417839 8.641784 2 | 5.9 1.882817 3.13 0.014 1.558216 10.24178 3 | 16.4 1.882817 8.71 0.000 12.05822 20.74178 ------------------------------------------------------------------------------ . pwcompare tx, pv mcomp(bon) Pairwise comparisons of marginal linear predictions Margins : asbalanced --------------------------- | Number of | Comparisons -------------+------------- tx | 3 --------------------------- ----------------------------------------------------- | Bonferroni | Contrast Std. Err. t P>|t| -------------+--------------------------------------- tx | 2 vs 1 | 1.6 2.662705 0.60 1.000 3 vs 1 | 12.1 2.662705 4.54 0.006 3 vs 2 | 10.5 2.662705 3.94 0.013 ----------------------------------------------------- . . * Mangold example . import delimited mangold.csv, clear (4 vars, 25 obs) . encode tx, gen(Tx) /* needed because tx has character values */ . anova yield row col Tx Number of obs = 25 R-squared = 0.7503 Root MSE = 12.091 Adj R-squared = 0.5007 Source | Partial SS df MS F Prob>F -----------+---------------------------------------------------- Model | 5272.32 12 439.36 3.01 0.0341 | row | 4240.24 4 1060.06 7.25 0.0033 col | 701.84 4 175.46 1.20 0.3604 Tx | 330.24 4 82.56 0.56 0.6930 | Residual | 1754.32 12 146.19333 -----------+---------------------------------------------------- Total | 7026.64 24 292.77667 . margins Tx, asbalanced /* asbalanced actually not needed here */ Adjusted predictions Number of obs = 25 Expression : Linear prediction, predict() at : row (asbalanced) col (asbalanced) Tx (asbalanced) ------------------------------------------------------------------------------ | Delta-method | Margin Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- Tx | A | 333.6 5.407279 61.69 0.000 321.8186 345.3814 B | 331.2 5.407279 61.25 0.000 319.4186 342.9814 C | 334.4 5.407279 61.84 0.000 322.6186 346.1814 D | 342 5.407279 63.25 0.000 330.2186 353.7814 E | 334.4 5.407279 61.84 0.000 322.6186 346.1814 ------------------------------------------------------------------------------ . lincom 4*4.Tx-1.Tx-2.Tx-3.Tx-5.Tx ( 1) - 1b.Tx - 2.Tx - 3.Tx + 4*4.Tx - 5.Tx = 0 ------------------------------------------------------------------------------ yield | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- (1) | 34.4 24.18209 1.42 0.180 -18.28824 87.08824 ------------------------------------------------------------------------------ . di 146.193333*(34.4/24.18209)^2 /* SS for contrast */ 295.83993 . . * Example 14.2 . import delimited ch14ta1.csv, clear (4 vars, 36 obs) . anova plates session tx Number of obs = 36 R-squared = 0.9913 Root MSE = .907785 Adj R-squared = 0.9809 Source | Partial SS df MS F Prob>F -----------+---------------------------------------------------- Model | 1499.5648 19 78.924464 95.77 0.0000 | session | 10.064815 11 .91498316 1.11 0.4127 tx | 1086.8148 8 135.85185 164.85 0.0000 | Residual | 13.185185 16 .82407407 -----------+---------------------------------------------------- Total | 1512.75 35 43.221429 . anova plates session tx, sequential Number of obs = 36 R-squared = 0.9913 Root MSE = .907785 Adj R-squared = 0.9809 Source | Seq. SS df MS F Prob>F -----------+---------------------------------------------------- Model | 1499.5648 19 78.924464 95.77 0.0000 | session | 412.75 11 37.522727 45.53 0.0000 tx | 1086.8148 8 135.85185 164.85 0.0000 | Residual | 13.185185 16 .82407407 -----------+---------------------------------------------------- Total | 1512.75 35 43.221429 . table tx, contents(mean plates) /* simple means */ ------------------------ tx | mean(plates) ----------+------------- 1 | 19.75 2 | 16.75 3 | 13.25 4 | 6.5 5 | 25.5 6 | 23.25 7 | 20.75 8 | 19.25 9 | 29.75 ------------------------ . margins tx, asbalanced /* asbalanced not needed here either */ Adjusted predictions Number of obs = 36 Expression : Linear prediction, predict() at : session (asbalanced) tx (asbalanced) ------------------------------------------------------------------------------ | Delta-method | Margin Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- tx | 1 | 19.75 .5167795 38.22 0.000 18.65448 20.84552 2 | 17.19444 .5167795 33.27 0.000 16.09892 18.28997 3 | 13.19444 .5167795 25.53 0.000 12.09892 14.28997 4 | 6.527778 .5167795 12.63 0.000 5.432254 7.623301 5 | 25.30556 .5167795 48.97 0.000 24.21003 26.40108 6 | 22.97222 .5167795 44.45 0.000 21.8767 24.06775 7 | 21.08333 .5167795 40.80 0.000 19.98781 22.17886 8 | 19.19444 .5167795 37.14 0.000 18.09892 20.28997 9 | 29.52778 .5167795 57.14 0.000 28.43225 30.6233 ------------------------------------------------------------------------------ . margins, over(tx) /* simple means */ Predictive margins Number of obs = 36 Expression : Linear prediction, predict() over : tx ------------------------------------------------------------------------------ | Delta-method | Margin Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- tx | 1 | 19.75 .4538926 43.51 0.000 18.78779 20.71221 2 | 16.75 .4538926 36.90 0.000 15.78779 17.71221 3 | 13.25 .4538926 29.19 0.000 12.28779 14.21221 4 | 6.5 .4538926 14.32 0.000 5.537791 7.462209 5 | 25.5 .4538926 56.18 0.000 24.53779 26.46221 6 | 23.25 .4538926 51.22 0.000 22.28779 24.21221 7 | 20.75 .4538926 45.72 0.000 19.78779 21.71221 8 | 19.25 .4538926 42.41 0.000 18.28779 20.21221 9 | 29.75 .4538926 65.54 0.000 28.78779 30.71221 ------------------------------------------------------------------------------ . margins, over(tx) asbalanced /* least squares means */ Adjusted predictions Number of obs = 36 Expression : Linear prediction, predict() over : tx at : 1.tx session (asbalanced) tx (asbalanced) 2.tx session (asbalanced) tx (asbalanced) 3.tx session (asbalanced) tx (asbalanced) 4.tx session (asbalanced) tx (asbalanced) 5.tx session (asbalanced) tx (asbalanced) 6.tx session (asbalanced) tx (asbalanced) 7.tx session (asbalanced) tx (asbalanced) 8.tx session (asbalanced) tx (asbalanced) 9.tx session (asbalanced) tx (asbalanced) ------------------------------------------------------------------------------ | Delta-method | Margin Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- tx | 1 | 19.75 .5167795 38.22 0.000 18.65448 20.84552 2 | 17.19444 .5167795 33.27 0.000 16.09892 18.28997 3 | 13.19444 .5167795 25.53 0.000 12.09892 14.28997 4 | 6.527778 .5167795 12.63 0.000 5.432254 7.623301 5 | 25.30556 .5167795 48.97 0.000 24.21003 26.40108 6 | 22.97222 .5167795 44.45 0.000 21.8767 24.06775 7 | 21.08333 .5167795 40.80 0.000 19.98781 22.17886 8 | 19.19444 .5167795 37.14 0.000 18.09892 20.28997 9 | 29.52778 .5167795 57.14 0.000 28.43225 30.6233 ------------------------------------------------------------------------------ . * same contrasts as in GO . lincom 1.tx+2.tx+3.tx+4.tx+5.tx+6.tx+7.tx+8.tx-8*9.tx ( 1) 1b.tx + 2.tx + 3.tx + 4.tx + 5.tx + 6.tx + 7.tx + 8.tx - 8*9.tx = 0 ------------------------------------------------------------------------------ plates | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- (1) | -91 4.447221 -20.46 0.000 -100.4277 -81.57231 ------------------------------------------------------------------------------ . lincom 1.tx+2.tx+3.tx+4.tx-5.tx-6.tx-7.tx-8.tx ( 1) 1b.tx + 2.tx + 3.tx + 4.tx - 5.tx - 6.tx - 7.tx - 8.tx = 0 ------------------------------------------------------------------------------ plates | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- (1) | -31.88889 1.482407 -21.51 0.000 -35.03145 -28.74633 ------------------------------------------------------------------------------ . lincom -3*1.tx-2.tx+3.tx+3*4.tx-3*5.tx-6.tx+7.tx+3*8.tx ( 1) - 3*1b.tx - 2.tx + 3.tx + 3*4.tx - 3*5.tx - 6.tx + 7.tx + 3*8.tx = 0 ------------------------------------------------------------------------------ plates | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- (1) | -63.88889 3.314763 -19.27 0.000 -70.91587 -56.86191 ------------------------------------------------------------------------------ . . * reload Mangold data . import delimited mangold.csv, clear (4 vars, 25 obs) . drop if col==5 /* subdataset for Youden square */ (5 observations deleted) . encode tx, gen(Tx) . anova yield row col Tx Number of obs = 20 R-squared = 0.7964 Root MSE = 12.4332 Adj R-squared = 0.5165 Source | Partial SS df MS F Prob>F -----------+---------------------------------------------------- Model | 4838.2833 11 439.84394 2.85 0.0742 | row | 4220.1333 4 1055.0333 6.83 0.0108 col | 366.95 3 122.31667 0.79 0.5320 Tx | 224.13333 4 56.033333 0.36 0.8289 | Residual | 1236.6667 8 154.58333 -----------+---------------------------------------------------- Total | 6074.95 19 319.73421 . margins Tx, asbalanced /* asbalanced not needed here either */ Adjusted predictions Number of obs = 20 Expression : Linear prediction, predict() at : row (asbalanced) col (asbalanced) Tx (asbalanced) ------------------------------------------------------------------------------ | Delta-method | Margin Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- Tx | A | 340.35 6.380199 53.34 0.000 325.6372 355.0628 B | 333.55 6.380199 52.28 0.000 318.8372 348.2628 C | 334.75 6.380199 52.47 0.000 320.0372 349.4628 D | 341.8833 6.380199 53.59 0.000 327.1706 356.5961 E | 334.2167 6.380199 52.38 0.000 319.5039 348.9294 ------------------------------------------------------------------------------ .