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.

Linear regression 269Extractor functions <strong>for</strong> lm()The lm () function is reticent, but we can coax out more in<strong>for</strong>mation as needed. This isdone using extractor functions. Useful ones are summarized in Table 10.1.These functions are called with the result of a modeling function, such as lm(). Thereare other types of modeling functions in R; these so-called “generic functions” may beused with them to return similar in<strong>for</strong>mation.To illustrate, the estimate <strong>for</strong> σ 2 can be found using the resid() function to retrieve theresiduals from the model fitting:> sum( resid(res.mhr)^2 ) / (length(age) − 2) #RSS/(n−2)[1] 14.15Or, the RSS part can be found directly with deviance ():Table 10.1 Extractor functions <strong>for</strong> the result of1m ()summary () returns summary in<strong>for</strong>mation about the regressionplot () makes diagnostic plotscoef() returns the coefficientsresiduals () returns the residuals (can be abbreviated resid())fitted ()returns the residualsdeviance() returns RSSpredict () per<strong>for</strong>ms predictionsanova () finds various sums of squaresAIC () is used <strong>for</strong> model selection> deviance(res.mhr)/ (length(age) −2)[1] 14.1510.1.5 Problems10.1 For the Cars93 (MASS) data set, answer the following:1. For MPG. highway modeled by Horsepower, find the simple regressioncoefficients. What is the predicted mileage <strong>for</strong> a car with 225 horsepower?2. Fit the linear model with MPG. highway modeled by Weight. Find the predictedhighway mileage of a 6,400 pound HUMMER H2 and a 2,524 pound MINI Cooper.3. Fit the linear model Max .Price modeled by Min .Price. Why might you expect theslope to be around 1 ?Can you think of any other linear relationships among the variables?

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

Saved successfully!

Ooh no, something went wrong!