10.07.2015 Views

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Linear regression 279Confidence intervalsWe can find a 95% confidence interval <strong>for</strong> β 0 withIn our example, this could be found with> n = length(age)> betahat0 = coef(res)[1] # first coefficient> sigmahat = sqrt( sum(resid(res)^2) / (n −2))> SE = sigmahat * sqrt(sum(age^2) / (n* sum( (age −mean(age))^2)))> tstar = qt(1 − 0.05/2,df= n − 2)> c(betahat0 − tstar*SE, betahat0 + tstar*SE)(Intercept) (Intercept)203.5 213.2Standard errorThe standard error above> SE[1] 2.357is given as part of the summary () function applied to the output of lm(). Find it in theCoefficients: part of the output under the column labeled Std. Error.> summary(res)Call:1m(<strong>for</strong>mula = mhr ~ age)Residuals:Min 1Q Median 3Q Max−9.21 −2.47 1.13 2.65 7.79Coefficients:Estimate Std. Error t value Pr(>|t|)(Intercept) 208.3613 2.3571 88.4 < 2e−16 ***age −0.7595 0.0561 −13.5 5.2e−13 ***…Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1‘ ’ 1Residual standard error: 3.76 on 25 degrees of freedomMultiple R-Squared: 0.88, Adjusted R-squared:0.875F-statistic: 183 on 1 and 25 DF, p-value: 5.15e-13By reading the standard error from this output, a 95% confidence interval <strong>for</strong> β 1 may bemore easily found than the one <strong>for</strong> β 0 above:> betahatl=−0.7595 # read from summary> SE=0.0561 # read from summary> tstar=qt(1–0.05/2,df= n−2)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!