### Transcription of Computing Primer for Applied Linear Regression, 4th ...

1 **Computing** **Primer** for AppliedLinear **regression** , 4th Edition,Using RVersion of October 27, 2014 Sanford WeisbergSchool of StatisticsUniversity of MinnesotaMinneapolis, Minnesota 55455 Copyrightc 2014, Sanford WeisbergThisPrimeris best viewed using a pdf viewer such as Adobe Reader with bookmarks showing atthe left, and in single page view, selected byView Page Display Single Page cite this **Primer** , use:Weisberg, S. (2014). **Computing** **Primer** for **Applied** **Linear** **regression** , 4th Edition, UsingR. Online, GettingRand Getting Started .. Packages You Will Need .. Using This **Primer** .. If You Are New toR.. Getting Help .. The Very Basics .. a Data File .. Your Own Data intoR.. Excel Files .. Text and Graphs .. ,F,tand 2tables .. xiviCONTENTSii1 Scatterplots and Scatterplots.

2 Summary Graph .. Tools for Looking at Scatterplots .. Scatterplot Matrices .. Problems ..82 Simple **Linear** Least Squares Criterion .. Estimating the Variance 2.. Estimated Variances .. Confidence Intervals andt-Tests .. The Coefficient of Determination,R2.. The Residuals .. Problems ..203 Multiple Adding a Term to a Simple **Linear** **regression** Model .. Variability .. Plots .. The Multiple **Linear** **regression** Model .. Regressors and Predictors .. Ordinary Least Squares .. Predictions, Fitted Values and **Linear** Combinations .. Problems ..314 Interpretation of Main Understanding Parameter Estimates .. of Change .. Depends on Other Terms in the Mean Function .. in Logarithmic Scale .. Problems ..385 Complex Factors.

3 Models .. a Continuous Predictor .. Main Effects Model .. Polynomial **regression** .. with Several Predictors .. Splines .. Principal Components .. Missing Data ..526 Testing and Analysis of TheanovaFunction .. TheAnovaFunction .. ThelinearHypothesisFunction .. Comparisons of Means .. Power .. Simulating Power ..697 Weighted Least Squares .. Misspecified Variances .. Misspecified Variance .. Test for Constant Variance .. General Correlation Structures .. Mixed Models .. The Delta Method .. The Bootstrap ..778 Transformation Basics .. Transformations .. Only the Predictor Variable .. One Predictor Variable .. A General Approach to Transformations .. the Response .. Transformations of Nonpositive Variables.

4 Additive Models .. Problems ..869 **regression** The Residuals .. Hat Matrix .. and the Hat Matrix with Weights .. Testing for Curvature .. Nonconstant Variance .. Outliers .. Influence of Cases .. Normality Assumption ..9810 Variable Variable Selection and Parameter Assessment .. Variable Selection for Discovery .. Information Criteria .. Stepwise **regression** .. Regularized Methods .. Model Selection for Prediction .. Cross Validation .. Problems .. 10411 Nonlinear Estimation for Nonlinear Mean Functions .. Starting Values .. Bootstrap Inference .. 11212 Binomial and Poisson Binomial **regression** .. Poisson **regression** .. 124A Estimating E(Y|X) Using a Smoother .. A Brief Introduction to Matrices and Vectors.

5 The QR Factorization .. Spectral Decomposition .. 131 CHAPTER0 IntroductionThis computer **Primer** supplementsApplied **Linear** **regression** , 4th Edition(Weisberg, 2014), abbrevi-atedalrthought this **Primer** . The expectation is that you will read the book and then consult thisprimer to see how to apply what you have learned **Primer** often refers to specific problems or sections inalrusing notation likealr[ ]oralr[ ], for a reference to Section or Appendix ,alr[ ]for Problem ,alr[ ]forFigure ,alr[ ]for an equation andalr[ ]for a table. The section numbers in the primercorrespond to section numbers inalr. An index ofRfunctions and packages is included at the end ofthe 0. GettingRand Getting StartedIf you don t already haveR, go to the website for the follow the directions Packages You Will NeedWhen you installRyou get the basic program and a common set of packages that give the programadditional functionality.

