# R data analysis: visual interpretation of mixed effect model. If you don’t understand it, you really can’t help it

Time：2022-2-15

Many students asked me about the mixed effect model. They need to talk about some problems many times. Just think about it and post it again. Try to write this article clearly for you.

Mixed effect models have many names,Hierarchical Modeling, also known as Mixed Effects Modeling，There are hierarchical models, hierarchical regression models, stochastic models and so on. You should know that it all refers to one thing.

This thing is used to analyze nested data———nested data

## Nested data

At this time, someone asked, what is nested data?

These are instances in which each observation is a member of a group, and you believe that group membership has an important effect on your outcome of interest.

Nested data is nested data. As you understand it, for example, I want to analyze the impact of students’ learning on income. I have investigated many schools. Can I reasonably believe that the characteristics at the school level will also affect students’ income?

At this time, students are nested at the school level.

Let’s take another example. For example, I want to investigate the relationship between anxiety and depression. I investigated 30 people and each person investigated five times. I got 150 data. Are these data nested at the individual level?

Do you understand?

Not yet. Okay, go on

Make a scatter chart of the data we collected:

R data analysis: visual interpretation of mixed effect model. If you don’t understand it, you really can’t help it

Let’s assume that the above data is the income data of employees. The horizontal axis is the working years and the vertical axis is the income. I investigated the employees of the whole company. Employees are distributed in different departments. I said that different departments will affect employees’ income. No problem. Different colors in the above figure represent different departments.

In fact, data is nested. It is as follows:

R data analysis: visual interpretation of mixed effect model. If you don’t understand it, you really can’t help it

Everyone is nested in different departments. Well, now you have to look at the relationship between income and working hours. What will you do if you don’t consider nesting?

Do you directly make a regression with working hours as the independent variable and income as the dependent variable?

It looks like this:

R data analysis: visual interpretation of mixed effect model. If you don’t understand it, you really can’t help it

Looks okay?

wrong!

Your coefficient is not accurate at all. You don’t consider nesting and higher-level variation between departments!

## Mixed effect model

So, tell me what to do,

Then look, you must have heard of random slope and random intercept.

Let’s take a look one by one. I just said that you didn’t consider a higher level of variation. What’s the possibility of this variation? Do you think it’s possible that the starting salary between departments is different? Is it possible that the salary growth rate among departments is different? Or both are different.

Then the random intercept describes the starting salary of different departments. Adding the random intercept means that we think the starting salary of different departments is different and can change. At this time, it is a mixed effect model with random intercept:

R data analysis: visual interpretation of mixed effect model. If you don’t understand it, you really can’t help it

In the above description, the slope is certain at the individual level, which is a fixed effect, and there can be different starting salaries at the department level, which is a random effect.

Look at the random slope,

In other words, it is possible that the starting salary of employees is the same, but the salary growth slope is different in different departments. To fit such a mixed effect model, we need to add a random slope to the high level of the model, that is, the Department Level:

R data analysis: visual interpretation of mixed effect model. If you don’t understand it, you really can’t help it

At this time, our model can fit the slopes of different departments, which is called random slope model. At this time, we believe that the personal salary is affected by the working years at the individual level and the salary growth of different departments. The working years are the main effect and the salary growth of departments is a random effect.

But we see that for our example, only random slope seems not ideal.

Keep looking,

## Random slope + random intercept

In other words, the more reasonable situation is that the starting salary of each department is different from the salary growth of each department. This situation is random intercept + random slope:

R data analysis: visual interpretation of mixed effect model. If you don’t understand it, you really can’t help it

In this case, we think that everyone’s salary is affected by the starting salary of the Department and the salary growth of the Department. At this time, the working years are the main effect, and the starting salary and salary growth of the Department are random effects.

## How to choose

After you understand the above three models, there is a problem again

How do I know whether I should add random intercept or random slope

Good question. At this time, either you have more theoretical experience. For example, I’m sure the starting salary of the Department is the same, so I’ll only add the random slope; In addition, you can try and make mistakes one by one, because the model has goodness of fit index. You can choose which model has the best goodness of fit.

## Summary

Today, I’ve written about different types of mixed effect models. As for how to do it, please see my previous article. Thank you for your patience. Your articles are written in detail and the codes are in the original text. I hope you can do it yourself. Please pay attention to the private letter and reply to “data link” to obtain all the data and learning materials I collected. If it’s useful to you, please collect it first, then like it and forward it.

If you are an undergraduate or graduate student, if you are worried about your statistical homework, data analysis, papers, reports, exams, etc., if you encounter any problems in using SPSS, R, python, Mplus, Excel, you can contact me. Because I can provide you with good, detailed and patient data analysis services.

If you have any questions about Z-test, t-test, analysis of variance, multiple analysis of variance, regression, chi square test, correlation, multilevel model, structural equation model, mediation, scale reliability and validity and other statistical skills, please trust me personally for detailed and patient guidance.

If you are a student and you are worried about you statistical #Assignments, #Data #Analysis, #Thesis, #reports, #composing, #Quizzes, Exams.. And if you are facing problem in #SPSS, #R-Programming, #Excel, Mplus, then contact me. Because I could provide you the best services for your Data Analysis.

Are you confused with statistical Techniques like z-test, t-test, ANOVA, MANOVA, Regression, Logistic Regression, Chi-Square, Correlation, Association, SEM, multilevel model, mediation and moderation etc. for your Data Analysis…??

Then Contact Me. I will solve your Problem…

Come on, worker!

## Guess you like it

R data analysis: examples of mixed effect models

From “I’m ugly to myself” — continuation of mixed effect model

Repeated measurement data analysis series: basis of mixed effect model

R data analysis: how to calculate the aggregate validity of the questionnaire and practice with examples

R data analysis: how to calculate the combined reliability of the questionnaire and practice with examples

## What is the meaning of log2fc and FDR values when genes are differentially expressed on September 16, 2021?

Transcriptome analysisdifferential expressionGenes appear in the resultsLog2FCandFDRValue, what do these two mean? log2FCFC in is fold change, which represents the ratio of expression between two samples (groups). After taking the logarithm based on 2, it is log2fc. Generally, the absolute value of log2fc is greater than 1 by default as the screening standard of differential […]