SlideShare a Scribd company logo
1 of 50
Download to read offline
Week 6.1: Crossed Random Effects
! Crossed Random Effects Analysis
! Example Design
! Joining Dataframes
! Random Slopes in Crossed Designs
! Between-Subjects & Within-Subjects Designs
! Between-Items & Within-Items Designs
! When are Random Slopes Necessary?
! Practice Activity
An Experimental Dataset
• naming.csv
• RT (response time) to “name” a word (read it aloud)
for students learning English
• 60 Subjects each presented with 49 Words we
randomly picked out of a dictionary
• Each row of data is a single trial (one subject
responding to one word)
• We’re interested in YearsOfStudy (of English) and
WordFreq (frequency in the English language)
• Also interested in their interaction
• Which of these should we consider Fixed
Effects? Which are Random Effects?
An Experimental Dataset
• naming.csv
• RT (response time) to “name” a word (read it aloud)
for students learning English
• 60 Subjects each presented with 49 Words we
randomly picked out of a dictionary
• Each row of data is a single trial (one subject
responding to one word)
• We’re interested in YearsOfStudy (of English) and
WordFreq (frequency in the English language)
• Also interested in their interaction
• Which of these should we consider Fixed
Effects? Which are Random Effects?
• Fixed: YearsOfStudy, WordFreq, & interaction
• Random: Subject, Word
Crossed Random Effects
• Now, we have >1 trial per Subject
• Level-1 observations (RTs) are nested within subjects
• Clear we need to take account of this
• Some subjects will have faster RTs in general than others
Subjects (Level-2)
Trials (Level-1) RT 1 RT 2 RT 3 RT 4
Subject
1
Subject
2
Crossed Random Effects
• Here are the different Words. Do some seem
easier than others?
Probably relatively
easy
Probably relatively
hard!
Crossed Random Effects
• Each word is also used in more than 1 trial
• Want to take account of that, too
• Observations from the same item will be more similar to
one another, too (“boy” easier than “carburetor”)
Subjects (Level-2)
Trials (Level-1) RT 1 RT 2 RT 3 RT 4
Subject
1
Subject
2
Words
“Boy” “Carbu
retor”
Crossed Random Effects
• In fact, we can think of each trial as the pairing of a
subject and a word
Subjects (Level-2)
Trials (Level-1) RT 1 RT 2 RT 3 RT 4
Subject
1
Subject
2
Words (Level-2)
“Boy” “Carbu
retor”
Crossed Random Effects
• Random effects not hierarchically nested
• Before: Each classroom appears in only 1 school
• Here: Each item presented to each subject
• If we draw all the lines in, we see they cross
Subjects (Level-2)
Trials (Level-1) RT 1 RT 2 RT 3 RT 4
Subject
1
Subject
2
Words (Level-2)
“Boy” “Carbu
retor”
Crossed Random Effects
• Crossed random effects structure
• a/k/a cross-classified when we’re dealing with
existing classifications
Subjects (Level-2)
Trials (Level-1) RT 1 RT 2 RT 3 RT 4
Subject
1
Subject
2
Words (Level-2)
“Boy” “Carbu
retor”
Crossed Random Effects
• Conceptually different sampling, but same syntax!
• Let’s try fitting a model with:
• A fixed effect of YearsOfStudy
• Random intercepts for Subject and Word
• model1 <- lmer(RT ~ 1 + YearsOfStudy +
(1|Subject) + (1|Word), data=naming)
Crossed Random Effects
• Conceptually different sampling, but same syntax!
• Let’s try fitting a model with:
• A fixed effect of YearsOfStudy
• Random intercepts for Subject and Word
• model1 <- lmer(RT ~ 1 + YearsOfStudy +
(1|Subject) + (1|Word), data=naming)
Crossed Random Effects
• model1 <- lmer(RT ~ 1 + YearsOfStudy +
(1|Subject) + (1|Word), data=naming)
Significant effect
of YearsOfStudy
– more study =
faster
responding
Crossed Random Effects
• Huge improvement over ANOVA analyses in
psycholinguistics / experimental psychology!
• We used to have to conduct separate analyses to
assess generalizability over subjects & items
• Or, item effects were simply ignored!
Subjects (Level-2)
Trials (Level-1) RT 1 RT 2 RT 3 RT 4
Subject
1
Subject
2
Words (Level-2)
“Boy” “Carbu
retor”
Week 6.1: Crossed Random Effects
! Crossed Random Effects Analysis
! Example Design
! Joining Dataframes
! Random Slopes in Crossed Designs
! Between-Subjects & Within-Subjects Designs
! Between-Items & Within-Items Designs
! When are Random Slopes Necessary?
! Practice Activity
Joining Dataframes
• Let’s also look at the effect of word frequency
• Problem: This is currently saved in a separate file
(subtlexus.csv)
• SUBTLEXUS norms for US English
Joining Dataframes
! Sometimes different files/dataframes contain
different variables relevant to the same
observations
! Common scenario in mixed effects models
context: Level-2 measurements are in a different
file than Level-1 measurements
naming.csv:
1 row per trial
Each word appears
in multiple rows
subtlexus.csv:
Each word has
only one row
with its
frequency
Joining Dataframes
! Sometimes different files/dataframes contain
different variables relevant to the same
observations
! Common scenario in mixed effects models
context: Level-2 measurements are in a different
file than Level-1 measurements
1 row per
trial
Each
subject has
multiple
rows
Each subject has only
one row with their
Working Memory score
Joining Dataframes
! Sometimes different files/dataframes contain
different variables relevant to the same
observations
! Common scenario in mixed effects models
context: Level-2 variables are in a different file
than Level-1 measurements
allschools: 1 row per student
Each classroom appears in multiple rows
tutoruse.csv:
Each class has only one row—did
this class use the tutor or not?
! “Look up word frequency from the other
dataframe”
! We can combine these dataframes if they have at
least one column in common
! Word tells us which word was presented on an
individual trial, and it also identifies the word in
our database of word frequency
naming.csv:
1 row per trial
Each word
appears in
multiple rows
subtlexus.csv:
Each word has
only one row
with its
frequency
Joining Dataframes
Inner Join
! inner_join(naming, subtlexus, by='Word')
-> naming2
! New dataframe (naming2) has both the columns from
naming (Subject, YearsOfStudy, RT) and the columns
from subtlexus (WordFreq)
! Matches the observations using the Word column
naming.csv:
1 row per trial
Each word
appears in
multiple rows
subtlexus.csv:
Each word has
only one row
with its
frequency
Inner Join
! inner_join(naming, subtlexus, by='Word')
-> naming2
! New dataframe (naming2) has both the columns from
naming (Subject, YearsOfStudy, RT) and the columns
from subtlexus (WordFreq)
! Matches the observations using the Word column
! Like VLOOKUP in Excel
Joins – Mismatching Column Names
! What if the columns have different names?
! Not true in this dataset—just a hypothetical
! Item in naming tells us which Word to look for in
subtlexus … how can we tell R that?
! inner_join(naming, subtlexus,
by=c('Item'='Word')) -> naming2
Name of the column in the
dataframe we listed second
Name of the column in the
dataframe we listed first
Other Types of Joins
! nrow(naming)
! nrow(naming2)
! Six words didn’t have a frequency measurement
! An inner join will drop rows that can’t be
matched
! Alternative:
! naming2 <- left_join(naming, subtlexus,
by='Word')
Keep the rows in the first dataframe (naming)
where we can’t find the matching WORD in the
second dataframe (subtlexus)
Can you guess what happens to WordFreq for
those trials?
2940
2580
Other Types of Joins
! nrow(naming)
! nrow(naming2)
! Six words didn’t have a frequency measurement
! An inner join will drop rows that can’t be
matched
! Alternative:
! naming2 <- left_join(naming, subtlexus,
by='Word')
Keep the rows in the first dataframe (naming)
where we can’t find the matching WORD in the
second dataframe (subtlexus)
WordFreq will be NA (missing data) in these rows
2940
2580
Other Types of Joins
! nrow(naming)
! nrow(naming2)
! Six words didn’t have a frequency measurement
! An inner join will drop rows that can’t be
matched
! A left or right join will keep every row in the first
or second dataframe, respectively
! A full join keeps every row in both dataframes
! full_join(naming, subtlexus,
by='Word') -> naming3
! Includes rows for every word in the
English word frequency database, even ones
not used in our experiment. We DON’T
need or want that in this case.
2940
2580
Matching by Multiple Columns
! Sometimes, one column isn’t enough to uniquely match
things across files/dataframes
! Can use multiple columns in join functions:
! inner_join(naming, subtlexus,
by=c('Word', 'Country')) -> naming2
! This is a logical AND. Has to match both Word and Country
Imagine doing our task in both the US and UK. Word frequency differs somewhat
between American English & British English, so now we need both Word and Country to
look up the frequency.
Crossed Random Effects
• Now that we’ve added the word frequency to our
dataframe, let’s add it to the model
• model2 <- lmer(RT ~ 1 + YearsOfStudy *
WordFreq + (1|Subject) + (1|Word),
data=naming2)
Greater Subject
variance than Item
variance.
Typical in
experiments
because we often
design items to be
similar
Week 6.1: Crossed Random Effects
! Crossed Random Effects Analysis
! Example Design
! Joining Dataframes
! Random Slopes in Crossed Designs
! Between-Subjects & Within-Subjects Designs
! Between-Items & Within-Items Designs
! When are Random Slopes Necessary?
! Practice Activity
• What kind of random slopes might be relevant
here?
• To answer this question, we need to understand
how “between-subjects variables” differ from
“within-subjects variables”
Between vs. Within Subjects
Between vs. Within Subjects
• In an experimental design, some variables are:
" Between-Subjects variables: Each subject is in 1
and only 1 group … or has 1 and only 1 value
• Randomly assigned to drug 1 vs. drug 2 vs. placebo
• Demographic variables; e.g., SES
• Cognitive/linguistic differences (e.g., working mem. score)
• “Between subjects” because differences in this variable
are only seen between one subject and another
SUBJECT 10’s
DATA
Native speaker
Trial 1: Correct
Trial 2: Correct
Trial 3: Incorrect
SUBJECT 11’s
DATA
Non-native
speaker
Trial 1: Incorrect
Trial 2: Correct
Trial 3: Incorrect
Between vs. Within Subjects
• In an experimental design, some variables are:
" Between-Subjects variables: Each subject is in 1
and only 1 group … or has 1 and only 1 value
• Randomly assigned to drug 1 vs. drug 2 vs. placebo
• Demographic variables; e.g., SES
• Cognitive/linguistic differences (e.g., working mem. score)
• “Between subjects” because differences in this variable
are only seen between one subject and another
" Within-Subjects variables: Same subject sees
more than 1 condition or has >1 value
• Same subject sees both congruent (green) and
incongruent (blue) Stroop trials
• Values that vary w/in a study, e.g., # of previous trials
• Variables where you’d use a repeated measures ANOVA
• “Within-subjects” because you can see differences in this
variable even within a single subject
Between vs. Within Subjects
• In an experimental design, some variables are:
" Between-Subjects variables: Each subject is in 1
and only 1 group … or has 1 and only 1 value
• Randomly assigned to @
• Demographic variables; e.g., SES
• Cognitive/linguistic differences (e.g., working mem. score)
• “Between subjects” because differences in this variable
are only seen between one subject and another
" Within-Subjects variables: Same subject sees
more than 1 condition or has >1 value
• Same subject sees both congruent (green) and
incongruent (blue) Stroop trials
• Values that vary w/in a study, e.g., # of previous trials
• Variables where you’d use a repeated measures ANOVA
• “Within-subjects” because you can see differences in this
variable even within a single subject
SUBJECT 12’S DATA
Trial 1: Congruent Stroop, 655 ms
Trial 2: Incongruent Stroop, 512 ms
Trial 3: Incongruent Stroop, 711 ms
Trial 4: Congruent Stroop: 642 ms
• The same variable could end up as between- or
within-subjects, depending on experimental
design
• I’m interested in maintenance rehearsal (repetition)
vs. elaborative rehearsal (relating to other concepts)
• Half of my participants study second-language
vocab using maintenance rehearsal, and half study
words using elaborative rehearsal # Between
Subjects
• Each participant studies some words with
maintenance rehearsal and some with elaborative
rehearsal # Within Subjects
Between vs. Within: Advanced
• How about in our naming dataset?
• Years of study is…
• This experiment takes place at a single point in time,
so the number of years a subject has been studying
English is fixed and never varies
• Between subjects
• Word frequency is…
• Each subject sees high-, medium- and low-frequency
words
• Within subjects
Between vs. Within Subjects
When are Random Slopes
Appropriate?
• If the random effect is subject…
• Random slopes for subjects appropriate for:
• Within-subjects variables
• We can draw a regression line for each subject
• Calculate the effect “within” each subject
• Random slopes for subjects inappropriate for:
• Between-subjects variables
• Can’t draw a regression line within each subject
Subject 1 High Frequency Subject 1 Low Frequency
Subject 2 High Frequency Subject 2 Low Frequency
Subject 1: 6 years of study
Subject 2: 2 years of study
Random Slopes: Implementation
• Remember, previous model was:
• model2 <- lmer(RT ~ 1 + YearsOfStudy * WordFreq
+ (1|Subject) + (1|Word), data=naming2)
• What variable varies within subjects? Try adding a
random slope for it
• model3 <- lmer(RT ~ 1 + YearsOfStudy * WordFreq
+ ???????????????? + (1|Word),
data=naming2)
Random Slopes: Implementation
• Remember, previous model was:
• model2 <- lmer(RT ~ 1 + YearsOfStudy * WordFreq
+ (1|Subject) + (1|Word), data=naming2)
• What variable varies within subjects? Try adding a
random slope for it
• model3 <- lmer(RT ~ 1 + YearsOfStudy * WordFreq
+ (1+WordFreq|Subject) + (1|Word),
data=naming2)
Again, miniature model
formula for things we
think will vary by subjects
Subjects differ in their
intercept (baseline RT) Subjects differ in the effect of
word frequency on their RTs
Random Slopes: Implementation
• Remember, previous model was:
• model2 <- lmer(RT ~ 1 + YearsOfStudy * WordFreq
+ (1|Subject) + (1|Word), data=naming2)
• What variable varies within subjects? Try adding a
random slope for it
• model3 <- lmer(RT ~ 1 + YearsOfStudy * WordFreq
+ (1+WordFreq|Subject) + (1|Word),
data=naming2)
Random Slopes
• Original model says
that subjects vary in
baseline RT
• Random intercept
• And that a 1-unit change
in word frequency ≈ 120
ms decrease in RT
• Fixed effect across subjects
1 2 3
500
600
700
800
900
1000
1100
1200
Word frequency
RT
Subject 1
1 2 3
500
600
700
800
900
1000
1100
1200
Subject 2
1 2 3
500
600
700
800
900
1000
1100
1200
Subject 3
1 2 3
500
600
700
800
900
1000
1100
1200
Subject 4
Different intercepts
for each subject
Slope is the same for
everyone
Random Slopes
• Original model says
that subjects vary in
baseline RT
• Random intercept
• And that a 1-unit change
in word frequency ≈ 120
ms decrease in RT
• Fixed effect across subjects
• Differences in slope
capture how individual
people vary in sensitivity
to word frequency
• Random slope
• Such differences may correlate with baseline
1 2 3
500
600
700
800
900
1000
1100
1200
Word frequency
RT
Subject 1
1 2 3
500
600
700
800
900
1000
1100
1200
Subject 2
1 2 3
500
600
700
800
900
1000
1100
1200
Subject 3
1 2 3
500
600
700
800
900
1000
1100
1200
Subject 4
Subjects still vary in
intercept
Slopes now also differ
across sampled subjects
Subjects with higher
baselines also have
steeper slopes
Week 6.1: Crossed Random Effects
! Crossed Random Effects Analysis
! Example Design
! Joining Dataframes
! Random Slopes in Crossed Designs
! Between-Subjects & Within-Subjects Designs
! Between-Items & Within-Items Designs
! When are Random Slopes Necessary?
! Practice Activity
Between vs. Within Items
• We can draw a similar distinction between
" Between-Items variables: Each item appears in 1
and only 1 condition … or has 1 and only 1 value
• Visual complexity of pictures
• One set of sentences is used in our “plausible” condition
and a completely different set is used in our “implausible”
condition
• “Between items” because differences in this variable are
only seen between one item and another
" Within-Items variables: Same item appears in
more than 1 condition or has >1 value
• Same science facts presented (across subjects) in either
an elaborative- or maintenance-rehearsal condition
• We manipulate the same fictitious resume to have either
a stereotypically African-American or European-American
name
Between vs. Within Items
• Try updating the most recent model with
random slope(s) for the within-items variable(s)
• Hint: Think about whether each variable is constant
for a particular Word or not
• The final full model:
• model.Full <- lmer(RT ~
1 + YearsOfStudy * WordFreq +
(1 + WordFreq|Subject) +
?????????????? , data=naming2)
Between vs. Within Items
• Try updating the most recent model with
random slope(s) for the within-items variable(s)
• Hint: Think about whether each variable is constant
for a particular Word or not
• The final full model:
• model.Full <- lmer(RT ~
1 + YearsOfStudy * WordFreq +
(1 + WordFreq|Subject) +
(1 + YearsOfStudy|Word), data=naming2)
Between vs. Within Items
• Why didn’t we include a
random slope of WordFreq
by items?
• Each word has a constant
frequency (within this experiment)
• Doesn’t make sense to discuss effect
of word frequency within an item
• No random slope of frequency by
items
• But, each item IS presented to
different subjects who differ in their
YearsOfStudy
1 2 3 4
300
400
500
600
700
Word frequency
RT
computer
1 2 3 4
300
400
500
600
700
panther
1 2 3 4
300
400
500
600
700
verify
1 2 3 4
300
400
500
600
700
memorandum
Week 6.1: Crossed Random Effects
! Crossed Random Effects Analysis
! Example Design
! Joining Dataframes
! Random Slopes in Crossed Designs
! Between-Subjects & Within-Subjects Designs
! Between-Items & Within-Items Designs
! When are Random Slopes Necessary?
! Practice Activity
When Are Random Slopes
Necessary?
• Remember that failing to account for clustering
could inflate our Type I error rate
• With factorial experiments, standard is to at
least try to include all random slopes we can (Barr
et al., 2013)
• Maximal random effects structure
• Expectation is that we assume that subjects could
vary in, say, their WordFreq effect—that’s why we
ran more than one subject
• If this does not converge, simplify using strategies
we discussed last class (e.g., removing correlation
parameters)
When Are Random Slopes
Necessary?
• Remember that failing to account for clustering
could inflate our Type I error rate
• In more observational data, not necessarily the
case you’d include all possible random slopes
• What’s theoretically relevant or expected?
The View Ahead
• We’ve covered the basics of fitting a mixed
effects model
• You will practice this in Wednesday’s lab
• But, we have only used continuous variables
• Next 3 weeks: Categorical variables (factors)
• Next two weeks: Categorical predictors (IVs)
• e.g., experimental vs. control condition; race/ethnicity
• After that: Categorical outcomes (DVs)
• e.g., recalled vs. didn’t recall a science fact; did or didn’t
graduate high school
Week 6.1: Crossed Random Effects
! Crossed Random Effects Analysis
! Example Design
! Joining Dataframes
! Random Slopes in Crossed Designs
! Between-Subjects & Within-Subjects Designs
! Between-Items & Within-Items Designs
! When are Random Slopes Necessary?
! Practice Activity

