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.

>
> heights.table <- read.table('http://www-stat.stanford.edu/~jtaylo/courses/stats191/data/heights.table', header=T, sep=',')
> attach(heights.table)
>
>

>
> wife.lm <- lm(WIFE ~ HUSBAND)
>
> # Compute coefficients by hand to make sure they agree
>
> beta.1.hat <- cov(HUSBAND, WIFE) / var(HUSBAND)
> beta.0.hat <- mean(WIFE) - beta.1.hat * mean(HUSBAND)
> print(c(beta.1.hat, beta.0.hat))
[1] 0.6959256 42.5487122
>
> # Estimate sigma squared -- df.resid are degrees of freedom
>
> sigma.hat <- sqrt(sum(resid(wife.lm)^2) / wife.lm$df.resid)
> print(sigma.hat)
[1] 5.951824
>
>
> print(summary(wife.lm))

Call:
lm(formula = WIFE ~ HUSBAND)

Residuals:
Min 1Q Median 3Q Max
-19.4235 -3.9438 0.8399 4.0123 11.1439

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 42.54871 10.77592 3.949 0.000153 ***
HUSBAND 0.69593 0.06176 11.268 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 5.952 on 93 degrees of freedom
Multiple R-squared: 0.5772, Adjusted R-squared: 0.5727
F-statistic: 127 on 1 and 93 DF, p-value: < 2.2e-16

> # find where beta.0.hat, beta.1.hat and
> # sigma.hat appear
>
> SSE = sum(resid(wife.lm)^2)
> SSR = sum((predict(wife.lm) - mean(WIFE))^2)
> SST = sum((WIFE-mean(WIFE)^2))
> print(c(SST, SSE+SSR))
[1] -2532677.642 7792.358
>
> F = (SSR / 1) / (SSE / 93)
> df.num = 1
> df.den = 93
> p.value = 1 - pf(F, df.num, df.den)
> print(data.frame(df.num, df.den, F, p.value))
df.num df.den F p.value
1 1 93 126.9727 0
>
>

>
> proc.time()
user system elapsed
0.552 0.052 0.729
R script