I've been tackling the concept of Mixed Effects Models on and off for the last 9 months. Every time I would give up and come back later to try and understand it again with my basic statistics knowledge (I come from a medicine background, so I have no high-level mathematics knowledge involving calculus and derivations for proofs, just intuitive understandings) in a never ending cycle. I'd see all these words about random and fixed effects and while on a superficial level they would make sense, my understanding would always break down when I'd try to dig deeper and understand how the P-values ARE CALCULATED. That is until recently where it has kind of started to click more than usual. The reason being VISUALISATION of how data in a mixed effects model works. I feel like I am almost there and have some questions. The post will be long with a lot of pictures(for visualization) but the questions will most likely be very simple for any of you with a formal training in statistics. I will start off with the basics and build my way up to questions which I consider more and more difficult.
I will be using the example from the following video: https://www.youtube.com/watch?v=4bGG02Jsjyc which helped me immensely in developing my intuition of mixed effects models through visualization (the video specifically discusses linear mixed effect models)
Let us begin with the data that's presented in the video example which involves 4 subjects following the same diet (Fig.1)
Fig.1 (Subjects and their weights in Repeated Measurements)
Let us now proceed and make a Simple Linear Regression for these data points (Fig.2) (Yes, I understand this is incorrect as our example violates the rule of complete independence between all data points but it is purely for explanation purposes just as was done in the video)
Fig.2 (A simple linear regression for all the data points with a P-value for Hypothesis testing)
We then proceed with hypothesis testing whereby the Null Hypothesis indicates that the diet actually has no effect on weight loss (which is just a different way of saying the Slope Coefficient = 0 and not actually -3.25 ). We get a p-value=0.372 which shows that the slope is indeed not statistically significant(<0.05) and that this slope coefficient we got from the sample could have likely happened due to random chance and not due to an actual effect of the diet.
The way we calculated this was through calculating a t-statistic for a one sample t-test for the regression line(Fig.3)
Fig.3 (Calculating a T-statistic for Hypothesis testing of Diet Effect in Simple Linear Regression)
However, what's weird is that every single person actually did demonstrate a weight loss effect in this experiment which makes the claim that the effect of the diet(the slope) is not statistically significant a bit dubious. This is indeed where we realize that a Simple Linear Regression is the wrong technique to use. The 2 reasons being that:
Simple Linear Regression requires that all data points are independent which is not the case with our Repeated measures data on each of the 4 subjects.
Because Simple Regression assumes that all data points are independent, in our case the Standard Error becomes very large because the data points are so far away from the Simple Regression Line against which their error/residual has to be measured. This is according to the Standard Error equation in Fig 3, specifically the (yi-ŷi)^2 part. You can also see this visually in Fig.4
Fig.4 (Large Standard Error due to data points being quite far away from Regression Line)
The large standard error gives us a result of the diet effect(slope) not being statistically significant and yet as we said, there is a visible effect of weight loss on every individual. So how do we account for this? This is where a Linear Mixed Effects Model kicks in.
Looking at our data points we can see that each subject did indeed experience a decline in their weight over time. The 2 variations between each of the subjects are
The weight they started this whole experiment at
The rate at which they lost weight (some people lost weight faster while others lost it a bit slower)
There are 2 ways of handling this in a Linear Mixed Effects Model:
Random Intercept + Fixed Slope
Random Intercept + Random Slope
Now, my first question is what is the Random Effect and what is the Fixed Effect in both of the scenarios above?
In the case of Random Intercept + Fixed Slope it makes sense that the random effect is the differing starting weights and the Fixed effect is the Fixed Slope(which is the effect of the diet)
But what about in the case of the Random Intercept + Random Slope? Is the random effect both the starting weight and the inherent randomness of the fixed effect within each individual? And the fixed effect is just the fact that weight is being lost?
Moving on, let us proceed with the Random Intercept + Fixed Slope model for our example (Fig.5)
Fig.5 (Random Intercept + Fixed Slope Model where each subject gets their own regression line which has the same slope taken from the overall sample regression line we calculated in the Simple Regression model)
If we proceed to do some hypothesis testing against the null hypothesis with our new model, we will get a p-value of <0.001 . Which shows us that the effect of the diet(slope) is indeed statistically significant unlike what the Simple Regression model told us. The reasoning behind this is that the Standard Error is significantly reduced when comparing each subjects data points to their own respective regression line and hence accounting for their inherent randomnesses. (Fig.6)
Fig.6 (Data points are much closer to their respective regression lines leading to a much smaller standard error which in turn results in a significantly lower p-value.)
My second question is: for this Random Intercept + Fixed Slope model, are we using the same formulas in Fig.3 to calculate the T-Statistic and the P-value as we did for the Simple Linear Regression model? That is, does calculating the p-value follow the same reasoning on a Random Intercept + Fixed Slope model as it does in the Simple Linear Regression model?
Third question: If we were to do a Random Intercept + Random Slope model, since each subject would have their own Slope Coefficient(Thus a total of 4 different slope coefficients) which Slope Coefficient would we be comparing with the zero slope in the Null Hypothesis? Or are we still comparing the overall sample slope coefficient (-3.125) with the zero slope? That is, we're just using the random intercept + random slope to derive the standard error but in the end we're using the -3.125 slope in our T-statistic calculation. So basically, T-score = -3.125 / (S.E of Random Intercept + Random Slope model)
Fourth question: We can see in our example that the random intercepts account for the random effect. But what is the calculation for proving that the random effects are statistically significant? How would we calculate the P-value to prove the significance of the random effects?
Finally(we're almost there I promise), moving on to the last example which is from the second part of the video series: https://www.youtube.com/watch?v=oI1_SV1Rpfc
This is the new data(Fig.7). Where now we divide 4 subjects equally into 2 DIET GROUPS
Fig.7 (Subjects following different Diets and their weights over repeated measurements)
We will proceed to make a random intercept + fixed slope model where we include the type of diet group as an effect as well (Fig.8)
Fig.8 (Random Intercept + Fixed Slope model where Diet Type is included as an effect)
We can see 3 P-values in Fig.8. The "Slope" row indicates that the Slope is statistically significant and thus the null hypothesis is rejected.
The "Diet B" row indicates that the mean weight difference of Diet Group B from A is statistically significant (P=0.003). My fifth question is how was this P-value calculated?
My final and 6th question is the "Intercept" Row uses the Diet A Group's mean weight as a baseline for the Intercept(97.962). But what does the P-value indicate here and how is it calculated? This intercept is statistically significant relative to what exactly? A null hypothesis? I can't see how that makes sense
If you've made it this far, I highly appreciate you taking the time to read my post and trying to help me out. All the best.