Я сделал две модели, объясняющие вес растения при четырех различных обработках с течением времени. В одной модели допускаются различия между перехватами:
ancova <- lm(weight ~ time + treatment)
, а в другой также допускаются различия в наклонах:
mod5 <- lm(weight ~ time + treatment + treatment:time)
при проверке, значительно ли отличаются эти модели друг от друга с помощью Команда anova:
anova(ancova, mod5)
Analysis of Variance Table
Model 1: weight ~ time + treatment
Model 2: weight ~ time + treatment + treatment:time
Res.Df RSS Df Sum of Sq F Pr(>F)
1 115 10392.0
2 112 9873.2 3 518.8 1.9617 0.1238
>
Никаких существенных различий между моделями не обнаружено.
Однако, скажем, я хочу предсказать вес при лечении B во время == 7 для обеих моделей, я получаю очень разные результаты (если я все правильно понимаю).
Different slopes Treatment B: y= 8.2*7 - 37.58 = 19.82
Different slopes and intercepts Treatment B: y= (1.31 + 3.80)7 - 27.18 = 8.59
Сводные таблицы для обеих моделей:
Ancova:
Call:
lm(formula = weight ~ time + treatment, data = df)
Residuals:
Min 1Q Median 3Q Max
-21.952 -7.674 0.770 6.851 21.514
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -37.5790 3.2897 -11.423 < 2e-16 ***
time 4.7478 0.2541 18.688 < 2e-16 ***
treatmentB 8.2000 2.4545 3.341 0.00113 **
treatmentC 5.4633 2.4545 2.226 0.02797 *
treatmentD 20.3533 2.4545 8.292 2.36e-13 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 9.506 on 115 degrees of freedom
Multiple R-squared: 0.7862, Adjusted R-squared: 0.7788
F-statistic: 105.7 on 4 and 115 DF, p-value: < 2.2e-16
mod5
Call:
lm(formula = weight ~ time + treatment + treatment:time, data = df)
Residuals:
Min 1Q Median 3Q Max
-21.281 -7.665 1.611 6.314 26.242
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -27.1785 5.7805 -4.702 7.4e-06 ***
time 3.8023 0.5019 7.576 1.1e-11 ***
treatmentB -6.1629 8.1749 -0.754 0.4525
treatmentC -3.9872 8.1749 -0.488 0.6267
treatmentD 2.5648 8.1749 0.314 0.7543
time:treatmentB 1.3057 0.7097 1.840 0.0685 .
time:treatmentC 0.8591 0.7097 1.210 0.2286
time:treatmentD 1.6171 0.7097 2.278 0.0246 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 9.389 on 112 degrees of freedom
Multiple R-squared: 0.7969, Adjusted R-squared: 0.7842
F-statistic: 62.78 on 7 and 112 DF, p-value: < 2.2e-16
заголовок данных:
treatment replicate time weight
1 A 1 6 2.0
2 A 2 6 0.0
3 A 3 6 0.0
4 A 4 6 0.0
5 A 5 6 0.5
6 B 1 6 2.6
Может кто-нибудь объяснить мне, откуда эти различия, или указать, где я испортил формулу?