Rich Jones
Monday, October 20, 2014
Why
Use R to
Learning resources for R
Use R to clean data
Monday, November 10, 2014, 2-3pm
Use R to do multivariable analysis
Monday, December 8, 2014, 2-3pm.
Use R to produce high-quality, publication quality statistical graphics
Two systems
Monday, January 12, 2015, 2-3pm
Use R to produce high-quality, publication quality statistical graphics
Two more systems
Monday, February 9, 2015, 2-3pm.
R/Markdown
Monday, March 16, 2015, 2-3pm.
Maps and geospatial data analysis
Monday, April 13, 2015, 2-3pm.
Monday, May 11, 2015, 2-3pm.
No meetings July 2015 Latent Variable Models Workshop
Install R by googling for “R Cran”
R has base packages and add-on packages
R base packages load automatically
R Users write packages and post them on the web (repositories)
Here I am installing Rcmdr
ASCII Data
Example at UCLA Institute for Digital Research and Education
(http://www.ats.ucla.edu/stat/paperexamples/atkins_mlm/default.htm)
Atkins, D. C. (2005). Using multilevel models to analyze couple and family treatment data: Basic and advanced issues. Journal of Family Psychology, 19, 98-110.
post-print version (PDF) (http://goo.gl/7uZiEH)
psycnet (http://psycnet.apa.org/journals/fam/19/1/98/)
findit at Brown full text (http://goo.gl/D6m2ID)
# Read data from UCLA Web site
url <- "http://www.ats.ucla.edu/stat/paperexamples/atkins_mlm/Atkins_JFP_data.txt"
data <- read.csv(url, sep="\t", header=TRUE)
# show the first six lines
head(data)
## ID SEX THERAPY TIME DAS PILOT MISS M.IND
## 1 1 0 -0.5 0 94.51204 1 0 1
## 2 1 0 -0.5 13 87.53364 1 0 1
## 3 1 0 -0.5 26 81.46659 1 1 1
## 4 1 0 -0.5 35 83.44614 1 1 1
## 5 1 1 -0.5 0 81.27981 1 0 1
## 6 1 1 -0.5 13 68.80343 1 0 1
R Package: foreign
R package: sjPlot
summary(data)
## ID SEX THERAPY TIME
## Min. : 1.0 Min. :0.0 Min. :-0.5 Min. : 0.00
## 1st Qu.: 34.0 1st Qu.:0.0 1st Qu.:-0.5 1st Qu.: 9.75
## Median : 67.5 Median :0.5 Median : 0.0 Median :19.50
## Mean : 67.5 Mean :0.5 Mean : 0.0 Mean :18.50
## 3rd Qu.:101.0 3rd Qu.:1.0 3rd Qu.: 0.5 3rd Qu.:28.25
## Max. :134.0 Max. :1.0 Max. : 0.5 Max. :35.00
## DAS PILOT MISS M.IND
## Min. : 40.66 Min. :0.0000 Min. :0.00000 Min. :0.0000
## 1st Qu.: 77.85 1st Qu.:0.0000 1st Qu.:0.00000 1st Qu.:0.0000
## Median : 88.19 Median :0.0000 Median :0.00000 Median :0.0000
## Mean : 89.00 Mean :0.2239 Mean :0.07836 Mean :0.1567
## 3rd Qu.: 99.12 3rd Qu.:0.0000 3rd Qu.:0.00000 3rd Qu.:0.0000
## Max. :154.31 Max. :1.0000 Max. :1.00000 Max. :1.0000
library(pipeR)
library(xtable)
library(plyr)
data %>>%
{do.call(data.frame,
list(mean = apply(., 2, mean),
sd = apply(., 2, sd),
median = apply(., 2, median),
min = apply(., 2, min),
max = apply(., 2, max),
n = apply(., 2, length)))} %>>%
xtable(caption = "Summary of the data",
digits=2) %>>%
print(type = "html", caption.placement="top",
html.table.attributes = FALSE)
| mean | sd | median | min | max | n | |
|---|---|---|---|---|---|---|
| ID | 67.50 | 38.70 | 67.50 | 1.00 | 134.00 | 1072 |
| SEX | 0.50 | 0.50 | 0.50 | 0.00 | 1.00 | 1072 |
| THERAPY | 0.00 | 0.50 | 0.00 | -0.50 | 0.50 | 1072 |
| TIME | 18.50 | 13.24 | 19.50 | 0.00 | 35.00 | 1072 |
| DAS | 89.00 | 16.67 | 88.19 | 40.66 | 154.31 | 1072 |
| PILOT | 0.22 | 0.42 | 0.00 | 0.00 | 1.00 | 1072 |
| MISS | 0.08 | 0.27 | 0.00 | 0.00 | 1.00 | 1072 |
| M.IND | 0.16 | 0.36 | 0.00 | 0.00 | 1.00 | 1072 |
Use R to clean data
Monday, November 10, 2014, 2-3pm
Inaugural BRAUN meeting