Programming the statistical procedures from SAS

Procedure for dichotomous level 1 predictor in multilevel modeling

New Contributor
Posts: 3

Procedure for dichotomous level 1 predictor in multilevel modeling

[ Edited ]

Hey everybody!

I apologize in advance for my noob-ness.


I am having a very hard time trying to figure out how to write SAS code that will properly analyze a multilevel data structure which has both:

a dichotomous level 1 predictor

a dichotomous level 2 predictor


We had people track a moving target on the screen with the mouse. At random times we blasted them with 200ms of loud white noise. This dysregulated mouse control accuracy right after the noise. Each person did 60 trials of tracking.. half of which had a noise, half of which were silent. Before doing the tracking task, we had people learn about non-attachment to aversive experience (non-attach condition) or learn about trees (control condition). Random assignment by subject number.


So, for the MLM, I have trials (60) of the tracking task nested within individuals (115). The DV is mouse tracking error or "target miss" just after blasted by noise. 

The trial-level (level 1) variables are:

sound (noise vs. silent, coded as 1,0, or even left as words. that seems to work too)

PC_Baseline_miss (tracking right before sound event or silent/nothing "event", person centered)


Person-level 2 variables:

experiment condition (1,0, or words)


Does anybody know what I'm talking about and how to adjust SAS code for this? Here is the code I am using now....

It doesn't work and I don't know why....

A primary question really is why is there are two “random” lines in the code I was given Smiley Happy I think they correspond to each level of analysis, but not sure about this.

CLASS subject trail sound condition;
MODEL Avds_recover = PCAVDS_base sound condition sound*condition / SOLUTION DDFM=Satterthwaite;
RANDOM INTERCEPT pcAVDS_base sound / SUBJECT=trial Group= sound TYPE=UN;
RANDOM INTERCEPT pcAVDS_base sound / SUBJECT=subject TYPE=UN GROUP=condition;
REPEATED / SUBJECT=subject TYPE=VC group = sound GROUP=condition ; run;

Posts: 275

Re: Procedure for dichotomous level 1 predictor in multilevel modeling

[ Edited ]
Posted in reply to Robert_Klein_ND

The statistical model for this experiment is known, in some quarters, as a random coefficients model (essentially, regression in a mixed model).


The current model assumes that the relationship between Avds_recover and PCAVDS_base is linear, and that the slope is the same regardless of sound or condition (because the model does not include interactions of sound and/or condition with PCAVDS_base). Are these assumptions valid?


IF I understand your study design correctly, then I would consider

proc mixed;
  class subject sound condition;
  model Avds_recover = PCAVDS_base | sound | condition;
  random subject(condition);
  random intercept PCAVDS_base / subject=sound*subject(condition);
  lsmeans sound | condition;

Generally, REML is preferable to ML. Assumptions include normality, homogeneity of variance, and linearity. Also that order of sound presentation doesn't matter--that a subsequent trial is not affected by previous trials. You don't say how sound level was assigned to trials.


Trial would never be a SUBJECT in a RANDOM statement (if I'm interpreting trial correctly). Sound probably should not be in a RANDOM statement with TYPE=UN; it would be better dealt with in a separate RANDOM statement as appropriate.


There are a variety of ways to specify the random structure for the model. Differences in the specification of SUBJECT= and optionally GROUP= produce different covariance structures. Theoretically, one will fit the data best. You definitely want to know what you're doing with different specifications. It's complicated (no surprise there).


Personally, I don't see the need for a REPEATED statement in a model like this, but some people include one to deal with the temporal autocorrelation among trials. If you include REPEATED, I doubt you can have two "group=" (although I've never tried), and you would need to either have the data set sorted appropriately by trial (which is the repeated measure) or, better yet, include trial (as REPEATED trial / ...).


I'll make my usual recommendation: read

This is a challenging model and you really don't want to go about it blindly.


 If you haven't already done so, plot your data.



Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation