#################################################### > Simple Linear Regression > > fit<-lm(Final~Exam1) > attributes(fit) $names [1] "coefficients" "residuals" "effects" "rank" [5] "fitted.values" "assign" "qr" "df.residual" [9] "xlevels" "call" "terms" "model" $class [1] "lm" > fit Call: lm(formula = Final ~ Exam1) Coefficients: (Intercept) Exam1 60.9026 0.9761 > summary(fit) Call: lm(formula = Final ~ Exam1) Residuals: Min 1Q Median 3Q Max -80.586 -13.634 1.223 15.076 32.485 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 60.9026 14.8897 4.090 0.000168 *** Exam1 0.9761 0.1807 5.401 2.14e-06 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 22.02 on 47 degrees of freedom Multiple R-squared: 0.383, Adjusted R-squared: 0.3699 F-statistic: 29.17 on 1 and 47 DF, p-value: 2.141e-06 > anova(fit) Analysis of Variance Table Response: Final Df Sum Sq Mean Sq F value Pr(>F) Exam1 1 14143.7 14143.7 29.173 2.141e-06 *** Residuals 47 22786.5 484.8 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > confint(fit) # Confidence Intervals 2.5 % 97.5 % (Intercept) 30.9483634 90.856852 Exam1 0.6125545 1.339687 > ?confint > confint(fit, level=.90) 5 % 95 % (Intercept) 35.918756 85.886459 Exam1 0.672882 1.279359 > ############################################################# > plot(Exam1,Final) > abline(fit) # Or abline(60.9026, .9761) > > # Residual plot > plot(Exam1, fit$residuals) > > # Add a reference line > abline(0,0) > # Confidence intervals for predicted values > predict.lm(fit,interval="confidence") fit lwr upr 1 151.68183 143.89753 159.4661 2 153.63407 145.40505 161.8631 3 122.39821 113.41683 131.3796 4 150.70571 143.12738 158.2840 5 158.51468 149.02010 168.0093 6 156.56243 147.59684 165.5280 7 144.84899 138.21595 151.4820 8 158.51468 149.02010 168.0093 9 153.63407 145.40505 161.8631 10 130.20718 122.99265 137.4217 11 123.37433 114.64720 132.1015 12 150.70571 143.12738 158.2840 13 109.70864 96.93167 122.4856 14 123.37433 114.64720 132.1015 15 103.85192 89.14016 118.5637 16 157.53856 148.31184 166.7653 17 127.27881 119.48153 135.0761 18 155.58631 146.87449 164.2981 19 138.99226 132.66136 145.3232 20 144.84899 138.21595 151.4820 21 141.92062 135.52929 148.3120 22 137.04002 130.64552 143.4345 23 142.89675 136.44429 149.3492 24 145.82511 139.07416 152.5761 25 124.35045 115.86959 132.8313 26 148.75347 141.54961 155.9573 27 135.08778 128.54895 141.6266 28 136.06390 129.60706 142.5207 29 147.77735 140.73998 154.8147 30 136.06390 129.60706 142.5207 31 138.01614 131.66376 144.3685 32 151.68183 143.89753 159.4661 33 154.61019 146.14413 163.0763 34 155.58631 146.87449 164.2981 35 135.08778 128.54895 141.6266 36 93.11459 74.71188 111.5173 37 153.63407 145.40505 161.8631 38 141.92062 135.52929 148.3120 39 147.77735 140.73998 154.8147 40 130.20718 122.99265 137.4217 41 94.09071 76.02897 112.1525 42 152.65795 144.65646 160.6594 43 154.61019 146.14413 163.0763 44 139.96838 133.63812 146.2986 45 100.92356 85.22014 116.6270 46 146.80123 139.91518 153.6873 47 122.39821 113.41683 131.3796 48 157.53856 148.31184 166.7653 49 153.63407 145.40505 161.8631 > To estimate expected values of new observations > predict.lm(fit,newdata=data.frame(Exam1=c(55, 95)),interval="confidence") fit lwr upr 1 114.5892 103.3554 125.8231 2 153.6341 145.4050 161.8631 > ######################################################################### > # Multiple Linear Regression > > fit<-lm(Final~Exam1+Exam2) > fit Call: lm(formula = Final ~ Exam1 + Exam2) Coefficients: (Intercept) Exam1 Exam2 17.8765 0.7800 0.6494 > summary(fit) Call: lm(formula = Final ~ Exam1 + Exam2) Residuals: Min 1Q Median 3Q Max -83.48 -10.57 4.80 16.05 31.48 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 17.8765 27.7671 0.644 0.522902 Exam1 0.7800 0.2068 3.772 0.000462 *** Exam2 0.6494 0.3571 1.819 0.075472 . --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 21.5 on 46 degrees of freedom Multiple R-squared: 0.4244, Adjusted R-squared: 0.3993 F-statistic: 16.96 on 2 and 46 DF, p-value: 3.042e-06 > anova(fit) Analysis of Variance Table Response: Final Df Sum Sq Mean Sq F value Pr(>F) Exam1 1 14143.7 14143.7 30.6056 1.446e-06 *** Exam2 1 1528.6 1528.6 3.3076 0.07547 . Residuals 46 21258.0 462.1 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > > confint(fit) # the default is a 95% confidence level 2.5 % 97.5 % (Intercept) -38.01587470 73.768866 Exam1 0.36372682 1.196230 Exam2 -0.06934886 1.368248