More Related Content

What's hot

Mixed Effects Models - Fixed Effects
Mixed Effects Models - Fixed EffectsMixed Effects Models - Fixed Effects
Mixed Effects Models - Fixed EffectsScott Fraundorf
 
Mixed Effects Models - Empirical Logit
Mixed Effects Models - Empirical LogitMixed Effects Models - Empirical Logit
Mixed Effects Models - Empirical LogitScott Fraundorf
 
Mixed Effects Models - Descriptive Statistics
Mixed Effects Models - Descriptive StatisticsMixed Effects Models - Descriptive Statistics
Mixed Effects Models - Descriptive StatisticsScott Fraundorf
 
Null hypothesis for a chi-square goodness of fit test
Null hypothesis for a chi-square goodness of fit testNull hypothesis for a chi-square goodness of fit test
Null hypothesis for a chi-square goodness of fit testKen Plummer
 
What is a Mann Whitney U?
What is a Mann Whitney U?What is a Mann Whitney U?
What is a Mann Whitney U?Ken Plummer
 
Null hypothesis for Wilcoxon Test
Null hypothesis for Wilcoxon TestNull hypothesis for Wilcoxon Test
Null hypothesis for Wilcoxon TestKen Plummer
 
What is a split plot anova
What is a split plot anovaWhat is a split plot anova
What is a split plot anovaKen Plummer
 
