I have an outcome variable painRating which represents how painful a participant found a sensation. I can reasonably expect ratings to be affected by a painful stimulation. Thus I would like to run a mixed-effects model (lme4) to test that.

In my experiment I have various stimulation levels which were acquired individually for each participant ** but following a predetermined protocol **, thus I have limited and influenced the stimulation levels. Let's call my painful stimulation variable stimulationValue. It is continuous numerical variable that ranges between 5 and 15.

In my understanding, stimulationValue could be:

A) a random effect because the actual value of the stimulation is due to a participant variability (another random effect participant) and whether or not a participant held a diagnosis (diagnosis). So my model could look like:

painRating ~ diagnosis + (1 | stimulationValue) + (1 | diagnosis/participant)

B) a fixed effect because despite participant variability, I have limited the actual value to a range:

painRating ~ diagnosis + stimulationValue + (1 | diagnosis/participant)

Question: Am I wrong that 'stimulationValue' could be both a RE and a FE? If not, is there one way that I should choose over the other?

** If needed clarification - Before the experiment, I determined 6 various stimulation levels based on each participant's pain threshold and pain tolerance. Both measures differ between participants thus the resulting stimulation levels also differ.

  • $\begingroup$ I think saying StimVal is continuous is a red herring. And I wonder about its importance to others who may read your report. It seems its a categorical variable with six levels, calibrated for individual patients to run from 'barely noticeable', to 'limit of toleration'. Would other researchers, possibly seeking to confirm your work, be able to understand and administer your 'predetermined protocol'. // Seems as if the take-away msg from your study might be that painrating increases with StimVal. Without clear set standards for both variables, it's hard to know what to say. $\endgroup$
    – BruceET
    Apr 21, 2020 at 22:39
  • $\begingroup$ Thank you, @BruceET, I understood your concern! I assure you the protocol is quite detailed but for the purpose of the question I avoided describing it. The resulting stimulation levels are indeed categorical but do not come to your described range. Another point, while for one participant stimulationValue of 10 represents weakest stimulation level, for another it may be the strongest. On the note of takeaway message, it would not be as simple either unfortunately (or fortunately!). I expect painRating to be mediated by several factors. $\endgroup$ Apr 22, 2020 at 8:54

2 Answers 2


This is an interesting design!

One thing before getting to your question. You have diagnosis as both a fixed and then a nested random intercept. That does not make a lot of sense. My initial thought, without knowing a lot about your data, is that diagnosis would be better left in the fixed part of the model and not included as a random intercept.

I would encourage you to treat stimulationValue in a way that is consistent with your research question(s) and theory. Theoretically, what is its role in a patient's painRating? Do you expect the effect of stimulationValue on painRating to be the same across individuals? If not, then you may consider a third alternative model in which you treat stimulationValue as a continuous predictor that has a varying effect on painRating depending on the participant. That model would be as follows:

m3 <- painRating ~ diagnosis + stimulationValue + (1 + stimulationValue | participant), data=df

Since diagnosis is presumably a participant-level variable, you might further be interested in whether diagnosis at all shifts the strength of the association between stimulationValue and painRating. That would involve you interacting the two variables.

This is just to show that you have lots of options for how to treat stimulationValue and the option you choose should be based on theory and other considerations as much as possible and less on purely statistical considerations.

  • 1
    $\begingroup$ Thank you, @ErikRuzek! It is a fairly common design in pain research! I'm certain I'm not the first one who wonders how to deal with it. $\endgroup$ Apr 22, 2020 at 8:38
  • 1
    $\begingroup$ I agree with you on diagnosis, it should remain as a fixed effect. Your advice to consider the theoretical context is spot on. I expect 'stimulationValue' to be varying depending on participant as well as diagnosis so m3 and proposed m4 (interaction between stimulationValue and diagnosis) seem very sensible. $\endgroup$ Apr 22, 2020 at 8:45
  • $\begingroup$ @kaleidoscopic - great! Good luck with your work! $\endgroup$
    – Erik Ruzek
    Apr 22, 2020 at 13:43

Sometimes the difference between 'fixed' and 'random' depends on purpose and point of view. One study, two perspectives:

Fixed. Suppose I have 10 new machines of a popular type made by Mfg A in my factory. I wonder if they are all going to perform according to my needs. As an experiment I run difficult jobs on all 10 machines. I do an ANOVA see if the machines differ as to quality of output. For me this is a random effects model. I care only about my 10 machines and a significant effect with ad hoc analysis is important to me. I now know that machines A, D, and H are not quite up to my most demanding standards, and the B, C, and J are especially good. For me Machine is a fixed effect.

Random. I discuss results of my experiment with a representative from Mfg A who visits my company regularly. She finds them interesting and wants a copy of my data and analysis for company engineers to study. For Mfg A, my ten machines are a random sample from an essentially infinite pool of such machines. For Mfg A, my study of ten machines should be viewed according to a random effects model. Mfg A will want to estimate the variance of my main effect.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.