Specifying a Random Intercept or Random Slope Model in SPSS GENLINMIXED

One of the things I love about MIXED in SPSS is that the syntax is very similar to GLM.  So anyone who is used to the GLM syntax has just a short jump to learn writing MIXED.

Which is a good thing, because many of the concepts are a big jump.

And because the MIXED dialogue menus are seriously unintuitive, I’ve concluded you’re much better off using syntax.

I was very happy a few years ago when, with version 19, SPSS finally introduced generalized linear mixed models so SPSS users could finally run logistic regression or count models on clustered data.

But then I tried it, and the menus are even less intuitive than in MIXED.

And the syntax isn’t much better.  In this case, the syntax structure is quite different than for MIXED.

And I find the model viewer output quite cumbersome to navigate. (Edit: There is now a way to turn off the model viewer. Woo hoo!)

But if you really need to use GENLINMIXED, I thought I’d show you how to write some of the syntax. Seriously, just skip the menus altogether.  They’re confusing.

Below is the exact same model written in both MIXED and GENLINMIXED.  Because the DV, JobsK, is quantitative, and I’m assuming normal residuals, I can get the same results in both.

If you are running something like a logistic regression model, you can’t use MIXED and will have to change the LINK and DISTRIBUTION options.

The Random Intercept Model in both procedures:

MIXED JobsK BY Rural WITH Time
/FIXED=Rural Time Rural*Time| SSTYPE(3)
/METHOD=REML
/RANDOM Intercept|Subject(County) COVTYPE(VC).

*Generalized Linear Mixed Models.
GENLINMIXED
/DATA_STRUCTURE SUBJECTS=County
/FIELDS TARGET=JobsK
/TARGET_OPTIONS DISTRIBUTION=NORMAL LINK=IDENTITY
/FIXED  EFFECTS=Rural Time Rural*Time USE_INTERCEPT=TRUE
/RANDOM USE_INTERCEPT=TRUE SUBJECTS=County
COVARIANCE_TYPE=VARIANCE_COMPONENTS
/BUILD_OPTIONS TARGET_CATEGORY_ORDER=ASCENDING
INPUTS_CATEGORY_ORDER=ASCENDING MAX_ITERATIONS=100
CONFIDENCE_LEVEL=95 DF_METHOD=RESIDUAL COVB=MODEL.

You will notice that, for example, both procedures have a FIXED and a RANDOM subcommand.  The FIXED subcommand lists the fixed effects.  The only really differences are that in GENLINMIXED you have to put EFFECTS= and you have to specify that you do want an intercept.

Likewise, the RANDOM subcommand tell SPSS the same thing in both models, but just has slightly different sytnax to do so.  In both cases, you need to list the random effects, indicate the subject and specify the covariance structure.

All the other subcommands in GENLINMIXED are explicity defining different parts of the model.  Not all of these are relevant to a linear model, but the options are there to change them for another type of Generalized Linear Mixed Model.

And just to be thorough, here again is the syntax for a random slope model in both procedures. I’ve bolded the parts in both that specify the random slope for Time.

The Random Slope for Time Model in Both Procedures:

MIXED JobsK BY Rural WITH Time
/FIXED=Rural Time Rural*Time| SSTYPE(3)
/METHOD=REML
/RANDOM Intercept Time|Subject(County) COVTYPE(VC).

GENLINMIXED
/DATA_STRUCTURE SUBJECTS=County
/FIELDS TARGET=JobsK
/TARGET_OPTIONS DISTRIBUTION=NORMAL LINK=IDENTITY
/FIXED  EFFECTS=Rural Time Rural*Time USE_INTERCEPT=TRUE
/RANDOM EFFECTS =Time USE_INTERCEPT=TRUE SUBJECTS=County
COVARIANCE_TYPE=VARIANCE_COMPONENTS
/BUILD_OPTIONS TARGET_CATEGORY_ORDER=ASCENDING
INPUTS_CATEGORY_ORDER=ASCENDING MAX_ITERATIONS=100
CONFIDENCE_LEVEL=95 DF_METHOD=RESIDUAL COVB=MODEL.

This was the example used in our free webinar: Random Intercept and Random Slope Models. The recording of the webinar is freely available for download.

 

What is GLMM and When Should You Use It?
When you have multilevel or repeated data and normality just isn't happening, you may need GLMM. Get started learning Generalized Linear Mixed Models and when and how to apply them to your data.

Reader Interactions

