<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/variable-vs-participant-wise-standardization/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://neuropsychology.github.io/psycho.R//2018/07/14/standardize_grouped_df.html"> Dominique Makowski</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<ul>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/07/14/standardize_grouped_df.html#the-data" target="_blank">The data</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/07/14/standardize_grouped_df.html#standardize" target="_blank">Standardize</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/07/14/standardize_grouped_df.html#effect-of-standardization" target="_blank">Effect of Standardization</a>
<ul>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/07/14/standardize_grouped_df.html#at-a-general-level" target="_blank">At a general level</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/07/14/standardize_grouped_df.html#at-a-participant-level" target="_blank">At a participant level</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/07/14/standardize_grouped_df.html#distribution" target="_blank">Distribution</a></li>
</ul>
</li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/07/14/standardize_grouped_df.html#correlation" target="_blank">Correlation</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/07/14/standardize_grouped_df.html#test" target="_blank">Test</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/07/14/standardize_grouped_df.html#conclusion" target="_blank">Conclusion</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/07/14/standardize_grouped_df.html#credits" target="_blank">Credits</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/07/14/standardize_grouped_df.html#previous-blogposts" target="_blank">Previous blogposts</a></li>
</ul>
<p>To make sense of their data and effects, psychologists often standardize (Z-score) their variables. However, in repeated-measures designs, there are three ways of standardizing data:</p>
<ul>
<li><strong>Variable-wise</strong>: The most common method. A simple scaling and reducing of each variable by their mean and SD.</li>
<li><strong>Participant-wise</strong>: Variables are standardized “within” each participant, <em>i.e.</em>, for each participant, by the participant’s mean and SD.</li>
<li><strong>Full</strong>: Participant-wise first and then re-standardizing variable-wise.</li>
</ul>
<p>Unfortunately, the method used is often not explicitly stated. This is an issue as these methods can generate important discrepancies that contribute to the reproducibility crisis of psychological science.</p>
<p>In the following, we will see how to perform those methods and look for differences.</p>
<h1>The data</h1>
<p>We will take a dataset in which participants were exposed to negative pictures and had to rate their emotions (<strong>valence</strong>) and the amount of memories associated with the picture (<strong>autobiographical link</strong>). One could make the hypothesis that for young participants with no context of war or violence, the most negative pictures (mutilations) are less related to memories than less negative pictures (involving for example car crashes or sick people). In other words, <strong>we expect a positive relationship between valence</strong> (with high values corresponding to less negativity) <strong>and autobiographical link</strong>.</p>
<p>Let’s have a look at the data, averaged by participants:</p>
<div>
<div>
<pre><code><span>library</span><span>(</span><span>tidyverse</span><span>)</span><span>
</span><span>library</span><span>(</span><span>psycho</span><span>)</span><span>
</span><span>df</span><span> </span><span>&lt;-</span><span> </span><span>psycho</span><span>::</span><span>emotion</span><span> </span><span>%>%</span><span> </span><span># Load the dataset from the psycho package</span><span>
</span><span>filter</span><span>(</span><span>Emotion_Condition</span><span> </span><span>==</span><span> </span><span>&quot;Negative&quot;</span><span>)</span><span> </span><span># Discard neutral pictures</span><span>
</span><span>df</span><span> </span><span>%>%</span><span> </span><span>group_by</span><span>(</span><span>Participant_ID</span><span>)</span><span> </span><span>%>%</span><span> </span><span>summarise</span><span>(</span><span>n_Trials</span><span> </span><span>=</span><span> </span><span>n</span><span>(),</span><span>
</span><span>Valence_Mean</span><span> </span><span>=</span><span> </span><span>mean</span><span>(</span><span>Subjective_Valence</span><span>,</span><span> </span><span>na.rm</span><span>=</span><span>TRUE</span><span>),</span><span>
</span><span>Valence_SD</span><span> </span><span>=</span><span> </span><span>sd</span><span>(</span><span>Subjective_Valence</span><span>,</span><span> </span><span>na.rm</span><span>=</span><span>TRUE</span><span>),</span><span>
</span><span>Autobiographical_Link_Mean</span><span> </span><span>=</span><span> </span><span>mean</span><span>(</span><span>Autobiographical_Link</span><span>,</span><span> </span><span>na.rm</span><span>=</span><span>TRUE</span><span>),</span><span>
</span><span>Autobiographical_Link_SD</span><span> </span><span>=</span><span> </span><span>sd</span><span>(</span><span>Autobiographical_Link</span><span>,</span><span> </span><span>na.rm</span><span>=</span><span>TRUE</span><span>))</span><span> </span><span>%>%</span><span> </span><span>mutate</span><span>(</span><span>Valence</span><span> </span><span>=</span><span> </span><span>paste</span><span>(</span><span>Valence_Mean</span><span>,</span><span> </span><span>Valence_SD</span><span>,</span><span> </span><span>sep</span><span>=</span><span>&quot; +- &quot;</span><span>),</span><span>
</span><span>Autobiographical_Link</span><span> </span><span>=</span><span> </span><span>paste</span><span>(</span><span>Autobiographical_Link_Mean</span><span>,</span><span> </span><span>Autobiographical_Link_SD</span><span>,</span><span> </span><span>sep</span><span>=</span><span>&quot; +- &quot;</span><span>))</span><span> </span><span>%>%</span><span> </span><span>select</span><span>(</span><span>-</span><span>ends_with</span><span>(</span><span>&quot;SD&quot;</span><span>),</span><span> </span><span>-</span><span>ends_with</span><span>(</span><span>&quot;Mean&quot;</span><span>))</span><span>
</span></code></pre>
</div>
</div>
<table>
<thead>
<tr>
<th>Participant_ID</th>
<th>n_Trials</th>
<th>Valence</th>
<th>Autobiographical_Link</th>
</tr>
</thead>
<tbody>
<tr>
<td>10S</td>
<td>24</td>
<td>-58.07 +- 42.59</td>
<td>49.88 +- 29.60</td>
</tr>
<tr>
<td>11S</td>
<td>24</td>
<td>-73.22 +- 37.01</td>
<td>0.94 +- 3.46</td>
</tr>
<tr>
<td>12S</td>
<td>24</td>
<td>-57.53 +- 26.56</td>
<td>30.24 +- 27.87</td>
</tr>
<tr>
<td>13S</td>
<td>24</td>
<td>-63.22 +- 23.72</td>
<td>27.86 +- 35.81</td>
</tr>
<tr>
<td>14S</td>
<td>24</td>
<td>-56.60 +- 26.47</td>
<td>3.31 +- 11.20</td>
</tr>
<tr>
<td>15S</td>
<td>24</td>
<td>-60.59 +- 33.71</td>
<td>17.64 +- 17.36</td>
</tr>
<tr>
<td>16S</td>
<td>24</td>
<td>-46.12 +- 24.88</td>
<td>15.33 +- 16.57</td>
</tr>
<tr>
<td>17S</td>
<td>24</td>
<td>-1.54 +- 4.98</td>
<td>0.13 +- 0.64</td>
</tr>
<tr>
<td>18S</td>
<td>24</td>
<td>-67.23 +- 34.98</td>
<td>22.71 +- 20.07</td>
</tr>
<tr>
<td>19S</td>
<td>24</td>
<td>-59.61 +- 33.22</td>
<td>28.37 +- 12.55</td>
</tr>
</tbody>
</table>
<p>As we can see from the means and SDs, there is a lot of variability <strong>between and within</strong> participants.</p>
<h1>Standardize</h1>
<p>We will create three dataframes standardized with each of the three techniques.</p>
<div>
<div>
<pre><code><span>Z_VarWise</span><span> </span><span>&lt;-</span><span> </span><span>df</span><span> </span><span>%>%</span><span> </span><span>standardize</span><span>()</span><span>
</span><span>Z_ParWise</span><span> </span><span>&lt;-</span><span> </span><span>df</span><span> </span><span>%>%</span><span> </span><span>group_by</span><span>(</span><span>Participant_ID</span><span>)</span><span> </span><span>%>%</span><span> </span><span>standardize</span><span>()</span><span> </span><span>Z_Full</span><span> </span><span>&lt;-</span><span> </span><span>df</span><span> </span><span>%>%</span><span> </span><span>group_by</span><span>(</span><span>Participant_ID</span><span>)</span><span> </span><span>%>%</span><span> </span><span>standardize</span><span>()</span><span> </span><span>%>%</span><span> </span><span>ungroup</span><span>()</span><span> </span><span>%>%</span><span> </span><span>standardize</span><span>()</span><span> </span></code></pre>
</div>
</div>
<h1>Effect of Standardization</h1>
<p>Let’s see how these three standardization techniques affected the <strong>Valence</strong> variable.</p>
<h2>At a general level</h2>
<div>
<div>
<pre><code><span># Create convenient function</span><span>
</span><span>print_summary</span><span> </span><span>&lt;-</span><span> </span><span>function</span><span>(</span><span>data</span><span>){</span><span>
</span><span>paste</span><span>(</span><span>deparse</span><span>(</span><span>substitute</span><span>(</span><span>data</span><span>)),</span><span> </span><span>&quot;:&quot;</span><span>,</span><span> </span><span>format_digit</span><span>(</span><span>mean</span><span>(</span><span>data</span><span>[[</span><span>&quot;Subjective_Valence&quot;</span><span>]])),</span><span>
</span><span>&quot;+-&quot;</span><span>,</span><span>
</span><span>format_digit</span><span>(</span><span>sd</span><span>(</span><span>data</span><span>[[</span><span>&quot;Subjective_Valence&quot;</span><span>]])),</span><span>
</span><span>&quot;[&quot;</span><span>,</span><span> </span><span>format_digit</span><span>(</span><span>min</span><span>(</span><span>data</span><span>[[</span><span>&quot;Subjective_Valence&quot;</span><span>]])),</span><span>
</span><span>&quot;,&quot;</span><span>,</span><span> </span><span>format_digit</span><span>(</span><span>max</span><span>(</span><span>data</span><span>[[</span><span>&quot;Subjective_Valence&quot;</span><span>]])),</span><span>
</span><span>&quot;]&quot;</span><span>)</span><span>
</span><span>}</span><span>
</span><span># Check the results</span><span>
</span><span>print_summary</span><span>(</span><span>Z_VarWise</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>[1] &quot;Z_VarWise : 0 +- 1.00 [ -1.18 , 3.10 ]&quot;
</code></pre>
</div>
</div>
<div>
<div>
<pre><code><span>print_summary</span><span>(</span><span>Z_ParWise</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>[1] &quot;Z_ParWise : 0 +- 0.98 [ -2.93 , 3.29 ]&quot;
</code></pre>
</div>
</div>
<div>
<div>
<pre><code><span>print_summary</span><span>(</span><span>Z_Full</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>[1] &quot;Z_Full : 0 +- 1.00 [ -2.99 , 3.36 ]&quot;
</code></pre>
</div>
</div>
<h2>At a participant level</h2>
<div>
<div>
<pre><code><span># Create convenient function</span><span>
</span><span>print_participants</span><span> </span><span>&lt;-</span><span> </span><span>function</span><span>(</span><span>data</span><span>){</span><span>
</span><span>data</span><span> </span><span>%>%</span><span> </span><span>group_by</span><span>(</span><span>Participant_ID</span><span>)</span><span> </span><span>%>%</span><span> </span><span>summarise</span><span>(</span><span>Mean</span><span> </span><span>=</span><span> </span><span>mean</span><span>(</span><span>Subjective_Valence</span><span>),</span><span> </span><span>SD</span><span> </span><span>=</span><span> </span><span>sd</span><span>(</span><span>Subjective_Valence</span><span>))</span><span> </span><span>%>%</span><span> </span><span>mutate_if</span><span>(</span><span>is.numeric</span><span>,</span><span> </span><span>round</span><span>,</span><span> </span><span>2</span><span>)</span><span> </span><span>%>%</span><span> </span><span>head</span><span>(</span><span>5</span><span>)</span><span> </span><span>}</span><span>
</span><span># Check the results</span><span>
</span><span>print_participants</span><span>(</span><span>Z_VarWise</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code># A tibble: 5 x 3
  Participant_ID    Mean    SD
  </code></pre></div></div>