SlideShare une entreprise Scribd logo
1  sur  65
Télécharger pour lire hors ligne
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()

Contenu connexe

Tendances

Mixed Effects Models - Orthogonal Contrasts
Mixed Effects Models - Orthogonal ContrastsMixed Effects Models - Orthogonal Contrasts
Mixed Effects Models - Orthogonal ContrastsScott Fraundorf
 
Mixed Effects Models - Autocorrelation
Mixed Effects Models - AutocorrelationMixed Effects Models - Autocorrelation
Mixed Effects Models - AutocorrelationScott Fraundorf
 
Mixed Effects Models - Crossed Random Effects
Mixed Effects Models - Crossed Random EffectsMixed Effects Models - Crossed Random Effects
Mixed Effects Models - Crossed Random EffectsScott Fraundorf
 
Multivariate analysis
Multivariate analysisMultivariate analysis
Multivariate analysisSubodh Khanal
 
Anthiil Inside workshop on NLP
Anthiil Inside workshop on NLPAnthiil Inside workshop on NLP
Anthiil Inside workshop on NLPSatyam Saxena
 
Reporting Spearman Rho in APA (independence)
Reporting Spearman Rho in APA (independence)Reporting Spearman Rho in APA (independence)
Reporting Spearman Rho in APA (independence)Ken Plummer
 
西山計量経済学第8章 制限従属変数モデル
西山計量経済学第8章 制限従属変数モデル西山計量経済学第8章 制限従属変数モデル
西山計量経済学第8章 制限従属変数モデルKatsuya Ito
 
What is an independent samples-t test?
What is an independent samples-t test?What is an independent samples-t test?
What is an independent samples-t test?Ken Plummer
 
Bayesian Structural Equations Modeling (SEM)
Bayesian Structural Equations Modeling (SEM)Bayesian Structural Equations Modeling (SEM)
Bayesian Structural Equations Modeling (SEM)Hamy Temkit
 
Word Embeddings, why the hype ?
Word Embeddings, why the hype ? Word Embeddings, why the hype ?
Word Embeddings, why the hype ? Hady Elsahar
 
Mplusの使い方 中級編
Mplusの使い方 中級編Mplusの使い方 中級編
Mplusの使い方 中級編Hiroshi Shimizu
 
Variable Selection Methods
Variable Selection MethodsVariable Selection Methods
Variable Selection Methodsjoycemi_la
 
What is a Single Sample Z Test?
What is a Single Sample Z Test?What is a Single Sample Z Test?
What is a Single Sample Z Test?Ken Plummer
 
Polynomial regression
Polynomial regressionPolynomial regression
Polynomial regressionnaveedaliabad
 
Ordinal logistic regression
Ordinal logistic regression Ordinal logistic regression
Ordinal logistic regression Dr Athar Khan
 
Hypothesis Testing With Python
Hypothesis Testing With PythonHypothesis Testing With Python
Hypothesis Testing With PythonMosky Liu
 
Ordinary least squares linear regression
Ordinary least squares linear regressionOrdinary least squares linear regression
Ordinary least squares linear regressionElkana Rorio
 

Tendances (20)

Mixed Effects Models - Orthogonal Contrasts
Mixed Effects Models - Orthogonal ContrastsMixed Effects Models - Orthogonal Contrasts
Mixed Effects Models - Orthogonal Contrasts
 
Mixed Effects Models - Autocorrelation
Mixed Effects Models - AutocorrelationMixed Effects Models - Autocorrelation
Mixed Effects Models - Autocorrelation
 
Mixed Effects Models - Crossed Random Effects
Mixed Effects Models - Crossed Random EffectsMixed Effects Models - Crossed Random Effects
Mixed Effects Models - Crossed Random Effects
 
Multivariate analysis
Multivariate analysisMultivariate analysis
Multivariate analysis
 
Anthiil Inside workshop on NLP
Anthiil Inside workshop on NLPAnthiil Inside workshop on NLP
Anthiil Inside workshop on NLP
 
Reporting Spearman Rho in APA (independence)
Reporting Spearman Rho in APA (independence)Reporting Spearman Rho in APA (independence)
Reporting Spearman Rho in APA (independence)
 
西山計量経済学第8章 制限従属変数モデル
西山計量経済学第8章 制限従属変数モデル西山計量経済学第8章 制限従属変数モデル
西山計量経済学第8章 制限従属変数モデル
 
