# mixed effect models

## 1. random effects

- As I understand it, these are effects that occur at the group level. So you can imagine that in a given hospital, you want to plot the outcome of each patient. The outcomes are effected by the drugs they take. But each doctor results in a different y-intercept for the group of patients that they are treating.
- random effects:
- the effects might change depending on how you did the experiment
- for example, the doctor effect should not be a fixed effect, since it was up to chance which doctors would be included in the experiment
- we assume that the doctors included in our study are drawn from a pool of doctors, which has its own distribution that can be estimated
- in this way, we can think of random effects a little like nuisance variables

- basically, random effects are there to avoid the problem of treating samples like they are all drawn from the same pool
- when in reality, they are drawn from many pools, where each pool is fairly homogeneous

- my favorite stack overflow answer

## 2. colin conwell's explanation

- random effect is something that we don't build into the model, but we still want to model it
- there are group effects that we want to model
- important where differences between individuals (groups) are important
- so you can fit a random slope and/or a random intercept to make assumptions about where individuals start with respect to the target, and where they will end up based on treatment

## 3. lmer

- How do I get the p-values?
`lmertest`

gives you p-values https://github.com/runehaubo/lmerTestR via Satterthwaite's degrees of freedom method- but this is not always advisable see https://stats.stackexchange.com/questions/22988/how-to-obtain-the-p-value-check-significance-of-an-effect-in-a-lme4-mixed-mode

and https://stat.ethz.ch/pipermail/r-sig-mixed-models/2008q2/000904.html