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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Using</strong> R <strong>for</strong> introductory statistics 280> c(betahatl—tstar*SE, betahatl+tstar*SE)[1] −0.875 −0.644Significance testsThe summary () function returns more than the standard errors. For each coefficient amarginal t-test is per<strong>for</strong>med. This is a two-sided hypothesis test of the null hypothesisthat β i =0 against the alternative that β i ≠0. We see in this case that both are rejected withvery low p-values. These small p-values are flagged in the output of summary () withsignificance stars.Other t-tests are possible. For example, we can test the null hypothesis that the slope is−1 with the commands> T.obs=(betahatl—(−1))/SE> T.obs[1] 4.287> 2*pt(−4.287,df=n−2) # or uselower.tail=F with 4.287[1] 0.0002364This is a small p-value, indicating that the model with slope −1 is unlikely to haveproduced this data or anything more extreme than it.Finding R 2The estimate <strong>for</strong> is marked Residual standard error and is labeled with 25=21−2degrees of freedom. The value of R 2 =cor (age ,mhr) ^2 is given along with an adjustedvalue.F-test <strong>for</strong> β 1 =0.Finally, the F-statistic is calculated. As this is given bydirectly withit can be found> (−0.7595 / 0.0561)^2[1] 183.3The significance test H 0 : β 1 =0 with two-sided alternative is per<strong>for</strong>med and again returns atiny p-value.The sum of squares to compute F are also given as the output of the ano va () extractorfunction.> anova(res)Analysis of Variance TableResponse: mhrDf Sum Sq Mean Sq F value Pr(>F)age 1 2596 2596 183 5.2e-13 ***Residuals 25 354 14--

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

Saved successfully!

Ooh no, something went wrong!