What is an independent samples-t test?
What is an independent samples-t test?What is an independent samples-t test?
What is an independent samples-t test?
 
Bayesian Structural Equations Modeling (SEM)
Bayesian Structural Equations Modeling (SEM)Bayesian Structural Equations Modeling (SEM)
Bayesian Structural Equations Modeling (SEM)
 
Autocorrelation
AutocorrelationAutocorrelation
Autocorrelation
 
Word Embeddings, why the hype ?
Word Embeddings, why the hype ? Word Embeddings, why the hype ?
Word Embeddings, why the hype ?
 
Mplusの使い方 中級編
Mplusの使い方 中級編Mplusの使い方 中級編
Mplusの使い方 中級編
 
Variable Selection Methods
Variable Selection MethodsVariable Selection Methods
Variable Selection Methods
 
Chapter 14
Chapter 14 Chapter 14
Chapter 14
 
What is a Single Sample Z Test?
What is a Single Sample Z Test?What is a Single Sample Z Test?
What is a Single Sample Z Test?
 
Polynomial regression
Polynomial regressionPolynomial regression
Polynomial regression
 
Ordinal logistic regression
Ordinal logistic regression Ordinal logistic regression
Ordinal logistic regression
 
Hypothesis Testing With Python
Hypothesis Testing With PythonHypothesis Testing With Python
Hypothesis Testing With Python
 
RとStanで分散分析
RとStanで分散分析RとStanで分散分析
RとStanで分散分析
 
Ordinary least squares linear regression
Ordinary least squares linear regressionOrdinary least squares linear regression
Ordinary least squares linear regression
 

Similaire à Mixed Effects Models - Descriptive Statistics

R programming slides
R  programming slidesR  programming slides
R programming slidesPankaj 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 researchAndrew Lowe
 
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 2016Spencer Fox
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packagesAjay Ohri
 
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.pptanshikagoel52
 

Similaire à 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
 

Plus de Scott Fraundorf

Mixed Effects Models - Signal Detection Theory
Mixed Effects Models - Signal Detection TheoryMixed Effects Models - Signal Detection Theory
Mixed Effects Models - Signal Detection TheoryScott Fraundorf
 
Mixed Effects Models - Power
Mixed Effects Models - PowerMixed Effects Models - Power
Mixed Effects Models - PowerScott Fraundorf
 
Mixed Effects Models - Effect Size
Mixed Effects Models - Effect SizeMixed Effects Models - Effect Size
Mixed Effects Models - Effect SizeScott Fraundorf
 
Mixed Effects Models - Growth Curve Analysis
Mixed Effects Models - Growth Curve AnalysisMixed Effects Models - Growth Curve Analysis
Mixed Effects Models - Growth Curve AnalysisScott Fraundorf
 
Mixed Effects Models - Missing Data
Mixed Effects Models - Missing DataMixed Effects Models - Missing Data
Mixed Effects Models - Missing DataScott Fraundorf
 
Mixed Effects Models - Empirical Logit
Mixed Effects Models - Empirical LogitMixed Effects Models - Empirical Logit
Mixed Effects Models - Empirical LogitScott Fraundorf
 
Mixed Effects Models - Logit Models
Mixed Effects Models - Logit ModelsMixed Effects Models - Logit Models
Mixed Effects Models - Logit ModelsScott Fraundorf
 
Mixed Effects Models - Post-Hoc Comparisons
Mixed Effects Models - Post-Hoc ComparisonsMixed Effects Models - Post-Hoc Comparisons
Mixed Effects Models - Post-Hoc ComparisonsScott Fraundorf
 
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 EffectsScott Fraundorf
 
Mixed Effects Models - Level-2 Variables
Mixed Effects Models - Level-2 VariablesMixed Effects Models - Level-2 Variables
Mixed Effects Models - Level-2 VariablesScott Fraundorf
 

Plus de Scott Fraundorf (11)

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 - 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 - Empirical Logit
Mixed Effects Models - Empirical LogitMixed Effects Models - Empirical Logit
Mixed Effects Models - Empirical Logit
 
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 - 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 - Level-2 Variables
Mixed Effects Models - Level-2 VariablesMixed Effects Models - Level-2 Variables
Mixed Effects Models - Level-2 Variables
 
Scott_Fraundorf_Resume
Scott_Fraundorf_ResumeScott_Fraundorf_Resume
Scott_Fraundorf_Resume
 

Dernier

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 

Dernier (20)

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 

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()