Welcome to R and RStudio ======================================================== author: Nick Horton, Danny Kaplan, and Randy Pruim date: St Olaf CIR 10/8/2013 This slide show introduces you to some basic commands in R, the `mosaic` package (which we'll be using in the USCOTS sessions), and RStudio. R and RStudio =============== * R is the language/environment for doing statistical and data-oriented computing. * RStudio is an "integrated development environment" (IDE) that makes it easier for instructors to produce notes and for students to access the computational power of R without having to install or manage anything on their own computer. * Both are open-source software packages that run on Windows, Mac OS X and Linux. Your RStudio Server account =============== Each participant in the workshop will be given an account on an RStudio web server (rstudio.stolaf.edu). You can also download and install R and RStudio on your desktop, or even set up an RStudio web server of your own. But for now, just use our server. Log in to that server now. Downloading this presentation =============== * Download the file "Welcome.Rpres" from http://www.amherst.edu/~nhorton/stolaf * Once you are logged in, select "Upload" from the Files tab on the bottom right. * Click on the "Welcome.Rpres" name (this should be at the bottom of your files) * Click "Preview" on the top left pane. Doing so will bring up these slides in the "Presentation" tab of your RStudio window. Resize it as bests suits you. The Console and Basic Commands ================= console: maximize, clear The RStudio display is divided into several **panes**. You can resize these at will. Panes contain **tabs** which give views into various aspects of R and RStudio. This slide show has just maximized the size of the pane containing the **Console**. The console is where you enter commands interactively. This is the most common way of using R, but there are others that you will see in these sessions. You'll also be using the **Plots** tab. Arithmetic =============== We've just put into the console commands illustrating basic arithmetic and exponentiation. ```{r} 3 + 2 3 * 2 3 ^ 2 ``` Assignment =============== We've just put into the console commands illustrating basic arithmetic and exponentiation. ```{r} x = 3 + 2 x x ^ 2 ``` Loading packages ================ Let's start to try some new things, using the `mosaic` package, which provides a few additional commands that we find helpful in smoothing the path for students. ```{r,message=FALSE} require(mosaic); data(HELPrct) ``` The package needs to be loaded each time before use (we've downloaded it from CRAN, the Comprehensive R Archive Network). Running commands ================ Let's explore the HELP (Health Evaluation and Linkage to Primary Care) RCT dataset. ```{r} names(HELPrct) ``` View(HELPrct) Running commands (univariate) ================ ```{r} favstats(~ age, data=HELPrct) ``` Running commands (univariate) ================ ```{r,fig.width=16} densityplot(~ age, data=HELPrct) ``` Running commands (bivariate) ================ ```{r,fig.width=16} densityplot(~ age, groups=substance, auto.key=TRUE, data=HELPrct) ``` Does the distribution of ages differ by substance of abuse? Running commands (bivariate) ================ ```{r,fig.width=16} favstats(age ~ substance, data=HELPrct) bwplot(age ~ substance, data=HELPrct) ``` Running commands (bivariate) ================ ```{r,fig.width=16} mod = lm(age ~ substance, data=HELPrct) coef(mod) confint(mod) ``` RStudio features ================ * Consistent look and feel * Expert friendly, but easy to learn * Integrated help * View the environment * Command completion * Support for reproducible analysis tools