class: center, middle, inverse, title-slide .title[ # Skills Lab 11: Mediation ] .subtitle[ ##
The Final FrontieR
] .author[ ### Dr Danielle Evans ] .date[ ### 30 March 2022 ] --- <style type="text/css"> a { color: #f77b00; } </style> ## Overview - **Quick Mediation Recap** + Total effects, indirect effects, & direct effects - **1-Mediator Model** + Defining our model + Fitting our model + Summarising our model + Interpreting our model + Building our model - **2-Mediator Model** + Defining our model + Fitting our model + Summarising our model + Interpreting our model + Building our model ??? --- ## Mediation Recap - **Mediation** occurs when the relationship between a **predictor** and an **outcome**, can be **explained** by their relationship to a third variable: the **mediator** - We're looking at **how** variables are related, we're attempting to further our understanding by **explaining** the relationship between the **predictor** and the **outcome** - With **mediation**, we're interested in **pathways** between variables: <br> .center[ <img src="data:image/png;base64,#img/med.png" width="60%" /> ] ??? --- ## Mediation Recap - We start with the **Total Effect**, which is the simple relationship between **predictor** and **outcome**, where we're not adjusting for any other variables: <br><br> .center[ <img src="data:image/png;base64,#img/te.png" width="70%" /> ] ??? --- ## Mediation Recap - We then partition this **Total Effect** into: + An **Indirect Effect** which is the effect of the **predictor** on the **outcome**, through the **mediator** (path a * path b) + & a **Direct Effect** which is the effect of the **predictor** on the **outcome**, adjusting for the **mediator** .center[ <img src="data:image/png;base64,#img/ef.png" width="60%" /> ] ??? --- ## Mediation Recap - The **Total Effect** is comprised of the **Indirect Effect** AND the **Direct Effect** - Even though we call it the **Total Effect**, it's still just the simple relationship between **predictor** and **outcome** - we haven't accounted for any other variables - By adding in a mediator, we can see how much of this **Total Effect** is a **Direct Effect** of our predictor, and how much can be explained by our mediator (i.e., the **Indirect Effect**) <br> .center[ <img src="data:image/png;base64,#img/floow.png" width="85%" /> ] ??? --- ## Mediation in R - Relatively straightforward to do in **R** with a 3-step process: + **Define model** + **Fit model** + **Summarise model** - We can then **interpret** our results and **build** our model! --- ## Today's Mathsy Mediation - **SES** predicts **parental involvement** in educational activities, which predicts **children's maths abilities**: <br><br><br> .center[ <img src="data:image/png;base64,#img/med3.png" width="85%" /> ] --- ## Step 1: Define Model - We define our model by writing out the paths as a **string of text** - We then save it into an **object** ('**my_mod**') that we can call on when we fit our model in step 2... + The code looks scarier than it really is, we're just **labelling** and **defining** each **pathway**: <div style="line-height:50%;"> <br> </div> ```r my_mod <- 'outcome ~ c*predictor + b*mediator mediator ~ a*predictor indirect_effect := a*b total_effect := c + (a*b) ' ``` <div style="line-height:50%;"> <br> </div> <div class="tu" style="font-size:90%"> <p><b>Top Tip!</b> The weird symbols in the model definition code mean different things: '<b>~</b>' means '<b>is predicted from</b>' and '<b>:=</b>' means '<b>is created from</b>' </p> </div> ??? --- ## Step 1: Define Model - So, we can use this syntax, replacing the '**outcome**', '**predictor**' and '**mediator**' with the names of the **variables** in our data: <br> ```r my_mod <- 'maths_att ~ c*ses + b*parent_inv parent_inv ~ a*ses indirect_effect := a*b total_effect := c + (a*b) ' ``` <br><br><br><br> <div class="tu" style="font-size:90%"> <p><b>Top Tip!</b> We don't need to change the second part of the code because we create the <b>a</b>, <b>b</b>, and <b>c</b> labels in the first 2 lines!</p> </div> --- ## Step 1: Define Model - So, we can use this syntax, replacing the '**outcome**', '**predictor**' and '**mediator**' with the names of the **variables** in our data: <br> ```r my_mod <- 'maths_att ~ c*ses + b*parent_inv parent_inv ~ a*ses indirect_effect := a*b total_effect := c + (a*b) ' ``` <br><br><br><br><br> <div class="pc" style="font-size:90%"> <p><b>Demo!</b> Fitting our Model in R!</p> </div> --- ## Step 2: Fit Model - To fit our mediation model we use the `sem()` function from the `lavaan` package - Here we specify the name of the model we just defined in **step 1**, the name of our data, how we want to handle missing data, and the estimation method we want to use... <br> ```r my_fit <- lavaan::sem(my_mod, data = my_data, missing = "something", estimator = "something") ``` ??? --- ## A Missing Data Detour... - By default, the `sem()` function will use **listwise deletion** to deal with any missing data - **Listwise deletion** this is where an entire participant is excluded from analysis if any single variable is missing - A better method to use that's available in the `sem()` function is **full information maximum likelihood** estimation (aka **FIML** - *no, not FML...*) - **FIML** produces unbiased **parameter estimates** and **standard errors** where there are missing data 🥳 + We would use `missing = "FIML"` in the previous code to change this option! <br> <div class="swr" style="font-size:90%"> <p><b>Don't Do It!!!</b> Listwise deletion is a bad method of dealing with missing data, much better ones include <b><a href = "https://drive.google.com/file/d/1UKKPW_qgfDobDrqnQCd02zTyyuTxmoAU/view">FIML</a></b> and <b><a href = "https://drive.google.com/file/d/1UKKPW_qgfDobDrqnQCd02zTyyuTxmoAU/view">multiple imputation</a></b>!</p> </div> ??? --- ## A Missing Data Detour... - We can only use **FIML** when we use **maximum likelihood** estimators - **Maximum likelihood** estimators work by choosing the parameters that make the data most likely to have happened - We would use `estimator = "ML"` in the previous code to change this option! - We can also use `estimator = "MLR"` instead to get **robust standard errors** (always a good idea!) - So our code becomes: <br> ```r my_fit <- lavaan::sem(my_mod, data = my_data, missing = "FIML", estimator = "MLR") ``` ??? --- ## Step 3: Summarise Model - Once we've fit our model using appropriate methods for handling missing data, we can **summarise** it with a few different functions(): - `broom::glance()` allows us to look at how good our model is - the **model fit statistics**: ```r broom::glance(my_fit) ``` <BR> - `broom::tidy()` allows us to look at our actual effects - the **model parameters**: ```r broom::tidy(my_fit, conf.int = TRUE) ``` ??? --- ## Step 4: Interpret Model - The output of `broom::tidy()` is the part we're most interested in! <br> <table class="table" style="font-size: 11px; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:left;background-color: #003b49; color: #fff; !important;"> term </th> <th style="text-align:left;background-color: #003b49; color: #fff; !important;"> op </th> <th style="text-align:left;background-color: #003b49; color: #fff; !important;"> label </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> estimate </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> std.error </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> statistic </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> p.value </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> conf.low </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> conf.high </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> std.lv </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> std.all </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> std.nox </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;background-color: #b6ccd1; color: #black; !important;"> maths_att ~ ses </td> <td style="text-align:left;background-color: #b6ccd1; color: #black; !important;"> ~ </td> <td style="text-align:left;background-color: #b6ccd1; color: #black; !important;"> c </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.12 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.01 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 8.95 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.00 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.10 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.15 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.12 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.35 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.02 </td> </tr> <tr> <td style="text-align:left;background-color: #b6ccd1; color: #black; !important;"> maths_att ~ parent_inv </td> <td style="text-align:left;background-color: #b6ccd1; color: #black; !important;"> ~ </td> <td style="text-align:left;background-color: #b6ccd1; color: #black; !important;"> b </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.72 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.06 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 11.25 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.00 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.59 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.84 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.72 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.49 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.49 </td> </tr> <tr> <td style="text-align:left;background-color: #b6ccd1; color: #black; !important;"> parent_inv ~ ses </td> <td style="text-align:left;background-color: #b6ccd1; color: #black; !important;"> ~ </td> <td style="text-align:left;background-color: #b6ccd1; color: #black; !important;"> a </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.07 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.01 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 6.73 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.00 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.05 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.09 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.07 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.30 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.01 </td> </tr> <tr> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> maths_att ~~ maths_att </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> ~~ </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 34.32 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 2.37 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 14.47 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.00 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 29.67 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 38.97 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 34.32 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.54 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.54 </td> </tr> <tr> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> parent_inv ~~ parent_inv </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> ~~ </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 27.00 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 1.88 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 14.33 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.00 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 23.31 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 30.69 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 27.00 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.91 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.91 </td> </tr> <tr> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> ses ~~ ses </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> ~~ </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 523.71 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.00 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> NA </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> NA </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 523.71 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 523.71 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 523.71 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 1.00 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 523.71 </td> </tr> <tr> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> maths_att ~1 </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> ~1 </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 3.68 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 2.61 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 1.41 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.16 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> -1.44 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 8.80 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 3.68 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.46 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.46 </td> </tr> <tr> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> parent_inv ~1 </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> ~1 </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 39.94 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.74 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 53.93 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.00 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 38.49 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 41.39 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 39.94 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 7.33 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 7.33 </td> </tr> <tr> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> ses ~1 </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> ~1 </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 55.29 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.00 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> NA </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> NA </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 55.29 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 55.29 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 55.29 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 2.42 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 55.29 </td> </tr> <tr> <td style="text-align:left;background-color: #b6ccd1; color: #black; !important;"> indirect_effect := a*b </td> <td style="text-align:left;background-color: #b6ccd1; color: #black; !important;"> := </td> <td style="text-align:left;background-color: #b6ccd1; color: #black; !important;"> indirect_effect </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.05 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.01 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 5.24 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.00 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.03 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.07 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.05 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.15 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.01 </td> </tr> <tr> <td style="text-align:left;background-color: #b6ccd1; color: #black; !important;"> total_effect := c+(a*b) </td> <td style="text-align:left;background-color: #b6ccd1; color: #black; !important;"> := </td> <td style="text-align:left;background-color: #b6ccd1; color: #black; !important;"> total_effect </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.17 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.01 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 12.28 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.00 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.15 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.20 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.17 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.50 </td> <td style="text-align:right;background-color: #b6ccd1; color: #black; !important;"> 0.02 </td> </tr> </tbody> </table> ??? --- ## Step 4: Interpret Model - The key parts are in **bold**: <br> <table class="table" style="font-size: 11px; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:left;background-color: #003b49; color: #fff; !important;"> term </th> <th style="text-align:left;background-color: #003b49; color: #fff; !important;"> op </th> <th style="text-align:left;background-color: #003b49; color: #fff; !important;"> label </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> estimate </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> std.error </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> statistic </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> p.value </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> conf.low </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> conf.high </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> std.lv </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> std.all </th> <th style="text-align:right;background-color: #003b49; color: #fff; !important;"> std.nox </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> maths_att ~ ses </td> <td style="text-align:left;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> ~ </td> <td style="text-align:left;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> c </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.12 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.01 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 8.95 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.00 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.10 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.15 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.12 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.35 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.02 </td> </tr> <tr> <td style="text-align:left;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> maths_att ~ parent_inv </td> <td style="text-align:left;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> ~ </td> <td style="text-align:left;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> b </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.72 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.06 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 11.25 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.00 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.59 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.84 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.72 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.49 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.49 </td> </tr> <tr> <td style="text-align:left;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> parent_inv ~ ses </td> <td style="text-align:left;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> ~ </td> <td style="text-align:left;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> a </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.07 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.01 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 6.73 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.00 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.05 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.09 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.07 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.30 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.01 </td> </tr> <tr> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> maths_att ~~ maths_att </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> ~~ </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 34.32 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 2.37 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 14.47 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.00 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 29.67 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 38.97 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 34.32 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.54 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.54 </td> </tr> <tr> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> parent_inv ~~ parent_inv </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> ~~ </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 27.00 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 1.88 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 14.33 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.00 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 23.31 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 30.69 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 27.00 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.91 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.91 </td> </tr> <tr> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> ses ~~ ses </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> ~~ </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 523.71 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.00 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> NA </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> NA </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 523.71 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 523.71 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 523.71 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 1.00 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 523.71 </td> </tr> <tr> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> maths_att ~1 </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> ~1 </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 3.68 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 2.61 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 1.41 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.16 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> -1.44 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 8.80 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 3.68 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.46 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.46 </td> </tr> <tr> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> parent_inv ~1 </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> ~1 </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 39.94 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.74 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 53.93 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.00 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 38.49 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 41.39 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 39.94 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 7.33 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 7.33 </td> </tr> <tr> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> ses ~1 </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> ~1 </td> <td style="text-align:left;background-color: #dce4e6; color: #black; !important;"> </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 55.29 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 0.00 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> NA </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> NA </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 55.29 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 55.29 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 55.29 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 2.42 </td> <td style="text-align:right;background-color: #dce4e6; color: #black; !important;"> 55.29 </td> </tr> <tr> <td style="text-align:left;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> indirect_effect := a*b </td> <td style="text-align:left;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> := </td> <td style="text-align:left;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> indirect_effect </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.05 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.01 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 5.24 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.00 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.03 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.07 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.05 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.15 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.01 </td> </tr> <tr> <td style="text-align:left;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> total_effect := c+(a*b) </td> <td style="text-align:left;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> := </td> <td style="text-align:left;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> total_effect </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.17 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.01 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 12.28 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.00 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.15 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.20 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.17 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.50 </td> <td style="text-align:right;font-weight: bold;background-color: #b6ccd1; color: #black; !important;"> 0.02 </td> </tr> </tbody> </table> ??? --- ## Step 5: Build Model - We can use `semPlot::semPaths()` to build a diagram of our model, but making it look pretty is quite tricky - Instead we can use any other software to create it (Word, PowerPoint etc.) - We can take each of the estimates from our `broom::tidy(my_fit, conf.int = TRUE)` summary, putting them into the correct paths: <br> .center[ <img src="data:image/png;base64,#img/uplo.png" width="85%" /> ] ??? --- ## 2-Mediator Model - We can extend our mediation model to include an **additional mediator**: <br> .center[ <img src="data:image/png;base64,#img/2med.png" width="65%" /> ] ??? --- ## 2-Mediator Model in R - To give this a go in **R**, let's have a look at the following model: <div style="line-height:50%;"> <br> </div> .center[ <img src="data:image/png;base64,#img/conmod.png" width="65%" /> ] <div style="line-height:50%;"> <br> </div> - Here our predictor is **maths anxiety**, our outcome is **maths attainment**, our first mediator is **general anxiety**, and our second mediator is **test anxiety** - With this model, we're saying that the relationship between maths anxiety and maths attainment can be explained by general and test anxiety ??? --- ## 2-Mediator Model in R - With 2 mediators, our model is largely the same - we just have to add in another **a** pathway, another **indirect** pathway, & model the **relationship** between our two mediators ```r my_mod_2 <- "outcome ~ c*predictor + b1*med_1 + b2*med_2 med_1 ~ a1*predictor med_2 ~ a2*predictor indirect_med_1 := a1*b1 indirect_med_2 := a2*b2 total_effect := c + (a1*b1) + (a2*b2) med_1 ~~ med_2 " ``` - We just need to change the **labels** to match the **variables** in our dataset like we did before! ??? -- <div class="pc" style="font-size:90%"> <p><b>Demo!</b> 2-Mediator Model in <b>R</b> </p> </div> ??? ```r "maths_att ~ c*maths_anx + b1*gen_anx + b2*test_anx gen_anx ~ a1*maths_anx test_anx ~ a2*maths_anx indirect_gen := a1*b1 indirect_test := a2*b2 total_effect := c + (a1*b1) + (a2*b2) gen_anx ~~ test_anx " ``` --- ## 2-Mediator Model Interpretation - The interpretation of our mediation is the same as before: + We can look at the **parameter estimates**, **confidence intervals**, and ***p*-values** to see if we have a **mediation effect** -- <br> .center[ <img src="data:image/png;base64,#img/medpic2.png" width="70%" /> ] <p style="text-align:left; font-size:50%">*all results are fictional 😉</p> ??? --- ## *That's all - foreveR!* 😱💔 <br> <br> <img src="data:image/png;base64,#./img/aa.gif" width="80%" style="display: block; margin: auto;" /> .center[ [Give session feedback here!](https://forms.gle/ZyXAB7kZzUUyct9n6) 😀 ]