picture of spaghetti

AMPHIBIAN Working Group 2014-2015

Switch2R 01 (http://goo.gl/LOCyBi)

Rich Jones

Monday, October 20, 2014

AMPHIBIAN logo

2014-2015 presentation series: Switch2R

BRAUN logo

Switch2R Series

October 2014: R Basics

November 2014: Clean Data with R

Monday, November 10, 2014, 2-3pm

December 2014 Analysis with R

Monday, December 8, 2014, 2-3pm.

January 2015 Graphics with R (1/2)

Use R to produce high-quality, publication quality statistical graphics

Monday, January 12, 2015, 2-3pm

February 2015: Graphics with R (2/2)

Use R to produce high-quality, publication quality statistical graphics

Monday, February 9, 2015, 2-3pm.

March 2015 Reproducible research with R

Monday, March 16, 2015, 2-3pm.

April 2015: GIS with R

Maps and geospatial data analysis

Monday, April 13, 2015, 2-3pm.

May 2015: Power and sample size

Monday, May 11, 2015, 2-3pm.

June, July Aug. 2015: Summer break

No meetings July 2015 Latent Variable Models Workshop

What is missing?

Installing R

Installing R

Install R by googling for “R Cran”

Installing R Packages

What are R Packages

Installing R & Packages

Here I am installing Rcmdr

Read in Data

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

Other ways to read in data

Basic descriptive statitics

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

More descriptive statistics

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)
Summary of the data
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

R Environments

R Environments

Regular R (Revolution R Open looks and feels the same)

RStudio

RCmdr

Where to get more information

Training

Web Sites

See you next time

Use R to clean data

Monday, November 10, 2014, 2-3pm

Inaugural BRAUN meeting