R version 2.9.2 (2009-08-24)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

>
> # Read in new data
>
> supervisor.table <- read.table('http://www-stat.stanford.edu/~jtaylo/courses/stats191/data/supervisor.table', header=T)
> attach(supervisor.table)
>

>
> pairs(supervisor.table, pch=23, bg='orange', cex.labels=6, cex=2)
>
> # Fit multiple regression model
>
>
>

>


> supervisor.lm <- lm(Y ~ X1 + X2 + X3 + X4 + X5 + X6)
> print(summary(supervisor.lm))

Call:
lm(formula = Y ~ X1 + X2 + X3 + X4 + X5 + X6)

Residuals:
Min 1Q Median 3Q Max
-10.9418 -4.3555 0.3158 5.5425 11.5990

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 10.78708 11.58926 0.931 0.361634
X1 0.61319 0.16098 3.809 0.000903 ***
X2 -0.07305 0.13572 -0.538 0.595594
X3 0.32033 0.16852 1.901 0.069925 .
X4 0.08173 0.22148 0.369 0.715480
X5 0.03838 0.14700 0.261 0.796334
X6 -0.21706 0.17821 -1.218 0.235577
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 7.068 on 23 degrees of freedom
Multiple R-squared: 0.7326, Adjusted R-squared: 0.6628
F-statistic: 10.5 on 6 and 23 DF, p-value: 1.240e-05

>
> # Confidence intervals for the coefficients
>
> print(confint(supervisor.lm))
2.5 % 97.5 %
(Intercept) -13.18712881 34.7612816
X1 0.28016866 0.9462066
X2 -0.35381806 0.2077178
X3 -0.02827872 0.6689430
X4 -0.37642935 0.5398936
X5 -0.26570179 0.3424647
X6 -0.58571106 0.1515977
>
> # Confidence intervals for the regression function
>
> print(predict(supervisor.lm, list(X1=60, X2=50, X3=55, X4=65, X5=75, X6=40), interval='confidence'))
fit lwr upr
1 61.05302 57.3486 64.75744
> print(predict(supervisor.lm, list(X1=60, X2=50, X3=55, X4=65, X5=75, X6=40), interval='prediction'))
fit lwr upr
1 61.05302 45.96979 76.13626
>
> # Adjusted R^2
>
> SST <- sum((Y - mean(Y))^2)
> MST <- SST / (length(Y) - 1)
> SSE <- sum(resid(supervisor.lm)^2)
> MSE <- SSE / supervisor.lm$df.residual
>
>
> R2 <- 1 - SSE/SST
> R2.adj <- 1 - MSE / MST
>
> print(data.frame(R2,R2.adj))
R2 R2.adj
1 0.732602 0.662846
>
>

>
> proc.time()
user system elapsed
0.792 0.040 1.092
R script