6 Three additional packages not in the basic distribution are used extensivelyinalr:alr4, which contains all the data used inalrin both text and homework problems,car, acomprehensive set of functions added toRto do almost everything inalrthat is not part of the basicR,and finallyeffects, used to draw effects plots discussed throughout thisPrimer. The website includesdirections for getting and installing these Using This PrimerComputer input is indicated in thePrimerinthis font, while output is inthis font. The usualcommand prompt > and continuation + characters inRare suppressed so you can cut and pastedirectly from thePrimerinto anRwindow. Beware, however that a current command may depend onearlier commands in the chapter you are reading!You can get a copy of this **Primer** while runningR, assuming you have an internet connection.

7 Hereare examples of the use of this function:library(alr4)alr4 Web() # opens the website for the book in your browseralr4 Web(" **Primer** ") # opens the **Primer** in a pdf viewerCHAPTER 0. INTRODUCTION viiiThe first of these calls toalr4 Webopens the web page in your browser. The second opens the latestversion of thisPrimerin your browser or pdf viewer. This **Primer** is formatted for reading on thecomputer screen, with aspect ratio similar to a tablet like an iPad in landscape you use Acrobat Reader to view thePrimer, setView Page Display Single Page , bookmarks should be visible to get a quick table of contents; if the bookmarks are not visible,click on the ribbon in the toolbar at the left of the Reader If You Are New toR..Chapter 1 of the bookAn R Companion To **Applied** **regression** , Fox and Weisberg (2011), provides anintroduction toRfor new users.

8 You can get the chapter for free, only warning: uselibrary(alr4)in place oflibrary(car), as the former loads the data setsfrom this book as well as Getting HelpEvery package,Rfunction, and data set in a package has a help page. You access help with thehelpfunction. For example, to get help about the functionsum, you can typehelp(sum)The help page isn t shown here: it will probably appear in your browser, depending on how you installedR. Reading anRhelp page can seem like an adventure in learning a new language. It is hard to writehelp pages, and also can be hard to read might ask for help, and get an error message:help(bs)CHAPTER 0. INTRODUCTIONixNo documentation for bs in specified packages and libraries:you could try ??bs In this instance thebsfunction is in the packagesplines, which has not been loaded. You could getthe help page anyway, by either of the following:help(bs, package="splines")orlibrary(splines)help (bs)You can get help about a package:help(package="car")which will list all the functions and data sets available in thecarpackage, with links to their help marks are sometimes needed when specifying the name of something; in the above examplethe quotation marks could have been has an alias: you can type eitherhelp(lm)or?

9 Lmto get help. We use both in this **Primer** when we want to remind you to look at a help The Very BasicsBefore you can begin doing any useful **Computing** , you need to be able to read data into the program,and after you are done you need to be able to save and print output and 0. Reading a Data FileNearly all the **Computing** in this book and in the homework problems will require that you work witha pre-defined data set in thealr4package. The name of the data set will be given in the text or inproblems. For example the first data set discussed inalr[ ]is theHeightsdata. All you need to dois startR, and then load thealr4package with thelibrarycommand, and the data file is immediatelyavailable:library(alr4)dim(He ights)[1] 1375 2names(Heights)[1] "mheight" "dheight"head(Heights)mheight dheight1 thedimcommand we see that the dimension of the data file is 1375 rows and 2 columns.

10 Fromnameswe see the names of the variables, and fromheadwe see the first 6 rows of the file. Similarly, forthewblakedata set,summary(wblake)CHAPTER 0. INTRODUCTIONxiAge Length ScaleMin. Min. : 55 Min. : Qu. 1st Qu.:138 1st Qu.: Median :194 Median : Mean :193 Mean : Qu. 3rd Qu.:252 3rd Qu.: Max. :362 Max. returns summary information about each of the the variables in the data file,such as the means, medians, and a few quantiles. You can view the whole data file either with theprintcommand,print(Heights)or simply by typing the name of the object,HeightsThe output from these last two commands has been Reading Your Own Data intoRThe used to read a plain data file (see alsoCompanion[ ]) . The generalform of this function is:d <- ("filename", header=TRUE, "?)