class: center, middle, inverse, title-slide .title[ # Skills Lab 06: Data Wrangling ] .subtitle[ ##
Straight Outta Composites
] .author[ ### Dr Danielle Evans ] .date[ ### 7 March 2024 ] --- <style type="text/css"> a { color: #009af5; font-weight: bold; } a.glossary { font-weight: bold; color: #8e7df1; cursor: help; position: relative; } .remark-inline-code { font-size: var(--code-inline-font-size); color: #4266ff; padding: 2px; } strong { font-weight: bold; color: black; } .remark-slide-number { color: black; opacity: 1; font-size: 0.9rem; } .hljs-github .hljs-string, .hljs-github .hljs-doctag { color: #333; } .hljs-github .hljs-literal { color: #333; } .hiddenFrame{ height:1px; width:1px; opacity: 0; } .red.remark-slide-content { background-color: #000000; font-size: 1rem; padding: 0; width: 100%; height: 100%; } <!-- .remark-container { --> <!-- background: #000000; --> <!-- margin: 0; --> <!-- overflow: hidden; --> <!-- } --> </style> ## Overview - **Reverse Coding** + What? + Why? + How? - **Composites** + What? + Why? + How? -- <br> <br> <br> <br> .center[ ### *Let's get ready to wRangle!! (Yes, again...)* ] --- ## Reverse Coding - What & Why? - When we design questionnaires & scales we have the choice of phrasing items **positively** or **negatively** - A positively-phrased item could be: .center[ **"I love R with all of my heart."** ] - Whereas a negatively-phrased item could be: .center[ **"I hate R with every part of my being."** ] - Both Qs measure the same underlying construct, but a high score on these two items reflects opposing feelings (i.e., high like or high dislike) <br><br> <div class="mb" style="font-size:90%"> <p><b>Woah!</b> Negatively-phrased items can help reduce/identify acquiescent or careless responding on surveys - the goal is always <b>high quality data</b> 😍</p> </div> --- ## Reverse Coding - What & Why? - <a class='glossary' title='Reverse coding, also known as reverse scoring, is a technique used in questionnaire design and data analysis. It involves changing the scoring direction of specific items in a questionnaire to counteract response biases. This entails selecting items with opposite meanings, scoring the responses in the opposite direction, and then incorporating these reversed scores into the overall analysis.'>Reverse Coding</a> (or reverse scoring) is where we change the **numeric values** assigned to **negatively-phrased items** so that a **high score** reflects the same type of response across all items in our questionnaire - With reverse coding, we're not changing participants' data, but just the numeric values we have assigned to the responses for a specific item --- ## Reverse Coding - What & Why? - Let's say we have the two example items below in our questionnaire, where **strongly disagree** is scored as **1** and **strongly agree** is scored as **5**: <div style="line-height:5%;"> <br> </div> .center[ **"Q1. I really enjoy learning R"** <img src="data:image/png;base64,#img/LS3.png" width="87%" /> **"Q2. I find R soul-destroying."** <img src="data:image/png;base64,#img/LS3.png" width="87%" /> ] <div style="line-height:5%;"> <br> </div> - Assuming our participant feels consistently **positive** about **R**, then they would get a score of **5** for **Q1** & a score of **1** for **Q2** - So if we calculated their mean score across these two items, we'd get **3**, which doesn't reflect their positive feelings towards R i.e., it looks as though they feel pretty neutral towards R, instead of reflecting their **R love** --- ## Reverse Coding - What & Why? - But we can reverse code/score the negatively-phrased item by flipping around the scoring - Now, the first item is still scored as **strongly disagree** = **1** and **strongly agree** = **5**, but our second item is now scored in the opposite direction where **strongly disagree** = **5** and **strongly agree** = **1** <div style="line-height:5%;"> <br> </div> .center[ **"Q1. I really enjoy learning R"** <img src="data:image/png;base64,#img/LS3.png" width="87%" /> **"Q2. I find R soul-destroying."** <img src="data:image/png;base64,#img/LS3.png" width="87%" /> ] <div style="line-height:5%;"> <br> </div> - Now if we calculated the mean score across these items for our R LovR participant, they would score a **5**, which accurately reflects their consistently positive feelings towards R --- ## Any Questions? .center[ <iframe src="https://embed.polleverywhere.com/discourses/P7Y7y8GAGmtGTIIgEGx4v?controls=none&short_poll=true" width="100%" height="450px"></iframe> ] --- ## Reverse Coding - How? - There are multiple ways we can reverse code our variables in **R**: + If we have **numeric data**, we can use simple maths or we can use the **dplyr::recode()** function - just like in the [skills lab last week..](https://canvas.sussex.ac.uk/courses/27493/pages/week-5) + If we have **factor data**, we can use the **forcats::relevel()** function + If we have **character data**, we can use **dplyr::recode()** - We can, but we don't *need* to reverse code items before we do a **factor analysis** (FA), but we *must* reverse code negative items before we do a **reliability analysis** (RA) - We also need to reverse code items before creating **composites** - but more on that later! <div style="line-height:5%;"> <br> </div> <div class="tu" style="font-size:90%"> <p><b>Top Tip!</b> It's a good idea to reverse code items <i>after</i> running a <b>FA</b>, because items you might assume are negatively-phrased, don't always turn out to be! </p> </div> --- ## Reverse Coding - How? **Step 1: Look at the factor loadings:** .pull-left[ <table> <thead> <tr> <th style="text-align:left;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> Variable </th> <th style="text-align:right;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> MR1 </th> <th style="text-align:right;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> MR2 </th> <th style="text-align:right;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> MR3 </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ6 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.91 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.12 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.15 </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ8 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.79 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> -0.08 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> -0.33 </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ7 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.71 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.16 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> -0.06 </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> RQ5 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> -0.54 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> 0.37 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> -0.08 </td> </tr> <tr> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> RQ3 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> 0.01 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> 0.95 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> -0.05 </td> </tr> <tr> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> RQ2 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> 0.04 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> 0.95 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> -0.02 </td> </tr> <tr> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ9_NEG </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> 0.08 </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> -0.14 </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> 0.95 </td> </tr> <tr> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ1_NEG </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> -0.19 </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> 0.01 </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> 0.81 </td> </tr> <tr> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ4_NEG </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> -0.35 </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> -0.20 </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> 0.42 </td> </tr> </tbody> </table> ] .pull-right[ <table> <thead> <tr> <th style="text-align:left;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> Variable </th> <th style="text-align:left;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> Question </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ6 </td> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> I enjoy working with computers. </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ8 </td> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> I feel confident using computers. </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ7 </td> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> I find computers easy to use. </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> RQ5 </td> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> I find technology challenging. </td> </tr> <tr> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> RQ3 </td> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> I love learning about statistics. </td> </tr> <tr> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> RQ2 </td> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> I like maths. </td> </tr> <tr> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ9_NEG </td> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> I hate RStudio </td> </tr> <tr> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ1_NEG </td> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> I dislike my R practicals. </td> </tr> <tr> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ4_NEG </td> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> I don't enjoy using R. </td> </tr> </tbody> </table> ] <br> <div class="tu" style="font-size:90%"> <p><b>Top Tip!</b> We're looking for <b>inconsistent signs +/-</b> on the <b>primary</b> factor loading!</p> </div> --- ## Reverse Coding - How? **Step 2: Decide which, if any, variables are negatively related** .pull-left[ <table> <thead> <tr> <th style="text-align:left;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> Variable </th> <th style="text-align:right;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> MR1 </th> <th style="text-align:right;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> MR2 </th> <th style="text-align:right;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> MR3 </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ6 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.91 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.12 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.15 </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ8 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.79 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> -0.08 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> -0.33 </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ7 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.71 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.16 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> -0.06 </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;font-weight: bold;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> RQ5 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;font-weight: bold;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> -0.54 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;font-weight: bold;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> 0.37 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;font-weight: bold;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> -0.08 </td> </tr> <tr> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> RQ3 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> 0.01 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> 0.95 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> -0.05 </td> </tr> <tr> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> RQ2 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> 0.04 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> 0.95 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> -0.02 </td> </tr> <tr> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ9_NEG </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> 0.08 </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> -0.14 </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> 0.95 </td> </tr> <tr> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ1_NEG </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> -0.19 </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> 0.01 </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> 0.81 </td> </tr> <tr> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ4_NEG </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> -0.35 </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> -0.20 </td> <td style="text-align:right;background-color: #a1aeff; color: black; !important;font-size: 16px;"> 0.42 </td> </tr> </tbody> </table> ] .pull-right[ <table> <thead> <tr> <th style="text-align:left;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> Variable </th> <th style="text-align:left;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> Question </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ6 </td> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> I enjoy working with computers. </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ8 </td> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> I feel confident using computers. </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ7 </td> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> I find computers easy to use. </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;font-weight: bold;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> RQ5 </td> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;font-weight: bold;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> I find technology challenging. </td> </tr> <tr> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> RQ3 </td> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> I love learning about statistics. </td> </tr> <tr> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> RQ2 </td> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> I like maths. </td> </tr> <tr> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ9_NEG </td> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> I hate RStudio </td> </tr> <tr> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ1_NEG </td> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> I dislike my R practicals. </td> </tr> <tr> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ4_NEG </td> <td style="text-align:left;background-color: #a1aeff; color: black; !important;font-size: 16px;"> I don't enjoy using R. </td> </tr> </tbody> </table> ] <br> <div class="tu" style="font-size:90%"> <p><b>Top Tip!</b> We're looking for <b>inconsistent signs +/-</b> on the primary factor loading!</p> </div> --- ## Reverse Coding - How? **Step 2: Decide which, if any, variables are negatively related** .pull-left[ <table> <thead> <tr> <th style="text-align:left;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> Variable </th> <th style="text-align:right;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> MR1 </th> <th style="text-align:right;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> MR2 </th> <th style="text-align:right;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> MR3 </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ6 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.91 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.12 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.15 </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ8 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.79 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> -0.08 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> -0.33 </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ7 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.71 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> 0.16 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;"> -0.06 </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> RQ5 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> -0.54 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> 0.37 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> -0.08 </td> </tr> <tr> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> RQ3 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> 0.01 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> 0.95 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> -0.05 </td> </tr> <tr> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> RQ2 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> 0.04 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> 0.95 </td> <td style="text-align:right;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> -0.02 </td> </tr> <tr> <td style="text-align:left;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ9_NEG </td> <td style="text-align:right;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> 0.08 </td> <td style="text-align:right;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> -0.14 </td> <td style="text-align:right;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> 0.95 </td> </tr> <tr> <td style="text-align:left;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ1_NEG </td> <td style="text-align:right;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> -0.19 </td> <td style="text-align:right;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> 0.01 </td> <td style="text-align:right;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> 0.81 </td> </tr> <tr> <td style="text-align:left;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ4_NEG </td> <td style="text-align:right;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> -0.35 </td> <td style="text-align:right;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> -0.20 </td> <td style="text-align:right;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> 0.42 </td> </tr> </tbody> </table> ] .pull-right[ <table> <thead> <tr> <th style="text-align:left;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> Variable </th> <th style="text-align:left;background-color: #3f51b5; color: #fff; !important;font-size: 16px;"> Question </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ6 </td> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> I enjoy working with computers. </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ8 </td> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> I feel confident using computers. </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> RQ7 </td> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;"> I find computers easy to use. </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> RQ5 </td> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> I find technology challenging. </td> </tr> <tr> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> RQ3 </td> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;"> I love learning about statistics. </td> </tr> <tr> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> RQ2 </td> <td style="text-align:left;background-color: #c8d0ff; color: black; !important;font-size: 16px;border-bottom: 3px solid white;"> I like maths. </td> </tr> <tr> <td style="text-align:left;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ9_NEG </td> <td style="text-align:left;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> I hate RStudio </td> </tr> <tr> <td style="text-align:left;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ1_NEG </td> <td style="text-align:left;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> I dislike my R practicals. </td> </tr> <tr> <td style="text-align:left;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> RQ4_NEG </td> <td style="text-align:left;font-weight: bold;background-color: #a1aeff; color: black; !important;font-size: 16px;"> I don't enjoy using R. </td> </tr> </tbody> </table> ] <br> <div class="tu" style="font-size:90%"> <p><b>Top Tip!</b> We're looking for <b>inconsistent signs +/-</b> on the primary factor loading!</p> </div> --- ## Reverse Coding - How? **Step 3: Recode our items** ```r # method 1 - using simple maths on a 5-point scale data <- data |> dplyr::mutate(column_name = 6-column_name) ``` ```r # method 2 - using recode data <- data |> dplyr::mutate(column_name = dplyr::recode( column_name, `1` = 5, `2` = 4, `3` = 3, `4` = 2, `5` = 1)) ``` **Step 4: Check recoding** Use the table() function to compare frequencies before and after recoding to check it has worked <div style="line-height:5%;"> <br> </div> <div class="pc" style="font-size:90%"> <p><b>Demo!</b> Reverse coding numeric items & double checking with table()! </p> </div> --- ## Creating Composites - What & Why? - <a class='glossary' title='A composite score typically refers to a combined measure that incorporates multiple individual variables or components into a single numerical value. In the context of questionnaires or surveys, a composite score refers to a single numerical value calculated from responses to multiple questions or items within the questionnaire. These questions or items typically pertain to related aspects of a particular construct or domain being measured.'>Composite Scores</a> are usually created by calculating the **mean** of a set of items from a scale or questionnaire - We can calculate composite scores from **all** items on a scale + We could have a measure of **"Love for R"** made up of all 50 survey items - Or we can create composites from different **subsets** of items that make up different **factors**/**subscales** + Maybe our measure of **"Love for R"** can be broken down into 3 **factors**/**subscales** of **"Love for Stats"**, **"Love for Computers"**, and **"Coolness"** - We look at the results of our **factor analysis** to decide how items can be combined into a composite (i.e., if we have one overall score, or different subscales), or we can use the **scoring instructions** for any pre-validated scales that we're using --- ## Creating Composites - What & Why? - For example, we could have 4 items of 'r_love' that we can use to create a composite measure by calculating the **mean** of those items for each participant .center[ <table> <thead> <tr> <th style="text-align:left;background-color: #3f51b5; color: #fff; !important;font-size: 19px;"> ID </th> <th style="text-align:right;background-color: #3f51b5; color: #fff; !important;font-size: 19px;"> r_love_1 </th> <th style="text-align:right;background-color: #3f51b5; color: #fff; !important;font-size: 19px;"> r_love_2 </th> <th style="text-align:right;background-color: #3f51b5; color: #fff; !important;font-size: 19px;"> r_love_3 </th> <th style="text-align:right;background-color: #3f51b5; color: #fff; !important;font-size: 19px;"> r_love_4 </th> <th style="text-align:right;background-color: #3f51b5; color: #fff; !important;font-size: 19px;"> r_love_comp </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 19px;"> ppt1 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 1 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 2 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 3 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 1 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 1.75 </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 19px;"> ppt2 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 2 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 5 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 3 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 5 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 3.75 </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 19px;"> ppt3 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 5 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 4 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 4 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 3 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 4.00 </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 19px;"> ppt4 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 3 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 1 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 2 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 1 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 1.75 </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 19px;"> ppt5 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 4 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 2 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 5 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 5 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 4.00 </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 19px;"> ppt6 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 2 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 3 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 3 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 1 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 2.25 </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 19px;"> ppt7 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 1 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 3 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 1 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 4 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 2.25 </td> </tr> <tr> <td style="text-align:left;background-color: #e4eaff; color: black; !important;font-size: 19px;"> ppt8 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 2 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 1 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 3 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 4 </td> <td style="text-align:right;background-color: #e4eaff; color: black; !important;font-size: 19px;"> 2.50 </td> </tr> </tbody> </table> ] - We can then use these **composites** to represent a given construct in further analyses/models --- ## Any Questions? .center[ <iframe src="https://embed.polleverywhere.com/discourses/P7Y7y8GAGmtGTIIgEGx4v?controls=none&short_poll=true" width="100%" height="450px"></iframe> ] --- ## Creating Composites - How? - We can use a combination of different functions to create a **composite score**: + **dplyr::mutate()**, **dplyr::rowwise()**, **mean()**, **c()** & **c_across()** - Before creating composites we should also **reverse score** any negative items because the scoring differs between **positive** and **negative** items and the **mean** of them would not be accurate - We often have to make some decisions around how we choose to handle **missing data** when creating composites + I.e., whether we'll calculate the mean regardless of any missing data, whether we'll calculate it for only complete cases, or whether we'll allow *some* missing data + This is entirely up to the researcher, or the scale creator (there may be specific recommendations you need to follow for scales created by others) --- ## Creating Composites - How? ```r # method 1 - using columns next to eachother comp_scores <- data |> dplyr::rowwise() |> dplyr::mutate(column_name1_comp = mean(c_across(item1:item3)), column_name2_comp = mean(c_across(item4:item5))) ``` ```r # method 2 - using columns NOT next to eachother data <- data |> dplyr::rowwise() |> dplyr::mutate(column_name1_comp = mean(c(item1, item2, item3)), column_name2_comp = mean(c(item4, item5))) ``` <br><br><br><br><br> <div class="pc" style="font-size:90%"> <p><b>Demo!</b> Creating composites! </p> </div> --- ## *That's all - happy wrangling!* <br> <br> <img src="data:image/png;base64,#./img/raw.jpg" width="100%" style="display: block; margin: auto;" /> <p style="text-align:right; font-size:50%">Artwork by @allison_horst</p> .center[ [Give session feedback here!](https://forms.gle/ZyXAB7kZzUUyct9n6) 😀 ]