MATH 376 -- Mathematical Statistics Example for Lab Class on 5/4 > x <- c(0,1,2,3,4,5,6) > y <- c(30.6,44.6,58.6,65.3,93.4,101.1,119.6) > reduced <- lm(y~x) > full <- lm(y~x + I(x^2)) > anova(full) Analysis of Variance Table Response: y Df Sum Sq Mean Sq F value Pr(>F) x 1 6145.0 6145.0 276.047 7.687e-05 *** I(x^2) 1 13.6 13.6 0.611 0.4781 Residuals 4 89.0 22.3 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > anova(reduced) Analysis of Variance Table Response: y Df Sum Sq Mean Sq F value Pr(>F) x 1 6145.0 6145.0 299.34 1.182e-05 *** Residuals 5 102.6 20.5 ################################################################## # # "By Hand" # ################################################################## > SSEC <- 89.0 > SSER <- 102.6 > n <- 7 > k <- 2 > g <- 1 > Fstat <- ((SSER - SSEC)/(k-g))/(SSEC/(n - k - 1)) > Fstat [1] 0.611236 > 1 - pf(Fstat,1,4) [1] 0.4780113 ################################################################### # # by R # ################################################################### > anova(reduced,full) Analysis of Variance Table Model 1: y ~ x Model 2: y ~ x + I(x^2) Res.Df RSS Df Sum of Sq F Pr(>F) 1 5 102.643 2 4 89.042 1 13.601 0.611 0.4781 #################################################################### # # Why? # #################################################################### > summary(full) Call: lm(formula = y ~ x + I(x^2)) Residuals: 1 2 3 4 5 6 7 -0.2833 0.9143 1.3071 -6.4048 6.4786 -1.8429 -0.1690 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 30.8833 4.1183 7.499 0.00169 ** x 12.4000 3.2149 3.857 0.01819 * I(x^2) 0.4024 0.5148 0.782 0.47810 <------------- ????? --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 4.718 on 4 degrees of freedom Multiple R-squared: 0.9857, Adjusted R-squared: 0.9786 F-statistic: 138.3 on 2 and 4 DF, p-value: 0.0002031