Simple linear models
In simple linear models in R using the lm library, we can write the formula as DV ~ IV (DV is a dependent variable). The command employs a few arithmetic symbols. A '+ sign' indicates more than one main effect or predictor (independent variable, IV) with no interaction. A '* sign' provides a short form of main effects with interaction. Number '1' with a '+ sign' refers to an intercept. There is no need to explicitly write this, as it is always implied and estimated by default. Sometimes, you want to omit this by simply writing '0'.
When we want to include fixed/random factors, we then use, e.g. the lmer library, and the syntax is slightly different.
DV ~ 1 + IV1 * IV2 DV ~ IV | grouping
- The dependent variable (DV) is the response variable to be predicted. The independent variable (IV) is the one whose effects we will assess. By default, IV is treated as a fixed factor.
- A vertical bar denotes a grouping factor or random factor. It separates expressions for design matrices from the grouping factor. For example: to fit a predictor for each random factor, you can write 1 + A|S, which means the same thing as (A|S).
- A '/ sign' indicates nesting. So (school/class) means classes are nested within school.
- Fixed factors can be included without any grouping. You can have additional random factors without any fixed factor (an intercept-only model). In each random/fixed factor, ask yourself whether you allow the intercept to change, the slope, or both!
Hierarchical Linear Modeling
Begin with the first and simplest model which is the intercept-only model. It has no predictor or independent variable (so, no slope!). Suppose we have one random factor, usually the participant factor. The model is also called the unconditional model.Y ~ (1|S) ; intercept-only model
The next model is the random intercept model. We assign a new variable or predictor X as Level 1, which acts as a fixed factor. Here, the intercepts for different subjects will vary but not the slopes. Note that the intercept for X can be omitted as the function understands it to be 1+X.
Y ~ X + (1|S) ; random intercept model
Now, we can add complexity by allowing different subjects to have different intercepts and slopes. This is the random intercept + slope model. There are two possibilities: the variations of intercept and slope can be independent or correlated!
Y ~ X + (1|S) + (0 + X|S) ; independent
Y ~ X + (X|S) ; correlated
Source: here


No comments:
Post a Comment