hi and welcome to this video lecture on linear mixed effects models. These
methods are an extension to the typical linear model such as linear regression
and they're often used with more complicated sampling designs. So in this
video you'll learn more about when to choose a mixed effects model, how to
interpret it, but keep in mind that these models can become very complicated and
we're only going to scratch the surface here so the linear model in its basic
sense is a general category but the most familiar case would likely be linear
regression where a dependent variable Y can be modeled by a dependent variable X
with coefficients indicating say a slope and an intercept so then your model can
include more than one independent predictor variable you can have multiple
terms it can be continuous numeric or categorical factors each with their own
coefficient beta so linear models such as those are best suited when all of the
observations come from a single homogeneous group without any underlying
structure but what if you have an experimental design or a data structure
where the observations actually belong to smaller subgroups that are nested
within this bigger population in this case some of the variants might be
explained by the subgroup that an observation is within and considering
that there might be differences between these subgroups may help you get better
answers so that data structure introduces the idea of fixed versus
random effects so in the previous example also shown here the color or the
shade of purple for the points and the shape of the points are treated as fixed
effects and the sampling block the perp the the green boxes could be treated as
random effects and I'll explain what that is in a second but how do you
determine that well there really isn't an objective rule what counts as a fixed
effect in one situation might be a random effect in another but there are
some guidelines so if you're trying to control for non independence created by
a nested data structure such as here where you don't really care about the
factor itself but you want to account for potential differences between the
groups that would be a case where you might treat it as a random effect and
this is probably the most common situation for mixed effects models the
fix effects are the parameters that you're typically interested in also our
variable is often treated as a random effect if the categories are at just a
subset of all the possible groups that could be sampled also there's a lot of
groups if there are only two groups and those are the only two possibilities
then it's almost certainly gonna be a fixed effect and not a random effect but
again there aren't really firm rules and the decision will really depend on your
question and your data but some examples might help so in this first example
we're treating nitrate as a fixed effect because it's a continuous variable and
it's the variable of interest and we can possibly treat these multiple river
basins as a random effect if we want to account for the possibility that
different rivers may have a different relationship between nitrogen and oxygen
but we could also treat River Basin as a fixed effect depending on the number of
basins and our goal and our data so in this example we might want to treat
these experimental blocks as a random effect if we aren't interested in their
effect but we want to account for this potential variability and finally in
this example we potentially could have two different levels of random effects
when evaluating this effect of light level on photosynthesis we might treat
the different species in our experiment as a random effect or it could be a
fixed effect if we care about the species and we can also treat the
individual plant itself as a random effect if we measured each one multiple
times so so yes random effects are actually a useful way of dealing with
repeated measures especially as an exultant OVA and note that mixed effects
models don't have to have a continuous independent variable the linear model is
a generic category and you can have categorical factors only so what are
done with the random effects what purpose do they serve in this
in this model well the way mixed effects models work at least an are and in
general typically is they use something called restricted maximum likelihood
estimation to fit these random effects and the residuals the difference between
the points and the lines they do this with the intercept and/or slope of the
random effects coming from a broader distribution and that distribution will
have a particular mean and a variance so the idea here is that our random effects
are just random draws from this larger population and so that's why they might
be slightly different from one another so after finding the best parameters to
describe the random effects and the residuals the method then can estimate
the coefficients for the fixed effects so given this one key decision that you
make when running mixed effects models is how to treat these random effects so
one option which is shown here is that you can just say these random effects
have different intercepts but they all have the same slope and so this is a
schematic of how that would be done in our the 1 bar group indicates varying
intercept for the random effects you can also model varying slopes but constant
intercept it's probably not that common or you can have a model where the slopes
and the intercepts both vary in that case the most common way is to model
that there's also a possibility that there's a correlation between the slope
of the intercept in our random effect sort of instances and that shown here
with this X bar group symbol where X is our independent variable but you can
also model the slope and the intercept without a correlation between the two so
how do you choose well there may be theoretical reasons given the question
the study system the data to choose a particular way of doing the random
effects but it's typically said that it's best to fit the full structure
which is this correlated slope and intercept variation that is if it's
possible with the data you have so we'll come back to that later on because there
could be problems fitting this more complicated model and if
are you can always investigate a simpler model so the previous examples were for
a single level of random effect but it's possible to have more complicated study
designs with these more complicated structures for example you might have
random effects that are nested which means that one level of one random
effect only occurs within one unique level of the high-rent effect gray box
one that group only occurs in the upper left green box gray box three only
occurs in the upper middle green box they don't occur in in all of them so
this is called nested and for a linear model which explains the outcome as a
function of the color of each point you would indicate nested random effects
this way with the gray level nested within the green random effect indicated
by the slash it's also possible to have crossed random effects which technically
are anything that's not nested but in a fully cross design like shown here all
combinations of the random effect levels occur together so the gray all two
combinations of that occur in each example of the green so the formula for
crossed random effects just for color is shown here with each listed as affecting
the independent variable color separately so that covers a little bit
about the model and the random effects and how you might specify them but as
with any linear model approach it's extremely important to check the
assumptions and make sure your model does a good job of describing the data
so you do this after fitting the model and then you can run a variety of model
Diagnostics so you can plot and should plot the residuals versus the fitted
values for the entire model which is shown here and if you have multiple
independent predictor variables you should plot residuals versus fitted for
each of those and so what you should see is hopefully something like this where
there's no trend or pattern in your residuals they should be
sort of normally distributed equally around this zero line and there should
be roughly equal variance in your in your fit in your residuals for every
point of fitted values when you have this random effect structure you should
also plot residuals versus fitted values for each random effect group and this as
you might guess can get quite complicated if you have crossed and or
nested complicated designs but you should do this to make sure that within
each group your residuals are also normally distributed that there's
roughly equal variance among fitted values within the group and that the
variance among groups is also similar so if we have small sample size in some of
your groups this can be very hard to tell if the variance is similar or
similar with different fitted values but it's also a caution if you have very
small sample sizes about interpreting your results also the means of the
random effects or the conditional means which is their mean relative to the
overall mean so that's the mean of the slope values the mean of the intercept
values should also be normally distributed because they're being drawn
from this single sort of common distribution and you can evaluate this
with QQ plots just to see that you know does it more or less follow this this
theoretical quantile line so there still are even more things you should consider
first your random effects should have many levels or categories within them
it's often said the one at least five levels or five groups within a random
effect variable but more is better because the method needs to estimate the
distribution of these means for your n FX from a common distribution now if you
only have you know five categories or four categories it's hard to really
estimate that that sort of parameter very accurately so if you only have two
or three groups or or four you know you can instead treat them as fixed effects
potentially also as a caution if you have independent variables that are
strong a collinear with one another that can
cause problems both with the coefficients and what they mean but also
with the model fitting and whether the model can actually fit itself to the
data so this is the case if you have strongly culinary variables you need to
think about this think about the data in the model more carefully do you need
both of them you know you have to investigate what you should do in this
situation as I've explained earlier you want to be
sure you're specifying the structure of your random effects you know correctly
and this goes beyond just whether you're varying the slope or the intercept this
is especially making sure that you are getting the nesting and the crossing
correct if they're already nested or crossed variables which independent
variables are affected by the nesting and out of a interact it can get quite
complicated so you need to understand your data and your study design very
well and finally this is true for almost anything but watch out for warning
messages you might get warning messages about the model convergence that the
model failed to converge can be bad in many cases that the boundary fit is
singular can also indicate there were problems with sort of estimating these
coefficients and and fitting them not always but this is I mean that you you
know is probably a concern that you would want to certainly investigate you
may need to simplify the model you might need to use an uncorrelated intercept in
slope instead of a correlated one we need to remove interactions between
independent variables if you have modelled interactions and and so forth
but again there are many possibilities here that involve you understanding your
data and your study system so there's one other way that you can help model
fitting and model interpretation and that is by States entering and
standardizing your independent variables so to do this to Center and to
standardize you take your raw data you subtract the mean from each data point
and this is the centering so we have R centered values where the middle of our
data is now 0 and then next you take each point and you divide it by the
standard deviation to standardize it then we get something where you know the
the value to measured in standard deviations away from them
centering and standardizing can help the model converge upon the solution in this
maximum likelihood estimation process this is especially true if your
independent variables have large values it can also help you compare the
magnitude of the effect you know among your multiple independent variables
which variable was more important or had a larger effect because they're now
measured on the same scale you can compare them the coefficients directly
to each other but note that after centering and standardizing the
regression coefficients now refer to the change you would expect in the dependent
variable when the independent variable increases by one standard deviation not
by one unit by one standard deviation so if you're using R and the LME for
package the output you're going to get is going to look something like this now
it will differ depending on whether you have crossed or nested effects how many
independent variables you have what your random effect structure is but this is
sort of a very basic look of it so what do you do with all this information well
the top part is about the model specification and the fit typically you
don't need to do much here because you shouldn't examine the residuals and
really dug into the model fitting earlier when you are doing the
Diagnostics the next block describes the random effects so these are showing you
the the residual variants that are explained by the intercept of our random
effects and the coefficient of the grouping factor you know the slope plus
the residuals themselves after that so these are all the residual variance
which is left over after the variance that the fixed effects deal with and so
our next block does have those fixed effects in it the coefficients again
here called estimate is very similar to what you would have seen in a regular
linear model you get its standard error but you'll note that there is something
that's missing and that is the p-values missing you don't get a p-value in this
function at least this is probably because it's difficult to get accurate
degrees of freedom in mixed effects models the variance is partitioned among
multiple levels it's hard to know and so it's hard to
calculate a p-value but we get an estimate and we get the standard error
on that estimate so it's straightforward to get a confidence interval on the size
of the effect on the size of the coefficient and that's what we really
care about we really care about the size of the effect also you know is that
effect you know likely in the direction we think it is but the size is important
and finally we get this correlation of fixed effects which is basically like if
you did multiple trials you would expect to see this correlation between the
slope and the intercept of our fixed effects if the slope is bigger the
intercept would be bigger as well in this situation but then often you don't
often do much with that either so finally the mixed effects models are
most often used to account for this non independence when the data belong to
these groups within a larger group but they can also be used to improve the
parameter estimates for the groups themself and so you may recall that
linear models can be used for hypothesis testing but they can also be used if
your goal is predicting something so in this example you might notice that one
of these groups does not look like the other group J has a slope and intercept
that differs very strongly from the other groups but you also notice that
has a small sample size only three points and it has a very restricted
range of sampling to so we might be a little you know sort of wondering like
is that slope really real how come it's so different from the other ones but if
we treat these ten groups as random effects in a mixed model we can use the
fact that these random effects if these ten things all did come from a
population with a particular mean and variance of slope and intercept we can
then use that common distribution and use that information to help inform each
individual group so this process is called partial pooling or shrinkage
because it's basically shrinking the individual mean and intercept estimates
closer to this common mean so that's going to bring our slopes closer to the
sort of the average slope and it does so much more strongly for these
small sample size groups like Jay and the other ones it doesn't really affect
them very much because they have a relatively large you know reasonably
large amount of data so overall mixed effects models are
great if you want to account for non independence because your observations
are grouped they're also very helpful for improving prediction from linear
models by taking advantage of the shrinkage to get better estimates but
also and by reiterating this caution they can become very complicated as you
get nesting and and crossing of factors so it's extremely important to
understand your questions your data your study design how to set up the model and
how to ensure that your data meet the assumptions and the model is a good
model for that data but if you can ensure all of that mixed effects models
can be very powerful tools