2012 SPSS Linear Mixed Models (LMM) Options in SPSS
2012 SPSS Linear Mixed Models (LMM) Options in SPSS
2012 SPSS Linear Mixed Models (LMM) Options in SPSS
H o w t h is d oc u ment sh ou ld b e u s ed :
This document has been designed to be suitable for both web based and face-to-face teaching. The text has been made
to be as interactive as possible with exercises, Multiple Choice Questions (MCQs) and web based exercises.
If you are using this document as part of a web-based course you are urged to use the online discussion board to discuss
the issues raised in this document and share your solutions with other students.
This document is part of a series see:
http://www.robin-beaumont.co.uk/virtualclassroom/contents.htm
Wh o t h is d oc u men t is a imed at :
This document is aimed at those people who want to learn more about statistics in a practical way and assumes you
have worked through a number documents already.
Acknowledgment
My sincere thanks go to Claire Nickerson for not only proofreading several drafts but also providing additional material
and technical advice.
Contents
1. INTRODUCTION .................................................................................................................................................... 3
2. WIDE AND LONG DATA FORMATS ........................................................................................................................ 4
3. GRAPHING CHANGE IN SPSS ................................................................................................................................. 4
4. GRAPHING CHANGE IN R....................................................................................................................................... 6
5. PARAMETER ESTIMATION ..................................................................................................................................... 8
6. GETTING TO GRIPS WITH THE MIXED MODELS DIALOG BOXES IN SPSS................................................................. 9
7. INDEPENDENT T TEST ............................................................................................................................................ 9
8. TAKING INTO ACCOUNT DEPENDENCY – FIXED AND RANDOM EFFECTS ..............................................................11
9. PAIRED SAMPLES T TEST ......................................................................................................................................12
10. COMPARING MODELS......................................................................................................................................14
11. MODEL COVARIANCE MATRIXES FOR REPEATED MEASURES (LEVEL ONE).......................................................16
12. SUMMARY .......................................................................................................................................................17
13. REFERENCES.....................................................................................................................................................17
1. Introduction
Mixed models are theoretically not new, and as with most statistical concepts Fisher first introduced them at the
beginning of the 20th century. However only very recently, that is in the last two decades, have they been considered
widely as a method of analysing repeated measures data. I will not mention here the many other approaches that have
been offered as a method of analysing such data, instead I will try to start with a blank slate.
Repeated measures are those measures that are repeated on more than one occasion, we met an example in the paired
t statistic chapter. Taking another example, say we have cholesterol levels measured four times (t1, t2, t3, t4) over a year
for each patient following commencement of a new cholesterol lowering drug. So for each patient we have four
measurements which can be depicted thus:
Level
2
Patient 1 Patient 2 Patient 3 ....... Patient n
4 observations clustered within each patient - observations within each cluster may be correlated?
We can say that the observations are the bottom level (level one) while they are clustered within the level two variable
patient.
There are several aspects of this situation we might be interested in investigating:
The difference between the first and last observation for each patient
The trend over time for the observations for each patient taking into account the initial value. Do they follow a
straight line or some type of curved one?
The relationship between the repeated observations, are they correlated or independent, do they become less
correlated as the observations become more distant, that is, is t1 to t2 more strongly correlated than that
between t1 and t4
How spread out are the scores at each time point, and do they become more spread out as time goes on or is
the variance constant.
How much of the variability in the observations is accounted for within the clusters compared to that between
the clusters
All the above questions are common for this type of situation which suggests that an appropriate analysis here is rather
an involved process. It is important to realise that some of the above questions are more valid than others an issue we
will discuss latter. As is usual a largely graphical initial exploratory data analysis (EDA) is always the first stage of any
analysis, both Singer & Willett (2003) and Diggle & Heagerty (2003) devote a whole chapter at the start of their books to
graphical techniques. Unfortunately both SPSS and R do not make life easy when it comes to developing various graphs
for repeated measures, Heck Thomas & Tabata 2010 attempt various graphs in SPSS, while using workarounds, while
Singer & Willett 2003 provide SPSS syntax.
Before we can do anything we need to consider the structure of the data as this affects our ability to analyse it.
t_test_paired_long_format.sav
4. Graphing change in R
The data needs to be in long format. To load the data, I'm using the SPSS file into R I use the r commander interface as
shown below.
Now we have the data in R and also know the names of the
variables we can request the graph we want.
20
with only two time points. But the same procedure would apply to a
much larger dataset with possibly many time points also we have only 10
barely scrapped the surface of the xyplot function in the lattice package,
there is even a whole book about it (Sarkar 2008)!
5
Exercise 1 2
Repeat the process above for SPSS and R using both the dataset demonstrated before - after
above and also the Twisk health lifestyle dataset (twisk_longitudinal_long.sav) which has four time points. How did you
resolve the problem of 4 times points in SPSS?
Also try running for the Twisk data: xyplot(health ~ time, groups = id, type="l", col= "grey",
alpha = 0.25, data = mydata) . What do you think the col and alpha parameters do?
5. Parameter Estimation
There are two methods available in SPSS for estimating the parameter
values, SPSS defaults to the Restricted Maximum Likelihood (REML)
method. Unfortunately there appears much controversy over which
method is the best to use Twisk presents a table comparing estimates
for a model using both methods and shows there is little difference
(Twisk 2006 p.29), Singer & Willett (2003 p.87-90) provides a fuller
description with references to simulation studies.
A major part of the analysis process involves hypothesis testing and
specifically evaluating alternative models and this is where the
problems arise. ML (also called the Full ML method [FML]) provides a
description of the fit of the full model (both fixed and random
parameters) whereas REML only takes into account the random
parameters.
7. Independent t test
Referring back to the data we used to demonstrate the paired t test I have restructured
it into long format opposite. Id represents the subject and time represents either a pre
intervention or post intervention observation.
While we know that the pre post observations are not independent we will assume they
are for this demonstration, therefore while this demonstrates how to carry out an
independent t test it is an inappropriate analysis for this dataset. We are just doing this
to demonstrate how you would carry out such an analysis.
The results below are from the usual t test option in SPSS, to allow us to compare them
with those produced from the Mixed models dialog boxes.
Group Statistics
time N Mean Std. Deviation Std. Error Mean
t_test_paired_long_format.sav
1 8 14.2500 10.40261 3.67788
result
2 8 16.8750 10.46678 3.70057
Estimates
Levene's Test for
Equality of t-test for Equality of Means
Variances
95% Confidence Interval of the
Sig. (2- Mean Std. Error
F Sig. t df Difference
tailed) Difference Difference
Lower Upper
Equal variances
.026 .874 -.503 14 .623 -2.62500 5.21737 -13.81515 8.56515
assumed
Equal variances not
-.503 13.999 .623 -2.62500 5.21737 -13.81519 8.56519
assumed
So now lets repeat the above analysis using the t_test_paired_long_format.sav and the Mixed models dialogues which
are accessed from the menu option:
analyse -> Mixed models -> linear.
The first dialog box that appears is for specifying the various levels of data, we can ignore this for our present analysis,
so just click continue.
While we have specified the variables in the above dialog box we also
need to specify for each factor/covariate if it is to be estimated as a
fixed or random variable (i.e. effect), for this analysis we just have one variable which we wish to model as a fixed
effect. Clicking on the fixed effect button above produces the dialog box below. We move the time variable to the
model box by clicking on the add button.
The results from this analysis are shown below.
Descriptive Statistics
result
Standard Coefficient of
time Count Mean
Deviation Variation
1 8 14.2500 10.40261 73.0%
2 8 16.8750 10.46678 62.0%
Total 16 15.5625 10.17165 65.4%
a
Model Dimension
Number of Number of
Levels Parameters
Fixed Intercept 1 1
Effects time 2 1
Residual 1
Total 3 3
a a. Dependent Variable: result.
Information Criteria
-2 Restricted Log Likelihood 109.553
Akaike's Information Criterion
111.553
(AIC)
b
Hurvich and Tsai's Criterion Estimates of Fixed Effects
111.886
(AICC) 95% Confidence Interval
Bozdogan's Criterion (CAIC) 113.192 Parameter Estimate Std. Error df t Sig.
Lower Bound Upper Bound
Schwarz's Bayesian Criterion (BIC) 112.192 Intercept 16.87 3.68 14 4.574 .000 8.962367 24.787633
The information criteria are displayed in smaller- [time=1] -2.62 5.21 14 -.503 .623 -13.815152 8.565152
is-better forms. [time=2] 0
a
0 . . . . .
a. Dependent Variable: result. a. This parameter is set to zero because it is redundant.
b. Dependent Variable: result.
It is interesting to note that we could have extended the above to many independent groups which would have been
equivalent to carrying out an ANOVA.
Comparing the about output with that from the traditional analysis we can see that they are pretty much identical, we
have the same descriptive statistics with the coefficient of variation replacing the sem. The t, p value and confidence
Level
2
Patient 1 Patient 2 Patient 3 ....... Patient n
Observation 1 Observation 1
Observation 1 Observation 1 Observation 1 Level
Observation 2 Observation 2 1
Observation 2 Observation 2 Observation 2
In the above analysis where we did not take into account this dependency we defined our parameter we estimated as a
fixed effect parameter. Basically this means we only estimated a single value (a point estimate). However to define the
degree of dependency between any two of the level 1 repeated measures pairs means that we would need to estimate
a fixed parameter (i.e. the covariance/correlation) value for each pair, this would use up a large number of our degrees
of freedom having to estimate as many parameters as half our sample size!
A solution to this problem is to estimate a Random Effect parameter instead. A random effect parameter specifies a
normal distribution instead of a single value and as we know a normal distribution is defined by its mean and variance
(standard deviation). Ignoring the mean value, this results in us now being able to estimate the (covariance/correlation)
between each of the repeated measures pairs as a normal distribution (assuming they are in reality normally
distributed).
Remembering that we need an estimate of the variance for each of the observations to calculate the
covariance/correlation, we have now reduced the number of parameters we need to estimate from half the sample size
down to just three, and thereby increasing the degrees of freedom substantially.
Another advantage of defining the relationship between the repeated measures as a Random effect parameter is that
we are not now just considering our observed repeated measures pairings but a population of repeated measures from
which they come clearly giving us more generalisability (assuming this is a valid assumption!).
In the following chapters we will look in much more depth at the concept of Random effects.
We will now consider the paired samples t test which does in effect take into account the dependency between the pre
and post test score for each subject.
Note from the above that when you square the standard deviations for the pre and post test scores you obtain the
variances of; 108.2 and 109.53 also remember that the correlation is just the standardised covariance, that is by dividing
the covariance by the product of the two standard deviations we obtain the correlation.
So: correlationa.b = covariance/(sda x sdb) = covariance /( √variance a x √variance b) = .94
To carry out the equivalent analysis using the Linear mixed models dialog boxes you need the data in log format using
the t_test_paired_long_format.sav file. Within the Linear mixed models dialog boxes you specify the repeated
measures, by using the first dialog box specifying the subjects and repeated measures variables as shown below.
We also need to change the repeated covariance type to unstructured which informs SPSS
that we wish to allow the pre post measures (i.e. the repeated measures) to be correlated
and have unequal variances in the model.
a a
Information Criteria Type III Tests of Fixed Effects
-2 Restricted Log Source Numerator df Denominator df F Sig.
94.526
Likelihood Intercept 1 7 18.347 .004
Akaike's time 1 7 4.200 .080
Information 100.526 a. Dependent Variable: result.
Criterion (AIC)
Hurvich and Tsai's
102.926
Criterion (AICC) Estimates of Fixed Effects
b
a
Estimates of Covariance Parameters Ignoring for now much of the above you will notice
Parameter Estimate Std. Error
UN (1,1) 108.214286 57.842969
that we obtained exactly the same t and p values as
Repeated that obtained by the traditional paired t test.
UN (2,1) 102.321429 56.473681
Measures
UN (2,2) 109.553571 58.558847
Referring back to the original SPSS paired t test
a. Dependent Variable: result. (using restricted ML if we had used ML we would
have got smaller values) output and noting that the variances are; 108.2 and
109.53 and also the correlation we have equivalent values in the estimates of covariance table.
variance
2
Diagonals = Variance = sd ; Off diagonals = Covariance
T1 = pre T2 = post
Remembering that the correlation is just the standardised covariance, that T1 = pre 108.214286
is if we divide the covariance by the product of the two standard deviations T2 = post 102.321429 109.553571
(= square roots of the variances) we obtain the correlation coefficient.
covariance variance
correlationa.b = covariance/(sda x sdb) = covariance /( √variance a x √variance b)
correlationpre.post = 102.3214 / ( √108.214 x √109.5535) = .939 0
a a
Model Dimension Information Criteria
Number -2 Log Likelihood 101.143
Number Covariance Number of Subject
of Akaike's Information Criterion
of Levels Structure Parameters Variables 109.143
Subjects (AIC)
Fixed Intercept 1 1 Hurvich and Tsai's Criterion
Effects time 2 1 112.780
(AICC)
Repeated Compound Bozdogan's Criterion (CAIC) 116.234
time 2 2 id 8
Effects Symmetry Schwarz's Bayesian Criterion (BIC) 112.234
Total 5 4 The information criteria are displayed in smaller-
a. Dependent Variable: result. is-better forms.
a. Dependent Variable: result.
b
Estimates of Fixed Effects
95% Confidence Interval
Parameter Estimate Std. Error df t Sig.Lower Upper
Bound Bound
Intercept 16.87 3.45 8.497 4.890 .001 8.99 24.75
[time=1] -2.62 1.19 8 -2.191 .060 -5.38 .137
a
[time=2] 0 0 . . . . .
a. This parameter is set to zero because it is redundant.
b. Dependent Variable: result.
a
Estimates of Covariance Parameters
Parameter Estimate Std. Error
CS diagonal offset 5.742187 2.871094
Repeated Measures
CS covariance 89.531250 46.223469
a. Dependent Variable: result.
Comparing the two models we have a -2 LL of 101.140 (corrected to 3 d.p) (df=5) for the more complex model and
101.143 (df=4) for the less complex one. Subtracting the value of the less complex model from that of the other gives a
value of 0.003 which if both models as equivalent, that is the difference is due to random sampling, then the value
follows a chi square distribution with degrees of freedom equal to the difference in degrees of freedom between the
models. Looking at the model dimension tables we see that the df difference is 5-4=1 and using r commander in r, we
can obtain a graphical interpretation of the P value this being the area under the curve to right of the chi square value.
Finally in R we can use the 1-pchisq(0.003,1) expression to obtain the numerical p value, that is the proportion of the
area under the curve highlighted below.
Chi-Squared Distribution: df = 1
1.
0
We can conclude that we would obtain two models displaying a
0.
similar degree of fit or one less similar 96 times in a hundred
8
given that they come from the same population. Considering the
hypothesis testing approach as this is greater than the traditional 0.
Density
name Variance at each time point Correlation (covariance) between measurement times
Scaled identity constant No correlation (i.e. independent)
Compound
constant constant
symmetry
Diagonal different at each time No correlation (i.e. independent)
Unstructured different at each time Different for each time pairing
AR(1) Correlation gets less as time points get further apart
constant
=Autoregressive (i.e. t1, t2 = ρ but t1, t3 = ρ2 )
12. Summary
This chapter has provided a short introduction into the Linear Mixed models dialog boxes in SPSS and has demonstrated
how you can obtain the equivalent to an independent sample t test (one way ANOVA) and also a paired t test. The
concepts of Maximum likelihood estimation and partial maximum likelihood estimation were introduced as well as
Fixed and Random effects. The ability to compare models was demonstrated by looking at the difference in the -2LL
and degrees of freedom between them where the value follows a chi square distribution (df= difference in the df's) and
also mention was make of Akaikes Information Criterion .
I have tried to emphasis the importance of visualising the data and this aspect, although can be difficult is an important
first step in the analysis.
This was very much an introduction which we will develop in the next few chapters.
I have deliberately not considered the R equivalents here – they are so much easier than the baroque dialog boxes of
SPSS. A YouTube video demonstrates this.
13. References
Bickel R 2007 Multilevel Analysis for Applied Research: It’s Just Regression! The Guilford Press.
Bollen K A, Curran P J. 2006 Latent Curve Models: A Structural Equation Perspective. Wiley
Bollen K. A. 1989 Structural Equations with Latent Variables. Wiley.
Brown H, Prescott R 2006 (2nd ed.) Applied Mixed models in Medicine. Wiley.
Campbell 2006 (2nd ed.) Statistics at square 2. BMJ books.
Crawley M J 2005 Statistics: An introduction using R. Wiley
Crowder M J.Hand D J. 1990 Analysis of repeated measures. London: Chapman and Hall.
Diggle P J Hegaerty P Liang K-Y. Zeger S. 2002 (2nd ed.) Analysis of Longitudinal Data. Oxford Science publications.
Duncan T E, Duncan S C, Strycker L A. 2006 (2nd ed.) An Introduction to Latent Variable Growth Curve Modeling:
Concepts, Issues, and Applications: Lawrence Erlbaum.
Everitt B S, Hothorn T 2006 (1st ed) A handbook of statistical analyses using R. Chapman & Hall.
Everitt B S, Hothorn T 2010 (2st ed) A handbook of statistical analyses using R. Chapman & Hall.
Field A 2009 Discovering Statistics Using SPSS. Sage [Chapter nineteen describes multilevel modelling including
restructuring data].
Fitzmaurice G M, Laird N M, Ware J M, 2004 Applied Longitudinal Analysis. Wiley
th
Goldstein H. 2011 (4 ed.) Multilevel statistical models. Wiley.
Hand D, Crowder M 1996 Practical Longitudinal data analysis. Chapman & hall
Heck R H, Thomas S L & Tabata L N. 2010 Multilevel and Longitudinal modelling with IBM SPSS. Routledge.
Hedeker, D., and R. D. Gibbons. 2006. Longitudinal Data Analysis. Wiley. Website: tigger.uic.edu/~hedeker/ml.html
Hox J 2010 (2nd ed) Multilevel analysis: Techniques and applications. Lawrence Erlbaum
Landau S, Everitt B S 2004 A handbook of statistical analyses using SPSS. Chapman & Hall.
Leeuw J D,·Meijer E 2008 (eds.) Handbook of Multilevel Analysis. Springer.
Matthews J N S, Altman D G, Campbell M J, Royston J P 1990 Analysis of serial measurements in medical research. B M J
300 230 – 235
rd
Norman G R, Streiner D L. 2008 (3 ed) Biostatistics: The bare Essentials.
Sarkar D 2008 Lattice: Multivariate Data Visualization with R. Springer.
Sheather S J 2009 A Modern approach to regression with R. Springer. Website, includes R tutorials and datasets:
http://www.stat.tamu.edu/~sheather/book/
Singer, J. D., and J. B. Willett. 2003. Applied Longitudinal Data Analysis: Modeling Change and Event Occurrence. Oxford
University Press Inc, USA. gseacademic.harvard.edu/alda/
Twisk J W R 2003 Applied Longitudinal analysis for Epidemiology: A practical Approach. Cambridge University Press.