<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/format-and-interpret-linear-mixed-models/"></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/05/10/interpret_mixed_models.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/05/10/interpret_mixed_models.html#the-data" target="_blank">The data</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/05/10/interpret_mixed_models.html#fit-the-model" target="_blank">Fit the model</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/05/10/interpret_mixed_models.html#the-analyze-function" target="_blank">The analyze function</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/05/10/interpret_mixed_models.html#summary" target="_blank">Summary</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/05/10/interpret_mixed_models.html#print" target="_blank">Print</a></li>
<li><a rel="nofollow" href="https://neuropsychology.github.io/psycho.R//2018/05/10/interpret_mixed_models.html#credits" target="_blank">Credits</a></li>
</ul>
<p>You find it time-consuming to manually format, copy and paste output values to your report or manuscript? That time is over: the <a rel="nofollow" href="https://github.com/neuropsychology/psycho.R" target="_blank"><code>psycho</code></a> package is here for you!</p>
<h1>The data</h1>
<p>Let’s take the example dataset included in the <code>psycho</code> package.</p>
<div>
<div>
<pre><code><span>library</span><span>(</span><span>psycho</span><span>)</span><span>
</span><span>library</span><span>(</span><span>tidyverse</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>select</span><span>(</span><span>Participant_ID</span><span>,</span><span> </span><span>Emotion_Condition</span><span>,</span><span> </span><span>Subjective_Valence</span><span>,</span><span>
</span><span>Autobiographical_Link</span><span>)</span><span>
</span><span>summary</span><span>(</span><span>df</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code> Participant_ID Emotion_Condition Subjective_Valence Autobiographical_Link
 10S    : 48    Negative:456      Min.   :-100.000   Min.   :  0.00       
 11S    : 48    Neutral :456      1st Qu.: -65.104   1st Qu.:  0.00       
 12S    : 48                      Median :  -2.604   Median : 16.15       
 13S    : 48                      Mean   : -18.900   Mean   : 28.99       
 14S    : 48                      3rd Qu.:   7.000   3rd Qu.: 59.90       
 15S    : 48                      Max.   : 100.000   Max.   :100.00       
 (Other):624                                         NA's   :1            
</code></pre>
</div>
</div>
<p>Our dataframe (called <code>df</code>) contains data from several participants, exposed to neutral and negative pictures (the <code>Emotion_Condition</code> column). Each row corresponds to a single trial. During each trial, the participant had to rate its emotional valence (<code>Subjective_Valence</code>: positive – negative) experienced during the picture presentation and the amount of personal memories associated with the picture (<code>Autobiographical_Link</code>).</p>
<p>Our dataframe contains, for each of the 48 trials, 4 variables: the <strong>name of the participant</strong> (<code>Participant_ID</code>), the <strong>emotion condition</strong> (<code>Emotion_Condition</code>), the <strong>valence rating</strong> (<code>Subjective_Valence</code>) and the <strong>Autobiographical Link</strong> (<code>Autobiographical_Link</code>).</p>
<h1>Fit the model</h1>
<p><strong>Let’s fit a linear mixed model to predict the autobiographical link with the condition and the subjective valence.</strong></p>
<div>
<div>
<pre><code><span>library</span><span>(</span><span>lmerTest</span><span>)</span><span>
</span><span>fit</span><span> </span><span>&lt;-</span><span> </span><span>lmer</span><span>(</span><span>Autobiographical_Link</span><span> </span><span>~</span><span> </span><span>Emotion_Condition</span><span> </span><span>*</span><span> </span><span>Subjective_Valence</span><span> </span><span>+</span><span> </span><span>(</span><span>1</span><span>|</span><span>Participant_ID</span><span>),</span><span> </span><span>data</span><span>=</span><span>df</span><span>)</span><span>
</span><span>summary</span><span>(</span><span>fit</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: Autobiographical_Link ~ Emotion_Condition * Subjective_Valence +  
    (1 | Participant_ID)
   Data: df

REML criterion at convergence: 8555.5

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.2682 -0.6696 -0.2371  0.7052  3.2187 

Random effects:
 Groups         Name        Variance Std.Dev.
 Participant_ID (Intercept) 243.1    15.59   
 Residual                   661.4    25.72   
Number of obs: 911, groups:  Participant_ID, 19

Fixed effects:
                                             Estimate Std. Error        df
(Intercept)                                  25.52248    4.23991  31.49944
Emotion_ConditionNeutral                      6.13715    2.66993 895.13045
Subjective_Valence                            0.05772    0.03430 898.46616
Emotion_ConditionNeutral:Subjective_Valence   0.16140    0.05020 896.26695
                                            t value Pr(>|t|)    
(Intercept)                                   6.020 1.09e-06 ***
Emotion_ConditionNeutral                      2.299  0.02176 *  
Subjective_Valence                            1.683  0.09280 .  
Emotion_ConditionNeutral:Subjective_Valence   3.215  0.00135 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation of Fixed Effects:
            (Intr) Emt_CN Sbjc_V
Emtn_CndtnN -0.459              
Sbjctv_Vlnc  0.455 -0.726       
Emtn_CN:S_V -0.308  0.301 -0.676
</code></pre>
</div>
</div>
<h1>The analyze function</h1>
<p>The <code>analyze</code> function, available in the <code>psycho</code> package, transforms a model fit object into user-friendly outputs.</p>
<div>
<div>
<pre><code><span>results</span><span> </span><span>&lt;-</span><span> </span><span>analyze</span><span>(</span><span>fit</span><span>,</span><span> </span><span>CI</span><span> </span><span>=</span><span> </span><span>95</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<h1>Summary</h1>
<p>Summarizing an analyzed object returns a dataframe, that can be easily saved and included in reports. It also includes standardized coefficients, as well as bootstrapped confidence intervals (CI) and effect sizes.</p>
<div>
<div>
<pre><code><span>summary</span><span>(</span><span>results</span><span>)</span><span> </span><span>%>%</span><span> </span><span>mutate</span><span>(</span><span>p</span><span> </span><span>=</span><span> </span><span>psycho</span><span>::</span><span>format_p</span><span>(</span><span>p</span><span>))</span><span>
</span></code></pre>
</div>
</div>
<table>
<thead>
<tr>
<th>Variable</th>
<th>Coef</th>
<th>SE</th>
<th>t</th>
<th>df</th>
<th>Coef.std</th>
<th>SE.std</th>
<th>p</th>
<th>Effect_Size</th>
<th>CI_lower</th>
<th>CI_higher</th>
</tr>
</thead>
<tbody>
<tr>
<td>(Intercept)</td>
<td>25.52</td>
<td>4.24</td>
<td>6.02</td>
<td>31.50</td>
<td>0.00</td>
<td>0.00</td>
<td>&lt; .001***</td>
<td>Very Small</td>
<td>17.16</td>
<td>33.93</td>
</tr>
<tr>
<td>Emotion_ConditionNeutral</td>
<td>6.14</td>
<td>2.67</td>
<td>2.30</td>
<td>895.13</td>
<td>0.10</td>
<td>0.04</td>
<td>&lt; .05*</td>
<td>Very Small</td>
<td>0.91</td>
<td>11.37</td>
</tr>
<tr>
<td>Subjective_Valence</td>
<td>0.06</td>
<td>0.03</td>
<td>1.68</td>
<td>898.47</td>
<td>0.09</td>
<td>0.06</td>
<td>= 0.09°</td>
<td>Very Small</td>
<td>-0.01</td>
<td>0.12</td>
</tr>
<tr>
<td>Emotion_ConditionNeutral:Subjective_Valence</td>
<td>0.16</td>
<td>0.05</td>
<td>3.22</td>
<td>896.27</td>
<td>0.13</td>
<td>0.04</td>
<td>&lt; .01**</td>
<td>Very Small</td>
<td>0.06</td>
<td>0.26</td>
</tr>
</tbody>
</table>
<h1>Print</h1>
<p>Moreover, the <code>print</code> method return a nicely formatted output that can be almost directly pasted into the manuscript.</p>
<div>
<div>
<pre><code><span>print</span><span>(</span><span>results</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>The overall model predicting Autobiographical_Link (formula = Autobiographical_Link ~ Emotion_Condition * Subjective_Valence + (1 | Participant_ID)) successfully converged and explained 32.48% of the variance of the endogen (the conditional R2). The variance explained by the fixed effects was of 7.66% (the marginal R2) and the one explained by the random effects of 24.82%. The model's intercept is at 25.52 (SE = 4.24, 95% CI [17.16, 33.93]). Within this model:
   - The effect of Emotion_ConditionNeutral is significant (beta = 6.14, SE = 2.67, 95% CI [0.91, 11.37], t(895.13) = 2.30, p &lt; .05*) and can be considered as very small (std. beta = 0.098, std. SE = 0.043).
   - The effect of Subjective_Valence is significant (beta = 0.058, SE = 0.034, 95% CI [-0.0097, 0.12], t(898.47) = 1.68, p = 0.09°) and can be considered as very small (std. beta = 0.095, std. SE = 0.056).
   - The effect of Emotion_ConditionNeutral:Subjective_Valence is significant (beta = 0.16, SE = 0.050, 95% CI [0.063, 0.26], t(896.27) = 3.22, p &lt; .01**) and can be considered as very small (std. beta = 0.13, std. SE = 0.041).
</code></pre>
</div>
</div>
<p>The intercept (the baseline level) corresponds, here, to the negative condition with subjective valence at 0 (the average, as the data is standardized). Compared to that, changing the condition from negative to neutral does not induce any significant change to the outcome. However, in the negative condition, there is a trending linear relationship between valence and autobiographical memories: the more an item is positive the more it is related to memories. Finally, the interaction is significant: the relationship between valence autobiographical memories is stronger (more positive) in the neutral condition.</p>
<h1>Credits</h1>
<p>This package helped you? You can cite <a rel="nofollow" href="https://github.com/neuropsychology/psycho.R" target="_blank"><code>psycho</code></a> as follows:</p>
<ul>
<li>Makowski, (2018). <em>The psycho Package: an Efficient and Publishing-Oriented Workflow for Psychological Science</em>. Journal of Open Source Software, 3(22), 470. <a rel="nofollow" href="https://doi.org/10.21105/joss.00470" target="_blank">https://doi.org/10.21105/joss.00470</a></li>
</ul>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://neuropsychology.github.io/psycho.R//2018/05/10/interpret_mixed_models.html"> Dominique Makowski</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/WJ_urzcQVcs" height="1"></a></div>