SlideShare a Scribd company logo
1 of 41
Download to read offline
Week 5.1: Level-2 Variables
! Notation
! Multiple Random Effects
! Combining Datasets in R
! Modeling
! Level-2 Variables
! Including Level-2 Variables in R
! Modeling Consequences
! Cross-Level Interactions
! Lab
Recap
• Last week, we created a model of middle
schoolers’ math performance that included a
random intercept for Classroom
• model1 <- lmer(FinalMathScore ~ 1 + TOI +
(1|Classroom), data=math)
Fixed effect of
naive theory
of intelligence
Average
intercept
(averaged all
classrooms)
Variance in
that intercept
from one class
to the next
Residual
(unexplained)
variance at
the child level
Notation
• What is this model doing mathematically?
• Let’s go back to our model of individual students
(now slightly different):
Student
Error
Ei(j)
=
End-of-year math
exam score
+ +
Baseline
Yi(j) B0j
Fixed mindset
γ10x1i(j)
Notation
• What is this model doing mathematically?
• Let’s go back to our model of individual students
(now slightly different):
Student
Error
Ei(j)
=
End-of-year math
exam score
+ +
Baseline
Yi(j) B0j
Fixed mindset
γ10x1i(j)
What now determines the baseline that
we should expect for students with
fixed mindset=0?
Notation
• What is this model doing mathematically?
• Baseline (intercept) for a student in classroom j
now depends on two things:
• Let’s go back to our model of individual students
(now slightly different):
Student
Error
Ei(j)
=
End-of-year math
exam score
+ +
Baseline
Yi(j) B0j
Fixed mindset
γ10x1i(j)
U0j
=
Intercept
+
Overall intercept
across everyone
B0j γ00
Teacher effect for this
classroom (Error)
Notation
• Essentially, we have two regression models
• Hierarchical linear model
• Model of classroom j:
• Model of student i:
Student
Error
Ei(j)
=
End-of-year math
exam score
+ +
Baseline
Yi(j) B0j
Fixed mindset
γ10x1i(j)
U0j
=
Intercept
+
B0j γ00
Teacher effect for this
classroom (Error)
LEVEL-1
MODEL
(Student)
LEVEL-2
MODEL
(Classroom)
Overall intercept
across everyone
Hierarchical Linear Model
Student
1
Student
2
Student
3
Student
4
Level-1 model:
Sampled STUDENTS
Mr.
Wagner’s
Class
Ms.
Fulton’s
Class
Ms.
Green’s
Class
Ms.
Cornell’s
Class
Level-2 model:
Sampled
CLASSROOMS
• Level-2 model is for the superordinate level here,
Level-1 model is for the subordinate level
Variance of classroom intercept is
the error variance at Level 2
Residual is the error variance at
Level 1
Notation
• Two models seems confusing. But we can simplify
with some algebra…
• Model of classroom j:
• Model of student i:
Student
Error
Ei(j)
=
End-of-year math
exam score
+ +
Baseline
Yi(j) B0j
Fixed mindset
γ10x1i(j)
U0j
=
Intercept
+
B0j γ00
Teacher effect for this
classroom (Error)
LEVEL-1
MODEL
(Student)
LEVEL-2
MODEL
(Classroom)
Overall intercept
across everyone
Notation
• Substitution gives us a single model that combines
level-1 and level-2
• Mixed effects model
• Combined model:
Student
Error
Ei(j)
=
End-of-year math
exam score
+ +
Yi(j)
Fixed mindset
γ10x1i(j)
U0j
+
Overall
intercept
γ00
Teacher effect for this
classroom (Error)
Notation
• Just two slightly different ways of writing the same
thing. Notation difference, not statistical!
• Mixed effects model:
• Hierarchical linear model:
Ei(j)
= + +
Yi(j)
γ10x1i(j)
U0j
+
γ00
Ei(j)
=
Yi(j) B0j
γ10x1i(j)
U0j
= +
B0j γ00
+ +
Notation
• lme4 always uses the mixed-effects model notation
• lmer(
FinalMathScore ~ 1 + TOI + (1|Classroom)
)
• (Level-1 error is always implied, don’t have to
include)
Student
Error
Ei(j)
=
End-of-year math
exam score
+ +
Yi(j)
Fixed mindset
γ10x1i(j) U0j
+
Overall
intercept
γ00
Teacher
effect
for this
class (Error)
Week 5.1: Level-2 Variables
! Notation
! Multiple Random Effects
! Combining Datasets in R
! Modeling
! Level-2 Variables
! Including Level-2 Variables in R
! Modeling Consequences
! Cross-Level Interactions
! Lab
! We’re continuing our study of naïve theories of
intelligence & math performance
! We’ve now collected data at three different
schools
! math1.csv from Jefferson Middle School
! math2.csv from Highland Middle School
! math3.csv from Hoover Middle School
Combining Datasets in R
Combining Datasets in R
! Look at the math1, math2, math3 dataframes
! How are they similar? How are they different?
! TOI and final math score for each student
Combining Datasets in R
! Look at the math1, math2, math3 dataframes
! How are they similar? How are they different?
! TOI and final math score for each student
Columns not always in same order
Combining Datasets in R
! Look at the math1, math2, math3 dataframes
! How are they similar? How are they different?
! TOI and final math score for each student
Only Hoover has GPA
reported
Combining Datasets in R
! Overall, this is similar information, so let’s
combine it all
! Paste together the rows from two (or more)
dataframes to create a new one:
! bind_rows(math1, math2, math3) -> math
! Useful when observations are spread across files
! Or, to create a dataframe that combines 2 filtered
dataframes
math1
math2
math3
math
bind_rows(): Results
! Resulting dataframe:
! nrow(math) is 720 – all three combined
math1
math2
math3
math
! Resulting dataframe:
! bind_rows() is smart!
! Not a problem that column order varies across
dataframes
! Looks at the column names
! Not a problem that GPA column only existed in one of
the original dataframes
! NA (missing data) for the students at the other schools
bind_rows(): Results
bind_rows(): Results
! Resulting dataframe:
! You can also add the optional .id argument
! bind_rows(math1, math2, math3,
.id='OriginalDataframe’) -> math
! Adds another column that tracks which of the original
dataframes (by number) each observation came from
Other, Similar Functions
! bind_rows() pastes together every row from
every dataframe, even if there are duplicates
! If you want to skip duplicates, use union()
! Same syntax as bind_rows(), just different function name
! Other related functions:
! intersect(): Keep only the rows that appear in all of
the source dataframes
! setdiff(): Keep only the rows that appear in a single
source dataframe—if duplicates, delete both copies
Week 5.1: Level-2 Variables
! Notation
! Multiple Random Effects
! Combining Datasets in R
! Modeling
! Level-2 Variables
! Including Level-2 Variables in R
! Modeling Consequences
! Cross-Level Interactions
! Lab
Multiple Random Effects
• Schools could differ in math achievement—let’s add
School to the model to control for that
• Is SCHOOL a fixed effect or a random effect?
• These schools are just a sample of possible schools of
interest " Random effect.
School
1
School
2
Sampled SCHOOLS
Sampled
CLASSROOMS
Sampled STUDENTS
LEVEL 3
LEVEL 2
LEVEL 1
Student
1
Student
2
Student
3
Student
4
Mr.
Wagner’s
Class
Ms.
Fulton’s
Class
Ms.
Green’s
Class
Ms.
Cornell’s
Class
Multiple Random Effects
• No problem to have more than 1 random effect in
the model! Let’s a random intercept for School.
School
1
School
2
Sampled SCHOOLS
Sampled
CLASSROOMS
Sampled STUDENTS
LEVEL 3
LEVEL 2
LEVEL 1
Student
1
Student
2
Student
3
Student
4
Mr.
Wagner’s
Class
Ms.
Fulton’s
Class
Ms.
Green’s
Class
Ms.
Cornell’s
Class
Multiple Random Effects
• model2 <- lmer(FinalMathScore ~ 1 + TOI
+ (1|Classroom) + (1|School), data=math)
School
1
School
2
Sampled SCHOOLS
Sampled
CLASSROOMS
Sampled STUDENTS
LEVEL 3
LEVEL 2
LEVEL 1
Student
1
Student
2
Student
3
Student
4
Mr.
Wagner’s
Class
Ms.
Fulton’s
Class
Ms.
Green’s
Class
Ms.
Cornell’s
Class
Multiple Random Effects
• model2 <- lmer(FinalMathScore ~ 1 + TOI
+ (1|Classroom) + (1|School), data=math)
• Less variability across schools than classrooms in a school
Multiple Random Effects
• This is an example of nested random effects.
• Each classroom is always in the same school.
• We’ll look at crossed random effects next week
School
1
School
2
Sampled SCHOOLS
Sampled
CLASSROOMS
Sampled STUDENTS
LEVEL 3
LEVEL 2
LEVEL 1
Student
1
Student
2
Student
3
Student
4
Mr.
Wagner’s
Class
Ms.
Fulton’s
Class
Ms.
Green’s
Class
Ms.
Cornell’s
Class
Week 5.1: Level-2 Variables
! Notation
! Multiple Random Effects
! Combining Datasets in R
! Modeling
! Level-2 Variables
! Including Level-2 Variables in R
! Modeling Consequences
! Cross-Level Interactions
! Lab
Level-2 Variables
• So far, all our model says about classrooms is
that they’re different
• Some classrooms have a large intercept
• Some classrooms have a small intercept
• But, we might also have some interesting
variables that characterize classrooms
• They might even be our main research interest!
• How about teacher theories of intelligence?
• Might affect how they interact with & teach students
Level-2 Variables
Student
1
Student
2
Student
3
Student
4
Sampled STUDENTS
Mr.
Wagner’s
Class
Ms.
Fulton’s
Class
Ms.
Green’s
Class
Ms.
Cornell’s
Class
Sampled
CLASSROOMS
• TeacherTheory characterizes Level 2
• All students in the same classroom will experience
the same TeacherTheory
LEVEL 2
LEVEL 1
TeacherTheory
TOI
Level-2 Variables
• Is TeacherTheory a fixed effect or random
effect?
• Teacher mindset is a fixed-effect variable
• We ARE interested in the effects of teacher mindset
on student math achievement … a research
question, not just something to control for
• Even if we ran this with a new random sample of 30
teachers, we WOULD hope to replicate whatever
regression slope for teacher mindset we observe
(whereas we wouldn’t get the same 30 teachers
back)
Level-2 Variables
• This becomes another variable in the level-2
model of classroom differences
• Tells us what we can expect this classroom to be like
Student
Error
Ei(j)
=
End-of-year math
exam score
+ +
Baseline
Yi(j) B0j
Growth mindset
γ10x1i(j)
U0j
=
Intercept
+
Overall
intercept
B0j
γ00
Teacher effect for this
classroom (Error)
LEVEL-1
MODEL
(Student)
LEVEL-2
MODEL
(Classroom)
Teacher
mindset
+
γ20x20j
Level-2 Variables
• Since R uses mixed effects notation, we don’t
have to do anything special to add a level-2
variable to the model
• model3 <- lmer(FinalMathScore ~ 1 + TOI
+ TeacherTheory + (1|Classroom) +
(1|School), data=math)
• R automatically figures out TeacherTheory is a
level-2 variable because it’s invariant for each
classroom
• We keep the random intercept for Classroom
because we don’t expect TeacherTheory will
explain all of the classroom differences. Intercept
captures residual differences.
Week 5.1: Level-2 Variables
! Notation
! Multiple Random Effects
! Combining Datasets in R
! Modeling
! Level-2 Variables
! Including Level-2 Variables in R
! Modeling Consequences
! Cross-Level Interactions
! Lab
What Changes? What Doesn’t?
• Random classroom & school variance is reduced.
• Teacher theories of intelligence accounts for some of the variance
among classrooms (and among the schools those classrooms are in).
• TeacherTheory explains some of the “Class j” effect we’re substituting
into the level 1 equation. No longer just a random intercept.
WITHOUT TEACHERTHEORY WITH TEACHERTHEORY
What Changes? What Doesn’t?
• Residual error at level 1 essentially unchanged.
• Describes how students vary from the class average
• Divergence from the class average cannot be explained by teacher
• Regardless of what explains the “Class j” effect, you’re still substituting it
into the same Lv 1 model
WITHOUT TEACHERTHEORY WITH TEACHERTHEORY
What Changes? What Doesn’t?
• Similarly, our level-1 fixed effect is essentially unchanged
• Explaining where level-2 variation comes from does not change our
level-1 model
• Note that average student TOI and TeacherTheory are very slightly
correlated (due to random chance); otherwise, there’d be no change.
WITHOUT TEACHERTHEORY WITH TEACHERTHEORY
Week 5.1: Level-2 Variables
! Notation
! Multiple Random Effects
! Combining Datasets in R
! Modeling
! Level-2 Variables
! Including Level-2 Variables in R
! Modeling Consequences
! Cross-Level Interactions
! Lab
Cross-Level Interactions
• Because R uses mixed effects notation, it’s also
very easy to add interactions between level-1
and level-2 variables
• model4 <- lmer(FinalMathScore ~ 1 + TOI
+ TeacherTheory + TOI:TeacherTheory +
(1|Classroom) + (1|School), data=math)
• Does the effect of a student’s theory of intelligence
depend on what the teacher’s theory is?
• e.g., maybe matching theories is beneficial
Cross-Level Interactions
• Because R uses mixed effects notation, it’s also
very easy to add interactions between level-1
and level-2 variables
• In this case, the interaction is not significant
Week 5.1: Level-2 Variables
! Notation
! Multiple Random Effects
! Combining Datasets in R
! Modeling
! Level-2 Variables
! Including Level-2 Variables in R
! Modeling Consequences
! Cross-Level Interactions
! Lab

More Related Content

What's hot

Functions based algebra 1 pesentation to department 042312
Functions based algebra 1 pesentation to department 042312Functions based algebra 1 pesentation to department 042312
Functions based algebra 1 pesentation to department 042312
maryannfoss
 
G6 m4-h-lesson 31-t
G6 m4-h-lesson 31-tG6 m4-h-lesson 31-t
G6 m4-h-lesson 31-t
mlabuski
 

What's hot (20)

Mixed Effects Models - Missing Data
Mixed Effects Models - Missing DataMixed Effects Models - Missing Data
Mixed Effects Models - Missing Data
 
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 - Random Intercepts
Mixed Effects Models - Random InterceptsMixed Effects Models - Random Intercepts
Mixed Effects Models - Random Intercepts
 
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 - Logit Models
Mixed Effects Models - Logit ModelsMixed Effects Models - Logit Models
Mixed Effects Models - Logit Models
 
Mixed Effects Models - Crossed Random Effects
Mixed Effects Models - Crossed Random EffectsMixed Effects Models - Crossed Random Effects
Mixed Effects Models - Crossed Random Effects
 
Mixed Effects Models - 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 - Power
Mixed Effects Models - PowerMixed Effects Models - Power
Mixed Effects Models - Power
 
Mixed Effects Models - Empirical Logit
Mixed Effects Models - Empirical LogitMixed Effects Models - Empirical Logit
Mixed Effects Models - Empirical Logit
 
Mixed Effects Models - Effect Size
Mixed Effects Models - Effect SizeMixed Effects Models - Effect Size
Mixed Effects Models - Effect Size
 
Mixed Effects Models - Data Processing
Mixed Effects Models - Data ProcessingMixed Effects Models - Data Processing
Mixed Effects Models - Data Processing
 
Mixed Effects Models - Descriptive Statistics
Mixed Effects Models - Descriptive StatisticsMixed Effects Models - Descriptive Statistics
Mixed Effects Models - Descriptive Statistics
 
Functions based algebra 1 pesentation to department 042312
Functions based algebra 1 pesentation to department 042312Functions based algebra 1 pesentation to department 042312
Functions based algebra 1 pesentation to department 042312
 
Assignment 1 (to be submitted through the assignment submiss
Assignment 1 (to be submitted through the assignment submissAssignment 1 (to be submitted through the assignment submiss
Assignment 1 (to be submitted through the assignment submiss
 
Joseph Jay Williams - WESST - Bridging Research via MOOClets and Collaborativ...
Joseph Jay Williams - WESST - Bridging Research via MOOClets and Collaborativ...Joseph Jay Williams - WESST - Bridging Research via MOOClets and Collaborativ...
Joseph Jay Williams - WESST - Bridging Research via MOOClets and Collaborativ...
 
G6 m4-h-lesson 31-t
G6 m4-h-lesson 31-tG6 m4-h-lesson 31-t
G6 m4-h-lesson 31-t
 
Fostering Systems Thinking in Your Students
Fostering Systems Thinking in Your StudentsFostering Systems Thinking in Your Students
Fostering Systems Thinking in Your Students
 
Automated Models for Quantifying Centrality of Survey Responses
Automated Models for Quantifying Centrality of Survey ResponsesAutomated Models for Quantifying Centrality of Survey Responses
Automated Models for Quantifying Centrality of Survey Responses
 
Joseph Jay Williams - WESST - Bridging Research and Practice via MOOClets & C...
Joseph Jay Williams - WESST - Bridging Research and Practice via MOOClets & C...Joseph Jay Williams - WESST - Bridging Research and Practice via MOOClets & C...
Joseph Jay Williams - WESST - Bridging Research and Practice via MOOClets & C...
 

Similar to Mixed Effects Models - Level-2 Variables

Math grade 1 training
Math grade 1 trainingMath grade 1 training
Math grade 1 training
Anthony Smith
 
Math grade 2 training
Math grade 2 trainingMath grade 2 training
Math grade 2 training
Anthony Smith
 
Agilemind presentation
Agilemind presentationAgilemind presentation
Agilemind presentation
teufelsdroch
 
M098 Syllabus Fall 2011
M098 Syllabus Fall 2011M098 Syllabus Fall 2011
M098 Syllabus Fall 2011
chairsty
 
Proposal for Assessment and Feedback
Proposal for Assessment and FeedbackProposal for Assessment and Feedback
Proposal for Assessment and Feedback
sarrrer
 
Math 205 syllabus Fall 2012
Math 205 syllabus Fall 2012Math 205 syllabus Fall 2012
Math 205 syllabus Fall 2012
Jeneva Clark
 
Math replacement program information.11.12
Math replacement program information.11.12Math replacement program information.11.12
Math replacement program information.11.12
Matt Coaty
 
Action research on grading and assessment practices of grade 7 mathematics
Action research on grading and assessment practices of grade 7 mathematicsAction research on grading and assessment practices of grade 7 mathematics
Action research on grading and assessment practices of grade 7 mathematics
Gary Johnston
 
Memo remedial math lab proposal
Memo remedial math lab proposalMemo remedial math lab proposal
Memo remedial math lab proposal
Nathan Penn
 

Similar to Mixed Effects Models - Level-2 Variables (20)

UNC CETL - JiTT - Making It Shine - Nov 2015
UNC CETL - JiTT - Making It Shine - Nov 2015UNC CETL - JiTT - Making It Shine - Nov 2015
UNC CETL - JiTT - Making It Shine - Nov 2015
 
Forest Hills Mmc
Forest Hills MmcForest Hills Mmc
Forest Hills Mmc
 
Math grade 1 training
Math grade 1 trainingMath grade 1 training
Math grade 1 training
 
Math Summit
Math SummitMath Summit
Math Summit
 
Solving Equations by Factoring KTIP lesson plan
Solving Equations by Factoring KTIP lesson planSolving Equations by Factoring KTIP lesson plan
Solving Equations by Factoring KTIP lesson plan
 
Math grade 2 training
Math grade 2 trainingMath grade 2 training
Math grade 2 training
 
Agilemind presentation
Agilemind presentationAgilemind presentation
Agilemind presentation
 
Blankenship sara stage2
Blankenship sara stage2Blankenship sara stage2
Blankenship sara stage2
 
Don’t fal out techno in
Don’t fal out techno inDon’t fal out techno in
Don’t fal out techno in
 
Maply TA - Toby Bailey
Maply TA - Toby BaileyMaply TA - Toby Bailey
Maply TA - Toby Bailey
 
An accurate ability evaluation method for every student with small problem it...
An accurate ability evaluation method for every student with small problem it...An accurate ability evaluation method for every student with small problem it...
An accurate ability evaluation method for every student with small problem it...
 
Accessing student performance by nlp
Accessing student performance by nlpAccessing student performance by nlp
Accessing student performance by nlp
 
ITL516 Week One Assignment One
ITL516 Week One Assignment OneITL516 Week One Assignment One
ITL516 Week One Assignment One
 
M098 Syllabus Fall 2011
M098 Syllabus Fall 2011M098 Syllabus Fall 2011
M098 Syllabus Fall 2011
 
Proposal for Assessment and Feedback
Proposal for Assessment and FeedbackProposal for Assessment and Feedback
Proposal for Assessment and Feedback
 
Math 205 syllabus Fall 2012
Math 205 syllabus Fall 2012Math 205 syllabus Fall 2012
Math 205 syllabus Fall 2012
 
Evaluating functions basic rules (day 3)
Evaluating functions   basic rules (day 3)Evaluating functions   basic rules (day 3)
Evaluating functions basic rules (day 3)
 
Math replacement program information.11.12
Math replacement program information.11.12Math replacement program information.11.12
Math replacement program information.11.12
 
Action research on grading and assessment practices of grade 7 mathematics
Action research on grading and assessment practices of grade 7 mathematicsAction research on grading and assessment practices of grade 7 mathematics
Action research on grading and assessment practices of grade 7 mathematics
 
Memo remedial math lab proposal
Memo remedial math lab proposalMemo remedial math lab proposal
Memo remedial math lab proposal
 

Recently uploaded

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 

Mixed Effects Models - Level-2 Variables

  • 1. Week 5.1: Level-2 Variables ! Notation ! Multiple Random Effects ! Combining Datasets in R ! Modeling ! Level-2 Variables ! Including Level-2 Variables in R ! Modeling Consequences ! Cross-Level Interactions ! Lab
  • 2. Recap • Last week, we created a model of middle schoolers’ math performance that included a random intercept for Classroom • model1 <- lmer(FinalMathScore ~ 1 + TOI + (1|Classroom), data=math) Fixed effect of naive theory of intelligence Average intercept (averaged all classrooms) Variance in that intercept from one class to the next Residual (unexplained) variance at the child level
  • 3. Notation • What is this model doing mathematically? • Let’s go back to our model of individual students (now slightly different): Student Error Ei(j) = End-of-year math exam score + + Baseline Yi(j) B0j Fixed mindset γ10x1i(j)
  • 4. Notation • What is this model doing mathematically? • Let’s go back to our model of individual students (now slightly different): Student Error Ei(j) = End-of-year math exam score + + Baseline Yi(j) B0j Fixed mindset γ10x1i(j) What now determines the baseline that we should expect for students with fixed mindset=0?
  • 5. Notation • What is this model doing mathematically? • Baseline (intercept) for a student in classroom j now depends on two things: • Let’s go back to our model of individual students (now slightly different): Student Error Ei(j) = End-of-year math exam score + + Baseline Yi(j) B0j Fixed mindset γ10x1i(j) U0j = Intercept + Overall intercept across everyone B0j γ00 Teacher effect for this classroom (Error)
  • 6. Notation • Essentially, we have two regression models • Hierarchical linear model • Model of classroom j: • Model of student i: Student Error Ei(j) = End-of-year math exam score + + Baseline Yi(j) B0j Fixed mindset γ10x1i(j) U0j = Intercept + B0j γ00 Teacher effect for this classroom (Error) LEVEL-1 MODEL (Student) LEVEL-2 MODEL (Classroom) Overall intercept across everyone
  • 7. Hierarchical Linear Model Student 1 Student 2 Student 3 Student 4 Level-1 model: Sampled STUDENTS Mr. Wagner’s Class Ms. Fulton’s Class Ms. Green’s Class Ms. Cornell’s Class Level-2 model: Sampled CLASSROOMS • Level-2 model is for the superordinate level here, Level-1 model is for the subordinate level Variance of classroom intercept is the error variance at Level 2 Residual is the error variance at Level 1
  • 8. Notation • Two models seems confusing. But we can simplify with some algebra… • Model of classroom j: • Model of student i: Student Error Ei(j) = End-of-year math exam score + + Baseline Yi(j) B0j Fixed mindset γ10x1i(j) U0j = Intercept + B0j γ00 Teacher effect for this classroom (Error) LEVEL-1 MODEL (Student) LEVEL-2 MODEL (Classroom) Overall intercept across everyone
  • 9. Notation • Substitution gives us a single model that combines level-1 and level-2 • Mixed effects model • Combined model: Student Error Ei(j) = End-of-year math exam score + + Yi(j) Fixed mindset γ10x1i(j) U0j + Overall intercept γ00 Teacher effect for this classroom (Error)
  • 10. Notation • Just two slightly different ways of writing the same thing. Notation difference, not statistical! • Mixed effects model: • Hierarchical linear model: Ei(j) = + + Yi(j) γ10x1i(j) U0j + γ00 Ei(j) = Yi(j) B0j γ10x1i(j) U0j = + B0j γ00 + +
  • 11. Notation • lme4 always uses the mixed-effects model notation • lmer( FinalMathScore ~ 1 + TOI + (1|Classroom) ) • (Level-1 error is always implied, don’t have to include) Student Error Ei(j) = End-of-year math exam score + + Yi(j) Fixed mindset γ10x1i(j) U0j + Overall intercept γ00 Teacher effect for this class (Error)
  • 12. Week 5.1: Level-2 Variables ! Notation ! Multiple Random Effects ! Combining Datasets in R ! Modeling ! Level-2 Variables ! Including Level-2 Variables in R ! Modeling Consequences ! Cross-Level Interactions ! Lab
  • 13. ! We’re continuing our study of naïve theories of intelligence & math performance ! We’ve now collected data at three different schools ! math1.csv from Jefferson Middle School ! math2.csv from Highland Middle School ! math3.csv from Hoover Middle School Combining Datasets in R
  • 14. Combining Datasets in R ! Look at the math1, math2, math3 dataframes ! How are they similar? How are they different? ! TOI and final math score for each student
  • 15. Combining Datasets in R ! Look at the math1, math2, math3 dataframes ! How are they similar? How are they different? ! TOI and final math score for each student Columns not always in same order
  • 16. Combining Datasets in R ! Look at the math1, math2, math3 dataframes ! How are they similar? How are they different? ! TOI and final math score for each student Only Hoover has GPA reported
  • 17. Combining Datasets in R ! Overall, this is similar information, so let’s combine it all ! Paste together the rows from two (or more) dataframes to create a new one: ! bind_rows(math1, math2, math3) -> math ! Useful when observations are spread across files ! Or, to create a dataframe that combines 2 filtered dataframes math1 math2 math3 math
  • 18. bind_rows(): Results ! Resulting dataframe: ! nrow(math) is 720 – all three combined math1 math2 math3 math
  • 19. ! Resulting dataframe: ! bind_rows() is smart! ! Not a problem that column order varies across dataframes ! Looks at the column names ! Not a problem that GPA column only existed in one of the original dataframes ! NA (missing data) for the students at the other schools bind_rows(): Results
  • 20. bind_rows(): Results ! Resulting dataframe: ! You can also add the optional .id argument ! bind_rows(math1, math2, math3, .id='OriginalDataframe’) -> math ! Adds another column that tracks which of the original dataframes (by number) each observation came from
  • 21. Other, Similar Functions ! bind_rows() pastes together every row from every dataframe, even if there are duplicates ! If you want to skip duplicates, use union() ! Same syntax as bind_rows(), just different function name ! Other related functions: ! intersect(): Keep only the rows that appear in all of the source dataframes ! setdiff(): Keep only the rows that appear in a single source dataframe—if duplicates, delete both copies
  • 22. Week 5.1: Level-2 Variables ! Notation ! Multiple Random Effects ! Combining Datasets in R ! Modeling ! Level-2 Variables ! Including Level-2 Variables in R ! Modeling Consequences ! Cross-Level Interactions ! Lab
  • 23. Multiple Random Effects • Schools could differ in math achievement—let’s add School to the model to control for that • Is SCHOOL a fixed effect or a random effect? • These schools are just a sample of possible schools of interest " Random effect. School 1 School 2 Sampled SCHOOLS Sampled CLASSROOMS Sampled STUDENTS LEVEL 3 LEVEL 2 LEVEL 1 Student 1 Student 2 Student 3 Student 4 Mr. Wagner’s Class Ms. Fulton’s Class Ms. Green’s Class Ms. Cornell’s Class
  • 24. Multiple Random Effects • No problem to have more than 1 random effect in the model! Let’s a random intercept for School. School 1 School 2 Sampled SCHOOLS Sampled CLASSROOMS Sampled STUDENTS LEVEL 3 LEVEL 2 LEVEL 1 Student 1 Student 2 Student 3 Student 4 Mr. Wagner’s Class Ms. Fulton’s Class Ms. Green’s Class Ms. Cornell’s Class
  • 25. Multiple Random Effects • model2 <- lmer(FinalMathScore ~ 1 + TOI + (1|Classroom) + (1|School), data=math) School 1 School 2 Sampled SCHOOLS Sampled CLASSROOMS Sampled STUDENTS LEVEL 3 LEVEL 2 LEVEL 1 Student 1 Student 2 Student 3 Student 4 Mr. Wagner’s Class Ms. Fulton’s Class Ms. Green’s Class Ms. Cornell’s Class
  • 26. Multiple Random Effects • model2 <- lmer(FinalMathScore ~ 1 + TOI + (1|Classroom) + (1|School), data=math) • Less variability across schools than classrooms in a school
  • 27. Multiple Random Effects • This is an example of nested random effects. • Each classroom is always in the same school. • We’ll look at crossed random effects next week School 1 School 2 Sampled SCHOOLS Sampled CLASSROOMS Sampled STUDENTS LEVEL 3 LEVEL 2 LEVEL 1 Student 1 Student 2 Student 3 Student 4 Mr. Wagner’s Class Ms. Fulton’s Class Ms. Green’s Class Ms. Cornell’s Class
  • 28. Week 5.1: Level-2 Variables ! Notation ! Multiple Random Effects ! Combining Datasets in R ! Modeling ! Level-2 Variables ! Including Level-2 Variables in R ! Modeling Consequences ! Cross-Level Interactions ! Lab
  • 29. Level-2 Variables • So far, all our model says about classrooms is that they’re different • Some classrooms have a large intercept • Some classrooms have a small intercept • But, we might also have some interesting variables that characterize classrooms • They might even be our main research interest! • How about teacher theories of intelligence? • Might affect how they interact with & teach students
  • 30. Level-2 Variables Student 1 Student 2 Student 3 Student 4 Sampled STUDENTS Mr. Wagner’s Class Ms. Fulton’s Class Ms. Green’s Class Ms. Cornell’s Class Sampled CLASSROOMS • TeacherTheory characterizes Level 2 • All students in the same classroom will experience the same TeacherTheory LEVEL 2 LEVEL 1 TeacherTheory TOI
  • 31. Level-2 Variables • Is TeacherTheory a fixed effect or random effect? • Teacher mindset is a fixed-effect variable • We ARE interested in the effects of teacher mindset on student math achievement … a research question, not just something to control for • Even if we ran this with a new random sample of 30 teachers, we WOULD hope to replicate whatever regression slope for teacher mindset we observe (whereas we wouldn’t get the same 30 teachers back)
  • 32. Level-2 Variables • This becomes another variable in the level-2 model of classroom differences • Tells us what we can expect this classroom to be like Student Error Ei(j) = End-of-year math exam score + + Baseline Yi(j) B0j Growth mindset γ10x1i(j) U0j = Intercept + Overall intercept B0j γ00 Teacher effect for this classroom (Error) LEVEL-1 MODEL (Student) LEVEL-2 MODEL (Classroom) Teacher mindset + γ20x20j
  • 33. Level-2 Variables • Since R uses mixed effects notation, we don’t have to do anything special to add a level-2 variable to the model • model3 <- lmer(FinalMathScore ~ 1 + TOI + TeacherTheory + (1|Classroom) + (1|School), data=math) • R automatically figures out TeacherTheory is a level-2 variable because it’s invariant for each classroom • We keep the random intercept for Classroom because we don’t expect TeacherTheory will explain all of the classroom differences. Intercept captures residual differences.
  • 34. Week 5.1: Level-2 Variables ! Notation ! Multiple Random Effects ! Combining Datasets in R ! Modeling ! Level-2 Variables ! Including Level-2 Variables in R ! Modeling Consequences ! Cross-Level Interactions ! Lab
  • 35. What Changes? What Doesn’t? • Random classroom & school variance is reduced. • Teacher theories of intelligence accounts for some of the variance among classrooms (and among the schools those classrooms are in). • TeacherTheory explains some of the “Class j” effect we’re substituting into the level 1 equation. No longer just a random intercept. WITHOUT TEACHERTHEORY WITH TEACHERTHEORY
  • 36. What Changes? What Doesn’t? • Residual error at level 1 essentially unchanged. • Describes how students vary from the class average • Divergence from the class average cannot be explained by teacher • Regardless of what explains the “Class j” effect, you’re still substituting it into the same Lv 1 model WITHOUT TEACHERTHEORY WITH TEACHERTHEORY
  • 37. What Changes? What Doesn’t? • Similarly, our level-1 fixed effect is essentially unchanged • Explaining where level-2 variation comes from does not change our level-1 model • Note that average student TOI and TeacherTheory are very slightly correlated (due to random chance); otherwise, there’d be no change. WITHOUT TEACHERTHEORY WITH TEACHERTHEORY
  • 38. Week 5.1: Level-2 Variables ! Notation ! Multiple Random Effects ! Combining Datasets in R ! Modeling ! Level-2 Variables ! Including Level-2 Variables in R ! Modeling Consequences ! Cross-Level Interactions ! Lab
  • 39. Cross-Level Interactions • Because R uses mixed effects notation, it’s also very easy to add interactions between level-1 and level-2 variables • model4 <- lmer(FinalMathScore ~ 1 + TOI + TeacherTheory + TOI:TeacherTheory + (1|Classroom) + (1|School), data=math) • Does the effect of a student’s theory of intelligence depend on what the teacher’s theory is? • e.g., maybe matching theories is beneficial
  • 40. Cross-Level Interactions • Because R uses mixed effects notation, it’s also very easy to add interactions between level-1 and level-2 variables • In this case, the interaction is not significant
  • 41. Week 5.1: Level-2 Variables ! Notation ! Multiple Random Effects ! Combining Datasets in R ! Modeling ! Level-2 Variables ! Including Level-2 Variables in R ! Modeling Consequences ! Cross-Level Interactions ! Lab