Comments

  1. Patrick Gomez says

    Great post!
    I am looking for a postmodel estimation function in SPSS that does what dy/dx does in STATA 🙂
    For a significant interaction between a categorical variable A and a continuous variable B, I can use dy/dx to estimate the regression coefficient of B for the different categories of A. How can I do that in SPSS?

  2. Brandon says

    Hi, great post! When setting up a random factor in genlinmixed, does effect need to be numerical? Or can it be a catagorical variable, like subject? If not, but I have subjects within groups, should those be nested together? Thanks!

    • Karen Grace-Martin says

      Random factors are always categorical. They have to be a unit that is sampled. So Subject is commonly a random factor. Groups sometimes are, depending on whether the group itself is something you want to test or whether it’s simply something sampled as part of the design.

  3. Prashant says

    Hi Karen,
    Using the Genlinmixed procedure in SPSS, I have noticed that it does not produce contrasts or post-hoc comparison statistics for interactions with more than three variables terms (i.e., four-way and more). Do you perhaps know whether it is due to an incomplete implementation of the Genlinmixed procedure in older versions (I have the v. 21) or is it something else that I am not aware of ?

    Thanks in advance,
    Prashant

  4. Pella says

    Hey Karen,

    still I feel like mixed and genlinmixed syntax are just strange. Actually I just tried two different models in mixed:

    The first:

    MIXED EDSS BY Nicotin_binary Alcohol_binary Sex Center WITH BMI
    /CRITERIA=CIN(95) MXITER(100) MXSTEP(10) SCORING(1) SINGULAR(0.000000000001) HCONVERGE(0,
    ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)
    /FIXED=Nicotin_binary Alcohol_binary | SSTYPE(3)
    /METHOD=REML
    /RANDOM=INTERCEPT Center | COVTYPE(VC) SOLUTION.

    The second:

    MIXED EDSS BY Nicotin_binary Alcohol_binary Sex WITH BMI
    /CRITERIA=CIN(95) MXITER(100) MXSTEP(10) SCORING(1) SINGULAR(0.000000000001) HCONVERGE(0,
    ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)
    /FIXED=Nicotin_binary Alcohol_binary | SSTYPE(3)
    /METHOD=REML
    /RANDOM=INTERCEPT | SUBJECT(Center) COVTYPE(VC) SOLUTION.

    Both yield the exact same parameter estiamtes, p-values and so on. Funny though, in the first approach I have a not converging Hessian but not in the second.

    I don’t really see what’s the different in subjects, subject combinations or simply random intercepts anyway. From my mathematical point of view, subject as spss uses it, is just the same as a random intercept.

    I’m curious what you think.

    Cheers

  5. Gabbie May says

    Hi Karen,

    Thank you for your webinars and blogs on LMM, they have been a real help to me. i do have a quick question though. I am wanting to know if I can look at two random effects of intercepts within the same model. For example, I want to control for the random effects of intercepts for Participants and Items/Trials. How would I go about writing this in my syntax please? I am working with SPSS.

    Kind regards,

    Gabbie

  6. Scott Stanley says

    Would it be possible for you to post the syntax above that produced the final output in SPSS in the webinar on random intercepts and slopes? I think I mostly get how the syntax above produce random intercept model for that example, and then random slope for that model, but I cannot figure out how to get out of GLMM the output you have that has the correlation between the random slope and intercept. I cannot figure anyway to build it in the menus (SPSS 25) nor can I imagine what it looks like in syntax. In other words, I don’t see how to get the output for the “estimates of covariance parameters” that you show on slide page 12 in the webinar.

    One other question. I do not understand why you do not specify the repeated measure of Time in the data structure. It seems like that would be what one would do, but the output gets further away from anything you have when I do that, but I just cannot imagine why that’s not a thing to do.

    Thanks for the great webinars, btw. Really helpful stuff to me.

    • Karen Grace-Martin says

      Hi Scott,

      It’s the covariance structure of the random effects. In the models above, both mixed and genlinmixed, I’m using variance components, which is telling spss to NOT estimate a covariance parameter between the intercept and slope. Just to include variance estimates.

      If you want that parameter estimate, you need to use unstructured instead.

  7. Rebecca says

    Can you do deviance statistics with GenLinMixed? that’s usually what I do with Mixed but the output of GenLinMixed is a little confusing and I don’t know what to do with (how to interpret) a Wald Z for each trial number.

  8. Richard says

    Hi Karen,

    Thanks for the quick response! SPSS 22 can provide Sattherwaite df’s so I’ll try that and see how my models look.

    Richard

  9. Richard says

    Dear Karen,

    I am running a series of generalized linear mixed models with SPSS version 22 using the GENLINMIXED procedure and I have read your post with great interest. I am examining the factors associated with how children travel to and from school (e.g. dichotomous outcome : active vs. motorized transport), so I am using a binomial distribution with a logit link. This is a 3-level model (e.g., children nested within schools nested within countries) which makes calculation of the degrees of freedom messy. I would like to know if there is any way to obtain Kenward-Roger degrees of freedom for my models.

    Thanks in advance!

    Richard

    • Karen says

      Hi Richard,

      Not in SPSS. As far as I know, only SAS has options for changing the type of df and I’d have to check whether that’s just in mixed or also glimmix.

      Karen


Leave a Reply

Your email address will not be published. Required fields are marked *

Please note that, due to the large number of comments submitted, any questions on problems related to a personal study/project will not be answered. We suggest joining Statistically Speaking, where you have access to a private forum and more resources 24/7.