R and RStudio Introduction - classes I, II, III, IV materials

1. Files and handouts for R RStudio short course part III and part IV ... Part IV classes to be announced soon.

2. Handout for class #2: R_RStudioShortCoursePart2.pdf ...

3. Some of the material covered in class #1 on R and RStudio: The R.html and moRe R examples page

4. Go to lynda.uni.edu and login with your UNI CatID and password. All UNI faculty, staff and students have a premium subscription to LYNDA. Watching some of the R tutorial material which uses RStudio as the interface to the R statistical software is a good way to review or to learn more.

Up and Running with R with Barton Poulson. (2 hours 25 minutes).

Join author Barton Poulson as he introduces the R statistical processing language, including how to install R on your computer, read data from SPSS and spreadsheets, and use packages for advanced R functions.

The course continues with examples on how to create charts and plots, check statistical assumptions and the reliability of your data, look for data outliers, and use other data analysis tools. Finally, learn how to get charts and tables out of R and share your results with presentations and web pages.

5. To be quickly reviewed in class #2: lm() - Simple Linear Regression - Linear Model function is lm(y ~ x)

Example from first class - R and RStudio Introduction - part I: x is Birthrate, which is the Independent Variable and y is Female Life Expectancy, the Dependent Variable.

6. In R and RStudio class #2, we'll do a few examples from the simpleR package, which is created for the book Using R for Introductory Statistics, by John Verzani..

I will hand out a few pages from the book, but the entire book has a free 114 page PDF version.
From Verzani PDF online textbook.

7. See PLOT and LINEAR REGRESSION by John Verzani - Pages 77-84...
Note that page 77 is on page 81 of the PDF. Use the page numbers on the document.

Note: The grammar of graphics package (ggplot2) will be introduced during part III or class #3 of the R RStudio short course series.

Chapter 12: Graphics - The plot() function: The Art of R Programming: A Tour of Statistical Software Design ... UNI library online book.

ggplot2.org...

```
# Introduction to ggplot2 and the mpg dataset (from the qqplot2 library)

install.packages("ggplot2")
library(ggplot2)

# Look at the data from ggplot2 libary that we're going to use - miles per gallon
?mpg
str(mpg)
names(mpg)

# Basic scatterplot
qplot(displ, hwy, data = mpg)

# Add an additional variable with aesthetics: colour, shape, size
qplot(displ, hwy, data = mpg, colour = class)
qplot(displ, hwy, data = mpg, colour = cyl)
qplot(displ, hwy, data = mpg, shape = factor(cyl))
qplot(displ, hwy, data = mpg, shape = factor(cyl), colour = factor(cyl))

# Add an additional variable with faceting
qplot(displ, hwy, data = mpg)
qplot(displ, hwy, data = mpg) + facet_grid(. ~ cyl)
qplot(displ, hwy, data = mpg) + facet_grid(drv ~ .)
qplot(displ, hwy, data = mpg) + facet_grid(drv ~ cyl)
qplot(displ, hwy, data = mpg) + facet_wrap(~ class)

# Deal with overplotting by using JITTER
qplot(cty, hwy, data = mpg)
qplot(cty, hwy, data = mpg, geom = "jitter")
qplot(cty, hwy, data = mpg, geom = "jitter", colour = year)
qplot(cty, hwy, data = mpg, geom = "jitter", colour = class)

# Note: On 09/11/Thursday
#      We did NOT do the following two R qplots
#      with the added very smooth GEOM method lm (linear model)

qplot(cty, hwy, data = mpg) + geom_smooth(method = "lm")

qplot(cty, hwy, data = mpg, geom = "jitter", colour = class) +
geom_smooth(method = "lm")

# Reordering + boxplots
qplot(class, hwy, data = mpg)
qplot(reorder(class, hwy), hwy, data = mpg)
qplot(reorder(class, hwy), hwy, data = mpg, geom = "jitter")
qplot(reorder(class, hwy), hwy, data = mpg, geom = "boxplot")
qplot(reorder(class, hwy), hwy, data = mpg, geom = c("jitter", "boxplot"))

```