What is a Point Biserial Correlation?
What is a Point Biserial Correlation?What is a Point Biserial Correlation?
What is a Point Biserial Correlation?Ken Plummer
 
Mixed Effects Models - Effect Size
Mixed Effects Models - Effect SizeMixed Effects Models - Effect Size
Mixed Effects Models - Effect SizeScott Fraundorf
 
Categorical data analysis.pptx
Categorical data analysis.pptxCategorical data analysis.pptx
Categorical data analysis.pptxBegashaw3
 
Kruskal Wallis test, Friedman test, Spearman Correlation
Kruskal Wallis test, Friedman test, Spearman CorrelationKruskal Wallis test, Friedman test, Spearman Correlation
Kruskal Wallis test, Friedman test, Spearman CorrelationRizwan S A
 
Introduction to STATA(2).pdf
Introduction to STATA(2).pdfIntroduction to STATA(2).pdf
Introduction to STATA(2).pdfYomif3
 
Regression, Multiple regression in statistics
Regression, Multiple regression in statistics Regression, Multiple regression in statistics
Regression, Multiple regression in statistics Rashna Asif
 
操作変数法の書き方_田淵貴大
操作変数法の書き方_田淵貴大操作変数法の書き方_田淵貴大
操作変数法の書き方_田淵貴大Takahiro Tabuchi
 
