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)
>
> # original regression model
>
> supervisor.lm <- lm(Y ~ X1 + X2 + X3 + X4 + X5 + X6)
> reduced.lm <- lm(Y ~ X1 + X4 + X5 + X6)
>
> # A function to do "nested" F-tests
>
> f.test.lm <- function(R.lm, F.lm) {
+ SSE.R <- sum(resid(R.lm)^2)
+ SSE.F <- sum(resid(F.lm)^2)
+ df.num <- R.lm$df - F.lm$df
+ df.den <- F.lm$df
+ F <- ((SSE.R - SSE.F) / df.num) / (SSE.F / df.den)
+ p.value <- 1 - pf(F, df.num, df.den)
+ return(data.frame(F, df.num, df.den, p.value))
+ }
>
> print(f.test.lm(reduced.lm, supervisor.lm))
F df.num df.den p.value
1 1.846191 2 23 0.1804745
>
> # R has another way to do this
>
> print(anova(reduced.lm, supervisor.lm))
Analysis of Variance Table

Model 1: Y ~ X1 + X4 + X5 + X6
Model 2: Y ~ X1 + X2 + X3 + X4 + X5 + X6
Res.Df RSS Df Sum of Sq F Pr(>F)
1 25 1333.46
2 23 1149.00 2 184.46 1.8462 0.1805
>
> # the models should be "nested"
> # that is, modelR should be a special case of modelF
> # R can recognize this for you (at least sometimes)
>
> print(anova(lm(Y ~ X1 + X3), lm(Y ~ X2 + X4)))
Analysis of Variance Table

Model 1: Y ~ X1 + X3
Model 2: Y ~ X2 + X4
Res.Df RSS Df Sum of Sq F Pr(>F)
1 27 1254.7
2 27 2657.7 0 -1403.0
>
>
>

>
> proc.time()
user system elapsed
0.588 0.028 0.623
R script