crime1 <- read.table("c:/temp/crime1.txt",header=T) names(crime1) crime1.lm1 <- lm(R ~ Age +S +Ed +Ex0 +Ex1 +LF +M +N +NW +U1 +U2 +W +X, data=crime1) # from the car package library(car) summary(crime1.lm1) #Call: #lm(formula = R ~ Age + S + Ed + Ex0 + Ex1 + LF + M + N + NW + # U1 + U2 + W + X, data = crime1) #Residuals: # Min 1Q Median 3Q Max #-34.884 -11.923 -1.135 13.495 50.560 #Coefficients: # Estimate Std. Error t value Pr(>|t|) #(Intercept) -6.918e+02 1.559e+02 -4.438 9.56e-05 *** #Age 1.040e+00 4.227e-01 2.460 0.01931 * #S -8.308e+00 1.491e+01 -0.557 0.58117 #Ed 1.802e+00 6.496e-01 2.773 0.00906 ** #Ex0 1.608e+00 1.059e+00 1.519 0.13836 #Ex1 -6.673e-01 1.149e+00 -0.581 0.56529 #LF -4.103e-02 1.535e-01 -0.267 0.79087 #M 1.648e-01 2.099e-01 0.785 0.43806 #N -4.128e-02 1.295e-01 -0.319 0.75196 #NW 7.175e-03 6.387e-02 0.112 0.91124 #U1 -6.017e-01 4.372e-01 -1.376 0.17798 #U2 1.792e+00 8.561e-01 2.093 0.04407 * #W 1.374e-01 1.058e-01 1.298 0.20332 #X 7.929e-01 2.351e-01 3.373 0.00191 ** #--- #Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 #Residual standard error: 21.94 on 33 degrees of freedom #Multiple R-squared: 0.7692, Adjusted R-squared: 0.6783 #F-statistic: 8.462 on 13 and 33 DF, p-value: 3.686e-07 # the confidenceEllipse function used below is from the car package ageconflower <- summary(crime1.lm1)$coefficients["Age",1] +qt(.025,33)*summary(crime1.lm1)$coefficients["Age",2] ageconfupper <- summary(crime1.lm1)$coefficients["Age",1] -qt(.025,33)*summary(crime1.lm1)$coefficients["Age",2] LFconflower <- summary(crime1.lm1)$coefficients["LF",1] +qt(.025,33)*summary(crime1.lm1)$coefficients["LF",2] LFconfupper <- summary(crime1.lm1)$coefficients["LF",1] -qt(.025,33)*summary(crime1.lm1)$coefficients["LF",2] par(mfrow=c(2,1)) plot(crime1$Age,crime1$LF,main="Scatterplot of two variables") confidenceEllipse(model=crime1.lm1,which.coef=c(2,7),levels=.95, main="Confidence Ellipse (Red) and Confidence Intervals (Blue)") abline(v=ageconflower,col=4) abline(v=ageconfupper,col=4) abline(h=LFconflower,col=4) abline(h=LFconfupper,col=4) par(mfrow=c(1,1)) windows() Ex0conflower <- summary(crime1.lm1)$coefficients["Ex0",1] +qt(.025,33)*summary(crime1.lm1)$coefficients["Ex0",2] Ex0confupper <- summary(crime1.lm1)$coefficients["Ex0",1] -qt(.025,33)*summary(crime1.lm1)$coefficients["Ex0",2] Ex1conflower <- summary(crime1.lm1)$coefficients["Ex1",1] +qt(.025,33)*summary(crime1.lm1)$coefficients["Ex1",2] Ex1confupper <- summary(crime1.lm1)$coefficients["Ex1",1] -qt(.025,33)*summary(crime1.lm1)$coefficients["Ex1",2] par(mfrow=c(2,1)) plot(crime1$Ex0,crime1$Ex1,main="Scatterplot of two variables") confidenceEllipse(model=crime1.lm1,which.coef=c(5,6),levels=.95, main="Confidence Ellipse (Red) and Confidence Intervals (Blue)") abline(v=Ex0conflower,col=4) abline(v=Ex0confupper,col=4) abline(h=Ex1conflower,col=4) abline(h=Ex1confupper,col=4) par(mfrow=c(1,1))