SlideShare a Scribd company logo
R Basics
R Basics
Week 2.1: Descriptive Statistics in R
! R commands & functions
! Tidyverse & the Pipe Operator
! Multiple Functions
! Reading in data
! Saving R scripts
! Descriptive statistics
! 1 variable
! 2 variable
! Grouping
! Plotting
! Scatterplot
! Bar graph
R Commands
! Simplest way to interact with R is by
typing in commands at the > prompt:
R STUDIO R
R as a Calculator
! Typing in a simple calculation shows us
the result:
! 608 + 28
! What’s 11527 minus 283?
! Some more examples:
! 400 / 65 (division)
! 2 * 4 (multiplication)
! 5 ^ 2 (exponentiation)
Functions
! More complex calculations can be done
with functions:
! sqrt(64)
! Can often read these
left to right (“square root of 64”)
! What do you think
this means?
! abs(-7)
What the function
is (square root)
In parenthesis: What
we want to perform the
function on
Arguments
! Some functions have settings
(“arguments”) that we can adjust:
! round(3.14)
- Rounds off to the nearest integer (zero
decimal places)
! round(3.14, digits=1)
- One decimal place
Week 2.1: Descriptive Statistics in R
! R commands & functions
! Tidyverse & the Pipe Operator
! Multiple Functions
! Reading in data
! Saving R scripts
! Descriptive statistics
! 1 variable
! 2 variable
! Grouping
! Plotting
! Scatterplot
! Bar graph
Tidyverse & the Pipe Operator
! tidyverse is a very popular add-on
package for many basic data-processing
tasks in R
! 2 steps to using:
! Install Tidyverse—only needs to be done
once per computer
Installing Tidyverse: RStudio
• Tools menu -> Install
Packages…
• Type in tidyverse
• Leave Install
Dependencies
checked
• Grabs the other packages
that tidyverse uses
• Only need to do this once
per computer!
Installing Tidyverse : R
• Packages & Data
menu -> Package
Installer -> Get List
• Find tidyverse
• Make sure to check
Install Dependencies
• Grabs the other packages
that tidyverse uses
• Only need to do this once
per computer!
Tidyverse & the Pipe Operator
! tidyverse is a very popular add-on
package for many basic data-processing
tasks in R
! 2 steps to using:
! Install Tidyverse—only needs to be done
once per computer
! Load Tidyverse—once per R session
! library(tidyverse)
Tidyverse & the Pipe Operator
! tidyverse provides another interface to
functions—the pipe operator
! a %>% b()
! Start with a and
apply function b()to it
! 3.14 %>% round()
! Helpful when we
have multiple
functions (as we’ll
see in a moment)
Week 2.1: Descriptive Statistics in R
! R commands & functions
! Tidyverse & the Pipe Operator
! Multiple Functions
! Reading in data
! Saving R scripts
! Descriptive statistics
! 1 variable
! 2 variable
! Grouping
! Plotting
! Scatterplot
! Bar graph
Multiple Functions
Multiple Functions
! The pipe operator makes it easy to do
multiple functions in a row
! -16 %>% sqrt() %>% abs()
• Start with -16
• Then take the square root
• Then take the absolute value
! Don't get scared when you see multiple
pipes!
- Just read left to right
Using Multiple Numbers at Once
! When we want to use multiple
numbers, we concatenate them
! c(2,6,16)
- A list of the numbers 2, 6, and 16
! Sometimes a computation requires multiple
numbers
- c(2,6,16) %>% mean()
! Also a quick way to do the same thing to
multiple different numbers:
- c(16,100,144) %>% sqrt()
CONCATENATE
Week 2.1: Descriptive Statistics in R
! R commands & functions
! Tidyverse & the Pipe Operator
! Multiple Functions
! Reading in data
! Saving R scripts
! Descriptive statistics
! 1 variable
! 2 variable
! Grouping
! Plotting
! Scatterplot
! Bar graph
Modules: Week 2.1: experiment.csv
! Reading plausible versus implausible
sentences
! “Scott chopped the carrots with a knife.”
“Scott chopped the carrots with a spoon.”
Measure
reading time
on final
word
Note: Simulated data; not a real experiment.
Modules: Week 2.1: experiment.csv
! Reading plausible versus implausible
sentences
! Reading time on critical word
! 36 subjects
! Each subject sees 30 items (sentences):
half plausible, half implausible
! Interested in changes over time, so we’ll
track number of trials remaining (29 vs
28 vs 27 vs 26…)
Reading in Data
! Make sure you have the dataset at this
point if you want to follow along:
Canvas "
Modules "
Week 2.1 "
experiment.csv
Reading in Data – RStudio
! Navigate to the
folder in lower-right
! More ->
Set as Working Directory
! Open a “comma-separated value” file:
- experiment <-read.csv('experiment.csv')
Name of the “dataframe”
we’re creating (whatever
we want to call this dataset) read.csv is the
function name
File name
Reading in Data – RStudio
! Navigate to the
folder in lower-right
! More ->
Set as Working Directory
! Open a “comma-separated value” file:
- experiment <-read.csv('experiment.csv’)
• General form of this:
dataframe.name <-read.csv('filename')
Reading in Data – Regular R
! Read in a “comma-separated value” file:
- experiment <- read.csv
('/Users/scottfraundorf/Desktop/experiment.csv')
Name of the “dataframe”
we’re creating (whatever
we want to call this dataset)
read.csv is the function
name
Folder & file name
• Drag & drop the file into R to get the
full folder & filename
Looking at the Data: Summary
! A “big picture” of the dataset:
! experiment %>% summary()
! summary() is a very important function!
! Basic info & descriptive statistics
! Check to make sure the data are correct
Looking at the Data: Summary
! A “big picture” of the dataset:
! experiment %>% summary()
! We can use $ to refer to a specific
column/variable in our dataset:
! experiment$RT %>% summary()
Looking at the Data: Raw Data
! Let’s look at the data!
! experiment
Looking at the Data: Raw Data
! Ack! That’s too much!
How about just a few rows?
! experiment %>% head()
! experiment %>% head(n=10)
Reading in Data: Other Formats
! Excel:
! Install the readxl package (only
needs to be done once)
- install.packages('readxl')
- Then, to read in Excel data:
- library(readxl)
- experiment <-
read_excel('/Users/scottfraundorf/Des
ktop/experiment.xlsx', sheet=2)
Excel files can have multiple sheets/tabs. In this
case, we are saying to use sheet 2.
Reading in Data: Other Formats
! SPSS:
! Uses the haven package—already
installed as part of tidyverse
! Then, to read in SPSS data:
- library(haven)
- experiment <-
read_spss('/Users/scottfraundorf/Desk
top/experiment.spss')
- This package also includes read_sas and
read_stata
Week 2.1: Descriptive Statistics in R
! R commands & functions
! Tidyverse & the Pipe Operator
! Multiple Functions
! Reading in data
! Saving R scripts
! Descriptive statistics
! 1 variable
! 2 variable
! Grouping
! Plotting
! Scatterplot
! Bar graph
R Scripts
! Save & reuse commands with a script
R STUDIO
R
File -> New Document
R Scripts
! Run commands without typing them all
again
! R Studio:
! Code -> Run Region -> Run All: Run entire script
! Code -> Run Line(s): Run just what you’ve
highlighted/selected
! R:
- Highlight the section of script you want to run
- Edit -> Execute
! Keyboard shortcut for this:
- Ctrl+Enter (PC), ⌘+Enter (Mac)
R Scripts
! Saves times when re-running analyses
! Other advantages?
! Some:
- Documentation for yourself
- Documentation for others
- Reuse with new analyses/experiments
- Quicker to run—can automatically
perform one analysis after another
R Scripts—Comments
! Add # before a line to make it a
comment
- Not commands to R, just notes to self
(or other readers)
• Can also add a # to make the rest of a
line a comment
• experiment$RT %>% summary() #awesome
Week 2.1: Descriptive Statistics in R
! R commands & functions
! Tidyverse & the Pipe Operator
! Multiple Functions
! Reading in data
! Saving R scripts
! Descriptive statistics
! 1 variable
! 2 variable
! Grouping
! Plotting
! Scatterplot
! Bar graph
Descriptive Statistics
! So far, we’ve used summary() to get a
high-level overview of our data
! Now, let’s use tidyverse to start testing
specific descriptive statistics
Descriptive Statistics
! Let’s try getting the mean of the RT column
! We start with our experiment dataframe…
experiment %>%
Dataframe name
Descriptive Statistics
! Let’s try getting the mean of the RT column
! We start with our experiment dataframe…
! …then, we start using summarize() to build a
table of descriptive statistics…
experiment %>% summarize(
Dataframe name
Descriptive Statistics
! Let’s try getting the mean of the RT column
! We start with our experiment dataframe…
! …then, we start using summarize() to build a
table of descriptive statistics…
! ..and, in particular, let’s get the mean() of the
RT column
experiment %>% summarize(MyMean=mean(RT))
Dataframe name Name of the column in
the resulting table (can
be whatever you want)
Descriptive
function Variable of
interest
Week 2.1: Descriptive Statistics in R
! R commands & functions
! Tidyverse & the Pipe Operator
! Multiple Functions
! Reading in data
! Saving R scripts
! Descriptive statistics
! 1 variable
! 2 variable
! Grouping
! Plotting
! Scatterplot
! Bar graph
Descriptive Statistics: 2 Variables
! Wow! That was complicated!
! But, once we have learned this general
format, we can easily make more complex
tables…
! Adds the SD (standard deviation) as a second
column
! Other relevant functions: median(), min(), max()
experiment %>% summarize(MyMean=mean(RT),
MySD=sd(RT))
Descriptive Statistics: 2 Variables
! Generic form:
dataframe.name %>%
summarize(TableHeader1=function(VariableName),
TableHeader2=function(VariableName))
experiment %>% summarize(MyMean=mean(RT),
MySD=sd(RT))
Week 2.1: Descriptive Statistics in R
! R commands & functions
! Tidyverse & the Pipe Operator
! Multiple Functions
! Reading in data
! Saving R scripts
! Descriptive statistics
! 1 variable
! 2 variable
! Grouping
! Plotting
! Scatterplot
! Bar graph
Descriptive Statistics: Grouping
! We often want to look at a dependent variable
as a function of some independent variable(s)
! e.g., RTs for Plausible vs. Implausible sentences
! We add an intermediate step – the group_by()
function
- experiment %>% group_by(Condition)
%>% summarize(M=mean(RT))
- “Group the data by Condition, then get the mean
RT”
Descriptive Statistics: Grouping
! We often want to look at a dependent variable
as a function of some independent variable(s)
! We add an intermediate step – the group_by()
function
! Can even group by 2 or more variables:
! experiment %>% group_by(Subject, Condition)
%>% summarize(M=mean(RT))
! Each subject’s mean RT in each condition
Descriptive Statistics: Grouping
! We often want to look at a dependent variable
as a function of some independent variable(s)
! We add an intermediate step – the group_by()
function
! Can even group by 2 or more variables:
! experiment %>% group_by(Subject, Condition)
%>% summarize(M=mean(RT))
! Generic version of this:
! dataframe.name %>%
group_by(IndependentVar1, IndependentVar2)
%>% summarize(TableHeader=
function(DependentVar))
Descriptive Statistics: Grouping
! With group_by() and the n() function, we
can create contingency tables for
categorical variables:
- experiment %>% group_by(Subject, Condition)
%>% summarize(Observations=n())
Now, we are not getting the mean of any particular
dependent variable
We just want a frequency count of the number of
observations for each subject in each condition
Week 2.1: Descriptive Statistics in R
! R commands & functions
! Tidyverse & the Pipe Operator
! Multiple Functions
! Reading in data
! Saving R scripts
! Descriptive statistics
! 1 variable
! 2 variable
! Grouping
! Plotting
! Scatterplot
! Bar graph
Plotting
! Tidyverse also includes a function
for creating plots: ggplot()
! Each ggplot consists of two main elements:
! Mapping the variables onto one or more aesthetic
elements in your plot (e.g., X and Y axes, color,
line type)
Plotting
! Tidyverse also includes a function
for creating plots: ggplot()
! Each ggplot consists of two main elements:
! Mapping the variables onto one or more aesthetic
elements in your plot (e.g., X and Y axes, color,
line type)
Plotting
! Tidyverse also includes a function
for creating plots: ggplot()
! Each ggplot consists of two main elements:
! Mapping the variables onto one or more aesthetic
elements in your plot (e.g., X and Y axes, color,
line type)
Plotting
! Tidyverse also includes a function
for creating plots: ggplot()
! Each ggplot consists of two main elements:
! Mapping the variables onto one or more aesthetic
elements in your plot (e.g., X and Y axes, color,
line type)
Day
Partner
Warmth
Plotting
! Tidyverse also includes a function
for creating plots: ggplot()
! Each ggplot consists of two main elements:
! Mapping the variables onto one or more aesthetic
elements in your plot (e.g., X and Y axes, color,
line type)
! Adding one or more visual elements (geoms) to
depict each observation (e.g., points, bars, lines)
Plotting: Scatterplot
! Does RT change over the course of the
experiment?
! Basic scatterplot:
! experiment %>%
ggplot(aes(x=TrialsRemaining, y=RT)) +
geom_point()
Here, we are saying how we want to
translate the variables into visual form:
the X axis will represent
TrialsRemaining, and the Y axis will
represent the RT variable
Then, we want to represent each
observation with a point
Plotting: Scatterplot
Plotting: Scatterplot
! Our scatterplot:
! experiment %>%
ggplot(aes(x=TrialsRemaining, y=RT)) +
geom_point()
! More generically:
! experiment %>%
ggplot(aes(x=XAxisVariableName,
y=YAxisVariableName)) + geom_point()
Plotting: Scatterplot
! We can add additional variables into the plot
by specifying what aesthetic element they
should be mapped to:
! experiment %>%
ggplot(aes(x=TrialsRemaining, y=RT,
color=Condition)) + geom_point()
! Now, we represent the Condition variable with
the color of each point
Plotting: Scatterplot
Week 2.1: Descriptive Statistics in R
! R commands & functions
! Tidyverse & the Pipe Operator
! Multiple Functions
! Reading in data
! Saving R scripts
! Descriptive statistics
! 1 variable
! 2 variable
! Grouping
! Plotting
! Scatterplot
! Bar graph
Plotting: Bar Graph
! Now let’s make a bar graph to compare
conditions
! KEY POINT: A bar graph displays means--
that is, summarized data
! Thus, we first need to compute those means
Plotting: Bar Graph
! Now let’s make a bar graph to compare
conditions
! KEY POINT: A bar graph displays means--
that is, summarized data
! Thus, we first need to compute those means
Plotting: Bar Graph
! Now let’s make a bar graph to compare
conditions
! experiment %>%
group_by(Condition) %>%
summarize(MeanRT=mean(RT)) %>%
ggplot(aes(x=Condition, fill=Condition,
y=MeanRT)) +
geom_col()
Here, we are
grouping by
Condition and getting
the mean RT in each
condition
The x-axis and bar color
will represent Condition
The y-axis (bar height)
will represent MeanRT
geom_col() for
bar graphs
Plotting: Bar Graph
Plotting: Bar Graph
! Generic form:
! dataframe.name %>%
group_by(IndependentVariable) %>%
summarize(M=mean(DependentVariable)) %>%
ggplot(aes(x=IndependentVariable,
fill=IndependentVaraible,
y=M)) +
geom_col()

More Related Content

What's hot

Mixed Effects Models - Simple and Main Effects
Mixed Effects Models - Simple and Main EffectsMixed Effects Models - Simple and Main Effects
Mixed Effects Models - Simple and Main Effects
Scott Fraundorf
 
Mixed Effects Models - Empirical Logit
Mixed Effects Models - Empirical LogitMixed Effects Models - Empirical Logit
Mixed Effects Models - Empirical Logit
Scott Fraundorf
 
Lecture sheet
Lecture sheetLecture sheet
Lecture sheet
IUBAT
 
Flow Metrics: What They Are & Why You Need Them
Flow Metrics: What They Are & Why You Need ThemFlow Metrics: What They Are & Why You Need Them
Flow Metrics: What They Are & Why You Need Them
Tasktop
 
Using Large Language Models in 10 Lines of Code
Using Large Language Models in 10 Lines of CodeUsing Large Language Models in 10 Lines of Code
Using Large Language Models in 10 Lines of Code
Gautier Marti
 
Forecasting warranty returns with Wiebull Fit
Forecasting warranty returns with Wiebull FitForecasting warranty returns with Wiebull Fit
Forecasting warranty returns with Wiebull Fit
Tonda MacLeod
 
Multiple linear regression
Multiple linear regressionMultiple linear regression
Multiple linear regression
Ken Plummer
 

What's hot (7)

Mixed Effects Models - Simple and Main Effects
Mixed Effects Models - Simple and Main EffectsMixed Effects Models - Simple and Main Effects
Mixed Effects Models - Simple and Main Effects
 
Mixed Effects Models - Empirical Logit
Mixed Effects Models - Empirical LogitMixed Effects Models - Empirical Logit
Mixed Effects Models - Empirical Logit
 
Lecture sheet
Lecture sheetLecture sheet
Lecture sheet
 
Flow Metrics: What They Are & Why You Need Them
Flow Metrics: What They Are & Why You Need ThemFlow Metrics: What They Are & Why You Need Them
Flow Metrics: What They Are & Why You Need Them
 
Using Large Language Models in 10 Lines of Code
Using Large Language Models in 10 Lines of CodeUsing Large Language Models in 10 Lines of Code
Using Large Language Models in 10 Lines of Code
 
Forecasting warranty returns with Wiebull Fit
Forecasting warranty returns with Wiebull FitForecasting warranty returns with Wiebull Fit
Forecasting warranty returns with Wiebull Fit
 
Multiple linear regression
Multiple linear regressionMultiple linear regression
Multiple linear regression
 

Similar to Mixed Effects Models - Descriptive Statistics

محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي   R program د.هديل القفيديمحاضرة برنامج التحليل الكمي   R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
مركز البحوث الأقسام العلمية
 
R programming slides
R  programming slidesR  programming slides
R programming slides
Pankaj Saini
 
Language-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible researchLanguage-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible research
Andrew Lowe
 
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي   R program د.هديل القفيديمحاضرة برنامج التحليل الكمي   R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
مركز البحوث الأقسام العلمية
 
Unit 3
Unit 3Unit 3
e_lumley.pdf
e_lumley.pdfe_lumley.pdf
e_lumley.pdf
betsegaw123
 
Introduction to R Short course Fall 2016
Introduction to R Short course Fall 2016Introduction to R Short course Fall 2016
Introduction to R Short course Fall 2016
Spencer Fox
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packages
Ajay Ohri
 
Hadoop map reduce concepts
Hadoop map reduce conceptsHadoop map reduce concepts
Hadoop map reduce concepts
Subhas Kumar Ghosh
 
Lecture1_R.ppt
Lecture1_R.pptLecture1_R.ppt
Lecture1_R.ppt
ArchishaKhandareSS20
 
Lecture1_R.ppt
Lecture1_R.pptLecture1_R.ppt
Lecture1_R.ppt
vikassingh569137
 
Lecture1 r
Lecture1 rLecture1 r
Lecture1 r
Sandeep242951
 
Modeling in R Programming Language for Beginers.ppt
Modeling in R Programming Language for Beginers.pptModeling in R Programming Language for Beginers.ppt
Modeling in R Programming Language for Beginers.ppt
anshikagoel52
 
Python basics
Python basicsPython basics
Python basics
Hoang Nguyen
 
Python basics
Python basicsPython basics
Python basics
Young Alista
 
Python basics
Python basicsPython basics
Python basics
Fraboni Ec
 
Python basics
Python basicsPython basics
Python basics
Harry Potter
 
Python basics
Python basicsPython basics
Python basics
James Wong
 
Python basics
Python basicsPython basics
Python basics
Tony Nguyen
 
Python basics
Python basicsPython basics
Python basics
Luis Goldster
 

Similar to Mixed Effects Models - Descriptive Statistics (20)

محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي   R program د.هديل القفيديمحاضرة برنامج التحليل الكمي   R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
 
R programming slides
R  programming slidesR  programming slides
R programming slides
 
Language-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible researchLanguage-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible research
 
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي   R program د.هديل القفيديمحاضرة برنامج التحليل الكمي   R program د.هديل القفيدي
محاضرة برنامج التحليل الكمي R program د.هديل القفيدي
 
Unit 3
Unit 3Unit 3
Unit 3
 
e_lumley.pdf
e_lumley.pdfe_lumley.pdf
e_lumley.pdf
 
Introduction to R Short course Fall 2016
Introduction to R Short course Fall 2016Introduction to R Short course Fall 2016
Introduction to R Short course Fall 2016
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packages
 
Hadoop map reduce concepts
Hadoop map reduce conceptsHadoop map reduce concepts
Hadoop map reduce concepts
 
Lecture1_R.ppt
Lecture1_R.pptLecture1_R.ppt
Lecture1_R.ppt
 
Lecture1_R.ppt
Lecture1_R.pptLecture1_R.ppt
Lecture1_R.ppt
 
Lecture1 r
Lecture1 rLecture1 r
Lecture1 r
 
Modeling in R Programming Language for Beginers.ppt
Modeling in R Programming Language for Beginers.pptModeling in R Programming Language for Beginers.ppt
Modeling in R Programming Language for Beginers.ppt
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 

More from Scott Fraundorf

Mixed Effects Models - Signal Detection Theory
Mixed Effects Models - Signal Detection TheoryMixed Effects Models - Signal Detection Theory
Mixed Effects Models - Signal Detection Theory
Scott Fraundorf
 
Mixed Effects Models - Power
Mixed Effects Models - PowerMixed Effects Models - Power
Mixed Effects Models - Power
Scott Fraundorf
 
Mixed Effects Models - Effect Size
Mixed Effects Models - Effect SizeMixed Effects Models - Effect Size
Mixed Effects Models - Effect Size
Scott Fraundorf
 
Mixed Effects Models - Autocorrelation
Mixed Effects Models - AutocorrelationMixed Effects Models - Autocorrelation
Mixed Effects Models - Autocorrelation
Scott Fraundorf
 
Mixed Effects Models - Growth Curve Analysis
Mixed Effects Models - Growth Curve AnalysisMixed Effects Models - Growth Curve Analysis
Mixed Effects Models - Growth Curve Analysis
Scott Fraundorf
 
Mixed Effects Models - Missing Data
Mixed Effects Models - Missing DataMixed Effects Models - Missing Data
Mixed Effects Models - Missing Data
Scott Fraundorf
 
Mixed Effects Models - Logit Models
Mixed Effects Models - Logit ModelsMixed Effects Models - Logit Models
Mixed Effects Models - Logit Models
Scott Fraundorf
 
Mixed Effects Models - Post-Hoc Comparisons
Mixed Effects Models - Post-Hoc ComparisonsMixed Effects Models - Post-Hoc Comparisons
Mixed Effects Models - Post-Hoc Comparisons
Scott Fraundorf
 
Mixed Effects Models - Crossed Random Effects
Mixed Effects Models - Crossed Random EffectsMixed Effects Models - Crossed Random Effects
Mixed Effects Models - Crossed Random Effects
Scott Fraundorf
 
Mixed Effects Models - Level-2 Variables
Mixed Effects Models - Level-2 VariablesMixed Effects Models - Level-2 Variables
Mixed Effects Models - Level-2 Variables
Scott Fraundorf
 
Mixed Effects Models - Introduction
Mixed Effects Models - IntroductionMixed Effects Models - Introduction
Mixed Effects Models - Introduction
Scott Fraundorf
 
Scott_Fraundorf_Resume
Scott_Fraundorf_ResumeScott_Fraundorf_Resume
Scott_Fraundorf_Resume
Scott Fraundorf
 

More from Scott Fraundorf (12)

Mixed Effects Models - Signal Detection Theory
Mixed Effects Models - Signal Detection TheoryMixed Effects Models - Signal Detection Theory
Mixed Effects Models - Signal Detection Theory
 
Mixed Effects Models - Power
Mixed Effects Models - PowerMixed Effects Models - Power
Mixed Effects Models - Power
 
Mixed Effects Models - Effect Size
Mixed Effects Models - Effect SizeMixed Effects Models - Effect Size
Mixed Effects Models - Effect Size
 
Mixed Effects Models - Autocorrelation
Mixed Effects Models - AutocorrelationMixed Effects Models - Autocorrelation
Mixed Effects Models - Autocorrelation
 
Mixed Effects Models - Growth Curve Analysis
Mixed Effects Models - Growth Curve AnalysisMixed Effects Models - Growth Curve Analysis
Mixed Effects Models - Growth Curve Analysis
 
Mixed Effects Models - Missing Data
Mixed Effects Models - Missing DataMixed Effects Models - Missing Data
Mixed Effects Models - Missing Data
 
Mixed Effects Models - Logit Models
Mixed Effects Models - Logit ModelsMixed Effects Models - Logit Models
Mixed Effects Models - Logit Models
 
Mixed Effects Models - Post-Hoc Comparisons
Mixed Effects Models - Post-Hoc ComparisonsMixed Effects Models - Post-Hoc Comparisons
Mixed Effects Models - Post-Hoc Comparisons
 
Mixed Effects Models - Crossed Random Effects
Mixed Effects Models - Crossed Random EffectsMixed Effects Models - Crossed Random Effects
Mixed Effects Models - Crossed Random Effects
 
Mixed Effects Models - Level-2 Variables
Mixed Effects Models - Level-2 VariablesMixed Effects Models - Level-2 Variables
Mixed Effects Models - Level-2 Variables
 
Mixed Effects Models - Introduction
Mixed Effects Models - IntroductionMixed Effects Models - Introduction
Mixed Effects Models - Introduction
 
Scott_Fraundorf_Resume
Scott_Fraundorf_ResumeScott_Fraundorf_Resume
Scott_Fraundorf_Resume
 

Recently uploaded

HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
Nguyen Thanh Tu Collection
 
How to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in useHow to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in use
Celine George
 
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
Nguyen Thanh Tu Collection
 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
TechSoup
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
سمير بسيوني
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
Mohammad Al-Dhahabi
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
RamseyBerglund
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
nitinpv4ai
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
nitinpv4ai
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 

Recently uploaded (20)

HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
 
How to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in useHow to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in use
 
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 

Mixed Effects Models - Descriptive Statistics

  • 3. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 4. R Commands ! Simplest way to interact with R is by typing in commands at the > prompt: R STUDIO R
  • 5. R as a Calculator ! Typing in a simple calculation shows us the result: ! 608 + 28 ! What’s 11527 minus 283? ! Some more examples: ! 400 / 65 (division) ! 2 * 4 (multiplication) ! 5 ^ 2 (exponentiation)
  • 6. Functions ! More complex calculations can be done with functions: ! sqrt(64) ! Can often read these left to right (“square root of 64”) ! What do you think this means? ! abs(-7) What the function is (square root) In parenthesis: What we want to perform the function on
  • 7. Arguments ! Some functions have settings (“arguments”) that we can adjust: ! round(3.14) - Rounds off to the nearest integer (zero decimal places) ! round(3.14, digits=1) - One decimal place
  • 8. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 9. Tidyverse & the Pipe Operator ! tidyverse is a very popular add-on package for many basic data-processing tasks in R ! 2 steps to using: ! Install Tidyverse—only needs to be done once per computer
  • 10. Installing Tidyverse: RStudio • Tools menu -> Install Packages… • Type in tidyverse • Leave Install Dependencies checked • Grabs the other packages that tidyverse uses • Only need to do this once per computer!
  • 11. Installing Tidyverse : R • Packages & Data menu -> Package Installer -> Get List • Find tidyverse • Make sure to check Install Dependencies • Grabs the other packages that tidyverse uses • Only need to do this once per computer!
  • 12. Tidyverse & the Pipe Operator ! tidyverse is a very popular add-on package for many basic data-processing tasks in R ! 2 steps to using: ! Install Tidyverse—only needs to be done once per computer ! Load Tidyverse—once per R session ! library(tidyverse)
  • 13. Tidyverse & the Pipe Operator ! tidyverse provides another interface to functions—the pipe operator ! a %>% b() ! Start with a and apply function b()to it ! 3.14 %>% round() ! Helpful when we have multiple functions (as we’ll see in a moment)
  • 14. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 16. Multiple Functions ! The pipe operator makes it easy to do multiple functions in a row ! -16 %>% sqrt() %>% abs() • Start with -16 • Then take the square root • Then take the absolute value ! Don't get scared when you see multiple pipes! - Just read left to right
  • 17. Using Multiple Numbers at Once ! When we want to use multiple numbers, we concatenate them ! c(2,6,16) - A list of the numbers 2, 6, and 16 ! Sometimes a computation requires multiple numbers - c(2,6,16) %>% mean() ! Also a quick way to do the same thing to multiple different numbers: - c(16,100,144) %>% sqrt() CONCATENATE
  • 18. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 19. Modules: Week 2.1: experiment.csv ! Reading plausible versus implausible sentences ! “Scott chopped the carrots with a knife.” “Scott chopped the carrots with a spoon.” Measure reading time on final word Note: Simulated data; not a real experiment.
  • 20. Modules: Week 2.1: experiment.csv ! Reading plausible versus implausible sentences ! Reading time on critical word ! 36 subjects ! Each subject sees 30 items (sentences): half plausible, half implausible ! Interested in changes over time, so we’ll track number of trials remaining (29 vs 28 vs 27 vs 26…)
  • 21. Reading in Data ! Make sure you have the dataset at this point if you want to follow along: Canvas " Modules " Week 2.1 " experiment.csv
  • 22. Reading in Data – RStudio ! Navigate to the folder in lower-right ! More -> Set as Working Directory ! Open a “comma-separated value” file: - experiment <-read.csv('experiment.csv') Name of the “dataframe” we’re creating (whatever we want to call this dataset) read.csv is the function name File name
  • 23. Reading in Data – RStudio ! Navigate to the folder in lower-right ! More -> Set as Working Directory ! Open a “comma-separated value” file: - experiment <-read.csv('experiment.csv’) • General form of this: dataframe.name <-read.csv('filename')
  • 24. Reading in Data – Regular R ! Read in a “comma-separated value” file: - experiment <- read.csv ('/Users/scottfraundorf/Desktop/experiment.csv') Name of the “dataframe” we’re creating (whatever we want to call this dataset) read.csv is the function name Folder & file name • Drag & drop the file into R to get the full folder & filename
  • 25. Looking at the Data: Summary ! A “big picture” of the dataset: ! experiment %>% summary() ! summary() is a very important function! ! Basic info & descriptive statistics ! Check to make sure the data are correct
  • 26. Looking at the Data: Summary ! A “big picture” of the dataset: ! experiment %>% summary() ! We can use $ to refer to a specific column/variable in our dataset: ! experiment$RT %>% summary()
  • 27. Looking at the Data: Raw Data ! Let’s look at the data! ! experiment
  • 28. Looking at the Data: Raw Data ! Ack! That’s too much! How about just a few rows? ! experiment %>% head() ! experiment %>% head(n=10)
  • 29. Reading in Data: Other Formats ! Excel: ! Install the readxl package (only needs to be done once) - install.packages('readxl') - Then, to read in Excel data: - library(readxl) - experiment <- read_excel('/Users/scottfraundorf/Des ktop/experiment.xlsx', sheet=2) Excel files can have multiple sheets/tabs. In this case, we are saying to use sheet 2.
  • 30. Reading in Data: Other Formats ! SPSS: ! Uses the haven package—already installed as part of tidyverse ! Then, to read in SPSS data: - library(haven) - experiment <- read_spss('/Users/scottfraundorf/Desk top/experiment.spss') - This package also includes read_sas and read_stata
  • 31. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 32. R Scripts ! Save & reuse commands with a script R STUDIO R File -> New Document
  • 33. R Scripts ! Run commands without typing them all again ! R Studio: ! Code -> Run Region -> Run All: Run entire script ! Code -> Run Line(s): Run just what you’ve highlighted/selected ! R: - Highlight the section of script you want to run - Edit -> Execute ! Keyboard shortcut for this: - Ctrl+Enter (PC), ⌘+Enter (Mac)
  • 34. R Scripts ! Saves times when re-running analyses ! Other advantages? ! Some: - Documentation for yourself - Documentation for others - Reuse with new analyses/experiments - Quicker to run—can automatically perform one analysis after another
  • 35. R Scripts—Comments ! Add # before a line to make it a comment - Not commands to R, just notes to self (or other readers) • Can also add a # to make the rest of a line a comment • experiment$RT %>% summary() #awesome
  • 36. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 37. Descriptive Statistics ! So far, we’ve used summary() to get a high-level overview of our data ! Now, let’s use tidyverse to start testing specific descriptive statistics
  • 38. Descriptive Statistics ! Let’s try getting the mean of the RT column ! We start with our experiment dataframe… experiment %>% Dataframe name
  • 39. Descriptive Statistics ! Let’s try getting the mean of the RT column ! We start with our experiment dataframe… ! …then, we start using summarize() to build a table of descriptive statistics… experiment %>% summarize( Dataframe name
  • 40. Descriptive Statistics ! Let’s try getting the mean of the RT column ! We start with our experiment dataframe… ! …then, we start using summarize() to build a table of descriptive statistics… ! ..and, in particular, let’s get the mean() of the RT column experiment %>% summarize(MyMean=mean(RT)) Dataframe name Name of the column in the resulting table (can be whatever you want) Descriptive function Variable of interest
  • 41. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 42. Descriptive Statistics: 2 Variables ! Wow! That was complicated! ! But, once we have learned this general format, we can easily make more complex tables… ! Adds the SD (standard deviation) as a second column ! Other relevant functions: median(), min(), max() experiment %>% summarize(MyMean=mean(RT), MySD=sd(RT))
  • 43. Descriptive Statistics: 2 Variables ! Generic form: dataframe.name %>% summarize(TableHeader1=function(VariableName), TableHeader2=function(VariableName)) experiment %>% summarize(MyMean=mean(RT), MySD=sd(RT))
  • 44. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 45. Descriptive Statistics: Grouping ! We often want to look at a dependent variable as a function of some independent variable(s) ! e.g., RTs for Plausible vs. Implausible sentences ! We add an intermediate step – the group_by() function - experiment %>% group_by(Condition) %>% summarize(M=mean(RT)) - “Group the data by Condition, then get the mean RT”
  • 46. Descriptive Statistics: Grouping ! We often want to look at a dependent variable as a function of some independent variable(s) ! We add an intermediate step – the group_by() function ! Can even group by 2 or more variables: ! experiment %>% group_by(Subject, Condition) %>% summarize(M=mean(RT)) ! Each subject’s mean RT in each condition
  • 47. Descriptive Statistics: Grouping ! We often want to look at a dependent variable as a function of some independent variable(s) ! We add an intermediate step – the group_by() function ! Can even group by 2 or more variables: ! experiment %>% group_by(Subject, Condition) %>% summarize(M=mean(RT)) ! Generic version of this: ! dataframe.name %>% group_by(IndependentVar1, IndependentVar2) %>% summarize(TableHeader= function(DependentVar))
  • 48. Descriptive Statistics: Grouping ! With group_by() and the n() function, we can create contingency tables for categorical variables: - experiment %>% group_by(Subject, Condition) %>% summarize(Observations=n()) Now, we are not getting the mean of any particular dependent variable We just want a frequency count of the number of observations for each subject in each condition
  • 49. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 50. Plotting ! Tidyverse also includes a function for creating plots: ggplot() ! Each ggplot consists of two main elements: ! Mapping the variables onto one or more aesthetic elements in your plot (e.g., X and Y axes, color, line type)
  • 51. Plotting ! Tidyverse also includes a function for creating plots: ggplot() ! Each ggplot consists of two main elements: ! Mapping the variables onto one or more aesthetic elements in your plot (e.g., X and Y axes, color, line type)
  • 52. Plotting ! Tidyverse also includes a function for creating plots: ggplot() ! Each ggplot consists of two main elements: ! Mapping the variables onto one or more aesthetic elements in your plot (e.g., X and Y axes, color, line type)
  • 53. Plotting ! Tidyverse also includes a function for creating plots: ggplot() ! Each ggplot consists of two main elements: ! Mapping the variables onto one or more aesthetic elements in your plot (e.g., X and Y axes, color, line type) Day Partner Warmth
  • 54. Plotting ! Tidyverse also includes a function for creating plots: ggplot() ! Each ggplot consists of two main elements: ! Mapping the variables onto one or more aesthetic elements in your plot (e.g., X and Y axes, color, line type) ! Adding one or more visual elements (geoms) to depict each observation (e.g., points, bars, lines)
  • 55. Plotting: Scatterplot ! Does RT change over the course of the experiment? ! Basic scatterplot: ! experiment %>% ggplot(aes(x=TrialsRemaining, y=RT)) + geom_point() Here, we are saying how we want to translate the variables into visual form: the X axis will represent TrialsRemaining, and the Y axis will represent the RT variable Then, we want to represent each observation with a point
  • 57. Plotting: Scatterplot ! Our scatterplot: ! experiment %>% ggplot(aes(x=TrialsRemaining, y=RT)) + geom_point() ! More generically: ! experiment %>% ggplot(aes(x=XAxisVariableName, y=YAxisVariableName)) + geom_point()
  • 58. Plotting: Scatterplot ! We can add additional variables into the plot by specifying what aesthetic element they should be mapped to: ! experiment %>% ggplot(aes(x=TrialsRemaining, y=RT, color=Condition)) + geom_point() ! Now, we represent the Condition variable with the color of each point
  • 60. Week 2.1: Descriptive Statistics in R ! R commands & functions ! Tidyverse & the Pipe Operator ! Multiple Functions ! Reading in data ! Saving R scripts ! Descriptive statistics ! 1 variable ! 2 variable ! Grouping ! Plotting ! Scatterplot ! Bar graph
  • 61. Plotting: Bar Graph ! Now let’s make a bar graph to compare conditions ! KEY POINT: A bar graph displays means-- that is, summarized data ! Thus, we first need to compute those means
  • 62. Plotting: Bar Graph ! Now let’s make a bar graph to compare conditions ! KEY POINT: A bar graph displays means-- that is, summarized data ! Thus, we first need to compute those means
  • 63. Plotting: Bar Graph ! Now let’s make a bar graph to compare conditions ! experiment %>% group_by(Condition) %>% summarize(MeanRT=mean(RT)) %>% ggplot(aes(x=Condition, fill=Condition, y=MeanRT)) + geom_col() Here, we are grouping by Condition and getting the mean RT in each condition The x-axis and bar color will represent Condition The y-axis (bar height) will represent MeanRT geom_col() for bar graphs
  • 65. Plotting: Bar Graph ! Generic form: ! dataframe.name %>% group_by(IndependentVariable) %>% summarize(M=mean(DependentVariable)) %>% ggplot(aes(x=IndependentVariable, fill=IndependentVaraible, y=M)) + geom_col()