Reporting chi square goodness of fit test of independence in apa
Reporting chi square goodness of fit test of independence in apaReporting chi square goodness of fit test of independence in apa
Reporting chi square goodness of fit test of independence in apaKen Plummer
 
Multiple linear regression II
Multiple linear regression IIMultiple linear regression II
Multiple linear regression IIJames Neill
 

What's hot (20)

Mixed Effects Models - Fixed Effects
Mixed Effects Models - Fixed EffectsMixed Effects Models - Fixed Effects
Mixed Effects Models - Fixed Effects
 
Mixed Effects Models - Empirical Logit
Mixed Effects Models - Empirical LogitMixed Effects Models - Empirical Logit
Mixed Effects Models - Empirical Logit
 
Mixed Effects Models - Descriptive Statistics
Mixed Effects Models - Descriptive StatisticsMixed Effects Models - Descriptive Statistics
Mixed Effects Models - Descriptive Statistics
 
Null hypothesis for a chi-square goodness of fit test
Null hypothesis for a chi-square goodness of fit testNull hypothesis for a chi-square goodness of fit test
Null hypothesis for a chi-square goodness of fit test
 
What is a Mann Whitney U?
What is a Mann Whitney U?What is a Mann Whitney U?
What is a Mann Whitney U?
 
Null hypothesis for Wilcoxon Test
Null hypothesis for Wilcoxon TestNull hypothesis for Wilcoxon Test
Null hypothesis for Wilcoxon Test
 
What is a split plot anova
What is a split plot anovaWhat is a split plot anova
What is a split plot anova
 
What is a Point Biserial Correlation?
What is a Point Biserial Correlation?What is a Point Biserial Correlation?
What is a Point Biserial Correlation?
 
Two way anova+manova
Two way anova+manovaTwo way anova+manova
Two way anova+manova
 
Mixed Effects Models - Effect Size
Mixed Effects Models - Effect SizeMixed Effects Models - Effect Size
Mixed Effects Models - Effect Size
 
Categorical data analysis.pptx
Categorical data analysis.pptxCategorical data analysis.pptx
Categorical data analysis.pptx
 
9. design of experiment
9. design of experiment9. design of experiment
9. design of experiment
 
Kruskal Wallis test, Friedman test, Spearman Correlation
Kruskal Wallis test, Friedman test, Spearman CorrelationKruskal Wallis test, Friedman test, Spearman Correlation
Kruskal Wallis test, Friedman test, Spearman Correlation
 
Introduction to STATA(2).pdf
Introduction to STATA(2).pdfIntroduction to STATA(2).pdf
Introduction to STATA(2).pdf
 
Regression, Multiple regression in statistics
Regression, Multiple regression in statistics Regression, Multiple regression in statistics
Regression, Multiple regression in statistics
 
操作変数法の書き方_田淵貴大
操作変数法の書き方_田淵貴大操作変数法の書き方_田淵貴大
操作変数法の書き方_田淵貴大
 
Reporting chi square goodness of fit test of independence in apa
Reporting chi square goodness of fit test of independence in apaReporting chi square goodness of fit test of independence in apa
Reporting chi square goodness of fit test of independence in apa
 
T test and ANOVA
T test and ANOVAT test and ANOVA
T test and ANOVA
 
Multiple linear regression II
Multiple linear regression IIMultiple linear regression II
Multiple linear regression II
 
