Difference between revisions of "R Analysis"

From REALab Wiki
Jump to navigation Jump to search
 
(39 intermediate revisions by the same user not shown)
Line 4: Line 4:




To get started, download R for free from the [http://www.r-project.org/ R website]
<p>To get started, download R for free from the [http://www.r-project.org/ R website]</p>
<p>Alternatively, for a better organized scripting environment with syntax highlighting, download [http://www.rstudio.com/ide/ Rstudio]</p>
 


==[[R basics|Part 1: R basics]]==
==[[R basics|Part 1: R basics]]==
Line 31: Line 33:
====[[R organizing data#prep stuff: data sets & making a new script|prep stuff: data sets & making a new script]]====
====[[R organizing data#prep stuff: data sets & making a new script|prep stuff: data sets & making a new script]]====
First download the following data sets, and unzip them to a local folder:
First download the following data sets, and unzip them to a local folder:
*[http://weblab1.psych.ubc.ca/wikiakje/uploads/akwikishr/attentional_blink_data_set.zip attentional_blink_data_set.zip]
<!-- *[http://weblab1.psych.ubc.ca/wikiakje/uploads/akwikishr/attentional_blink_data_set.zip attentional_blink_data_set.zip] -->
*[http://weblab1.psych.ubc.ca/wikiakje/uploads/akwikishr/gaze_cueing_data_set.zip gaze_cueing_data_set.zip]
<!-- *[http://weblab1.psych.ubc.ca/wikiakje/uploads/akwikishr/gaze_cueing_data_set.zip gaze_cueing_data_set.zip]  -->
*[http://real.psych.ubc.ca/images/1/14/Attentional_blink_data_set.zip attentional_blink_data_set.zip]
*[http://real.psych.ubc.ca/images/0/03/Gaze_cueing_data_set.zip gaze_cueing_data_set.zip]
(you can also find these in the bar.laboratory@gmail.com dropbox account, in the "\stats meetings\data sets" folder - please make copies for yourself as these should remain in this folder as originals)
(you can also find these in the bar.laboratory@gmail.com dropbox account, in the "\stats meetings\data sets" folder - please make copies for yourself as these should remain in this folder as originals)


*[[R organizing data#how to make a new script?|how to make a new script?]]
*[[R organizing data#how to make a new script?|how to make a new script?]]
Line 49: Line 54:
====[[R organizing data#how to fill out and complete your main data frame|how to fill out and complete your main data frame]]====
====[[R organizing data#how to fill out and complete your main data frame|how to fill out and complete your main data frame]]====
*[[R organizing data#adding a new variable based on another variable (substr)?|adding a new variable based on another variable (substr)?]]
*[[R organizing data#adding a new variable based on another variable (substr)?|adding a new variable based on another variable (substr)?]]
*adding a new variable based on another variable (ifelse)
*[[R organizing data#adding a new variable based on another variable (ifelse)?|adding a new variable based on another variable (ifelse)?]]
*adding a new variable based on another variable (ifelse & substr)  
*[[R organizing data#adding a new variable based on another variable (ifelse & substr)?|adding a new variable based on another variable (ifelse & substr)?]]
*adding a new variable based on another variable (selecting string subset by regular expression)
*adding a new variable based on another variable (selecting string subset by regular expression)
*adding a new variable based on another variable (logical statement using regular expressions)
*adding a new variable based on another variable (logical statement using regular expressions)
Line 56: Line 61:
====[[R organizing data#how to select a subset of your main data frame|how to select a subset of your main data frame]]====
====[[R organizing data#how to select a subset of your main data frame|how to select a subset of your main data frame]]====


*selecting rows from your main data frame
*[[R organizing data#selecting rows from your main data frame?|selecting rows from your main data frame?]]
*selecting columns and rows from your main data frame
*[[R organizing data#example: RT cutoffs based on condition means|example: RT cutoffs based on condition means?]]
*changing your RT variable into a validity effect variable (invalid RT - valid RT)
*[[R organizing data#selecting columns and rows from your main data frame?|selecting columns and rows from your main data frame?]]
*[[R organizing data#changing your RT variable into a validity effect variable (invalid RT - valid RT)?|changing your RT variable into a validity effect variable (invalid RT - valid RT)?]]
 
====[[R organizing data#reorganizing your data for export to Excel/SPSS|reorganizing your data for export to Excel/SPSS]]====


==Part 3: Analyzing your data==
==[[R analyzing data|Part 3: Analyzing your data]]==
This section outlines how to perform descriptive stats, inferential stats, and output graphs once your data frame is organized
This section outlines how to perform descriptive stats, inferential stats, and output graphs once your data frame is organized
====[[R analyzing data#Performing ANOVAs|Performing ANOVAs]]====
*[[R analyzing data#how to perform ANOVAs using aov()|ANOVA using built-in R function (aov)?]]
*[[R analyzing data#how to perform ANOVAs using ezANOVA()|ANOVA using "ez" package (ezANOVA)?]]
====[[R analyzing data#Means tables and simple plots|Means tables and simple plots]]====
*[[R analyzing data#means tables with the tapply command|means tables with the tapply command]]
*[[R analyzing data#simple plots with the plot and barplot commands|simple plots with the plot and barplot commands]]
====[[R analyzing data#Follow-up tests|Follow-up tests]]====
=====[[R analyzing data#Following up on significant main effect of a factor with more than 2 levels|Following up on significant main effect of a factor with more than 2 levels]]=====
=====[[R analyzing data#Following up on significant interaction|Following up on significant interaction]]=====
*[[R analyzing data#Simple main effect of factor B at level of factor A|Simple main effect of factor B at level of factor A]]
*[[R analyzing data#Tukey's HSD tests for factor B at level of factor A|Tukey's HSD tests for factor B at level of factor A]]
====[[R analyzing data#Full graphs with error bars|Full graphs with error bars]]====
*[[R analyzing data#Bar graph with error bars example|Bar graph with error bars example]]
*[[R analyzing data#Bar graph template|Bar graph template]]
*[[R analyzing data#Line graph with error bars example|Line graph with error bars example]]
*[[R analyzing data#Line graph template|Line graph template]]
*[[R analyzing data#Customizing your graph|Customizing your graph]]

Latest revision as of 19:49, 27 August 2015

This wiki is designed to help anyone perform statistical analyses on their data using R. It is divided into 3 broad sections: the first section outlines basics of how R deals with data using built in data sets, the second will help you to read in and organize your own data, and the third will help to summarize, run stats, and output graphs of your data.

Each section is organized into a series of questions. Start from the beginning if you are new to R, or click on a question to go to a detailed answer and/or examples.


To get started, download R for free from the R website

Alternatively, for a better organized scripting environment with syntax highlighting, download Rstudio


Part 1: R basics

Part 2: Organizing your data

This section describes how to load in data files into a data frame, add or drop columns, create a new data frame from a subset of the full data, and generally get your data into the form you need so you can then conduct your analyses.

prep stuff: data sets & making a new script

First download the following data sets, and unzip them to a local folder:

(you can also find these in the bar.laboratory@gmail.com dropbox account, in the "\stats meetings\data sets" folder - please make copies for yourself as these should remain in this folder as originals)


how to read your data into R

how to fill out and complete your main data frame

how to select a subset of your main data frame

reorganizing your data for export to Excel/SPSS

Part 3: Analyzing your data

This section outlines how to perform descriptive stats, inferential stats, and output graphs once your data frame is organized

Performing ANOVAs

Means tables and simple plots

Follow-up tests

Following up on significant main effect of a factor with more than 2 levels
Following up on significant interaction

Full graphs with error bars