Appendix a R

Appendix a R

Appendix A R R (R Core Team, 2015)isthelingua franca of data analysis and graphics. In this book we will learn the fundamentals of the language and immediately use it for the statistical analysis of data. We will graph both the data and the results of the anal- yses. We will work with the basic statistical tools (regression, analysis of variance, and contingency tables) and some more specialized tools. Many of our examples use the additional functions we have provided in the HH package (Appendix B) (Heiberger, 2015). The R code for all tables and graphs in the book is included in the HH package. In later appendices we will also look at the Rcmdr menu system (Appendix C), RExcel integration of R with Excel (Appendix D), and the shiny package for inte- gration of R with interactive html web pages (Appendix E). A.1 Installing R—Initial Installation R is an open-source publicly licensed software system. R is free under the GPL (Gnu Public License). R is available for download on Windows, Macintosh OSX, and Linux com- puter systems. Start at http://www.R-project.org. Click on “download R” in the “Getting Started” box, pick a mirror near you, and download and install the most recent release of R for your operating system. Once R is running, you will download several necessary contributed packages. You get them from a running R session while connected to the internet. This install.packages statement will install all the packages listed and additional packages that these specified packages need. © Springer Science+Business Media New York 2015 699 R.M. Heiberger, B. Holland, Statistical Analysis and Data Display, Springer Texts in Statistics, DOI 10.1007/978-1-4939-2122-5 700 A R A.1.1 Packages Needed for This Book—Macintosh and Linux Start R, then enter install.packages(c("HH","RcmdrPlugin.HH","RcmdrPlugin.mosaic", "fortunes","ggplot2","shiny","gridExtra", "gridBase","Rmpfr","png","XLConnect", "matrixcalc", "sem", "relimp", "lmtest", "markdown", "knitr", "effects", "aplpack", "RODBC", "TeachingDemos", "gridGraphics", "gridSVG"), dependencies=TRUE) ## This is the sufficient list (as of 16 August 2015) of packages ## needed in order to install the HH package. Should ## additional dependencies be declared by any of these packages ## after that date, the first use of "library(HH)" after the ## installation might ask for permission to install some more ## packages. The install.packages command might tell you that it can’t write in a system directory and will then ask for permission to create a personal library. The question might be in a message box that is behind other windows. Should the installation seem to freeze, find the message box and respond “yes” and accept its recommend directory. It might ask you for a CRAN mirror. Take the mirror from which you downloaded R. A.1.2 Packages and Other Software Needed for This Book—Windows A.1.2.1 RExcel If you are running on a Windows machine and have access to Excel, then we rec- ommend that you also install RExcel.TheRExcel software provides a seamless integration of R and Excel. See Appendix D for further information on RExcel, including the download statements and licensing information. See Section A.1.2.2 for information about using Rcmdr with RExcel. A.1 Installing R—Initial Installation 701 A.1.2.2 RExcel Users Need to Install Rcmdr as Administrator Should you choose to install RExcel then you need to install Rcmdr as Adminis- trator. Otherwise you can install Rcmdr as an ordinary user. Start R as Administrator (on Windows 7 and 8 you need to right-click the R icon and click the “Run as administrator” item). In R, run the following commands (again, you must have started R as Administrator to do this) ## Tell Windows that R should have the same access to the ## outside internet that is granted to Internet Explorer. setInternet2() install.packages("Rcmdr", dependencies=TRUE) Close R with q("no"). Answer with n if it asks Save workspace image? [y/n/c]: A.1.2.3 Packages Needed for This Book—Windows The remaining packages can be installed as an ordinary user. Rcmdr is one of the dependencies of RcmdrPlugin.HH, so it will be installed by the following state- ment (unless it was previously installed). Start R, then enter ## Tell Windows that R should have the same access to the ## outside internet that is granted to Internet Explorer. setInternet2() install.packages(c("HH","RcmdrPlugin.HH","RcmdrPlugin.mosaic", "fortunes","ggplot2","shiny","gridExtra", "gridBase","Rmpfr","png","XLConnect", "matrixcalc", "sem", "relimp", "lmtest", "markdown", "knitr", "effects", "aplpack", "RODBC", "TeachingDemos", "gridGraphics", "gridSVG"), dependencies=TRUE) ## This is the sufficient list (as of 16 August 2015) of packages ## needed in order to install the HH package. Should ## additional dependencies be declared by any of these packages ## after that date, the first use of "library(HH)" after the ## installation might ask for permission to install some more ## packages. 702 A R A.1.2.4 Rtools Rtools provides all the standard Unix utilities (C and Fortran compilers, command- line editing tools such as grep, awk, diff, and many others) that are not in- cluded with the Windows operating system. These utilities are needed in two circumstances. 1. Should you decide to collect your R functions and datasets into a package, you will need Rtools to build the package. See Appendix F for more information. 2. Should you need to use the ediff command in Emacs for visual comparison of two different versions of a file (yesterday’s version and today’s after some editing, for example), you will need Rtools. See Section M.1.2 for an example of visual comparison of files. You may download Rtools from the Windows download page at CRAN. Please see the references from that page for more details. A.1.2.5 Windows Potential Complications: Internet, Firewall, and Proxy When install.packages on a Windows machine gives an Error message that includes the phrase “unable to connect”, then you are probably working behind a company firewall. You will need the R statement setInternet2() before the install.packages statement. This statement tells the firewall to give R the same access to the outside internet that is granted to Internet Explorer. When the install.packages gives a Warning message that says you don’t have write access to one directory, but it will install the packages in a different directory, that is normal and the installation is successful. When the install.packages gives an Error message that says you don’t have write access and doesn’t offer an alternative, then you will have to try the package installation as Administrator. Close R, then reopen R by right-clicking the R icon, and selecting “Run as administrator”. If this still doesn’t allow the installation, then 1. Run the R line sessionInfo() 2. Run the install.packages lines. 3. Highlight and pick up the entire contents of the R console and save it in a text file. Screenshots are usually not helpful. 4. Show your text listing to an R expert. A.1 Installing R—Initial Installation 703 A.1.3 Installation Problems—Any Operating System The most likely source of installation problems is settings (no write access to res- tricted directories on your machine, or system-wide firewalls to protect against offsite internet problems) that your computer administrator has placed on your machine. Check the FAQ (Frequently Asked Questions) files linked to at http://cran.r-project.org/faqs.html. For Windows, see also Section A.1.2.5. If outside help is needed, then save the contents of the R console window to show to your outside expert. In addition to the lines and results leading to the problem, including ALL messages that R produces, you must include the line (and its results) sessionInfo() in the material you show the expert. Screenshots are not a good way to capture information. The informative way to get the contents of the console window is by highlighting the entire window (including the off-screen part) and saving it in a text file. Show your text listing to an R expert. A.1.4 XLConnect: All Operating Systems The XLConnect package lets you read MS Excel files directly from R on any oper- ating system. You may use an R statement similar to the following library(XLConnect) WB <- ## pathname of file with some additional information loadWorkbook( ## "c:/Users/rmh/MyWorkbook.xlsx" ## rmh pathname in Windows "~/MyWorkbook.xlsx" ## rmh pathname in Macintosh ) mydata <- readWorksheet(WB, sheet="Sheet1", region="A1:D11") If you get an error from library(XLConnect) of the form Error : .onLoad failed in loadNamespace() for ’rJava’ then you need to install java on your machine from http://java.com.Thejava installer will ask you if you want to install ask as your default search provider. You may deselect both checkboxes to retain your preferred search provider. 704 A R A.2 Installing R—Updating R is under constant development with new releases every few months. At this writ- ing (August 2015) the current release is R-3.2.2 (2015-08-14). See the FAQ for general update information, and in addition the Windows FAQ or MacOs X FAQ for those operating systems. Links to all three FAQs are available at http://cran.r-project.org/faqs.html. The FAQ files are included in the documentation placed on your machine during installation. The update.packages mechanism works for packages on CRAN. It does not work for packages downloaded from elsewhere. Specifically, Windows users with RExcel installed will need to update the RExcel packages by reinstalling them as described in Section D.1.2.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    188 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us