Repeated Measures ANOVA
Repeated Measures ANOVARepeated Measures ANOVA
Repeated Measures ANOVA
 

Similar to Mixed Effects Models - Crossed Random Effects

Webinar: Simpler Semantic Search with Solr
Webinar: Simpler Semantic Search with SolrWebinar: Simpler Semantic Search with Solr
Webinar: Simpler Semantic Search with SolrLucidworks
 
A Panorama of Natural Language Processing
A Panorama of Natural Language ProcessingA Panorama of Natural Language Processing
A Panorama of Natural Language ProcessingTed Xiao
 
Word embeddings
Word embeddingsWord embeddings
Word embeddingsShruti kar
 
Chapter 6 Query Language .pdf
Chapter 6 Query Language .pdfChapter 6 Query Language .pdf
Chapter 6 Query Language .pdfHabtamu100
 
code4lib 2011 preconference: What's New in Solr (since 1.4.1)
code4lib 2011 preconference: What's New in Solr (since 1.4.1)code4lib 2011 preconference: What's New in Solr (since 1.4.1)
code4lib 2011 preconference: What's New in Solr (since 1.4.1)Erik Hatcher
 
Automated Software Requirements Labeling
Automated Software Requirements LabelingAutomated Software Requirements Labeling
Automated Software Requirements LabelingData Works MD
 
Introduction to search engine-building with Lucene
Introduction to search engine-building with LuceneIntroduction to search engine-building with Lucene
Introduction to search engine-building with LuceneKai Chan
 
Introduction to search engine-building with Lucene
Introduction to search engine-building with LuceneIntroduction to search engine-building with Lucene
Introduction to search engine-building with LuceneKai Chan
 
Text based search engine on a fixed corpus and utilizing indexation and ranki...
Text based search engine on a fixed corpus and utilizing indexation and ranki...Text based search engine on a fixed corpus and utilizing indexation and ranki...
Text based search engine on a fixed corpus and utilizing indexation and ranki...Soham Mondal
 
Search explained T3DD15
Search explained T3DD15Search explained T3DD15
Search explained T3DD15Hans Höchtl
 
Semi-automated Exploration and Extraction of Data in Scientific Tables
Semi-automated Exploration and Extraction of Data in Scientific TablesSemi-automated Exploration and Extraction of Data in Scientific Tables
Semi-automated Exploration and Extraction of Data in Scientific TablesElsevier
 
Textrank algorithm
Textrank algorithmTextrank algorithm
Textrank algorithmAndrew Koo
 
A Simple Walkthrough of Word Sense Disambiguation
A Simple Walkthrough of Word Sense DisambiguationA Simple Walkthrough of Word Sense Disambiguation
A Simple Walkthrough of Word Sense DisambiguationMaryOsborne11
 

Similar to Mixed Effects Models - Crossed Random Effects (20)

Text features
Text featuresText features
Text features
 
Ir 03
Ir   03Ir   03
Ir 03
 
Webinar: Simpler Semantic Search with Solr
Webinar: Simpler Semantic Search with SolrWebinar: Simpler Semantic Search with Solr
Webinar: Simpler Semantic Search with Solr
 
A-Study_TopicModeling
A-Study_TopicModelingA-Study_TopicModeling
A-Study_TopicModeling
 
Some Information Retrieval Models and Our Experiments for TREC KBA
Some Information Retrieval Models and Our Experiments for TREC KBASome Information Retrieval Models and Our Experiments for TREC KBA
Some Information Retrieval Models and Our Experiments for TREC KBA
 
A Panorama of Natural Language Processing
A Panorama of Natural Language ProcessingA Panorama of Natural Language Processing
A Panorama of Natural Language Processing
 
2_Capability.ppt
2_Capability.ppt2_Capability.ppt
2_Capability.ppt
 
Word embeddings
Word embeddingsWord embeddings
Word embeddings
 
Search pitb
Search pitbSearch pitb
Search pitb
 
Chapter 6 Query Language .pdf
Chapter 6 Query Language .pdfChapter 6 Query Language .pdf
Chapter 6 Query Language .pdf
 
code4lib 2011 preconference: What's New in Solr (since 1.4.1)
code4lib 2011 preconference: What's New in Solr (since 1.4.1)code4lib 2011 preconference: What's New in Solr (since 1.4.1)
code4lib 2011 preconference: What's New in Solr (since 1.4.1)
 
Automated Software Requirements Labeling
Automated Software Requirements LabelingAutomated Software Requirements Labeling
Automated Software Requirements Labeling
 
Introduction to search engine-building with Lucene
Introduction to search engine-building with LuceneIntroduction to search engine-building with Lucene
Introduction to search engine-building with Lucene
 
Introduction to search engine-building with Lucene
Introduction to search engine-building with LuceneIntroduction to search engine-building with Lucene
Introduction to search engine-building with Lucene
 
Text based search engine on a fixed corpus and utilizing indexation and ranki...
Text based search engine on a fixed corpus and utilizing indexation and ranki...Text based search engine on a fixed corpus and utilizing indexation and ranki...
Text based search engine on a fixed corpus and utilizing indexation and ranki...
 
Eacl 2006 Pedersen
Eacl 2006 PedersenEacl 2006 Pedersen
Eacl 2006 Pedersen
 
Search explained T3DD15
Search explained T3DD15Search explained T3DD15
Search explained T3DD15
 
Semi-automated Exploration and Extraction of Data in Scientific Tables
Semi-automated Exploration and Extraction of Data in Scientific TablesSemi-automated Exploration and Extraction of Data in Scientific Tables
Semi-automated Exploration and Extraction of Data in Scientific Tables
 
Textrank algorithm
Textrank algorithmTextrank algorithm
Textrank algorithm
 
A Simple Walkthrough of Word Sense Disambiguation
A Simple Walkthrough of Word Sense DisambiguationA Simple Walkthrough of Word Sense Disambiguation
A Simple Walkthrough of Word Sense Disambiguation
 

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 TheoryScott Fraundorf
 
Mixed Effects Models - Power
Mixed Effects Models - PowerMixed Effects Models - Power
Mixed Effects Models - PowerScott Fraundorf
 
Mixed Effects Models - Autocorrelation
Mixed Effects Models - AutocorrelationMixed Effects Models - Autocorrelation
Mixed Effects Models - AutocorrelationScott 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 - 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
 

More from Scott Fraundorf (10)

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

Recently uploaded

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
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
 
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
 
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
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 

Recently uploaded (20)

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
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
 
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
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
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
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 

