-
Notifications
You must be signed in to change notification settings - Fork 41
/
introduction.Rmd
52 lines (32 loc) · 3 KB
/
introduction.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Introduction
## Overview
Mixed models are an extremely useful modeling tool for situations in which there is some dependency among observations in the data, where the correlation typically arises from the observations being clustered in some way. For example, it is quite common to have data in which we have repeated measurements for the units of observation, or in which the units of observation are otherwise grouped together (e.g. students within school, cities within geographic region). While there are different ways to approach such a situation, mixed models are a very common and powerful tool to use. In addition, they have ties to other statistical approaches that further expand their applicability.
### Goals
The goal here is primarily to provide a sense of when one would use mixed models, and a variety of standard techniques to implement them. While it can be seen as a standalone treatment, the document originally served as the basis for a workshop, and from that, exercises are available to practice your skills.
### Prerequisites
The document is for the most part very applied in nature, and only assumes a basic understanding of standard regression models. Use of R for regression modeling is also assumed, though there will be some review. Demonstrations will be done almost entirely with the <span class="pack">lme4</span> package.
Note the following color coding used in this document:
- <span class="emph">emphasis</span>
- <span class="pack">package</span>
- <span class="func">function</span>
- <span class="objclass">object/class</span>
- [link]()
## Data and Exercises
All data used can be downloaded [here](https://github.com/m-clark/mixed-models-with-R/blob/master/data.zip).
If you are interested in doing the examples and exercises, you can follow these steps.
0. Download the zip file at [GitHub](https://github.com/m-clark/mixed-models-with-r-workshop-2019/archive/master.zip). Be mindful of where you put it.
1. Unzip it. Be mindful of where you put the resulting folder.
2. Open RStudio.
3. File/Open Project and click on the blue icon (`mixed-models-with-r-workshop-2019.Rproj`) in the folder you just created.
4. File/Open Click on the ReadMe file and do what it says.
Otherwise just download the data files from [GitHub](https://github.com/m-clark/mixed-models-with-R/tree/master/data).
## Key packages
To run the code in this document you'll really only need the following:
- <span class="pack">lme4</span>
- <span class="pack">tidyverse</span>: for data processing
- <span class="pack">merTools</span>: optional
- <span class="pack">glmmTMB</span>: optional
- <span class="pack">brms</span>: optional
- <span class="pack">modelr</span>: optional
- <span class="pack">nlme</span>: part of base R, no need for install
I also use a custom package called <span class="pack">mixedup</span> that provides more usable and consistent output for mixed models from <span class="pack">lme4</span>, <span class="pack">brms</span>, <span class="pack">mgcv</span>, etc. Much of the output you see will come from that.