### Feb. 9, 2009

> nels<-read.table("NELSsample.txt", header=T)

> head(nels)

HW.Hours StdMathScore

345 -0.3329931 42.432

759 -0.2136822 53.698

95 -1.0077991 49.205

325 0.2059000 53.698

355 -0.1177185 55.980

377 0.1413540 65.331

> attach(nels)

> model<-lm(StdMathScore~HW.Hours, data=nels)

> summary(model)

Call:

lm(formula = StdMathScore ~ HW.Hours, data = nels)

Residuals:

Min 1Q Median 3Q Max

-19.9886 -8.5163 -0.7377 8.2180 21.5530

Coefficients:

Estimate Std. Error t value Pr(>|t|)

(Intercept) 51.3947 0.7055 72.853 < 2e-16 ***

HW.Hours 1.7826 0.5811 3.068 0.00246 **

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 9.959 on 198 degrees of freedom

Multiple R-squared: 0.04538, Adjusted R-squared: 0.04055

F-statistic: 9.411 on 1 and 198 DF, p-value: 0.002458

Y-hat = 51.34 + 1.78(x)

H-not (intercept): Beta-not = 0

H-not (coefficient): Beta-sub-one = 0

From the above output we can tell that HW.Hours accounts for only about 5% of the variation in Math Score.

It also tell sus that our 95% margin of error is about +/- 19.92 (9.96*2) points.

BETA-hat-sub-one = 1.78

## Confidence interval for slope

We are saying that we used a method that works 95% of the time.

> confint(model)

2.5 % 97.5 %

(Intercept) 50.0035113 52.785848

HW.Hours 0.6367181 2.928483

Our interval estimate in this case is anywhere from .64 to 2.93

**Remember we have been talking about the confidence interval for the parameter.**

## Other confidence intervals in regression besides parameter estimates

If our end goal is to use the model to predict we probably are more interested in a conf. interval for the prediciton that we can make based on that model.

We can get a confidence interval for the predicted individual value or we can get the interval for the conditional mean (mean of all points at a particular measurement).

### predicting the conditional mean

mu-sub-X|Y

predict(modelName,interval="confidence")

> predict(model,interval="confidence")

fit lwr upr

345 50.80109 49.33697 52.26520

759 51.01377 49.58705 52.44049

95 49.59818 47.73843 51.45792

325 51.76172 50.36448 53.15895

...

> model.predictions<-predict(model,interval="confidence")

**Confidence Bands**

> library(NCStats)

Loading required package: car

Loading required package: gplots

Loading required package: gtools

Attaching package: 'gtools'

The following object(s) are masked from package:car :

logit

Loading required package: gdata

Attaching package: 'gplots'

The following object(s) are masked from package:stats :

lowess

Loading required package: Hmisc

Attaching package: 'Hmisc'

The following object(s) are masked from package:gdata :

combine,

reorder.factor

The following object(s) are masked from package:car :

recode

The following object(s) are masked from package:base :

format.pval,

round.POSIXt,

trunc.POSIXt,

units

Loading required package: multcomp

Loading required package: mvtnorm

Loading required package: nortest

Loading required package: sciplot

Loading required package: tcltk

Loading Tcl/Tk interface ... done

Loading required package: TeachingDemos

Attaching package: 'TeachingDemos'

The following object(s) are masked from package:Hmisc :

cnvrt.coords,

subplot

##########################################

## NCStats package by Derek H. Ogle ##

## type ?NCStats for documentation. ##

##########################################

Attaching package: 'NCStats'

The following object(s) are masked from package:stats :

print.anova

The following object(s) are masked from package:methods :

Summary

> help(prediciton.plot)

No documentation for 'prediciton.plot' in specified packages and libraries:

you could try '??prediciton.plot'

> help(prediction.plot)

> prediction.plot(model,interval="confidence",newdata=nels)

obs HW.Hours StdMathScore fit lwr upr

345 1 -0.332993081 42.432 50.80109 49.33697 52.26520

759 2 -0.213682155 53.698 51.01377 49.58705 52.44049

95 3 -1.007799147 49.205 49.59818 47.73843 51.45792

325 4 0.205899984 53.698 51.76172 50.36448 53.15895

...

>