Mixed Effects Models - Crossed Random Effects

  • 1. Week 6.1: Crossed Random Effects ! Crossed Random Effects Analysis ! Example Design ! Joining Dataframes ! Random Slopes in Crossed Designs ! Between-Subjects & Within-Subjects Designs ! Between-Items & Within-Items Designs ! When are Random Slopes Necessary? ! Practice Activity
  • 2. An Experimental Dataset • naming.csv • RT (response time) to “name” a word (read it aloud) for students learning English • 60 Subjects each presented with 49 Words we randomly picked out of a dictionary • Each row of data is a single trial (one subject responding to one word) • We’re interested in YearsOfStudy (of English) and WordFreq (frequency in the English language) • Also interested in their interaction • Which of these should we consider Fixed Effects? Which are Random Effects?
  • 3. An Experimental Dataset • naming.csv • RT (response time) to “name” a word (read it aloud) for students learning English • 60 Subjects each presented with 49 Words we randomly picked out of a dictionary • Each row of data is a single trial (one subject responding to one word) • We’re interested in YearsOfStudy (of English) and WordFreq (frequency in the English language) • Also interested in their interaction • Which of these should we consider Fixed Effects? Which are Random Effects? • Fixed: YearsOfStudy, WordFreq, & interaction • Random: Subject, Word
  • 4. Crossed Random Effects • Now, we have >1 trial per Subject • Level-1 observations (RTs) are nested within subjects • Clear we need to take account of this • Some subjects will have faster RTs in general than others Subjects (Level-2) Trials (Level-1) RT 1 RT 2 RT 3 RT 4 Subject 1 Subject 2
  • 5. Crossed Random Effects • Here are the different Words. Do some seem easier than others? Probably relatively easy Probably relatively hard!
  • 6. Crossed Random Effects • Each word is also used in more than 1 trial • Want to take account of that, too • Observations from the same item will be more similar to one another, too (“boy” easier than “carburetor”) Subjects (Level-2) Trials (Level-1) RT 1 RT 2 RT 3 RT 4 Subject 1 Subject 2 Words “Boy” “Carbu retor”
  • 7. Crossed Random Effects • In fact, we can think of each trial as the pairing of a subject and a word Subjects (Level-2) Trials (Level-1) RT 1 RT 2 RT 3 RT 4 Subject 1 Subject 2 Words (Level-2) “Boy” “Carbu retor”
  • 8. Crossed Random Effects • Random effects not hierarchically nested • Before: Each classroom appears in only 1 school • Here: Each item presented to each subject • If we draw all the lines in, we see they cross Subjects (Level-2) Trials (Level-1) RT 1 RT 2 RT 3 RT 4 Subject 1 Subject 2 Words (Level-2) “Boy” “Carbu retor”
  • 9. Crossed Random Effects • Crossed random effects structure • a/k/a cross-classified when we’re dealing with existing classifications Subjects (Level-2) Trials (Level-1) RT 1 RT 2 RT 3 RT 4 Subject 1 Subject 2 Words (Level-2) “Boy” “Carbu retor”
  • 10. Crossed Random Effects • Conceptually different sampling, but same syntax! • Let’s try fitting a model with: • A fixed effect of YearsOfStudy • Random intercepts for Subject and Word • model1 <- lmer(RT ~ 1 + YearsOfStudy + (1|Subject) + (1|Word), data=naming)
  • 11. Crossed Random Effects • Conceptually different sampling, but same syntax! • Let’s try fitting a model with: • A fixed effect of YearsOfStudy • Random intercepts for Subject and Word • model1 <- lmer(RT ~ 1 + YearsOfStudy + (1|Subject) + (1|Word), data=naming)
  • 12. Crossed Random Effects • model1 <- lmer(RT ~ 1 + YearsOfStudy + (1|Subject) + (1|Word), data=naming) Significant effect of YearsOfStudy – more study = faster responding
  • 13. Crossed Random Effects • Huge improvement over ANOVA analyses in psycholinguistics / experimental psychology! • We used to have to conduct separate analyses to assess generalizability over subjects & items • Or, item effects were simply ignored! Subjects (Level-2) Trials (Level-1) RT 1 RT 2 RT 3 RT 4 Subject 1 Subject 2 Words (Level-2) “Boy” “Carbu retor”
  • 14. Week 6.1: Crossed Random Effects ! Crossed Random Effects Analysis ! Example Design ! Joining Dataframes ! Random Slopes in Crossed Designs ! Between-Subjects & Within-Subjects Designs ! Between-Items & Within-Items Designs ! When are Random Slopes Necessary? ! Practice Activity
  • 15. Joining Dataframes • Let’s also look at the effect of word frequency • Problem: This is currently saved in a separate file (subtlexus.csv) • SUBTLEXUS norms for US English
  • 16. Joining Dataframes ! Sometimes different files/dataframes contain different variables relevant to the same observations ! Common scenario in mixed effects models context: Level-2 measurements are in a different file than Level-1 measurements naming.csv: 1 row per trial Each word appears in multiple rows subtlexus.csv: Each word has only one row with its frequency
  • 17. Joining Dataframes ! Sometimes different files/dataframes contain different variables relevant to the same observations ! Common scenario in mixed effects models context: Level-2 measurements are in a different file than Level-1 measurements 1 row per trial Each subject has multiple rows Each subject has only one row with their Working Memory score
  • 18. Joining Dataframes ! Sometimes different files/dataframes contain different variables relevant to the same observations ! Common scenario in mixed effects models context: Level-2 variables are in a different file than Level-1 measurements allschools: 1 row per student Each classroom appears in multiple rows tutoruse.csv: Each class has only one row—did this class use the tutor or not?
  • 19. ! “Look up word frequency from the other dataframe” ! We can combine these dataframes if they have at least one column in common ! Word tells us which word was presented on an individual trial, and it also identifies the word in our database of word frequency naming.csv: 1 row per trial Each word appears in multiple rows subtlexus.csv: Each word has only one row with its frequency Joining Dataframes
  • 20. Inner Join ! inner_join(naming, subtlexus, by='Word') -> naming2 ! New dataframe (naming2) has both the columns from naming (Subject, YearsOfStudy, RT) and the columns from subtlexus (WordFreq) ! Matches the observations using the Word column naming.csv: 1 row per trial Each word appears in multiple rows subtlexus.csv: Each word has only one row with its frequency
  • 21. Inner Join ! inner_join(naming, subtlexus, by='Word') -> naming2 ! New dataframe (naming2) has both the columns from naming (Subject, YearsOfStudy, RT) and the columns from subtlexus (WordFreq) ! Matches the observations using the Word column ! Like VLOOKUP in Excel
  • 22. Joins – Mismatching Column Names ! What if the columns have different names? ! Not true in this dataset—just a hypothetical ! Item in naming tells us which Word to look for in subtlexus … how can we tell R that? ! inner_join(naming, subtlexus, by=c('Item'='Word')) -> naming2 Name of the column in the dataframe we listed second Name of the column in the dataframe we listed first
  • 23. Other Types of Joins ! nrow(naming) ! nrow(naming2) ! Six words didn’t have a frequency measurement ! An inner join will drop rows that can’t be matched ! Alternative: ! naming2 <- left_join(naming, subtlexus, by='Word') Keep the rows in the first dataframe (naming) where we can’t find the matching WORD in the second dataframe (subtlexus) Can you guess what happens to WordFreq for those trials? 2940 2580
  • 24. Other Types of Joins ! nrow(naming) ! nrow(naming2) ! Six words didn’t have a frequency measurement ! An inner join will drop rows that can’t be matched ! Alternative: ! naming2 <- left_join(naming, subtlexus, by='Word') Keep the rows in the first dataframe (naming) where we can’t find the matching WORD in the second dataframe (subtlexus) WordFreq will be NA (missing data) in these rows 2940 2580
  • 25. Other Types of Joins ! nrow(naming) ! nrow(naming2) ! Six words didn’t have a frequency measurement ! An inner join will drop rows that can’t be matched ! A left or right join will keep every row in the first or second dataframe, respectively ! A full join keeps every row in both dataframes ! full_join(naming, subtlexus, by='Word') -> naming3 ! Includes rows for every word in the English word frequency database, even ones not used in our experiment. We DON’T need or want that in this case. 2940 2580
  • 26. Matching by Multiple Columns ! Sometimes, one column isn’t enough to uniquely match things across files/dataframes ! Can use multiple columns in join functions: ! inner_join(naming, subtlexus, by=c('Word', 'Country')) -> naming2 ! This is a logical AND. Has to match both Word and Country Imagine doing our task in both the US and UK. Word frequency differs somewhat between American English & British English, so now we need both Word and Country to look up the frequency.
  • 27. Crossed Random Effects • Now that we’ve added the word frequency to our dataframe, let’s add it to the model • model2 <- lmer(RT ~ 1 + YearsOfStudy * WordFreq + (1|Subject) + (1|Word), data=naming2) Greater Subject variance than Item variance. Typical in experiments because we often design items to be similar
  • 28. Week 6.1: Crossed Random Effects ! Crossed Random Effects Analysis ! Example Design ! Joining Dataframes ! Random Slopes in Crossed Designs ! Between-Subjects & Within-Subjects Designs ! Between-Items & Within-Items Designs ! When are Random Slopes Necessary? ! Practice Activity
  • 29. • What kind of random slopes might be relevant here? • To answer this question, we need to understand how “between-subjects variables” differ from “within-subjects variables” Between vs. Within Subjects
  • 30. Between vs. Within Subjects • In an experimental design, some variables are: " Between-Subjects variables: Each subject is in 1 and only 1 group … or has 1 and only 1 value • Randomly assigned to drug 1 vs. drug 2 vs. placebo • Demographic variables; e.g., SES • Cognitive/linguistic differences (e.g., working mem. score) • “Between subjects” because differences in this variable are only seen between one subject and another SUBJECT 10’s DATA Native speaker Trial 1: Correct Trial 2: Correct Trial 3: Incorrect SUBJECT 11’s DATA Non-native speaker Trial 1: Incorrect Trial 2: Correct Trial 3: Incorrect
  • 31. Between vs. Within Subjects • In an experimental design, some variables are: " Between-Subjects variables: Each subject is in 1 and only 1 group … or has 1 and only 1 value • Randomly assigned to drug 1 vs. drug 2 vs. placebo • Demographic variables; e.g., SES • Cognitive/linguistic differences (e.g., working mem. score) • “Between subjects” because differences in this variable are only seen between one subject and another " Within-Subjects variables: Same subject sees more than 1 condition or has >1 value • Same subject sees both congruent (green) and incongruent (blue) Stroop trials • Values that vary w/in a study, e.g., # of previous trials • Variables where you’d use a repeated measures ANOVA • “Within-subjects” because you can see differences in this variable even within a single subject
  • 32. Between vs. Within Subjects • In an experimental design, some variables are: " Between-Subjects variables: Each subject is in 1 and only 1 group … or has 1 and only 1 value • Randomly assigned to @ • Demographic variables; e.g., SES • Cognitive/linguistic differences (e.g., working mem. score) • “Between subjects” because differences in this variable are only seen between one subject and another " Within-Subjects variables: Same subject sees more than 1 condition or has >1 value • Same subject sees both congruent (green) and incongruent (blue) Stroop trials • Values that vary w/in a study, e.g., # of previous trials • Variables where you’d use a repeated measures ANOVA • “Within-subjects” because you can see differences in this variable even within a single subject SUBJECT 12’S DATA Trial 1: Congruent Stroop, 655 ms Trial 2: Incongruent Stroop, 512 ms Trial 3: Incongruent Stroop, 711 ms Trial 4: Congruent Stroop: 642 ms
  • 33. • The same variable could end up as between- or within-subjects, depending on experimental design • I’m interested in maintenance rehearsal (repetition) vs. elaborative rehearsal (relating to other concepts) • Half of my participants study second-language vocab using maintenance rehearsal, and half study words using elaborative rehearsal # Between Subjects • Each participant studies some words with maintenance rehearsal and some with elaborative rehearsal # Within Subjects Between vs. Within: Advanced
  • 34. • How about in our naming dataset? • Years of study is… • This experiment takes place at a single point in time, so the number of years a subject has been studying English is fixed and never varies • Between subjects • Word frequency is… • Each subject sees high-, medium- and low-frequency words • Within subjects Between vs. Within Subjects
  • 35. When are Random Slopes Appropriate? • If the random effect is subject… • Random slopes for subjects appropriate for: • Within-subjects variables • We can draw a regression line for each subject • Calculate the effect “within” each subject • Random slopes for subjects inappropriate for: • Between-subjects variables • Can’t draw a regression line within each subject Subject 1 High Frequency Subject 1 Low Frequency Subject 2 High Frequency Subject 2 Low Frequency Subject 1: 6 years of study Subject 2: 2 years of study
  • 36. Random Slopes: Implementation • Remember, previous model was: • model2 <- lmer(RT ~ 1 + YearsOfStudy * WordFreq + (1|Subject) + (1|Word), data=naming2) • What variable varies within subjects? Try adding a random slope for it • model3 <- lmer(RT ~ 1 + YearsOfStudy * WordFreq + ???????????????? + (1|Word), data=naming2)
  • 37. Random Slopes: Implementation • Remember, previous model was: • model2 <- lmer(RT ~ 1 + YearsOfStudy * WordFreq + (1|Subject) + (1|Word), data=naming2) • What variable varies within subjects? Try adding a random slope for it • model3 <- lmer(RT ~ 1 + YearsOfStudy * WordFreq + (1+WordFreq|Subject) + (1|Word), data=naming2) Again, miniature model formula for things we think will vary by subjects Subjects differ in their intercept (baseline RT) Subjects differ in the effect of word frequency on their RTs
  • 38. Random Slopes: Implementation • Remember, previous model was: • model2 <- lmer(RT ~ 1 + YearsOfStudy * WordFreq + (1|Subject) + (1|Word), data=naming2) • What variable varies within subjects? Try adding a random slope for it • model3 <- lmer(RT ~ 1 + YearsOfStudy * WordFreq + (1+WordFreq|Subject) + (1|Word), data=naming2)
  • 39. Random Slopes • Original model says that subjects vary in baseline RT • Random intercept • And that a 1-unit change in word frequency ≈ 120 ms decrease in RT • Fixed effect across subjects 1 2 3 500 600 700 800 900 1000 1100 1200 Word frequency RT Subject 1 1 2 3 500 600 700 800 900 1000 1100 1200 Subject 2 1 2 3 500 600 700 800 900 1000 1100 1200 Subject 3 1 2 3 500 600 700 800 900 1000 1100 1200 Subject 4 Different intercepts for each subject Slope is the same for everyone
  • 40. Random Slopes • Original model says that subjects vary in baseline RT • Random intercept • And that a 1-unit change in word frequency ≈ 120 ms decrease in RT • Fixed effect across subjects • Differences in slope capture how individual people vary in sensitivity to word frequency • Random slope • Such differences may correlate with baseline 1 2 3 500 600 700 800 900 1000 1100 1200 Word frequency RT Subject 1 1 2 3 500 600 700 800 900 1000 1100 1200 Subject 2 1 2 3 500 600 700 800 900 1000 1100 1200 Subject 3 1 2 3 500 600 700 800 900 1000 1100 1200 Subject 4 Subjects still vary in intercept Slopes now also differ across sampled subjects Subjects with higher baselines also have steeper slopes
  • 41. Week 6.1: Crossed Random Effects ! Crossed Random Effects Analysis ! Example Design ! Joining Dataframes ! Random Slopes in Crossed Designs ! Between-Subjects & Within-Subjects Designs ! Between-Items & Within-Items Designs ! When are Random Slopes Necessary? ! Practice Activity
  • 42. Between vs. Within Items • We can draw a similar distinction between " Between-Items variables: Each item appears in 1 and only 1 condition … or has 1 and only 1 value • Visual complexity of pictures • One set of sentences is used in our “plausible” condition and a completely different set is used in our “implausible” condition • “Between items” because differences in this variable are only seen between one item and another " Within-Items variables: Same item appears in more than 1 condition or has >1 value • Same science facts presented (across subjects) in either an elaborative- or maintenance-rehearsal condition • We manipulate the same fictitious resume to have either a stereotypically African-American or European-American name
  • 43. Between vs. Within Items • Try updating the most recent model with random slope(s) for the within-items variable(s) • Hint: Think about whether each variable is constant for a particular Word or not • The final full model: • model.Full <- lmer(RT ~ 1 + YearsOfStudy * WordFreq + (1 + WordFreq|Subject) + ?????????????? , data=naming2)
  • 44. Between vs. Within Items • Try updating the most recent model with random slope(s) for the within-items variable(s) • Hint: Think about whether each variable is constant for a particular Word or not • The final full model: • model.Full <- lmer(RT ~ 1 + YearsOfStudy * WordFreq + (1 + WordFreq|Subject) + (1 + YearsOfStudy|Word), data=naming2)
  • 45. Between vs. Within Items • Why didn’t we include a random slope of WordFreq by items? • Each word has a constant frequency (within this experiment) • Doesn’t make sense to discuss effect of word frequency within an item • No random slope of frequency by items • But, each item IS presented to different subjects who differ in their YearsOfStudy 1 2 3 4 300 400 500 600 700 Word frequency RT computer 1 2 3 4 300 400 500 600 700 panther 1 2 3 4 300 400 500 600 700 verify 1 2 3 4 300 400 500 600 700 memorandum
  • 46. Week 6.1: Crossed Random Effects ! Crossed Random Effects Analysis ! Example Design ! Joining Dataframes ! Random Slopes in Crossed Designs ! Between-Subjects & Within-Subjects Designs ! Between-Items & Within-Items Designs ! When are Random Slopes Necessary? ! Practice Activity
  • 47. When Are Random Slopes Necessary? • Remember that failing to account for clustering could inflate our Type I error rate • With factorial experiments, standard is to at least try to include all random slopes we can (Barr et al., 2013) • Maximal random effects structure • Expectation is that we assume that subjects could vary in, say, their WordFreq effect—that’s why we ran more than one subject • If this does not converge, simplify using strategies we discussed last class (e.g., removing correlation parameters)
  • 48. When Are Random Slopes Necessary? • Remember that failing to account for clustering could inflate our Type I error rate • In more observational data, not necessarily the case you’d include all possible random slopes • What’s theoretically relevant or expected?
  • 49. The View Ahead • We’ve covered the basics of fitting a mixed effects model • You will practice this in Wednesday’s lab • But, we have only used continuous variables • Next 3 weeks: Categorical variables (factors) • Next two weeks: Categorical predictors (IVs) • e.g., experimental vs. control condition; race/ethnicity • After that: Categorical outcomes (DVs) • e.g., recalled vs. didn’t recall a science fact; did or didn’t graduate high school
  • 50. Week 6.1: Crossed Random Effects ! Crossed Random Effects Analysis ! Example Design ! Joining Dataframes ! Random Slopes in Crossed Designs ! Between-Subjects & Within-Subjects Designs ! Between-Items & Within-Items Designs ! When are Random Slopes Necessary? ! Practice Activity