(a)
optics<-read.csv("optics_dat.csv")
colnames(optics)<-c("ID","OptPost","InstType","gender","reading","science","OptPre","Attendance","IEP" )
head(optics)
## ID OptPost InstType gender reading science OptPre Attendance IEP
## 1 4 50 1 0 368 339 50 14 0
## 2 5 67 1 0 372 389 50 11 0
## 3 6 61 1 0 360 380 30 13 0
## 4 8 92 1 0 378 380 67 12 0
## 5 12 59 1 1 385 365 42 15 0
## 6 13 16 1 1 382 373 8 9 0
optics.fit<-lm(OptPost ~ as.factor(InstType) + OptPre + Attendance, data =optics)
summary(optics.fit)
##
## Call:
## lm(formula = OptPost ~ as.factor(InstType) + OptPre + Attendance,
## data = optics)
##
## Residuals:
## Min 1Q Median 3Q Max
## -24.550 -8.332 1.168 7.185 27.970
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 12.8172 9.1042 1.408 0.1685
## as.factor(InstType)1 7.4704 5.0156 1.489 0.1459
## OptPre 0.5377 0.1197 4.493 8.14e-05 ***
## Attendance 1.7734 0.7540 2.352 0.0248 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.07 on 33 degrees of freedom
## Multiple R-squared: 0.5258, Adjusted R-squared: 0.4827
## F-statistic: 12.2 on 3 and 33 DF, p-value: 1.569e-05
(b)
library(car)
## Loading required package: carData
#Residual plots
residualPlots(model = optics.fit, id.n = 4)

## Test stat Pr(>|Test stat|)
## as.factor(InstType)
## OptPre 0.2738 0.7860
## Attendance 0.9401 0.3542
## Tukey test -0.0755 0.9398
#Dfbeta
dfbetasPlots(model = optics.fit, id.n = 4, ylim = c(-1,1)*1.5)

#Influence
influenceIndexPlot(model = optics.fit, id.n = 4)

influencePlot(model = optics.fit, id.n = 4)

## StudRes Hat CookD
## 6 -2.1588756 0.15877357 0.1979580651
## 14 0.1084064 0.23849058 0.0009485288
## 15 2.3917300 0.08464414 0.1156935674
## 36 0.2497088 0.20164174 0.0040523689
#Leverage
leveragePlots(model = optics.fit, id.n = 4)
