├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ └── deploy_bookdown.yml ├── .gitignore ├── .nojekyll ├── 01-module-1.Rmd ├── 02-multiple-regression.Rmd ├── 03-module-3.Rmd ├── 04-module-4.Rmd ├── 05-module-5.Rmd ├── 06-module-6.Rmd ├── 07-module-7.Rmd ├── 08-module-8.Rmd ├── 09-module-9.Rmd ├── 10-module-10.Rmd ├── 11-module-11.Rmd ├── 12-module-12.Rmd ├── 13-appendix.Rmd ├── LICENSE.txt ├── README.md ├── Rscripts ├── 02-multiple-regression.R ├── 03-module-3.R ├── 04-module-4.R ├── 05-module-5.R ├── 06-module-6.R ├── 07-module-7.R ├── 08-module-8.R ├── 09-module-9.R ├── 10-module-10.R ├── 11-module-11.R └── 12-module-12.R ├── _book ├── img │ └── effect_types.png ├── open_mlm_materials.epub ├── open_mlm_materials_files │ └── figure-html │ │ ├── graph-1.png │ │ ├── unnamed-chunk-101-1.png │ │ ├── unnamed-chunk-109-1.png │ │ ├── unnamed-chunk-112-1.png │ │ ├── unnamed-chunk-113-1.png │ │ ├── unnamed-chunk-115-1.png │ │ ├── unnamed-chunk-115-2.png │ │ ├── unnamed-chunk-115-3.png │ │ ├── unnamed-chunk-115-4.png │ │ ├── unnamed-chunk-115-5.png │ │ ├── unnamed-chunk-120-1.png │ │ ├── unnamed-chunk-121-1.png │ │ ├── unnamed-chunk-123-1.png │ │ ├── unnamed-chunk-124-1.png │ │ ├── unnamed-chunk-127-1.png │ │ ├── unnamed-chunk-129-1.png │ │ ├── unnamed-chunk-130-1.png │ │ ├── unnamed-chunk-131-1.png │ │ ├── unnamed-chunk-134-1.png │ │ ├── unnamed-chunk-136-1.png │ │ ├── unnamed-chunk-137-1.png │ │ ├── unnamed-chunk-138-1.png │ │ ├── unnamed-chunk-138-2.png │ │ ├── unnamed-chunk-139-1.png │ │ ├── unnamed-chunk-139-2.png │ │ ├── unnamed-chunk-142-1.png │ │ ├── unnamed-chunk-143-1.png │ │ ├── unnamed-chunk-144-1.png │ │ ├── unnamed-chunk-145-1.png │ │ ├── unnamed-chunk-146-1.png │ │ ├── unnamed-chunk-16-1.png │ │ ├── unnamed-chunk-17-1.png │ │ ├── unnamed-chunk-25-1.png │ │ ├── unnamed-chunk-42-1.png │ │ ├── unnamed-chunk-46-1.png │ │ ├── unnamed-chunk-53-1.png │ │ ├── unnamed-chunk-6-1.png │ │ ├── unnamed-chunk-92-1.png │ │ ├── unnamed-chunk-93-1.png │ │ └── unnamed-chunk-94-1.png ├── reference-keys.txt ├── search_index.json └── style.css ├── _bookdown.yml ├── _output.yml ├── book.bib ├── data ├── casto2016.csv ├── heck2011.csv ├── hoffman2007.csv ├── rb2002.csv └── teachsat.csv ├── docs ├── 01-module-1.html ├── 02-multiple-regression.html ├── 03-module-3.html ├── 04-module-4.html ├── 05-module-5.html ├── 06-module-6.html ├── 07-module-7.html ├── 08-module-8.html ├── 09-module-9.html ├── 10-module-10.html ├── 11-module-11.html ├── 12-module-12.html ├── 13-appendix.html ├── 404.html ├── CNAME ├── img │ └── effect_types.png ├── index.html ├── libs │ ├── anchor-sections-1.0.1 │ │ ├── anchor-sections.css │ │ └── anchor-sections.js │ ├── anchor-sections-1.1.0 │ │ ├── anchor-sections-hash.css │ │ ├── anchor-sections.css │ │ └── anchor-sections.js │ ├── gitbook-2.6.7 │ │ ├── css │ │ │ ├── fontawesome │ │ │ │ └── fontawesome-webfont.ttf │ │ │ ├── plugin-bookdown.css │ │ │ ├── plugin-clipboard.css │ │ │ ├── plugin-fontsettings.css │ │ │ ├── plugin-highlight.css │ │ │ ├── plugin-search.css │ │ │ ├── plugin-table.css │ │ │ └── style.css │ │ └── js │ │ │ ├── app.min.js │ │ │ ├── clipboard.min.js │ │ │ ├── jquery.highlight.js │ │ │ ├── plugin-bookdown.js │ │ │ ├── plugin-clipboard.js │ │ │ ├── plugin-fontsettings.js │ │ │ ├── plugin-search.js │ │ │ └── plugin-sharing.js │ ├── header-attrs-2.11 │ │ └── header-attrs.js │ └── jquery-3.6.0 │ │ └── jquery-3.6.0.min.js ├── open_mlm_materials_files │ └── figure-html │ │ ├── graph-1.png │ │ ├── unnamed-chunk-101-1.png │ │ ├── unnamed-chunk-102-1.png │ │ ├── unnamed-chunk-103-1.png │ │ ├── unnamed-chunk-109-1.png │ │ ├── unnamed-chunk-11-1.png │ │ ├── unnamed-chunk-110-1.png │ │ ├── unnamed-chunk-111-1.png │ │ ├── unnamed-chunk-112-1.png │ │ ├── unnamed-chunk-113-1.png │ │ ├── unnamed-chunk-114-1.png │ │ ├── unnamed-chunk-115-1.png │ │ ├── unnamed-chunk-115-2.png │ │ ├── unnamed-chunk-115-3.png │ │ ├── unnamed-chunk-115-4.png │ │ ├── unnamed-chunk-115-5.png │ │ ├── unnamed-chunk-116-1.png │ │ ├── unnamed-chunk-116-2.png │ │ ├── unnamed-chunk-116-3.png │ │ ├── unnamed-chunk-116-4.png │ │ ├── unnamed-chunk-116-5.png │ │ ├── unnamed-chunk-117-1.png │ │ ├── unnamed-chunk-117-2.png │ │ ├── unnamed-chunk-117-3.png │ │ ├── unnamed-chunk-117-4.png │ │ ├── unnamed-chunk-117-5.png │ │ ├── unnamed-chunk-119-1.png │ │ ├── unnamed-chunk-120-1.png │ │ ├── unnamed-chunk-121-1.png │ │ ├── unnamed-chunk-122-1.png │ │ ├── unnamed-chunk-123-1.png │ │ ├── unnamed-chunk-124-1.png │ │ ├── unnamed-chunk-125-1.png │ │ ├── unnamed-chunk-126-1.png │ │ ├── unnamed-chunk-127-1.png │ │ ├── unnamed-chunk-128-1.png │ │ ├── unnamed-chunk-129-1.png │ │ ├── unnamed-chunk-13-1.png │ │ ├── unnamed-chunk-130-1.png │ │ ├── unnamed-chunk-131-1.png │ │ ├── unnamed-chunk-132-1.png │ │ ├── unnamed-chunk-133-1.png │ │ ├── unnamed-chunk-134-1.png │ │ ├── unnamed-chunk-135-1.png │ │ ├── unnamed-chunk-136-1.png │ │ ├── unnamed-chunk-137-1.png │ │ ├── unnamed-chunk-137-2.png │ │ ├── unnamed-chunk-138-1.png │ │ ├── unnamed-chunk-138-2.png │ │ ├── unnamed-chunk-139-1.png │ │ ├── unnamed-chunk-139-2.png │ │ ├── unnamed-chunk-14-1.png │ │ ├── unnamed-chunk-140-1.png │ │ ├── unnamed-chunk-140-2.png │ │ ├── unnamed-chunk-141-1.png │ │ ├── unnamed-chunk-141-2.png │ │ ├── unnamed-chunk-142-1.png │ │ ├── unnamed-chunk-143-1.png │ │ ├── unnamed-chunk-144-1.png │ │ ├── unnamed-chunk-145-1.png │ │ ├── unnamed-chunk-146-1.png │ │ ├── unnamed-chunk-147-1.png │ │ ├── unnamed-chunk-148-1.png │ │ ├── unnamed-chunk-15-1.png │ │ ├── unnamed-chunk-16-1.png │ │ ├── unnamed-chunk-17-1.png │ │ ├── unnamed-chunk-18-1.png │ │ ├── unnamed-chunk-19-1.png │ │ ├── unnamed-chunk-20-1.png │ │ ├── unnamed-chunk-21-1.png │ │ ├── unnamed-chunk-22-1.png │ │ ├── unnamed-chunk-22-2.png │ │ ├── unnamed-chunk-23-1.png │ │ ├── unnamed-chunk-23-2.png │ │ ├── unnamed-chunk-25-1.png │ │ ├── unnamed-chunk-26-1.png │ │ ├── unnamed-chunk-27-1.png │ │ ├── unnamed-chunk-28-1.png │ │ ├── unnamed-chunk-29-1.png │ │ ├── unnamed-chunk-30-1.png │ │ ├── unnamed-chunk-4-1.png │ │ ├── unnamed-chunk-42-1.png │ │ ├── unnamed-chunk-43-1.png │ │ ├── unnamed-chunk-44-1.png │ │ ├── unnamed-chunk-46-1.png │ │ ├── unnamed-chunk-47-1.png │ │ ├── unnamed-chunk-48-1.png │ │ ├── unnamed-chunk-5-1.png │ │ ├── unnamed-chunk-53-1.png │ │ ├── unnamed-chunk-54-1.png │ │ ├── unnamed-chunk-55-1.png │ │ ├── unnamed-chunk-6-1.png │ │ ├── unnamed-chunk-7-1.png │ │ ├── unnamed-chunk-8-1.png │ │ ├── unnamed-chunk-92-1.png │ │ ├── unnamed-chunk-93-1.png │ │ ├── unnamed-chunk-94-1.png │ │ ├── unnamed-chunk-95-1.png │ │ └── unnamed-chunk-96-1.png ├── reference-keys.txt ├── search_index.json └── style.css ├── img ├── .DS_Store └── effect_types.png ├── index.Rmd ├── open_mlm_materials.Rproj ├── open_mlm_materials_files └── figure-html │ ├── graph-1.png │ ├── unnamed-chunk-102-1.png │ ├── unnamed-chunk-110-1.png │ ├── unnamed-chunk-113-1.png │ ├── unnamed-chunk-114-1.png │ ├── unnamed-chunk-116-1.png │ ├── unnamed-chunk-116-2.png │ ├── unnamed-chunk-116-3.png │ ├── unnamed-chunk-116-4.png │ ├── unnamed-chunk-116-5.png │ ├── unnamed-chunk-120-1.png │ ├── unnamed-chunk-121-1.png │ ├── unnamed-chunk-123-1.png │ ├── unnamed-chunk-124-1.png │ ├── unnamed-chunk-127-1.png │ ├── unnamed-chunk-129-1.png │ ├── unnamed-chunk-130-1.png │ ├── unnamed-chunk-131-1.png │ ├── unnamed-chunk-134-1.png │ ├── unnamed-chunk-136-1.png │ ├── unnamed-chunk-137-1.png │ ├── unnamed-chunk-138-1.png │ ├── unnamed-chunk-138-2.png │ ├── unnamed-chunk-139-1.png │ ├── unnamed-chunk-139-2.png │ ├── unnamed-chunk-142-1.png │ ├── unnamed-chunk-143-1.png │ ├── unnamed-chunk-144-1.png │ ├── unnamed-chunk-145-1.png │ ├── unnamed-chunk-146-1.png │ ├── unnamed-chunk-16-1.png │ ├── unnamed-chunk-17-1.png │ ├── unnamed-chunk-26-1.png │ ├── unnamed-chunk-43-1.png │ ├── unnamed-chunk-47-1.png │ ├── unnamed-chunk-54-1.png │ ├── unnamed-chunk-6-1.png │ ├── unnamed-chunk-93-1.png │ ├── unnamed-chunk-94-1.png │ └── unnamed-chunk-95-1.png ├── packages.bib ├── preamble.tex ├── style.css └── worksheets ├── module10.docx ├── module11.docx ├── module12.docx ├── module2.docx ├── module3.docx ├── module4.docx ├── module5.docx ├── module6.docx ├── module7.docx ├── module8.docx └── module9.docx /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^\.github$ 2 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/deploy_bookdown.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - master 5 | 6 | 7 | 8 | name: renderbook 9 | 10 | jobs: 11 | bookdown: 12 | name: Render-Book 13 | runs-on: macOS-latest 14 | steps: 15 | - uses: actions/checkout@v1 16 | - uses: r-lib/actions/setup-r@v1 17 | - uses: r-lib/actions/setup-pandoc@v1 18 | - name: Install rmarkdown 19 | run: Rscript -e 'install.packages(c("rmarkdown","bookdown"))' 20 | - name: Render Book 21 | run: Rscript -e 'bookdown::render_book("index.Rmd")' 22 | - uses: actions/upload-artifact@v1 23 | with: 24 | name: _book 25 | path: _book/ 26 | 27 | # Need to first create an empty gh-pages branch 28 | # see https://pkgdown.r-lib.org/reference/deploy_site_github.html 29 | # and also add secrets for a GH_PAT and EMAIL to the repository 30 | # gh-action from Cecilapp/GitHub-Pages-deploy 31 | checkout-and-deploy: 32 | runs-on: ubuntu-latest 33 | needs: bookdown 34 | steps: 35 | - name: Checkout 36 | uses: actions/checkout@master 37 | - name: Download artifact 38 | uses: actions/download-artifact@v1.0.0 39 | with: 40 | # Artifact name 41 | name: _book # optional 42 | # Destination path 43 | path: _book # optional 44 | - name: Deploy to GitHub Pages 45 | uses: Cecilapp/GitHub-Pages-deploy@master 46 | env: 47 | EMAIL: ${{ secrets.EMAIL }} # must be a verified email 48 | GH_TOKEN: ${{ secrets.GH_PAT }} # https://github.com/settings/tokens 49 | BUILD_DIR: _book/ # "_site/" by default 50 | 51 | 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | _book/ 2 | _bookdown_files/ 3 | .Rproj.user 4 | .Rhistory 5 | .RData 6 | .Ruserdata 7 | .DS_Store 8 | data/mathmot* 9 | -------------------------------------------------------------------------------- /.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/.nojekyll -------------------------------------------------------------------------------- /01-module-1.Rmd: -------------------------------------------------------------------------------- 1 | # Introduction {#introduction} 2 | 3 | ## Overview 4 | 5 | These materials focus on conceptual foundations of multilevel models (MLMs), specifiying them, and interpreting the results. Topics include multilevel data and approaches to dependence, specifying and interpreting fixed and random effects, model estimation, centering, repeated measures and longitudinal models, assumptions testing, and effect sizes in MLMs. 6 | 7 | ## Goals 8 | 9 | These materials are intended for students and instructors. 10 | 11 | By the end of this course, students will be able to: 12 | 13 | 1. Estimate variance components and interpret the intraclass correlation coefficient; 14 | 2. Decide if and when a multilevel model is needed; 15 | 3. Specify and build multilevel models with covariates at level 1 and 2 with both cross-sectional and repeated measures designs; 16 | 4. Interpret regression coefficients and variance components from multilevel models; 17 | 5. Assess the assumptions of multilevel models; 18 | 6. Calculate effect sizes for multilevel models. 19 | 20 | ## Prerequisites 21 | 22 | Readers should be comfortable with multiple linear regression, including building regression models, interpreting regression output, and testing for and interpreting regression coefficients including interactions. The first module reviews multiple regression and can be used to gauge your preparedness for continuing. For those wishing to brush up their regression skills before working through these materials, we recommend UCLA's Statistical Methods and Data Analytics resources and online seminars: https://stats.oarc.ucla.edu/other/mult-pkg/seminars/ 23 | 24 | The worked examples will be conducted using `lme4` in R. The `lme4` documentation provides details of the workings of `lme4`, for interested readers. 25 | 26 | ## Materials 27 | 28 | All materials are available for download in the appendix. The following are available for download: 29 | 30 | * Data: the data used in each chapter 31 | * R Script: an R script of the code used in each chapter 32 | * Worksheet: a worksheet with questions that follows a similar structure to each chapter, but without answers provided 33 | 34 | We recommend that people self-studying download the data and R script and following along with the code and output interpretations in each chapter. Instructors can benefit from downloading the data, code, and worksheets for use in a lab portion in their classes. 35 | -------------------------------------------------------------------------------- /02-multiple-regression.Rmd: -------------------------------------------------------------------------------- 1 | # Multiple Regression Review {#module-2} 2 | 3 | ## Learning Objectives 4 | 5 | In this module, we will review simple and multiple linear regression to establish a strong foundation before moving onto multilevel models. Note that this is intended more as review than a comprehensive guide to regression; for the latter, we recommend https://stats.oarc.ucla.edu/other/mult-pkg/seminars/. 6 | 7 | All materials for this chapter are available for download here. 8 | 9 | The learning objectives for this chapter are: 10 | 11 | 1. Understand using file paths for project management/loading data; 12 | 2. Review using simple and multiple linear regression to analyze data. 13 | 14 | ## Data Demonstration 15 | 16 | In this data demo, we will first review setting up an R session, then simple and multiple linear regression. 17 | 18 | The data for this chapter were taken from chapter 3 of Heck, R. H., Thomas, S. L., & Tabata, L. N. (2011). *Multilevel and Longitudinal Modeling with IBM SPSS*: Taylor & Francis. These data have a multilevel structure, which we will work with in chapter 3, but for this chapter we will ignore the clustering structure and conduct regular regression. The following variables are in this data set: 19 | 20 | |Variable|Level|Description|Values|Measurement| 21 | |:-------|:----|:----------|:-----|:----------| 22 | |schcode|School|School identifier (419 schools)|Integer|Ordinal| 23 | |Rid|Individual|A within-group level identifier representing a sequential identifier for each student within 419 schools.|1 to 37|Ordinal| 24 | |id|Individual|Student identifier (6,871 students)|Integer|Ordinal| 25 | |female|Individual|Student sex|0 = Male, 1 = Female|Scale| 26 | |ses|Individual|Z-score measuring student socioeconomic status composition within the schools|-2.41 to 1.87|Scale| 27 | |femses|Individual|Grand-mean-centered variable measuring student socioeconomic status by gender (female)|-2.41 to 1.85|Scale| 28 | |math|Individual|Student math achievement test score|27.42 to 99.98|Scale| 29 | |ses_mean|School|Grand-mean-centered variable measuring student socioeconomic status|-1.30 to 1.44|Scale| 30 | |pro4yrc|School|Aggregate proportion of students who intend to study at 4-year universities|0.00 to 1.00|Scale| 31 | |public|School|Dichotomous variable identifying school type|0 = Other, 1 = Public School|Scale| 32 | 33 | ### Creating R Projects 34 | 35 | Before we get into analyzing the data, let's start by creating a new project file for this module. R project files help you keep all of the files associated with your project -- data, R scripts, and output (including figures) -- in one location so you can easily navigate everything related to your project. 36 | 37 | To create a project, open R, click "File" and "New Project...". If you have already created a folder for this chapter, you can add an R Project to that folder by clicking "Existing Directory"; the R project file will take on the name of that folder. If you do not already have a folder, click "New Directory," choose where you want to put your new folder and what you want to call it. The R Project file will again take on the name of your new folder. 38 | 39 | ### Loading Data and Dependencies 40 | 41 | Next, let's load in the data and packages we'll be using for this demo. We'll be using the following packages: 42 | 43 | ```{r data-dependencies, message=FALSE, warning=FALSE} 44 | library(ggplot2) # for data visualization 45 | library(magrittr) # for pipe, %>% 46 | ``` 47 | 48 | You must install a given package before you can use it. For example: `install.package("ggplot2")`. Once you have installed a package, you can load it into any future sessions with `library(package_name)`. 49 | 50 | Next, let's read in the data. If you have your code and data in the same directory, you can read the data in as follows: 51 | 52 | ```{r data, eval=FALSE} 53 | data <- read.csv('heck2011.csv') 54 | ``` 55 | 56 | ```{r, echo = FALSE} 57 | # this actually loads my code, but will be hidden 58 | data <- read.csv('data/heck2011.csv') 59 | ``` 60 | 61 | This is called a *relative* file path, because you're telling your computer where to find the data relative to your current folder (a folder can also be called a "directory"). You could also use an absolute file path that fully states where your files are located, like: 62 | 63 | ```{r, eval=FALSE} 64 | read.csv('/Users/maireadshaw/open_mlm_materials/heck2011.csv') 65 | ``` 66 | 67 | Let's calculate some descriptive statistics and compare them to the above table to make sure we read our data in correctly. 68 | 69 | ```{r} 70 | summary(data) 71 | ``` 72 | 73 | That looks good, so let's proceed to conducting regressions. 74 | 75 | ### Simple Linear Regression 76 | 77 | Let's run a simple linear regression predicting math achievement (`math`) from socioeconomic status (`ses`). The syntax for the `lm()` (linear modelling) command in R is `lm(DV ~ IV1 + IV2 + ... + IVn, data = dataframe)`. 78 | 79 | ```{r simple-regression} 80 | model1 <- lm(math ~ ses, data = data) 81 | summary(model1) 82 | ``` 83 | 84 | The intercept from this regression is 57.60, indicating that students at the mean level of SES within a school (i.e., when SES = 0, given that SES is z-scored) have an average math achievement score of 57.6 out of 100. This score is significantly different from 0, per the p-value. 85 | 86 | Per the coefficient for SES, a one-unit increase in SES is associated with a 4.25-point increase in student math achievement on average, also significant. 87 | 88 | The adjusted R-squared value is 14.3%, indicating that 14.3% of the variance in math achievement is explained by socioeconomic status. 89 | 90 | We can visualize this relationship by graphing a scatter plot. 91 | 92 | ```{r graph} 93 | ggplot(data = data, mapping = aes(x = ses, y = math)) + 94 | geom_point() 95 | ``` 96 | 97 | Our graph reflects the positive relationship between SES and math achievement (and also shows a lot of math scores collecting around the 60 mark). 98 | 99 | ### Multiple Regression 100 | 101 | Next, let's add the available sex variable `female` (0 = male, 1 = female) as a predictor in our regression and interpret the coefficients and R-squared value. 102 | 103 | ```{r} 104 | model2 <- lm(math ~ ses + female, data = data) 105 | summary(model2) 106 | ``` 107 | 108 | The intercept of 58.13 reflects the average math achievement score (out of 100) for male students (`female` = 0) at their class average SES (`ses` = 0). For a one-unit increase in SES, math achievement increases by 4.23 points, controlling for sex. Female students had a math achievement score lower by 1.06 points on average, controlling for SES. SES and sex together explain 14.6% of the variance in math achievement. 109 | 110 | ### Interaction Terms 111 | 112 | In the previous model, we assumed that the relationship between SES and math achievement was constant for both sexes (homogeneity of regression slopes, i.e., an ANCOVA model). As a final exercise, let's add an interaction term to our regression between sex and SES. 113 | 114 | ```{r} 115 | model3 <- lm(math ~ ses + female + ses:female, data = data) 116 | summary(model3) 117 | 118 | # Could also succinctly code it as follows: 119 | # lm(math ~ ses*female, data = data) 120 | ``` 121 | 122 | An interaction captures that the relationship between two variables may differ based on the level of another variable (i.e., different slopes for different folks). An interaction term, A:B, has two possible interpretations: 123 | 124 | 1. The effect of A on the effect of B on your outcome Y. 125 | 2. The effect of B on the effect of A on your outcome Y. 126 | 127 | The `ses:female` interaction term, .34, represents the effect of being female on the relationship between SES and math achievement. Alternatively, it could represent the effect of SES on the relationship between being female and math achievement. In this case, the latter is a more intuitive interpretation: female students from higher socioeconomic statuses are slightly insulated from the negative relationship between female and math achievement in this sample. As SES increases by one point, the relationship between being female and math achievement becomes less negative, from -1.07 to -.73 (-1.07 + .34). However, this interaction term is not statistically significantly different from zero per the p-value. 128 | 129 | We can see this graphically using the `sjPlot` package: 130 | 131 | ```{r} 132 | sjPlot::plot_model(model3, type = "pred", terms = c("ses", "female")) 133 | ``` 134 | 135 | As we can see, math scores for males (`female` = 0, the red line) are higher than those for females (`female` = 1, the blue line) at all levels of SES. However, the difference between males and females shrinks with increasing SES, as indicated by math scores at higher SES levels being closer than those at lower levels of SES. 136 | 137 | The other coefficients have the same interpretations as before. The R-squared indicates that SES and sex account for 14.7% of the variance in math achievement. 138 | 139 | ## Conclusion 140 | 141 | If you feel comfortable with the material presented in this data demonstration, then you have a sufficiently strong baseline to move forward with the materials. In this chapter, we ignored that students were clustered into schools; in the next chapter, we'll examine that clustering, consider its implications for our analyses, and introduce one non-multilevel-model method for handling clustered data. -------------------------------------------------------------------------------- /03-module-3.Rmd: -------------------------------------------------------------------------------- 1 | # Approaches to Multilevel Data {#module-3} 2 | 3 | ## Learning Objectives 4 | 5 | In this chapter, we will discuss implications of clustered data and review non-multilevel-modelling options for handling that clustering. 6 | 7 | The learning objectives for this chapter are: 8 | 9 | 1. Understand the implications of treating clustered data as unclustered; 10 | 2. Use cluster-robust standard errors to account for clustering; 11 | 3. Compare results between regular and cluster-robust regression. 12 | 13 | All materials for this chapter are available for download [here](https://www.learn-mlms.com/13-appendix.html). 14 | 15 | ## Data Demonstration 16 | 17 | The data for this chapter were taken from chapter 3 of Heck, R. H., Thomas, S. L., & Tabata, L. N. (2011). *Multilevel and Longitudinal Modeling with IBM SPSS*: Taylor & Francis. Students are clustered within schools in the dataset. 18 | 19 | ### Load Data and Dependencies 20 | 21 | First, let's load in the data and packages we'll be using for this data demo. We will use the following packages: 22 | 23 | ```{r message=FALSE} 24 | library(dplyr) # for data processing 25 | library(lmtest) # for cluster-robust standard errors 26 | library(sandwich) # for cluster-robust standard errors 27 | ``` 28 | 29 | We'll store the data in an object called `data`. If you want to read the data in with the relative filepath (i.e., just referencing "heck2011.csv"), make sure the file is in the same folder as your R script. If the file is in a different folder, tell your computer exactly where to find it with an absolute file path. 30 | 31 | ```{r, eval=FALSE} 32 | data <- read.csv('heck2011.csv') 33 | ``` 34 | 35 | ```{r, echo = FALSE} 36 | # this actually loads my code, but will be hidden 37 | data <- read.csv('data/heck2011.csv', fileEncoding = "UTF-8-BOM") 38 | ``` 39 | 40 | ### Dealing with Dependence 41 | 42 | Our dataset is clustered, students within schools, but in Chapter 2 we treated it as if it were not clustered, i.e., as if each student was randomly selected from a population of students, regardless of school. When we treat clustered data as unclustered, we bias the significance testing for our models such that we are more likely to make a Type I error. A *t* value is based on dividing a regression coefficient by the standard error: $t = \frac{b}{SE}$. The standard error is a quotient of the standard deviation and the square root of the degrees of freedom, the sample size *n*: $SE = \frac{\sigma}{\sqrt n}$. When we assume that data are unclustered, we act like we have a larger sample size than we do (e.g., 100 independent observations rather than 10 classes of 10 students), which reduces the standard error and inflates the t-value, making it more likely that our coefficients will be significant. 43 | 44 | We have multiple options for dealing with dependence. Multilevel models are one option, accounting for the clustered data structure by quantifying how the clusters vary across the entire sample. For example, looking at student math achievement, we can move beyond having a single intercept to having a mean intercept across all schools *and* a term representing how schools' mean math achievements vary around the mean intercept. Multilevel models are a powerful tool! But in providing more information to the researcher (e.g., how schools vary around the grand mean intercept), they also require more input from the researcher: do we expect our intercepts to vary? Do we expect our slopes to vary? If so, which slopes? 45 | 46 | Sometimes, we don't need an MLM (and the assumptions that come along with it) because we don't want to ask questions at multiple levels, like "how does student SES and teacher years of experience affect student math achievement?" We just want to know "how does student SES affect student math achievement?" In this case, we might think of the clustering in our data as a nuisance, something to be handled so that our standard errors aren't biased, but not theoretically investigated. In such a case where we want to run a single-level regression that controls bias in the standard errors, we can use cluster-robust standard errors. 47 | 48 | ### Cluster-Robust Standard Errors 49 | 50 | Cluster-robust standard errors account for clustering but retain the interpretation of regular regression models. That is, the coefficients do not delineate within and between effects, but provide average effects pooled across the whole dataset and unbiased standard errors that take into account the clustering. For more information on clustered standard errors, see this helpful overview: https://mldscenter.maryland.gov/egov/Publications/ResearchSeries/Clustered%20Data,%20Are%20Multilevel%20Models%20Really%20Necessary.pdf. Let's look at cluster-robust standard errors in action! 51 | 52 | In chapter 2, we conducted a linear regression predicting math achievement from socioeconomic status and sex. Let's run that same model. 53 | 54 | ```{r} 55 | model <- lm(math ~ ses + female, data = data) 56 | summary(model) 57 | ``` 58 | 59 | Now, let's run the same model with cluster-robust standard errors and compare the coefficients and their significance between the regular and cluster-robust models. 60 | 61 | ```{r} 62 | model_crse <- coeftest(model, vcov = vcovCL, cluster = ~ schcode) 63 | model_crse 64 | ``` 65 | 66 | As expected, the coefficients are the same between the two models, but the significance levels differ. In this case, the differences are trivial, and all coefficients retain their significance. But in your case, correcting for clustering might make the difference between significant and non-significant results. 67 | 68 | ## Conclusion 69 | 70 | In this chapter, we discussed why we need to account for clustering in our analyses. We then demonstrated an MLM alternative, cluster-robust standard errors, that can be used to account for clustering if you're asking questions at one level and want to run a single-level regression, but adjust the standard errors. 71 | 72 | In chapter 4, we will look at our first multilevel models for handling clustered data structures and asking multilevel questions. 73 | 74 | ## Further Reading 75 | 76 | McCoach, D. B. (2010). Dealing With Dependence (Part II): A Gentle Introduction to Hierarchical Linear Modeling. Gifted Child Quarterly, 54(3), 252–256. https://doi.org/10.1177/0016986210373475 77 | 78 | McCoach, D. B., & Adelson, J. L. (2010). Dealing with dependence (Part 1): Understanding the effects of clustered data. Gifted Child Quarterly, 54(2), 152–155. https://doi.org/10.1177/0016986210363076 79 | 80 | McNeish, D., Stapleton, L. M., & Silverman, R. D. (2017). On the unnecessary ubiquity of hierarchical linear modeling. Psychological Methods, 22(1), 114–140. https://doi.org/10.1037/met0000078 81 | 82 | -------------------------------------------------------------------------------- /05-module-5.Rmd: -------------------------------------------------------------------------------- 1 | # Adding Fixed Predictors to MLMs {#module-5} 2 | 3 | ## Learning Objectives 4 | 5 | In this chapter, we will introduce fixed predictors at both level-1 and level-2. 6 | 7 | The learning objectives for this chapter are: 8 | 9 | 1. Code and interpret fixed effects in multilevel models; 10 | 2. Explain the difference between conditional and unconditional effects; 11 | 3. Evaluate the utility of predictors in a model by considering the information from regression coefficients and variance reduced. 12 | 13 | All materials for this chapter are available for download [here](https://www.learn-mlms.com/13-appendix.html). 14 | 15 | ## Data Demonstration 16 | 17 | The data for this chapter were taken from chapter 3 of Heck, R. H., Thomas, S. L., & Tabata, L. N. (2011). *Multilevel and Longitudinal Modeling with IBM SPSS*: Taylor & Francis. Students are clustered within schools in the data. 18 | 19 | ### Load Data and Dependencies 20 | 21 | For this data demo, we will use the following packages: 22 | 23 | ```{r message=FALSE, warning=FALSE} 24 | library(dplyr) # for data manipulation 25 | library(ggplot2) # for visualizations 26 | library(lme4) # for multilevel models 27 | library(lmerTest) # for p-values 28 | library(performance) # for intraclass correlation 29 | ``` 30 | 31 | And the same dataset of students' math achievement: 32 | 33 | ```{r, eval=FALSE} 34 | data <- read.csv('heck2011.csv') 35 | ``` 36 | 37 | ```{r, echo = FALSE} 38 | # this actually loads my data, but will be hidden 39 | data <- read.csv('data/heck2011.csv', fileEncoding = "UTF-8-BOM") 40 | ``` 41 | 42 | ### MLM with Level-1 Predictor 43 | 44 | As a reminder, in Chapter 4 we estimated the random-intercept-only model, also called the null model: 45 | 46 | ```{r} 47 | null_model <- lmer(math ~ 1 + (1|schcode), data = data) 48 | summary(null_model) 49 | ``` 50 | 51 | Now that we've explored the null model and variance decomposition it gives us access to, let's practice adding a level-1 predictor to our model. Level-1 predictors vary at level-1, which in our example is the student level, meaning that students have different values for a variable. In our data, socioeconomic status (`ses`) and sex (`female`) vary across students, at level-1. Let's add a fixed effect for `ses` as a predictor to our model. 52 | 53 | The following equations describe this model: 54 | 55 | | Level | Equation | 56 | |:-------|:---------| 57 | |Level 1 | $math_{ij} = \beta_{0j} + \beta_{1j}ses_{ij} + R_{ij}$| 58 | |Level 2 | $\beta_{0j} = \gamma_{00} + U_{0j}$| 59 | | | $\beta_{1j} = \gamma_{10}$| 60 | |Combined| $math_{ij} = \gamma_{00} + \gamma_{10}ses_{ij} + U_{0j} + R_{ij}$| 61 | 62 | We'll be estimating four parameters: 63 | 64 | 1. $\gamma_{00}$: the fixed effect for the intercept, controlling for `ses`; 65 | 2. $\gamma_{10}$: the fixed effect for the slope of `ses`; 66 | 3. $\tau_0^2$: a random effect variance for the intercept capturing the variance of schools around the intercept, controlling for `ses`; 67 | 4. $\sigma^2$: a random effect variance capturing the variance of students around their school mean math achievement, controlling for `ses`. 68 | 69 | Notice that the parameters are now conditional on `ses`. The intercept is no longer interpreted as the intercept across all schools; it's the intercept across all schools *conditional on `ses` being equal to 0*, or at the mean `ses` level for the sample given that `ses` is z-scored in these data. Additionally, note that there is no $U_j$ term associated with the coefficient for `ses`; that's because we're only adding a fixed effect for `ses` right now. This implies that the relationship between `ses` and math achievement is the same across all schools (i.e., the slope is fixed, not randomly varying). We'll look at adding random slope effects in the next chapter. For now, let's run our model. 70 | 71 | ```{r} 72 | ses_l1 <- lmer(math ~ ses + (1|schcode), data = data, REML = TRUE) 73 | summary(ses_l1) 74 | ``` 75 | 76 | Per the intercept, the average math achievement across all schools at mean `ses` is 57.596. A one-standard-deviation increase in `ses` is associated with a 3.87-point increase in math achievement. The variance term describing how schools vary around the intercept is 3.469, whereas the variance term describing how the students vary within schools, about their schools' mean, is 62.807. These variance terms are different from our null model that had no predictors; we can quantify that difference in at least two ways. 77 | 78 | One option is to calculate how much level-1 variance was reduced by adding `ses` as a level-1 predictor. If we divide the difference between our null model's level-1 variance and this new model's (l1) level-1 variance by the null model variance, we can see what proportion of variance was reduced. 79 | 80 | ```{r} 81 | null <- sigma(null_model)^2 82 | l1 <- sigma(ses_l1)^2 83 | 84 | (null - l1) / null 85 | ``` 86 | 87 | So we reduced about 5.6% of level-1 variance by adding `ses` as a level-1 predictor. Another way of stating this is that we reduced the unexplained within school variance by 5.6%. 88 | 89 | Another option is to calculate the conditional ICC, or the proportion of variance explained by clustering after we account for `ses`. Recall from last chapter that the adjusted ICC accounts only for random effect variances, while the conditional ICC accounts for both variance of both random effects and fixed effects. With the null model, the adjusted and conditional ICC values from `performance` are the same because there are no predictors in the model, but with a fixed level-1 predictor in the model, we should reference the conditional ICC. 90 | 91 | ```{r} 92 | performance::icc(ses_l1) 93 | ``` 94 | 95 | After accounting for the effect of socioeconomic status, 4.6% of the variance in math achievement is accounted for by school membership. 96 | 97 | ### Compare Regular and Multilevel Regression 98 | 99 | In the previous chapter, we compared a regular regression to a cluster-robust standard error regression. Now, let's compare those two with a multilevel model. 100 | 101 | The regular regression from Chapter 4: 102 | 103 | ```{r} 104 | model <- lm(math ~ ses, data = data) 105 | summary(model) 106 | ``` 107 | 108 | The cluster-robust standard error regression from Chapter 4: 109 | 110 | ```{r} 111 | model_crse <- lmtest::coeftest(model, vcov = sandwich::vcovCL, cluster = ~ schcode) 112 | model_crse 113 | ``` 114 | 115 | These two models had the same coefficients, with different significance values. 116 | 117 | This is our multilevel model: 118 | 119 | ```{r} 120 | summary(ses_l1) 121 | ``` 122 | 123 | The intercepts are the same between the MLM and regular regressions, but the coefficient for `ses` is not. Why? The coefficient for `ses` represents the mean relationship between SES and math achievement across all schools, weighted by the reliability of the cluster. The weighting reflects cluster-level sample size, and thus varies from the regular regression estimates that treat all observations equally. 124 | 125 | ### MLM with Level-2 Predictor 126 | 127 | We added `ses` as a level-1 predictor to explain some of the student-level variance in math achievement. Now, let's add a predictor that varies at level-2, meaning that the value is different across level 2 units, which is the school level. Level-2 predictors are different across schools but the same for all students within a school. There are three possible level-2 predictors: 128 | 129 | * `ses_mean`: the mean SES per school (this variable is centered, we'll discuss centering more in Chapter 9) 130 | * `pro4yc`: the percentage of students at a school who intend to study at a 4-year college/university 131 | * `public`: whether the school is private (0) or public (1) 132 | 133 | This is where we begin to unlock the potential of MLMs, to ask questions about both individual differences (level-1 variables) and school differences (level-2 variables) at the same time while accounting for clustered data structures. Let's consider the role of school type in our model by adding a fixed effect for `public` as a predictor of our intercept. 134 | 135 | The following equations describe this model: 136 | 137 | | Level | Equation | 138 | |:-------|:---------| 139 | |Level 1 | $math_{ij} = \beta_{0j} + \beta_{1j}ses_{ij} + R_{ij}$| 140 | |Level 2 | $\beta_{0j} = \gamma_{00} + \gamma_{01}public_j + U_{0j}$| 141 | | | $\beta_{1j} = \gamma_{10}$| 142 | |Combined| $math_{ij} = \gamma_{00} + \gamma_{01}public_{j} + \gamma_{10}ses_{ij} + U_{0j} + R_{ij}$| 143 | 144 | A few things to note here: first, `public_j` only has a j subscript because only different schools (j's) have different values of `public`. All students (i's) within a school have the same value. Second, `public` is currently only a predictor for the intercept. In Chapter 6 we'll look at using level-2 variables as predictors of level-1 slopes and the cross-level interactions that result. 145 | 146 | We'll be estimating five parameters: 147 | 148 | 1. $\gamma_{00}$: the fixed effect for the intercept, controlling for `ses` and `public`; 149 | 2. $\gamma_{01}$: the fixed effect for the slope of `public` controlling for `ses` 150 | 3. $\gamma_{10}$: the fixed effect for the slope of `ses` controlling for `public`; 151 | 4. $\tau_0^2$: a random effect variance for the intercept capturing the variance of schools around the intercept, controlling for `ses` and `public`; 152 | 5. $\sigma^2$: a random effect variance capturing the variance of students around their school mean math achievement, controlling for `ses` and `public`. 153 | 154 | Notice that the parameters are conditional on both `ses` and on `public` now. Let's run our model. 155 | 156 | ```{r} 157 | ses_l1_public_l2 <- lmer(math ~ 1 + ses + public + (1|schcode), data = data, REML = TRUE) 158 | summary(ses_l1_public_l2) 159 | ``` 160 | 161 | Let's look at our fixed effects, which describes the conditional mean effect of a variable on the outcome, across all schools. Per the intercept, the average math achievement across all private schools (`public` = 0) at mean SES (`ses` = 0) is 57.70. A one-standard-deviation increase in `ses` across all private schools is associated with a 3.87-point increase in math achievement. Public schools at mean `ses` have a -0.14-point decrease on average in math achievement relative to private schools. 162 | 163 | From our random effect variances, the variance term describing how schools vary around the intercept (at mean SES at private schools) is 3.48, and the variance term describing how students vary around their school means is 62.81. 164 | 165 | Let's calculate variance reduced at level 1 and level 2 by adding school type as a predictor. 166 | 167 | ```{r} 168 | # level-1 variance reduced 169 | sigma2_null <- sigma(null_model)^2 170 | sigma2_public <- sigma(ses_l1_public_l2)^2 171 | (sigma2_null - sigma2_public) / sigma2_null 172 | ``` 173 | 174 | ```{r} 175 | # level-2 variance reduced 176 | tau2_null <- VarCorr(null_model)$schcode[1] 177 | tau2_public <- VarCorr(ses_l1_public_l2)$schcode[1] 178 | (tau2_null - tau2_public) / tau2_null 179 | ``` 180 | 181 | We reduced around 5.6% of variance in math achievement at level-1 and 67.2% of variance at level-2 by adding `public` as a level-2 predictor. It makes sense that the variance at level-2 was reduced by so much more, because we added a level-2 predictor that varies at level-2. 182 | 183 | So, does it seem like school type is related to math achievement? We have two sources of information to consider so far: the regression coefficient and the variance reduced. While the regression coefficient is relatively small, the intercept variance reduced at level-2 is quite large (67%!), so it seems like school type is a valuable predictor in our model. 184 | 185 | ## Conclusion 186 | 187 | In this chapter, we added level-1 and level-2 fixed effects to our models, considered the difference between conditional and unconditional effects, and used regression coefficients and variance reduced to make a decision about retaining model parameters. In Chapter 6, we'll work with random slopes and explain cross-level interactions. -------------------------------------------------------------------------------- /13-appendix.Rmd: -------------------------------------------------------------------------------- 1 | # (APPENDIX) Appendix {-} 2 | 3 | # Download Materials 4 | 5 | |Chapter|Data|R Script|Worksheet| 6 | |:-----:|:--:|:------:|:-------:| 7 | |[2](#module-2)|`r xfun::embed_file('data/heck2011.csv', text = "heck2011.csv")`|`r xfun::embed_file('Rscripts/02-multiple-regression.R', text = "02-multiple-regression.R")`|`r xfun::embed_file('worksheets/module2.docx', text = "Linear Regression Review")`| 8 | |[3](#module-3)|`r xfun::embed_file('data/heck2011.csv', text = "heck2011.csv")`|`r xfun::embed_file('Rscripts/03-module-3.R', text = "03-module-3.R")`|`r xfun::embed_file('worksheets/module3.docx', text = "Approaches to Multilevel Data")`| 9 | |[4](#module-4)|`r xfun::embed_file('data/heck2011.csv', text = "heck2011.csv")`|`r xfun::embed_file('Rscripts/04-module-4.R', text = "04-module-4.R")`|`r xfun::embed_file('worksheets/module4.docx', text = "Our First MLM: The Null Model")`| 10 | |[5](#module-5)|`r xfun::embed_file('data/heck2011.csv', text = "heck2011.csv")`|`r xfun::embed_file('Rscripts/05-module-5.R', text = "05-module-5.R")`|`r xfun::embed_file('worksheets/module5.docx', text = "Adding Fixed Predictors")`| 11 | |[6](#module-6)|`r xfun::embed_file('data/heck2011.csv', text = "heck2011.csv")`|`r xfun::embed_file('Rscripts/06-module-6.R', text = "06-module-6.R")`|`r xfun::embed_file('worksheets/module6.docx', text = "Random Effects and Cross-level Interactions")`| 12 | |[7](#module-7)|`r xfun::embed_file('data/heck2011.csv', text = "heck2011.csv")`|`r xfun::embed_file('Rscripts/07-module-7.R', text = "07-module-7.R")`|`r xfun::embed_file('worksheets/module7.docx', text = "Estimation Options and Troubleshooting")`| 13 | |[8](#module-8)|`r xfun::embed_file('data/heck2011.csv', text = "heck2011.csv")`|`r xfun::embed_file('Rscripts/08-module-8.R', text = "08-module-8.R")`|`r xfun::embed_file('worksheets/module8.docx', text = "Centering")`| 14 | |[9](#module-9)|`r xfun::embed_file('data/hoffman2007.csv', text = "hoffman2007.csv")`|`r xfun::embed_file('Rscripts/09-module-9.R', text = "09-module-9.R")`|`r xfun::embed_file('worksheets/module9.docx', text = "Repeated Measures")`| 15 | |[10](#module-10)|`r xfun::embed_file('data/casto2016.csv', text = "casto2016.csv")`|`r xfun::embed_file('Rscripts/10-module-10.R', text = "10-module-10.R")`|`r xfun::embed_file('worksheets/module10.docx', text = "Longitudinal Measures")`| 16 | |[11](#module-11)|`r xfun::embed_file('data/teachsat.csv', text = "teachsat.csv")`|`r xfun::embed_file('Rscripts/11-module-11.R', text = "11-module-11.R")`|`r xfun::embed_file('worksheets/module11.docx', text = "Effect Sizes in MLMs")`| 17 | |[12](#module-12)|`r xfun::embed_file('data/rb2002.csv', text = "rb2002.csv")`|`r xfun::embed_file('Rscripts/12-module-12.R', text = "12-module-12.R")`|`r xfun::embed_file('worksheets/module12.docx', text = "Assumptions")`| -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Introduction to Multilevel Modelling 2 | 3 | learn-mlms.com focuses on conceptual foundations of multilevel models (MLMs), specifiying them, and interpreting the results. Topics include multilevel data and approaches to dependence, specifying and interpreting fixed and random effects, model estimation, centering, repeated measures and longitudinal models, assumptions testing, and effect sizes in MLMs. 4 | 5 | The chapters are: 6 | 7 | 1. Introduction 8 | 2. Multiple Regression Review 9 | 3. Approaches to Multilevel Data 10 | 4. Our First Multilevel Models 11 | 5. Adding Fixed Predictors to MLMs 12 | 6. Random Effects and Cross-level Interactions 13 | 7. Model Estimation Options, Problems, and Troubleshooting 14 | 8. Centering Options and Interpretations 15 | 9. Multilevel Modelling with Repeated Measures Data 16 | 10. Multilevel Modelling with Longitudinal Data 17 | 11. Effect Sizes in Multilevel Models 18 | 12. Assumptions 19 | 20 | ## About the Authors 21 | 22 | Mairead Shaw is a graduate student in the Quantitative Psychology and Modelling area at McGill University. Her research interests center around effect sizes in multilevel models and measurement considerations for multi-group and replication research. 23 | 24 | Dr. Jessica Flake is an Assistant Professor of Quantitative Psychology and Modelling at McGill University. She received an MA in quantitative psychology from James Madison University and a a PhD in Measurement, Evaluation, and Assessment from the University of Connecticut. Her work focuses on technical and applied aspects of psychological measurement including scale development, psychometric modelling, and scale use and replicability. 25 | 26 | ## Funding 27 | 28 | These materials were made possible by funding from the APS Fund for Teaching and Public Understanding of Psychological Science. You can read more about the fund here. 29 | 30 | ## Contributions 31 | 32 | If you have any feedback or suggested changes, please file an issue. 33 | -------------------------------------------------------------------------------- /Rscripts/02-multiple-regression.R: -------------------------------------------------------------------------------- 1 | # Load Data and Dependencies ---------------------------------------------- 2 | 3 | library(ggplot2) # for data visualization 4 | library(magrittr) # for pipe, %>% 5 | 6 | data <- read.csv('heck2011.csv') 7 | summary(data) 8 | 9 | # Simple Linear Regression ------------------------------------------------ 10 | 11 | model1 <- lm(math ~ ses, data = data) 12 | summary(model1) 13 | 14 | ggplot(data = data, mapping = aes(x = ses, y = math)) + 15 | geom_point() 16 | 17 | # Multiple Regression ----------------------------------------------------- 18 | 19 | model2 <- lm(math ~ ses + female, data = data) 20 | summary(model2) 21 | 22 | # Interaction Terms ------------------------------------------------------- 23 | 24 | model3 <- lm(math ~ ses + female + ses:female, data = data) 25 | summary(model3) 26 | 27 | # Could also succinctly code model3 as lm(math ~ ses*female, data = data) 28 | 29 | sjPlot::plot_model(model3, type = "pred", terms = c("ses", "female")) 30 | 31 | -------------------------------------------------------------------------------- /Rscripts/03-module-3.R: -------------------------------------------------------------------------------- 1 | # Load Data and Dependencies ---------------------------------------------- 2 | 3 | library(dplyr) # for data processing 4 | library(lmtest) # for cluster-robust standard errors 5 | library(sandwich) # for cluster-robust standard errors 6 | 7 | data <- read.csv('data/heck2011.csv', fileEncoding = "UTF-8-BOM") 8 | 9 | # Cluster-Robust Standard Errors ------------------------------------------ 10 | 11 | model <- lm(math ~ ses + female, data = data) 12 | summary(model) 13 | 14 | model_crse <- coeftest(model, vcov = vcovCL, cluster = ~ schcode) 15 | model_crse -------------------------------------------------------------------------------- /Rscripts/04-module-4.R: -------------------------------------------------------------------------------- 1 | # Load Data and Dependencies ---------------------------------------------- 2 | 3 | library(dplyr) # for data manipulation 4 | library(ggplot2) # for visualizations 5 | library(lme4) # for multilevel models 6 | library(lmerTest) # for p-values 7 | library(performance) # for intraclass correlation 8 | 9 | data <- read.csv('data/heck2011.csv', fileEncoding = "UTF-8-BOM") 10 | 11 | # Why Multilevel Models? -------------------------------------------------- 12 | 13 | data_sub <- data %>% 14 | filter(schcode <= 10) 15 | 16 | data_sub %>% 17 | ggplot(mapping = aes(x = ses, y = math)) + 18 | geom_point() + 19 | geom_smooth(method = "lm", se = FALSE, fullrange = TRUE) 20 | 21 | data_sub %>% 22 | ggplot(mapping = aes(x = ses, y = math, colour = factor(schcode))) + 23 | geom_point() + 24 | geom_smooth(mapping = aes(group = schcode), method = "lm", se = FALSE, fullrange = TRUE) + 25 | labs(colour = "schcode") 26 | 27 | # The Null Model ---------------------------------------------------------- 28 | 29 | null_model <- lmer(math ~ 1 + (1|schcode), data = data) 30 | summary(null_model) 31 | 32 | # Understanding Variance -------------------------------------------------- 33 | 34 | performance::icc(null_model) 35 | 36 | Tau0 <- VarCorr(null_model)$schcode[1] 37 | 38 | lower_bound <- null_model@beta - 1.96*sqrt(Tau0) 39 | upper_bound <- null_model@beta + 1.96*sqrt(Tau0) 40 | 41 | lower_bound 42 | upper_bound 43 | 44 | # Empirical Bayes Estimates ----------------------------------------------- 45 | 46 | data %>% 47 | filter(schcode == 1) %>% # select only school code 1 48 | summarize( 49 | mean(math) 50 | ) 51 | 52 | data %>% 53 | filter(schcode == 1) %>% 54 | count() 55 | 56 | empirical_bayes_data <- as_tibble(ranef(null_model)) 57 | 58 | head(empirical_bayes_data, 1) 59 | 60 | ggplot(data = empirical_bayes_data, mapping = aes(x = condval)) + # "condval" is the name of the EB estimates returned by the ranef function above 61 | geom_histogram() + 62 | labs(x = "EB estimate of U0j") 63 | 64 | -------------------------------------------------------------------------------- /Rscripts/05-module-5.R: -------------------------------------------------------------------------------- 1 | # Load Data and Dependencies ---------------------------------------------- 2 | 3 | library(dplyr) # for data manipulation 4 | library(ggplot2) # for visualizations 5 | library(lme4) # for multilevel models 6 | library(lmerTest) # for p-values 7 | library(performance) # for intraclass correlation 8 | 9 | data <- read.csv('data/heck2011.csv', fileEncoding = "UTF-8-BOM") 10 | 11 | # MLM with Level-1 Predictor ---------------------------------------------- 12 | 13 | null_model <- lmer(math ~ 1 + (1|schcode), data = data) 14 | summary(null_model) 15 | 16 | ses_l1 <- lmer(math ~ ses + (1|schcode), data = data, REML = TRUE) 17 | summary(ses_l1) 18 | 19 | null <- sigma(null_model)^2 20 | l1 <- sigma(ses_l1)^2 21 | 22 | (null - l1) / null 23 | 24 | performance::icc(ses_l1) 25 | 26 | # Compare Regular and Multilevel Regression ------------------------------- 27 | 28 | model <- lm(math ~ ses, data = data) 29 | summary(model) 30 | 31 | model_crse <- lmtest::coeftest(model, vcov = sandwich::vcovCL, cluster = ~ schcode) 32 | model_crse 33 | 34 | summary(ses_l1) 35 | 36 | # MLM with Level-2 Predictor ---------------------------------------------- 37 | 38 | ses_l1_public_l2 <- lmer(math ~ 1 + ses + public + (1|schcode), data = data, REML = TRUE) 39 | summary(ses_l1_public_l2) 40 | 41 | # level-1 variance reduced 42 | sigma2_null <- sigma(null_model)^2 43 | sigma2_public <- sigma(ses_l1_public_l2)^2 44 | (sigma2_null - sigma2_public) / sigma2_null 45 | 46 | # level-2 variance reduced 47 | tau2_null <- VarCorr(null_model)$schcode[1] 48 | tau2_public <- VarCorr(ses_l1_public_l2)$schcode[1] 49 | (tau2_null - tau2_public) / tau2_null 50 | -------------------------------------------------------------------------------- /Rscripts/06-module-6.R: -------------------------------------------------------------------------------- 1 | # Load Data and Dependencies ---------------------------------------------- 2 | 3 | library(dplyr) # for data manipulation 4 | library(ggplot2) # for visualizations 5 | library(lme4) # for multilevel models 6 | library(lmerTest) # for p-values 7 | 8 | data <- read.csv('data/heck2011.csv', fileEncoding = "UTF-8-BOM") 9 | 10 | # MLM with Random Slope Effect -------------------------------------------- 11 | 12 | data %>% 13 | filter(schcode <= 10) %>% 14 | ggplot(mapping = aes(x = ses, y = math, colour = factor(schcode))) + 15 | geom_point() + 16 | geom_smooth(mapping = aes(group = schcode), method = "lm", se = FALSE, fullrange = TRUE) + 17 | labs(colour = "schcode") 18 | 19 | ses_l1_random <- lmer(math ~ ses + (1 + ses|schcode), data = data, REML = TRUE) 20 | summary(ses_l1_random) 21 | 22 | Matrix::bdiag(VarCorr(ses_l1_random)) 23 | 24 | -1.58/(1.79*0.88) 25 | 26 | empirical_bayes_data <- ranef(ses_l1_random) # extract random effects for each school 27 | 28 | empirical_bayes_intercepts <- empirical_bayes_data$schcode["(Intercept)"] 29 | 30 | empirical_bayes_slopes <- empirical_bayes_data$schcode["ses"] # extracts the SES/slope EB estimates from the list 31 | 32 | bind_cols(empirical_bayes_intercepts, empirical_bayes_slopes) %>% # combine EB slopes and intercepts into a useable dataframe for graphing 33 | ggplot(mapping = aes(x = ses, y = `(Intercept)`)) + 34 | geom_point() 35 | 36 | # MLM with Crosslevel Effect ---------------------------------------------- 37 | 38 | crosslevel_model <- lmer(math ~ 1 + ses + public + ses:public + (1 + ses|schcode), data = data, REML = TRUE) 39 | summary(crosslevel_model) 40 | 41 | Matrix::bdiag(VarCorr(crosslevel_model)) 42 | 43 | -------------------------------------------------------------------------------- /Rscripts/07-module-7.R: -------------------------------------------------------------------------------- 1 | # Load Data and Dependencies ---------------------------------------------- 2 | 3 | library(dplyr) # for data manipulation 4 | library(ggplot2) # for graphing 5 | library(lme4) # for multilevel models 6 | library(lmerTest) # for p-values 7 | 8 | data <- read.csv('data/heck2011.csv', fileEncoding = "UTF-8-BOM") 9 | 10 | # Introduction to Estimation Problems ------------------------------------- 11 | 12 | ses_l1_random <- lmer(math ~ 1 + ses + (1 + ses|schcode), data = data, REML = TRUE) 13 | 14 | # Estimation and Optimizers ----------------------------------------------- 15 | 16 | data %>% 17 | filter(schcode <= 10) %>% # subset data to make it easier to see 18 | ggplot(mapping = aes(x = ses, y = math)) + 19 | geom_point() + 20 | geom_smooth(method = "lm", se = FALSE, fullrange = TRUE) 21 | 22 | # Singularity ------------------------------------------------------------- 23 | 24 | ses_l1_random <- lmer(math ~ 1 + ses + (1 + ses|schcode), data = data, REML = TRUE) 25 | 26 | Matrix::bdiag(VarCorr(ses_l1_random)) 27 | 28 | summary(ses_l1_random) 29 | 30 | confint(ses_l1_random, oldNames = FALSE) 31 | 32 | ses_l1_random_cov0 <- lmer(math ~ 1 + ses + (1|schcode) + (0 + ses|schcode), data = data, REML = TRUE) 33 | summary(ses_l1_random_cov0) 34 | 35 | Matrix::bdiag(VarCorr(ses_l1_random_cov0)) 36 | 37 | # Deviance Testing for Model Comparison ----------------------------------- 38 | 39 | ses_l1 <- lmer(math ~ 1 + ses + (1|schcode), data = data, REML = TRUE) 40 | ses_l1_random_cov0 <- lmer(math ~ 1 + ses + (1|schcode) + (0 + ses|schcode), data = data, REML = TRUE) 41 | 42 | # deviance test to compare model fit 43 | anova(ses_l1, ses_l1_random_cov0, refit = FALSE) 44 | 45 | -------------------------------------------------------------------------------- /Rscripts/08-module-8.R: -------------------------------------------------------------------------------- 1 | # Load Data and Dependencies ---------------------------------------------- 2 | 3 | library(dplyr) # for data manipulation 4 | library(magrittr) # for assignment pipe %<>% 5 | library(lme4) # for multilevel models 6 | library(lmerTest) # for p-values 7 | 8 | data <- read.csv('data/heck2011.csv', fileEncoding = "UTF-8-BOM") 9 | 10 | # Options for Centering in MLMs ------------------------------------------- 11 | 12 | model <- lmer(math ~ 1 + ses + (1|schcode), data = data, REML = TRUE) 13 | summary(model) 14 | 15 | # Centering Within Cluster (CWC) ------------------------------------------ 16 | 17 | data %<>% # this symbol is an assignment operator and pipe, equivalent to data <- data %>% 18 | group_by(schcode) %>% 19 | mutate(ses_mean = mean(ses)) 20 | 21 | data %<>% 22 | mutate(ses_cwc = ses - ses_mean) 23 | 24 | data %>% 25 | group_by(schcode) %>% 26 | summarize( 27 | mean(ses_cwc) 28 | ) 29 | 30 | model_cwc <- lmer(math ~ 1 + ses_cwc + (1|schcode), data = data, REML = TRUE) 31 | summary(model_cwc) 32 | 33 | model_cwc_l2 <- lmer(math ~ 1 + ses_cwc + ses_mean + (1|schcode), data = data, REML = TRUE) 34 | summary(model_cwc_l2) 35 | 36 | # Centering Grand Mean (CGM) ---------------------------------------------- 37 | 38 | data %<>% 39 | ungroup() %>% # remove the grouping by school that we added in the CWC section 40 | mutate(ses_grand_mean = mean(ses)) 41 | 42 | data %<>% 43 | mutate(ses_cgm = ses - ses_grand_mean) 44 | 45 | data %>% 46 | summarize( 47 | mean(ses_cgm) 48 | ) 49 | 50 | cgm_model <- lmer(math ~ 1 + ses_cgm + ses_mean + (1|schcode), data = data, REML = TRUE) 51 | summary(cgm_model) 52 | 53 | -------------------------------------------------------------------------------- /Rscripts/09-module-9.R: -------------------------------------------------------------------------------- 1 | # Load Data and Dependencies ---------------------------------------------- 2 | 3 | library(lme4) # for multilevel models 4 | library(lmerTest) # for p-values 5 | library(performance) # for ICC 6 | 7 | data <- read.csv('data/hoffman2007.csv', fileEncoding = "UTF-8-BOM") 8 | head(data) 9 | 10 | # Random-Intercept-Only/Null Model ---------------------------------------- 11 | 12 | null_model <- lmer(lg_rt ~ 1 + (1|id), data = data, REML = FALSE) # note that REML = FALSE 13 | performance::icc(null_model) 14 | 15 | # Adding Level-1 Fixed Effects -------------------------------------------- 16 | 17 | l1_model <- lmer(lg_rt ~ 1 + c_mean + c_sal + (1|id), data = data, REML = FALSE) 18 | summary(l1_model) 19 | 20 | anova(null_model, l1_model) 21 | 22 | # Adding Random Slopes ---------------------------------------------------- 23 | 24 | l1_random <- lmer(lg_rt ~ 1 + c_mean + c_sal + (1|id) + (0 + c_mean|id) + (0 + c_sal|id), data = data, REML = FALSE) 25 | summary(l1_random) 26 | 27 | l1_random_without_cmean <- lmer(lg_rt ~ 1 + c_mean + c_sal + (1|id) + (0 + c_sal|id), data = data, REML = FALSE) 28 | summary(l1_random_without_cmean) 29 | 30 | anova(l1_random, l1_random_without_cmean) 31 | 32 | # Adding Level-2 Fixed Effects -------------------------------------------- 33 | 34 | l2_model <- lmer(lg_rt ~ 1 + c_mean + c_sal + oldage + sex + (1|id), data = data, REML = FALSE) 35 | summary(l2_model) 36 | 37 | # model 38 | l2_model_no_sex <- lmer(lg_rt ~ 1 + c_mean + c_sal + oldage + (1|id), data = data, REML = FALSE) 39 | 40 | # deviance test 41 | anova(l2_model, l2_model_no_sex) 42 | 43 | # Adding Cross-Level Interactions ----------------------------------------- 44 | 45 | crosslevel_model <- lmer(lg_rt ~ 1 + c_mean + c_sal + oldage + oldage:c_mean + (1|id), data = data, REML = FALSE) 46 | summary(crosslevel_model) 47 | 48 | -------------------------------------------------------------------------------- /Rscripts/10-module-10.R: -------------------------------------------------------------------------------- 1 | # Load Data and Dependencies ---------------------------------------------- 2 | 3 | library(dplyr) # for data manipulation 4 | library(ggplot2) # for graphing 5 | library(lme4) # for multilevel models 6 | library(lmerTest) # for p-values 7 | library(performance) # for ICC 8 | 9 | data <- read.csv('data/casto2016.csv', fileEncoding = "UTF-8-BOM") 10 | head(data) 11 | 12 | # Visualizing Testosterone Levels Over Time ------------------------------- 13 | 14 | data %>% 15 | group_by(time0) %>% 16 | mutate(tmean = mean(Testosterone)) %>% # mean testosterone per timepoint 17 | ggplot(mapping = aes(x = time0, y = tmean)) + 18 | geom_line() + 19 | labs(title = "Testosterone Over Time for Entire Sample") 20 | 21 | data %>% 22 | group_by(time0, Played) %>% # group by timepoint and played 23 | mutate(tmean = mean(Testosterone)) %>% 24 | ggplot(mapping = aes(x = time0, y = tmean, colour = factor(Played))) + 25 | geom_line() + 26 | labs(title = "Testosterone Over Time, Played vs. Did Not Play") 27 | 28 | data %>% 29 | group_by(time0, HormonCont) %>% # group by timepoint and birth control 30 | mutate(tmean = mean(Testosterone)) %>% 31 | ggplot(mapping = aes(x = time0, y = tmean, colour = factor(HormonCont))) + 32 | geom_line() + 33 | labs(title = "Testosterone Over Time, Birth Control or Not") 34 | 35 | # Random-Intercept-Only/Null Model ---------------------------------------- 36 | 37 | null_model <- lmer(Testosterone ~ 1 + (1|Code), data = data, REML = FALSE) 38 | summary(null_model) 39 | 40 | performance::icc(null_model) 41 | 42 | 43 | # Adding Level-1 Fixed and Random Effects --------------------------------- 44 | 45 | l1_model <- lmer(Testosterone ~ 1 + time0 + (time0|Code), data = data, REML = FALSE) 46 | summary(l1_model) 47 | 48 | as.matrix(Matrix::bdiag(VarCorr(l1_model))) 49 | 50 | # Evidence for Retaining Effects ------------------------------------------ 51 | 52 | l1_model_no_U1j <- lmer(Testosterone ~ 1 + time0 + (1|Code), data = data, REML = FALSE) 53 | 54 | anova(l1_model, l1_model_no_U1j) 55 | 56 | confint(l1_model, oldNames = F) 57 | 58 | l1_model_cov0 <- lmer(Testosterone ~ 1 + time0 + (1|Code) + (0 + time0|Code), data = data, REML = FALSE) 59 | anova(l1_model, l1_model_cov0) 60 | 61 | confint(l1_model_cov0, oldNames = F) 62 | 63 | # Extract Empirical Bayes estimates and graph them 64 | as_tibble(coef(l1_model)$Code) %>% 65 | ggplot(mapping = aes(x = time0)) + 66 | geom_histogram(bins = 5) 67 | 68 | # Adding Level-2 Fixed Effects -------------------------------------------- 69 | 70 | l2_played <- lmer(Testosterone ~ 1 + time0 + Played + Played:time0 + (1|Code) + (0 + time0|Code), data = data, REML = FALSE) 71 | summary(l2_played) 72 | 73 | anova(l1_model_cov0, l2_played) 74 | 75 | l2_played_birthcontrol <- lmer(Testosterone ~ 1 + time0 + Played + time0:Played + HormonCont + time0:HormonCont + (1|Code) + (0 + time0|Code), data = data, REML = FALSE) 76 | summary(l2_played_birthcontrol) 77 | Matrix::bdiag(VarCorr(l2_played_birthcontrol)) 78 | 79 | anova(l2_played, l2_played_birthcontrol) 80 | 81 | -------------------------------------------------------------------------------- /Rscripts/11-module-11.R: -------------------------------------------------------------------------------- 1 | # Load Data and Dependencies ---------------------------------------------- 2 | 3 | library(r2mlm) # for R-squared values 4 | library(lme4) # for multilevel models 5 | library(lmerTest) # for p-values 6 | library(performance) # for ICC 7 | 8 | data(teachsat) 9 | 10 | # Single Model, Automatic Entry ------------------------------------------- 11 | 12 | null_model <- lmer(satisfaction ~ 1 + (1|schoolID), data = teachsat, REML = TRUE) 13 | summary(null_model) 14 | 15 | r2mlm(null_model) 16 | 17 | performance::icc(null_model) 18 | 19 | full_model <- lmer(satisfaction ~ 1 + control_c + salary_c + s_t_ratio + (1 + control_c | schoolID), 20 | data = teachsat, 21 | REML = TRUE) 22 | summary(full_model) 23 | Matrix::bdiag(VarCorr(full_model)) 24 | 25 | r2mlm(full_model) 26 | 27 | # Single Model, Manual Entry ---------------------------------------------- 28 | 29 | r2mlm_manual(data = teachsat, 30 | within_covs = c(4, 5), 31 | between_covs = c(8), 32 | random_covs = c(4), 33 | gamma_w = c(0.311, 0.074), 34 | gamma_b = c(7.186, -0.037), 35 | Tau = matrix(c(0.575, 0.009, 0.009, 0.028), 2, 2), 36 | sigma2 = 0.766, 37 | has_intercept = TRUE, 38 | clustermeancentered = TRUE) 39 | 40 | # Model Comparison -------------------------------------------------------- 41 | 42 | reduced_model <- lmer(satisfaction ~ 1 + control_c + salary_c + (1 + control_c | schoolID), 43 | data = teachsat, 44 | REML = TRUE) 45 | 46 | r2mlm_comp(full_model, reduced_model) 47 | 48 | -------------------------------------------------------------------------------- /Rscripts/12-module-12.R: -------------------------------------------------------------------------------- 1 | ## ----message=FALSE, warning=FALSE----------------------------------------------------- 2 | library(lme4) # for multilevel models 3 | library(lmerTest) # for p-values 4 | library(dplyr) # for data manipulation 5 | library(ggplot2) # for graphing 6 | 7 | 8 | ## ---- eval=FALSE---------------------------------------------------------------------- 9 | ## data <- read.csv('rb2002.csv') 10 | 11 | 12 | ## ---- echo = FALSE-------------------------------------------------------------------- 13 | # this actually loads my code, but will be hidden 14 | data <- read.csv('data/rb2002.csv', fileEncoding = "UTF-8-BOM") 15 | 16 | 17 | ## ------------------------------------------------------------------------------------- 18 | data %>% 19 | ggplot(mapping = aes(x = ses, y = mathach)) + 20 | geom_point() 21 | 22 | 23 | ## ------------------------------------------------------------------------------------- 24 | data %>% 25 | ggplot(mapping = aes(x = ses, y = mathach)) + 26 | geom_point(alpha = .2) 27 | 28 | 29 | ## ------------------------------------------------------------------------------------- 30 | data <- data %>% 31 | filter(SCHOOL %in% head(unique(SCHOOL), n = 30)) 32 | 33 | 34 | ## ------------------------------------------------------------------------------------- 35 | data %>% 36 | ggplot() + 37 | geom_point(mapping = aes(x = ses, y = mathach)) + 38 | facet_wrap(~ SCHOOL) 39 | 40 | 41 | ## ------------------------------------------------------------------------------------- 42 | data %>% 43 | group_by(SCHOOL) %>% 44 | ggplot(mapping = aes(x = ses, y = mathach, colour = factor(SCHOOL))) + 45 | geom_point(show.legend = FALSE) + 46 | geom_smooth(method = lm, se = FALSE, show.legend = FALSE, fullrange = TRUE) 47 | 48 | 49 | ## ------------------------------------------------------------------------------------- 50 | model <- lmer(mathach ~ CWCses*ses_mean + (1|SCHOOL) + (0 + CWCses|SCHOOL), data = data, REML = TRUE) 51 | summary(model) 52 | 53 | 54 | ## ------------------------------------------------------------------------------------- 55 | data$l1resid <- residuals(model) 56 | head(data$l1resid) 57 | 58 | 59 | ## ------------------------------------------------------------------------------------- 60 | data %>% 61 | ggplot(mapping = aes(x = CWCses, y = l1resid)) + 62 | geom_point() + 63 | labs(x = "CWCses", y = "residuals") 64 | 65 | 66 | ## ------------------------------------------------------------------------------------- 67 | cor.test(data$l1resid, data$CWCses) 68 | 69 | 70 | ## ------------------------------------------------------------------------------------- 71 | data %>% 72 | ggplot(mapping = aes(x = l1resid)) + 73 | geom_histogram() 74 | 75 | 76 | ## ------------------------------------------------------------------------------------- 77 | data %>% 78 | ggplot(mapping = aes(x = l1resid)) + 79 | geom_histogram(bins = 15) 80 | 81 | 82 | ## ------------------------------------------------------------------------------------- 83 | data %>% 84 | ggplot(mapping = aes(sample = l1resid)) + 85 | stat_qq() 86 | 87 | 88 | ## ------------------------------------------------------------------------------------- 89 | l2_data <- data %>% 90 | group_by(SCHOOL) %>% # group data by clustering variable, school 91 | mutate( 92 | mathach_mean = mean(mathach) # create mean math achievement per school 93 | ) %>% 94 | select(SCHOOL, ses_mean, mathach_mean) %>% 95 | unique() # select unique rows (rather than having school, ses_mean, and mathach_mean repeating over and over again) 96 | 97 | 98 | ## ------------------------------------------------------------------------------------- 99 | l2_data$intercept_resid = ranef(model)$SCHOOL[, 1] 100 | l2_data$slope_resid = ranef(model)$SCHOOL[, 2] 101 | 102 | 103 | ## ------------------------------------------------------------------------------------- 104 | l2_data %>% 105 | ggplot(mapping = aes(x = intercept_resid, y = ses_mean)) + 106 | geom_point() 107 | 108 | 109 | ## ------------------------------------------------------------------------------------- 110 | cor.test(l2_data$ses_mean, l2_data$intercept_resid) 111 | 112 | 113 | ## ------------------------------------------------------------------------------------- 114 | l2_data %>% 115 | ggplot(mapping = aes(x = slope_resid, y =ses_mean)) + 116 | geom_point() 117 | 118 | cor.test(l2_data$ses_mean, l2_data$slope_resid) 119 | 120 | 121 | ## ------------------------------------------------------------------------------------- 122 | l2_data %>% 123 | ggplot(mapping = aes(x = slope_resid, y = intercept_resid)) + 124 | geom_point() 125 | 126 | cor.test(l2_data$intercept_resid, l2_data$slope_resid) 127 | 128 | 129 | ## ------------------------------------------------------------------------------------- 130 | l2_data %>% 131 | ggplot(mapping = aes(x = intercept_resid)) + 132 | geom_histogram(binwidth = .75) 133 | 134 | l2_data %>% 135 | ggplot(mapping = aes(sample = intercept_resid)) + 136 | stat_qq() 137 | 138 | 139 | ## ------------------------------------------------------------------------------------- 140 | l2_data %>% 141 | ggplot(mapping = aes(x = slope_resid)) + 142 | geom_histogram(binwidth = .50) 143 | 144 | l2_data %>% 145 | ggplot(mapping = aes(sample = slope_resid)) + 146 | stat_qq() 147 | 148 | 149 | ## ------------------------------------------------------------------------------------- 150 | n_per_school <- data %>% 151 | group_by(SCHOOL) %>% # group by school 152 | select(SCHOOL) %>% # we just want to count schools 153 | count() %>% 154 | ungroup() %>% 155 | select(n) %>% 156 | unlist() 157 | 158 | 159 | ## ------------------------------------------------------------------------------------- 160 | data$intercept_resid <- rep(l2_data$intercept_resid, times = n_per_school) 161 | data$slope_resid <- rep(l2_data$slope_resid, times = n_per_school) 162 | 163 | 164 | ## ------------------------------------------------------------------------------------- 165 | data %>% 166 | ggplot(mapping = aes(x = l1resid, y = intercept_resid)) + 167 | geom_point() 168 | 169 | cor.test(data$l1resid, data$intercept_resid) 170 | 171 | 172 | ## ------------------------------------------------------------------------------------- 173 | data %>% 174 | ggplot(mapping = aes(x = l1resid, y = slope_resid)) + 175 | geom_point() 176 | 177 | cor.test(data$l1resid, data$slope_resid) 178 | 179 | 180 | ## ------------------------------------------------------------------------------------- 181 | data %>% 182 | ggplot(mapping = aes(x = l1resid, y = ses_mean)) + 183 | geom_point() 184 | 185 | cor.test(data$l1resid, data$ses_mean) 186 | 187 | 188 | ## ------------------------------------------------------------------------------------- 189 | data %>% 190 | ggplot(mapping = aes(x = intercept_resid, y = CWCses)) + 191 | geom_point() 192 | 193 | cor.test(data$intercept_resid, data$CWCses) 194 | 195 | 196 | ## ------------------------------------------------------------------------------------- 197 | data %>% 198 | ggplot(mapping = aes(x = slope_resid, y = CWCses)) + 199 | geom_point() 200 | 201 | cor.test(data$slope_resid, data$CWCses) 202 | 203 | -------------------------------------------------------------------------------- /_book/img/effect_types.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/img/effect_types.png -------------------------------------------------------------------------------- /_book/open_mlm_materials.epub: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials.epub -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/graph-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/graph-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-101-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-101-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-109-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-109-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-112-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-112-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-113-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-113-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-115-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-115-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-115-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-115-2.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-115-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-115-3.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-115-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-115-4.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-115-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-115-5.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-120-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-120-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-121-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-121-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-123-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-123-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-124-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-124-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-127-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-127-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-129-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-129-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-130-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-130-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-131-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-131-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-134-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-134-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-136-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-136-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-137-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-137-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-138-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-138-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-138-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-138-2.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-139-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-139-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-139-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-139-2.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-142-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-142-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-143-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-143-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-144-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-144-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-145-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-145-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-146-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-146-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-16-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-16-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-17-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-17-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-25-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-25-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-42-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-42-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-46-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-46-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-53-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-53-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-92-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-92-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-93-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-93-1.png -------------------------------------------------------------------------------- /_book/open_mlm_materials_files/figure-html/unnamed-chunk-94-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/_book/open_mlm_materials_files/figure-html/unnamed-chunk-94-1.png -------------------------------------------------------------------------------- /_book/reference-keys.txt: -------------------------------------------------------------------------------- 1 | introduction 2 | overview 3 | goals 4 | prerequisites 5 | materials 6 | multiple-regression 7 | learning-objectives 8 | data-demonstration 9 | creating-r-projects 10 | loading-data-and-dependencies 11 | simple-linear-regression 12 | multiple-regression-1 13 | interaction-terms 14 | conclusion 15 | module-3 16 | learning-objectives-1 17 | data-demonstration-1 18 | load-data-and-dependencies 19 | dealing-with-dependence 20 | cluster-robust-standard-errors 21 | conclusion-1 22 | further-reading 23 | module-4 24 | learning-objectives-2 25 | data-demonstration-2 26 | load-data-and-dependencies-1 27 | why-multilevel-models 28 | fixed-vs-random-effects 29 | the-null-model 30 | understanding-variance 31 | intraclass-correlation-coefficient-icc 32 | plausible-values-range 33 | empirical-bayes-estimates 34 | conclusion-2 35 | module-5 36 | learning-objectives-3 37 | data-demonstration-3 38 | load-data-and-dependencies-2 39 | mlm-with-level-1-predictor 40 | compare-regular-and-multilevel-regression 41 | mlm-with-level-2-predictor 42 | conclusion-3 43 | module-6 44 | learning-objectives-4 45 | data-demonstration-4 46 | load-data-and-dependencies-3 47 | mlm-with-random-slope-effect 48 | mlm-with-crosslevel-effect 49 | conclusion-4 50 | module-7 51 | learning-objectives-5 52 | data-demonstration-5 53 | load-data-and-dependencies-4 54 | introduction-to-estimation-problems 55 | estimation-and-optimizers 56 | non-convergence 57 | singularity 58 | deviance-testing-for-model-comparison 59 | conclusion-5 60 | further-reading-1 61 | module-8 62 | learning-objectives-6 63 | data-demonstration-6 64 | load-data-and-dependencies-5 65 | why-center-variables 66 | within-between-and-contextual-effects 67 | options-for-centering-in-mlms 68 | centering-within-cluster-cwc 69 | centering-grand-mean-cgm 70 | what-kind-of-centering-should-you-use 71 | conclusion-6 72 | further-reading-2 73 | module-9 74 | learning-objectives-7 75 | data-demonstration-7 76 | load-dependencies 77 | review-of-multilevel-modelling-procedure 78 | multilevel-models-for-repeated-measures 79 | data-structures-long-vs-wide 80 | our-data-reaction-time 81 | random-intercept-onlynull-model 82 | adding-level-1-fixed-effects 83 | adding-random-slopes 84 | adding-level-2-fixed-effects 85 | adding-cross-level-interactions 86 | conclusion-7 87 | module-10 88 | learning-objectives-8 89 | data-demonstration-8 90 | load-dependencies-1 91 | multilevel-models-for-longitudinal-data 92 | data-structures-long-vs-wide-1 93 | visualizing-testosterone-levels-over-time 94 | random-intercept-onlynull-model-1 95 | adding-level-1-fixed-and-random-effects 96 | evidence-for-retaining-effects 97 | adding-level-2-fixed-effects-1 98 | conclusion-8 99 | module-11 100 | learning-objectives-9 101 | data-demonstration-9 102 | load-data-and-dependencies-6 103 | defining-effect-sizes 104 | r-squared-in-multilevel-models 105 | within-variance-explained 106 | between-variance-explained 107 | total-variance-explained 108 | single-model-automatic-entry 109 | single-model-manual-entry 110 | model-comparison 111 | conclusion-9 112 | additional-reading 113 | module-12 114 | learning-objectives-10 115 | data-demonstration-10 116 | load-data-and-dependencies-7 117 | assumptions-of-mlms 118 | assumption-1-model-specification 119 | assumption-2-functional-form-is-correct 120 | an-aside-extracting-residuals 121 | assumption-3-level-1-residuals-are-independent-and-normally-distributed 122 | independent 123 | normally-distributed 124 | assumption-4-level-2-residuals-are-independent-and-multivariate-normal 125 | independent-1 126 | multivariate-normal 127 | assumption-5-residuals-at-level-1-and-level-2-are-independent 128 | assumption-6-level-1-residuals-independent-of-level-2-predictors-level-2-residuals-independent-of-level-1-predictors 129 | conclusion-10 130 | date-2022-06-07 131 | date-2022-06-08 132 | defining-effect-sizes-1 133 | r-squared-in-multilevel-models-1 134 | within-variance-explained-1 135 | between-variance-explained-1 136 | total-variance-explained-1 137 | single-model-automatic-entry-1 138 | single-model-manual-entry-1 139 | model-comparison-1 140 | additional-reading-1 141 | learning-objectives-11 142 | data-demonstration-11 143 | load-data-and-dependencies-8 144 | conclusion-11 145 | learning-objectives-12 146 | data-demonstration-12 147 | load-data-and-dependencies-9 148 | assumptions-of-mlms-1 149 | assumption-1-model-specification-1 150 | assumption-2-functional-form-is-correct-1 151 | an-aside-extracting-residuals-1 152 | assumption-3-level-1-residuals-are-independent-and-normally-distributed-1 153 | independent-2 154 | normally-distributed-1 155 | assumption-4-level-2-residuals-are-independent-and-multivariate-normal-1 156 | independent-3 157 | multivariate-normal-1 158 | assumption-5-residuals-at-level-1-and-level-2-are-independent-1 159 | assumption-6-level-1-residuals-independent-of-level-2-predictors-level-2-residuals-independent-of-level-1-predictors-1 160 | conclusion-12 161 | module-2 162 | creating-r-projects-1 163 | loading-data-and-dependencies-1 164 | simple-linear-regression-1 165 | multiple-regression-2 166 | interaction-terms-1 167 | download-materials 168 | -------------------------------------------------------------------------------- /_book/search_index.json: -------------------------------------------------------------------------------- 1 | [["13-appendix.html", "A Download Materials", " A Download Materials Chapter Data R Script Worksheet 2 heck2011.csv filler2 filler3 3 heck2011.csv filler2 filler3 4 heck2011.csv filler2 filler3 5 heck2011.csv filler2 filler3 6 heck2011.csv filler2 filler3 7 heck2011.csv filler2 filler3 8 heck2011.csv filler2 filler3 9 hoffman2007.csv filler2 filler3 10 casto2016.csv filler2 filler3 11 teachsat included in r2mlm filler2 filler3 12 rb2002.csv filler2 filler3 "],["404.html", "Page not found", " Page not found The page you requested cannot be found (perhaps it was moved or renamed). You may want to try searching to find the page's new location, or use the table of contents to find the page you are looking for. "]] 2 | -------------------------------------------------------------------------------- /_book/style.css: -------------------------------------------------------------------------------- 1 | p.caption { 2 | color: #777; 3 | margin-top: 10px; 4 | } 5 | p code { 6 | white-space: inherit; 7 | } 8 | pre { 9 | word-break: normal; 10 | word-wrap: normal; 11 | } 12 | pre code { 13 | white-space: inherit; 14 | } 15 | -------------------------------------------------------------------------------- /_bookdown.yml: -------------------------------------------------------------------------------- 1 | book_filename: "open_mlm_materials" 2 | delete_merged_file: true 3 | language: 4 | ui: 5 | chapter_name: "Chapter " 6 | output_dir: "docs" 7 | -------------------------------------------------------------------------------- /_output.yml: -------------------------------------------------------------------------------- 1 | bookdown::gitbook: 2 | css: style.css 3 | split_by: rmd 4 | config: 5 | toc: 6 | depth: 2 7 | collapse: section 8 | scroll_highlight: yes 9 | before: | 10 |
  • Introduction to Multilevel Modelling
  • 11 | after: | 12 |
  • Mairead Shaw
  • 13 |
  • Jessica Kay Flake
  • 14 | download: ["pdf", "epub"] 15 | # bookdown::pdf_book: 16 | # includes: 17 | # in_header: preamble.tex 18 | # latex_engine: xelatex 19 | # citation_package: natbib 20 | # keep_tex: yes 21 | bookdown::epub_book: default 22 | -------------------------------------------------------------------------------- /book.bib: -------------------------------------------------------------------------------- 1 | @Book{xie2015, 2 | title = {Dynamic Documents with {R} and knitr}, 3 | author = {Yihui Xie}, 4 | publisher = {Chapman and Hall/CRC}, 5 | address = {Boca Raton, Florida}, 6 | year = {2015}, 7 | edition = {2nd}, 8 | note = {ISBN 978-1498716963}, 9 | url = {http://yihui.org/knitr/}, 10 | } 11 | -------------------------------------------------------------------------------- /data/casto2016.csv: -------------------------------------------------------------------------------- 1 | Code,position,HormonCont,Played,minplayed,game,time,Cortisol,Testosterone,Estradiol,time0 2 | 1224,1,0,1,90,1,2,.456,84.541,3.706,0 3 | 1224,1,0,1,90,1,3,.575,118.942,5.631,1 4 | 1224,1,0,1,90,1,4,.303,104.803,3.372,2 5 | 1348,2,0,1,90,1,2,.649,39.547,2.62,0 6 | 1348,2,0,1,90,1,3,.323,44.291,3.01,1 7 | 1348,2,0,1,90,1,4,.879,62.774,3.65,2 8 | 1569, ,0,0,0,1,2,.215,35.492,2.55,0 9 | 1569, ,0,0,0,1,3,.136,34.74,1.84,1 10 | 1569, ,0,0,0,1,4,.171,43.24,1.99,2 11 | 2157,2,0,1,90,1,2,.265,56.141,2.866,0 12 | 2157,2,0,1,90,1,3,.213,63.638,3.208,1 13 | 2157,2,0,1,90,1,4,.465,89.228,3.085,2 14 | 2674, ,1,0,0,1,2,.218,24.914,2.9,0 15 | 2674, ,1,0,0,1,3,.428,39.145,3.88,1 16 | 2674, ,1,0,0,1,4,.21,35.321,3.23,2 17 | 2874,4,1,1,30,1,2,.485,62.2,5.64,0 18 | 2874,4,1,1,30,1,3,.377,69.72,4.48,1 19 | 2874,4,1,1,30,1,4,.439,78.35,4.45,2 20 | 3136,3,1,1,65,1,2,.371,53.288,4.318,0 21 | 3136,3,1,1,65,1,3,.303,64.363,7.114,1 22 | 3136,3,1,1,65,1,4,1.16,94.119,4.825,2 23 | 3225,3,1,1,20,1,2,.168,43.814,3.301,0 24 | 3225,3,1,1,20,1,3,.173,45.962,4.598,1 25 | 3225,3,1,1,20,1,4,.587,58.37,2.558,2 26 | 3543,2,1,1,90,1,2,.496,56.323,3.87,0 27 | 3543,2,1,1,90,1,3,.223,74.76,4.52,1 28 | 3543,2,1,1,90,1,4,.805,117.265,5.7,2 29 | 4254,4,0,1,45,1,2,.756,52.533,3.619,0 30 | 4254,4,0,1,45,1,3,.454,67.138,4.182,1 31 | 4254,4,0,1,45,1,4,.421,68.913,2.912,2 32 | 4598,3,1,1,65,1,2,.483,37.411,2.953,0 33 | 4598,3,1,1,65,1,3,.298,39.484,3.555,1 34 | 4598,3,1,1,65,1,4,1.103,45.992,2.396,2 35 | 4871,4,0,1,40,1,2,.255,61.69,4.85,0 36 | 4871,4,0,1,40,1,3,.345,91.94,5.61,1 37 | 4871,4,0,1,40,1,4,.683,96.07,4.56,2 38 | 5035,2,1,1,70,1,2,.315,42.599,3.29,0 39 | 5035,2,1,1,70,1,3,.201,40.553,4.03,1 40 | 5035,2,1,1,70,1,4,.762,59.387,4.43,2 41 | 5326,2,1,1,70,1,2,.312,59.3,4.61,0 42 | 5326,2,1,1,70,1,3,.307,85.11,6.04,1 43 | 5326,2,1,1,70,1,4,1.482,108.21,4.99,2 44 | 5625, ,1,0,0,1,2,.502,41.981,4.74,0 45 | 5625, ,1,0,0,1,3,.334,62.718,5.55,1 46 | 5625, ,1,0,0,1,4,.214,48.053,3.42,2 47 | 6189,3,1,1,20,1,2,.198,55.323,2.7,0 48 | 6189,3,1,1,20,1,3,.285,63.301,4.415,1 49 | 6189,3,1,1,20,1,4,.518,62.253,3.198,2 50 | 6502,3,1,1,45,1,2,.356,57.91,5.29,0 51 | 6502,3,1,1,45,1,3,.315,74.794,5.12,1 52 | 6502,3,1,1,45,1,4,.605,72.272,5.03,2 53 | 7638, ,0,0,0,1,2,.378,60.754,4.28,0 54 | 7638, ,0,0,0,1,3,.221,90.563,8.92,1 55 | 7638, ,0,0,0,1,4,.179,80.794,6.55,2 56 | 7749,2,1,0,0,1,2,.297,37.682,4.064,0 57 | 7931,3,1,1,70,1,2,.224,42.534,3.365,0 58 | 7931,3,1,1,70,1,3,.358,44.312,3.469,1 59 | 7931,3,1,1,70,1,4,.626,46.86,3.251,2 60 | 8751, ,1,0,0,1,2,.331,52.16,3.51,0 61 | 8751, ,1,0,0,1,3,.235,67.1,4.5,1 62 | 8751, ,1,0,0,1,4,.196,64.27,3.66,2 63 | 8976,4,0,1,45,1,2,.425,66.61,4.59,0 64 | 8976,4,0,1,45,1,3,.487,84.55,4.75,1 65 | 8976,4,0,1,45,1,4,.536,65.29,4.48,2 66 | 9125, ,1,0,0,1,2,.358,49.783,3.778,0 67 | 9125, ,1,0,0,1,3,.202,53.705,4.191,1 68 | 9125, ,1,0,0,1,4,.191,36.941,7.162,2 69 | 9161,4,1,1,30,1,2,.201,30.59,3.79,0 70 | 9161,4,1,1,30,1,3,.207,44.858,3.45,1 71 | 9161,4,1,1,30,1,4,.391,57.003,3.52,2 72 | 9748, ,0,0,0,1,2,.164,29.945,2.729,0 73 | 9748, ,0,0,0,1,3,.183,43.182,3.513,1 74 | 9748, ,0,0,0,1,4,.171,39.552,2.335,2 75 | -------------------------------------------------------------------------------- /docs/CNAME: -------------------------------------------------------------------------------- 1 | www.learn-mlms.com -------------------------------------------------------------------------------- /docs/img/effect_types.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/docs/img/effect_types.png -------------------------------------------------------------------------------- /docs/libs/anchor-sections-1.0.1/anchor-sections.css: -------------------------------------------------------------------------------- 1 | /* Styles for section anchors */ 2 | a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} 3 | a.anchor-section::before {content: '#';} 4 | .hasAnchor:hover a.anchor-section {visibility: visible;} 5 | ul > li > .anchor-section {display: none;} 6 | -------------------------------------------------------------------------------- /docs/libs/anchor-sections-1.0.1/anchor-sections.js: -------------------------------------------------------------------------------- 1 | // Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. 2 | document.addEventListener('DOMContentLoaded', function() { 3 | // Do nothing if AnchorJS is used 4 | if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { 5 | return; 6 | } 7 | 8 | const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); 9 | 10 | // Do nothing if sections are already anchored 11 | if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { 12 | return null; 13 | } 14 | 15 | // Use section id when pandoc runs with --section-divs 16 | const section_id = function(x) { 17 | return ((x.classList.contains('section') || (x.tagName === 'SECTION')) 18 | ? x.id : ''); 19 | }; 20 | 21 | // Add anchors 22 | h.forEach(function(x) { 23 | const id = x.id || section_id(x.parentElement); 24 | if (id === '' || x.matches(':empty')) { 25 | return null; 26 | } 27 | let anchor = document.createElement('a'); 28 | anchor.href = '#' + id; 29 | anchor.classList = ['anchor-section']; 30 | x.classList.add('hasAnchor'); 31 | x.appendChild(anchor); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /docs/libs/anchor-sections-1.1.0/anchor-sections-hash.css: -------------------------------------------------------------------------------- 1 | /* Styles for section anchors */ 2 | a.anchor-section::before {content: '#';font-size: 80%;} 3 | -------------------------------------------------------------------------------- /docs/libs/anchor-sections-1.1.0/anchor-sections.css: -------------------------------------------------------------------------------- 1 | /* Styles for section anchors */ 2 | a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} 3 | .hasAnchor:hover a.anchor-section {visibility: visible;} 4 | ul > li > .anchor-section {display: none;} 5 | -------------------------------------------------------------------------------- /docs/libs/anchor-sections-1.1.0/anchor-sections.js: -------------------------------------------------------------------------------- 1 | document.addEventListener('DOMContentLoaded', function () { 2 | // If section divs is used, we need to put the anchor in the child header 3 | const headers = document.querySelectorAll("div.hasAnchor.section[class*='level'] > :first-child") 4 | 5 | headers.forEach(function (x) { 6 | // Add to the header node 7 | if (!x.classList.contains('hasAnchor')) x.classList.add('hasAnchor') 8 | // Remove from the section or div created by Pandoc 9 | x.parentElement.classList.remove('hasAnchor') 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /docs/libs/gitbook-2.6.7/css/fontawesome/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/docs/libs/gitbook-2.6.7/css/fontawesome/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /docs/libs/gitbook-2.6.7/css/plugin-bookdown.css: -------------------------------------------------------------------------------- 1 | .book .book-header h1 { 2 | padding-left: 20px; 3 | padding-right: 20px; 4 | } 5 | .book .book-header.fixed { 6 | position: fixed; 7 | right: 0; 8 | top: 0; 9 | left: 0; 10 | border-bottom: 1px solid rgba(0,0,0,.07); 11 | } 12 | span.search-highlight { 13 | background-color: #ffff88; 14 | } 15 | @media (min-width: 600px) { 16 | .book.with-summary .book-header.fixed { 17 | left: 300px; 18 | } 19 | } 20 | @media (max-width: 1240px) { 21 | .book .book-body.fixed { 22 | top: 50px; 23 | } 24 | .book .book-body.fixed .body-inner { 25 | top: auto; 26 | } 27 | } 28 | @media (max-width: 600px) { 29 | .book.with-summary .book-header.fixed { 30 | left: calc(100% - 60px); 31 | min-width: 300px; 32 | } 33 | .book.with-summary .book-body { 34 | transform: none; 35 | left: calc(100% - 60px); 36 | min-width: 300px; 37 | } 38 | .book .book-body.fixed { 39 | top: 0; 40 | } 41 | } 42 | 43 | .book .book-body.fixed .body-inner { 44 | top: 50px; 45 | } 46 | .book .book-body .page-wrapper .page-inner section.normal sub, .book .book-body .page-wrapper .page-inner section.normal sup { 47 | font-size: 85%; 48 | } 49 | 50 | @media print { 51 | .book .book-summary, .book .book-body .book-header, .fa { 52 | display: none !important; 53 | } 54 | .book .book-body.fixed { 55 | left: 0px; 56 | } 57 | .book .book-body,.book .book-body .body-inner, .book.with-summary { 58 | overflow: visible !important; 59 | } 60 | } 61 | .kable_wrapper { 62 | border-spacing: 20px 0; 63 | border-collapse: separate; 64 | border: none; 65 | margin: auto; 66 | } 67 | .kable_wrapper > tbody > tr > td { 68 | vertical-align: top; 69 | } 70 | .book .book-body .page-wrapper .page-inner section.normal table tr.header { 71 | border-top-width: 2px; 72 | } 73 | .book .book-body .page-wrapper .page-inner section.normal table tr:last-child td { 74 | border-bottom-width: 2px; 75 | } 76 | .book .book-body .page-wrapper .page-inner section.normal table td, .book .book-body .page-wrapper .page-inner section.normal table th { 77 | border-left: none; 78 | border-right: none; 79 | } 80 | .book .book-body .page-wrapper .page-inner section.normal table.kable_wrapper > tbody > tr, .book .book-body .page-wrapper .page-inner section.normal table.kable_wrapper > tbody > tr > td { 81 | border-top: none; 82 | } 83 | .book .book-body .page-wrapper .page-inner section.normal table.kable_wrapper > tbody > tr:last-child > td { 84 | border-bottom: none; 85 | } 86 | 87 | div.theorem, div.lemma, div.corollary, div.proposition, div.conjecture { 88 | font-style: italic; 89 | } 90 | span.theorem, span.lemma, span.corollary, span.proposition, span.conjecture { 91 | font-style: normal; 92 | } 93 | div.proof>*:last-child:after { 94 | content: "\25a2"; 95 | float: right; 96 | } 97 | .header-section-number { 98 | padding-right: .5em; 99 | } 100 | #header .multi-author { 101 | margin: 0.5em 0 -0.5em 0; 102 | } 103 | #header .date { 104 | margin-top: 1.5em; 105 | } 106 | -------------------------------------------------------------------------------- /docs/libs/gitbook-2.6.7/css/plugin-clipboard.css: -------------------------------------------------------------------------------- 1 | div.sourceCode { 2 | position: relative; 3 | } 4 | 5 | .copy-to-clipboard-button { 6 | position: absolute; 7 | right: 0; 8 | top: 0; 9 | visibility: hidden; 10 | } 11 | 12 | .copy-to-clipboard-button:focus { 13 | outline: 0; 14 | } 15 | 16 | div.sourceCode:hover > .copy-to-clipboard-button { 17 | visibility: visible; 18 | } 19 | -------------------------------------------------------------------------------- /docs/libs/gitbook-2.6.7/css/plugin-fontsettings.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Theme 1 3 | */ 4 | .color-theme-1 .dropdown-menu { 5 | background-color: #111111; 6 | border-color: #7e888b; 7 | } 8 | .color-theme-1 .dropdown-menu .dropdown-caret .caret-inner { 9 | border-bottom: 9px solid #111111; 10 | } 11 | .color-theme-1 .dropdown-menu .buttons { 12 | border-color: #7e888b; 13 | } 14 | .color-theme-1 .dropdown-menu .button { 15 | color: #afa790; 16 | } 17 | .color-theme-1 .dropdown-menu .button:hover { 18 | color: #73553c; 19 | } 20 | /* 21 | * Theme 2 22 | */ 23 | .color-theme-2 .dropdown-menu { 24 | background-color: #2d3143; 25 | border-color: #272a3a; 26 | } 27 | .color-theme-2 .dropdown-menu .dropdown-caret .caret-inner { 28 | border-bottom: 9px solid #2d3143; 29 | } 30 | .color-theme-2 .dropdown-menu .buttons { 31 | border-color: #272a3a; 32 | } 33 | .color-theme-2 .dropdown-menu .button { 34 | color: #62677f; 35 | } 36 | .color-theme-2 .dropdown-menu .button:hover { 37 | color: #f4f4f5; 38 | } 39 | .book .book-header .font-settings .font-enlarge { 40 | line-height: 30px; 41 | font-size: 1.4em; 42 | } 43 | .book .book-header .font-settings .font-reduce { 44 | line-height: 30px; 45 | font-size: 1em; 46 | } 47 | 48 | /* sidebar transition background */ 49 | div.book.color-theme-1 { 50 | background: #f3eacb; 51 | } 52 | .book.color-theme-1 .book-body { 53 | color: #704214; 54 | background: #f3eacb; 55 | } 56 | .book.color-theme-1 .book-body .page-wrapper .page-inner section { 57 | background: #f3eacb; 58 | } 59 | 60 | /* sidebar transition background */ 61 | div.book.color-theme-2 { 62 | background: #1c1f2b; 63 | } 64 | 65 | .book.color-theme-2 .book-body { 66 | color: #bdcadb; 67 | background: #1c1f2b; 68 | } 69 | .book.color-theme-2 .book-body .page-wrapper .page-inner section { 70 | background: #1c1f2b; 71 | } 72 | .book.font-size-0 .book-body .page-inner section { 73 | font-size: 1.2rem; 74 | } 75 | .book.font-size-1 .book-body .page-inner section { 76 | font-size: 1.4rem; 77 | } 78 | .book.font-size-2 .book-body .page-inner section { 79 | font-size: 1.6rem; 80 | } 81 | .book.font-size-3 .book-body .page-inner section { 82 | font-size: 2.2rem; 83 | } 84 | .book.font-size-4 .book-body .page-inner section { 85 | font-size: 4rem; 86 | } 87 | .book.font-family-0 { 88 | font-family: Georgia, serif; 89 | } 90 | .book.font-family-1 { 91 | font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 92 | } 93 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal { 94 | color: #704214; 95 | } 96 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal a { 97 | color: inherit; 98 | } 99 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h1, 100 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h2, 101 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h3, 102 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h4, 103 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h5, 104 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h6 { 105 | color: inherit; 106 | } 107 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h1, 108 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h2 { 109 | border-color: inherit; 110 | } 111 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h6 { 112 | color: inherit; 113 | } 114 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal hr { 115 | background-color: inherit; 116 | } 117 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal blockquote { 118 | border-color: #c4b29f; 119 | opacity: 0.9; 120 | } 121 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal pre, 122 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal code { 123 | background: #fdf6e3; 124 | color: #657b83; 125 | border-color: #f8df9c; 126 | } 127 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal .highlight { 128 | background-color: inherit; 129 | } 130 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table th, 131 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table td { 132 | border-color: #f5d06c; 133 | } 134 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table tr { 135 | color: inherit; 136 | background-color: #fdf6e3; 137 | border-color: #444444; 138 | } 139 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n) { 140 | background-color: #fbeecb; 141 | } 142 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal { 143 | color: #bdcadb; 144 | } 145 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal a { 146 | color: #3eb1d0; 147 | } 148 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h1, 149 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h2, 150 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h3, 151 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h4, 152 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h5, 153 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h6 { 154 | color: #fffffa; 155 | } 156 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h1, 157 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h2 { 158 | border-color: #373b4e; 159 | } 160 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h6 { 161 | color: #373b4e; 162 | } 163 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal hr { 164 | background-color: #373b4e; 165 | } 166 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal blockquote { 167 | border-color: #373b4e; 168 | } 169 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal pre, 170 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal code { 171 | color: #9dbed8; 172 | background: #2d3143; 173 | border-color: #2d3143; 174 | } 175 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal .highlight { 176 | background-color: #282a39; 177 | } 178 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table th, 179 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table td { 180 | border-color: #3b3f54; 181 | } 182 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table tr { 183 | color: #b6c2d2; 184 | background-color: #2d3143; 185 | border-color: #3b3f54; 186 | } 187 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n) { 188 | background-color: #35394b; 189 | } 190 | .book.color-theme-1 .book-header { 191 | color: #afa790; 192 | background: transparent; 193 | } 194 | .book.color-theme-1 .book-header .btn { 195 | color: #afa790; 196 | } 197 | .book.color-theme-1 .book-header .btn:hover { 198 | color: #73553c; 199 | background: none; 200 | } 201 | .book.color-theme-1 .book-header h1 { 202 | color: #704214; 203 | } 204 | .book.color-theme-2 .book-header { 205 | color: #7e888b; 206 | background: transparent; 207 | } 208 | .book.color-theme-2 .book-header .btn { 209 | color: #3b3f54; 210 | } 211 | .book.color-theme-2 .book-header .btn:hover { 212 | color: #fffff5; 213 | background: none; 214 | } 215 | .book.color-theme-2 .book-header h1 { 216 | color: #bdcadb; 217 | } 218 | .book.color-theme-1 .book-body .navigation { 219 | color: #afa790; 220 | } 221 | .book.color-theme-1 .book-body .navigation:hover { 222 | color: #73553c; 223 | } 224 | .book.color-theme-2 .book-body .navigation { 225 | color: #383f52; 226 | } 227 | .book.color-theme-2 .book-body .navigation:hover { 228 | color: #fffff5; 229 | } 230 | /* 231 | * Theme 1 232 | */ 233 | .book.color-theme-1 .book-summary { 234 | color: #afa790; 235 | background: #111111; 236 | border-right: 1px solid rgba(0, 0, 0, 0.07); 237 | } 238 | .book.color-theme-1 .book-summary .book-search { 239 | background: transparent; 240 | } 241 | .book.color-theme-1 .book-summary .book-search input, 242 | .book.color-theme-1 .book-summary .book-search input:focus { 243 | border: 1px solid transparent; 244 | } 245 | .book.color-theme-1 .book-summary ul.summary li.divider { 246 | background: #7e888b; 247 | box-shadow: none; 248 | } 249 | .book.color-theme-1 .book-summary ul.summary li i.fa-check { 250 | color: #33cc33; 251 | } 252 | .book.color-theme-1 .book-summary ul.summary li.done > a { 253 | color: #877f6a; 254 | } 255 | .book.color-theme-1 .book-summary ul.summary li a, 256 | .book.color-theme-1 .book-summary ul.summary li span { 257 | color: #877f6a; 258 | background: transparent; 259 | font-weight: normal; 260 | } 261 | .book.color-theme-1 .book-summary ul.summary li.active > a, 262 | .book.color-theme-1 .book-summary ul.summary li a:hover { 263 | color: #704214; 264 | background: transparent; 265 | font-weight: normal; 266 | } 267 | /* 268 | * Theme 2 269 | */ 270 | .book.color-theme-2 .book-summary { 271 | color: #bcc1d2; 272 | background: #2d3143; 273 | border-right: none; 274 | } 275 | .book.color-theme-2 .book-summary .book-search { 276 | background: transparent; 277 | } 278 | .book.color-theme-2 .book-summary .book-search input, 279 | .book.color-theme-2 .book-summary .book-search input:focus { 280 | border: 1px solid transparent; 281 | } 282 | .book.color-theme-2 .book-summary ul.summary li.divider { 283 | background: #272a3a; 284 | box-shadow: none; 285 | } 286 | .book.color-theme-2 .book-summary ul.summary li i.fa-check { 287 | color: #33cc33; 288 | } 289 | .book.color-theme-2 .book-summary ul.summary li.done > a { 290 | color: #62687f; 291 | } 292 | .book.color-theme-2 .book-summary ul.summary li a, 293 | .book.color-theme-2 .book-summary ul.summary li span { 294 | color: #c1c6d7; 295 | background: transparent; 296 | font-weight: 600; 297 | } 298 | .book.color-theme-2 .book-summary ul.summary li.active > a, 299 | .book.color-theme-2 .book-summary ul.summary li a:hover { 300 | color: #f4f4f5; 301 | background: #252737; 302 | font-weight: 600; 303 | } 304 | -------------------------------------------------------------------------------- /docs/libs/gitbook-2.6.7/css/plugin-search.css: -------------------------------------------------------------------------------- 1 | .book .book-summary .book-search { 2 | padding: 6px; 3 | background: transparent; 4 | position: absolute; 5 | top: -50px; 6 | left: 0px; 7 | right: 0px; 8 | transition: top 0.5s ease; 9 | } 10 | .book .book-summary .book-search input, 11 | .book .book-summary .book-search input:focus, 12 | .book .book-summary .book-search input:hover { 13 | width: 100%; 14 | background: transparent; 15 | border: 1px solid #ccc; 16 | box-shadow: none; 17 | outline: none; 18 | line-height: 22px; 19 | padding: 7px 4px; 20 | color: inherit; 21 | box-sizing: border-box; 22 | } 23 | .book.with-search .book-summary .book-search { 24 | top: 0px; 25 | } 26 | .book.with-search .book-summary ul.summary { 27 | top: 50px; 28 | } 29 | .with-search .summary li[data-level] a[href*=".html#"] { 30 | display: none; 31 | } 32 | -------------------------------------------------------------------------------- /docs/libs/gitbook-2.6.7/css/plugin-table.css: -------------------------------------------------------------------------------- 1 | .book .book-body .page-wrapper .page-inner section.normal table{display:table;width:100%;border-collapse:collapse;border-spacing:0;overflow:auto}.book .book-body .page-wrapper .page-inner section.normal table td,.book .book-body .page-wrapper .page-inner section.normal table th{padding:6px 13px;border:1px solid #ddd}.book .book-body .page-wrapper .page-inner section.normal table tr{background-color:#fff;border-top:1px solid #ccc}.book .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n){background-color:#f8f8f8}.book .book-body .page-wrapper .page-inner section.normal table th{font-weight:700} 2 | -------------------------------------------------------------------------------- /docs/libs/gitbook-2.6.7/js/clipboard.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * clipboard.js v2.0.4 3 | * https://zenorocha.github.io/clipboard.js 4 | * 5 | * Licensed MIT © Zeno Rocha 6 | */ 7 | !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardJS=e():t.ClipboardJS=e()}(this,function(){return function(n){var o={};function r(t){if(o[t])return o[t].exports;var e=o[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,r),e.l=!0,e.exports}return r.m=n,r.c=o,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=function(){function o(t,e){for(var n=0;n indicates arrow keys):', 82 | '/: navigate to previous/next page', 83 | 's: Toggle sidebar']; 84 | if (config.search !== false) info.push('f: Toggle search input ' + 85 | '(use //Enter in the search input to navigate through search matches; ' + 86 | 'press Esc to cancel search)'); 87 | if (config.info !== false) gitbook.toolbar.createButton({ 88 | icon: 'fa fa-info', 89 | label: 'Information about the toolbar', 90 | position: 'left', 91 | onClick: function(e) { 92 | e.preventDefault(); 93 | window.alert(info.join('\n\n')); 94 | } 95 | }); 96 | 97 | // highlight the current section in TOC 98 | var href = window.location.pathname; 99 | href = href.substr(href.lastIndexOf('/') + 1); 100 | // accentuated characters need to be decoded (#819) 101 | href = decodeURIComponent(href); 102 | if (href === '') href = 'index.html'; 103 | var li = $('a[href^="' + href + location.hash + '"]').parent('li.chapter').first(); 104 | var summary = $('ul.summary'), chaps = summary.find('li.chapter'); 105 | if (li.length === 0) li = chaps.first(); 106 | li.addClass('active'); 107 | chaps.on('click', function(e) { 108 | chaps.removeClass('active'); 109 | $(this).addClass('active'); 110 | gs.set('tocScrollTop', summary.scrollTop()); 111 | }); 112 | 113 | var toc = config.toc; 114 | // collapse TOC items that are not for the current chapter 115 | if (toc && toc.collapse) (function() { 116 | var type = toc.collapse; 117 | if (type === 'none') return; 118 | if (type !== 'section' && type !== 'subsection') return; 119 | // sections under chapters 120 | var toc_sub = summary.children('li[data-level]').children('ul'); 121 | if (type === 'section') { 122 | toc_sub.hide() 123 | .parent().has(li).children('ul').show(); 124 | } else { 125 | toc_sub.children('li').children('ul').hide() 126 | .parent().has(li).children('ul').show(); 127 | } 128 | li.children('ul').show(); 129 | var toc_sub2 = toc_sub.children('li'); 130 | if (type === 'section') toc_sub2.children('ul').hide(); 131 | summary.children('li[data-level]').find('a') 132 | .on('click.bookdown', function(e) { 133 | if (href === $(this).attr('href').replace(/#.*/, '')) 134 | $(this).parent('li').children('ul').toggle(); 135 | }); 136 | })(); 137 | 138 | // add tooltips to the 's that are truncated 139 | $('a').each(function(i, el) { 140 | if (el.offsetWidth >= el.scrollWidth) return; 141 | if (typeof el.title === 'undefined') return; 142 | el.title = el.text; 143 | }); 144 | 145 | // restore TOC scroll position 146 | var pos = gs.get('tocScrollTop'); 147 | if (typeof pos !== 'undefined') summary.scrollTop(pos); 148 | 149 | // highlight the TOC item that has same text as the heading in view as scrolling 150 | if (toc && toc.scroll_highlight !== false && li.length > 0) (function() { 151 | // scroll the current TOC item into viewport 152 | var ht = $(window).height(), rect = li[0].getBoundingClientRect(); 153 | if (rect.top >= ht || rect.top <= 0 || rect.bottom <= 0) { 154 | summary.scrollTop(li[0].offsetTop); 155 | } 156 | // current chapter TOC items 157 | var items = $('a[href^="' + href + '"]').parent('li.chapter'), 158 | m = items.length; 159 | if (m === 0) { 160 | items = summary.find('li.chapter'); 161 | m = items.length; 162 | } 163 | if (m === 0) return; 164 | // all section titles on current page 165 | var hs = bookInner.find('.page-inner').find('h1,h2,h3'), n = hs.length, 166 | ts = hs.map(function(i, el) { return $(el).text(); }); 167 | if (n === 0) return; 168 | var scrollHandler = function(e) { 169 | var ht = $(window).height(); 170 | clearTimeout($.data(this, 'scrollTimer')); 171 | $.data(this, 'scrollTimer', setTimeout(function() { 172 | // find the first visible title in the viewport 173 | for (var i = 0; i < n; i++) { 174 | var rect = hs[i].getBoundingClientRect(); 175 | if (rect.top >= 0 && rect.bottom <= ht) break; 176 | } 177 | if (i === n) return; 178 | items.removeClass('active'); 179 | for (var j = 0; j < m; j++) { 180 | if (items.eq(j).children('a').first().text() === ts[i]) break; 181 | } 182 | if (j === m) j = 0; // highlight the chapter title 183 | // search bottom-up for a visible TOC item to highlight; if an item is 184 | // hidden, we check if its parent is visible, and so on 185 | while (j > 0 && items.eq(j).is(':hidden')) j--; 186 | items.eq(j).addClass('active'); 187 | }, 250)); 188 | }; 189 | bookInner.on('scroll.bookdown', scrollHandler); 190 | bookBody.on('scroll.bookdown', scrollHandler); 191 | })(); 192 | 193 | // do not refresh the page if the TOC item points to the current page 194 | $('a[href="' + href + '"]').parent('li.chapter').children('a') 195 | .on('click', function(e) { 196 | bookInner.scrollTop(0); 197 | bookBody.scrollTop(0); 198 | return false; 199 | }); 200 | 201 | var toolbar = config.toolbar; 202 | if (!toolbar || toolbar.position !== 'static') { 203 | var bookHeader = $('.book-header'); 204 | bookBody.addClass('fixed'); 205 | bookHeader.addClass('fixed') 206 | .css('background-color', bookBody.css('background-color')) 207 | .on('click.bookdown', function(e) { 208 | // the theme may have changed after user clicks the theme button 209 | bookHeader.css('background-color', bookBody.css('background-color')); 210 | }); 211 | } 212 | 213 | }); 214 | 215 | gitbook.events.bind("page.change", function(e) { 216 | // store TOC scroll position 217 | var summary = $('ul.summary'); 218 | gs.set('tocScrollTop', summary.scrollTop()); 219 | }); 220 | 221 | var bookBody = $('.book-body'), bookInner = bookBody.find('.body-inner'); 222 | var chapterTitle = function() { 223 | return bookInner.find('.page-inner').find('h1,h2').first().text(); 224 | }; 225 | var saveScrollPos = function(e) { 226 | // save scroll position before page is reloaded 227 | gs.set('bodyScrollTop', { 228 | body: bookBody.scrollTop(), 229 | inner: bookInner.scrollTop(), 230 | focused: document.hasFocus(), 231 | title: chapterTitle() 232 | }); 233 | }; 234 | $(document).on('servr:reload', saveScrollPos); 235 | 236 | // check if the page is loaded in an iframe (e.g. the RStudio preview window) 237 | var inIFrame = function() { 238 | var inIframe = true; 239 | try { inIframe = window.self !== window.top; } catch (e) {} 240 | return inIframe; 241 | }; 242 | if (inIFrame()) { 243 | $(window).on('blur unload', saveScrollPos); 244 | } 245 | 246 | $(function(e) { 247 | var pos = gs.get('bodyScrollTop'); 248 | if (pos) { 249 | if (pos.title === chapterTitle()) { 250 | if (pos.body !== 0) bookBody.scrollTop(pos.body); 251 | if (pos.inner !== 0) bookInner.scrollTop(pos.inner); 252 | } 253 | } 254 | if ((pos && pos.focused) || !inIFrame()) bookInner.find('.page-wrapper').focus(); 255 | // clear book body scroll position 256 | gs.remove('bodyScrollTop'); 257 | }); 258 | 259 | }); 260 | -------------------------------------------------------------------------------- /docs/libs/gitbook-2.6.7/js/plugin-clipboard.js: -------------------------------------------------------------------------------- 1 | gitbook.require(["gitbook", "jQuery"], function(gitbook, $) { 2 | 3 | var copyButton = ''; 4 | var clipboard; 5 | 6 | gitbook.events.bind("page.change", function() { 7 | 8 | if (!ClipboardJS.isSupported()) return; 9 | 10 | // the page.change event is thrown twice: before and after the page changes 11 | if (clipboard) { 12 | // clipboard is already defined but we are on the same page 13 | if (clipboard._prevPage === window.location.pathname) return; 14 | // clipboard is already defined and url path change 15 | // we can deduct that we are before page changes 16 | clipboard.destroy(); // destroy the previous events listeners 17 | clipboard = undefined; // reset the clipboard object 18 | return; 19 | } 20 | 21 | $(copyButton).prependTo("div.sourceCode"); 22 | 23 | clipboard = new ClipboardJS(".copy-to-clipboard-button", { 24 | text: function(trigger) { 25 | return trigger.parentNode.textContent; 26 | } 27 | }); 28 | 29 | clipboard._prevPage = window.location.pathname 30 | 31 | }); 32 | 33 | }); 34 | -------------------------------------------------------------------------------- /docs/libs/gitbook-2.6.7/js/plugin-fontsettings.js: -------------------------------------------------------------------------------- 1 | gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) { 2 | var fontState; 3 | 4 | var THEMES = { 5 | "white": 0, 6 | "sepia": 1, 7 | "night": 2 8 | }; 9 | 10 | var FAMILY = { 11 | "serif": 0, 12 | "sans": 1 13 | }; 14 | 15 | // Save current font settings 16 | function saveFontSettings() { 17 | gitbook.storage.set("fontState", fontState); 18 | update(); 19 | } 20 | 21 | // Increase font size 22 | function enlargeFontSize(e) { 23 | e.preventDefault(); 24 | if (fontState.size >= 4) return; 25 | 26 | fontState.size++; 27 | saveFontSettings(); 28 | }; 29 | 30 | // Decrease font size 31 | function reduceFontSize(e) { 32 | e.preventDefault(); 33 | if (fontState.size <= 0) return; 34 | 35 | fontState.size--; 36 | saveFontSettings(); 37 | }; 38 | 39 | // Change font family 40 | function changeFontFamily(index, e) { 41 | e.preventDefault(); 42 | 43 | fontState.family = index; 44 | saveFontSettings(); 45 | }; 46 | 47 | // Change type of color 48 | function changeColorTheme(index, e) { 49 | e.preventDefault(); 50 | 51 | var $book = $(".book"); 52 | 53 | if (fontState.theme !== 0) 54 | $book.removeClass("color-theme-"+fontState.theme); 55 | 56 | fontState.theme = index; 57 | if (fontState.theme !== 0) 58 | $book.addClass("color-theme-"+fontState.theme); 59 | 60 | saveFontSettings(); 61 | }; 62 | 63 | function update() { 64 | var $book = gitbook.state.$book; 65 | 66 | $(".font-settings .font-family-list li").removeClass("active"); 67 | $(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")").addClass("active"); 68 | 69 | $book[0].className = $book[0].className.replace(/\bfont-\S+/g, ''); 70 | $book.addClass("font-size-"+fontState.size); 71 | $book.addClass("font-family-"+fontState.family); 72 | 73 | if(fontState.theme !== 0) { 74 | $book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, ''); 75 | $book.addClass("color-theme-"+fontState.theme); 76 | } 77 | }; 78 | 79 | function init(config) { 80 | var $bookBody, $book; 81 | 82 | //Find DOM elements. 83 | $book = gitbook.state.$book; 84 | $bookBody = $book.find(".book-body"); 85 | 86 | // Instantiate font state object 87 | fontState = gitbook.storage.get("fontState", { 88 | size: config.size || 2, 89 | family: FAMILY[config.family || "sans"], 90 | theme: THEMES[config.theme || "white"] 91 | }); 92 | 93 | update(); 94 | }; 95 | 96 | 97 | gitbook.events.bind("start", function(e, config) { 98 | var opts = config.fontsettings; 99 | if (!opts) return; 100 | 101 | // Create buttons in toolbar 102 | gitbook.toolbar.createButton({ 103 | icon: 'fa fa-font', 104 | label: 'Font Settings', 105 | className: 'font-settings', 106 | dropdown: [ 107 | [ 108 | { 109 | text: 'A', 110 | className: 'font-reduce', 111 | onClick: reduceFontSize 112 | }, 113 | { 114 | text: 'A', 115 | className: 'font-enlarge', 116 | onClick: enlargeFontSize 117 | } 118 | ], 119 | [ 120 | { 121 | text: 'Serif', 122 | onClick: _.partial(changeFontFamily, 0) 123 | }, 124 | { 125 | text: 'Sans', 126 | onClick: _.partial(changeFontFamily, 1) 127 | } 128 | ], 129 | [ 130 | { 131 | text: 'White', 132 | onClick: _.partial(changeColorTheme, 0) 133 | }, 134 | { 135 | text: 'Sepia', 136 | onClick: _.partial(changeColorTheme, 1) 137 | }, 138 | { 139 | text: 'Night', 140 | onClick: _.partial(changeColorTheme, 2) 141 | } 142 | ] 143 | ] 144 | }); 145 | 146 | 147 | // Init current settings 148 | init(opts); 149 | }); 150 | }); 151 | 152 | 153 | -------------------------------------------------------------------------------- /docs/libs/gitbook-2.6.7/js/plugin-search.js: -------------------------------------------------------------------------------- 1 | gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) { 2 | var index = null; 3 | var fuse = null; 4 | var _search = {engine: 'lunr', opts: {}}; 5 | var $searchInput, $searchLabel, $searchForm; 6 | var $highlighted = [], hi, hiOpts = { className: 'search-highlight' }; 7 | var collapse = false, toc_visible = []; 8 | 9 | function init(config) { 10 | // Instantiate search settings 11 | _search = gitbook.storage.get("search", { 12 | engine: config.search.engine || 'lunr', 13 | opts: config.search.options || {}, 14 | }); 15 | }; 16 | 17 | // Save current search settings 18 | function saveSearchSettings() { 19 | gitbook.storage.set("search", _search); 20 | } 21 | 22 | // Use a specific index 23 | function loadIndex(data) { 24 | // [Yihui] In bookdown, I use a character matrix to store the chapter 25 | // content, and the index is dynamically built on the client side. 26 | // Gitbook prebuilds the index data instead: https://github.com/GitbookIO/plugin-search 27 | // We can certainly do that via R packages V8 and jsonlite, but let's 28 | // see how slow it really is before improving it. On the other hand, 29 | // lunr cannot handle non-English text very well, e.g. the default 30 | // tokenizer cannot deal with Chinese text, so we may want to replace 31 | // lunr with a dumb simple text matching approach. 32 | if (_search.engine === 'lunr') { 33 | index = lunr(function () { 34 | this.ref('url'); 35 | this.field('title', { boost: 10 }); 36 | this.field('body'); 37 | }); 38 | data.map(function(item) { 39 | index.add({ 40 | url: item[0], 41 | title: item[1], 42 | body: item[2] 43 | }); 44 | }); 45 | return; 46 | } 47 | fuse = new Fuse(data.map((_data => { 48 | return { 49 | url: _data[0], 50 | title: _data[1], 51 | body: _data[2] 52 | }; 53 | })), Object.assign( 54 | { 55 | includeScore: true, 56 | threshold: 0.1, 57 | ignoreLocation: true, 58 | keys: ["title", "body"] 59 | }, 60 | _search.opts 61 | )); 62 | } 63 | 64 | // Fetch the search index 65 | function fetchIndex() { 66 | return $.getJSON(gitbook.state.basePath+"/search_index.json") 67 | .then(loadIndex); // [Yihui] we need to use this object later 68 | } 69 | 70 | // Search for a term and return results 71 | function search(q) { 72 | let results = []; 73 | switch (_search.engine) { 74 | case 'fuse': 75 | if (!fuse) return; 76 | results = fuse.search(q).map(function(result) { 77 | var parts = result.item.url.split('#'); 78 | return { 79 | path: parts[0], 80 | hash: parts[1] 81 | }; 82 | }); 83 | break; 84 | case 'lunr': 85 | default: 86 | if (!index) return; 87 | results = _.chain(index.search(q)).map(function(result) { 88 | var parts = result.ref.split("#"); 89 | return { 90 | path: parts[0], 91 | hash: parts[1] 92 | }; 93 | }) 94 | .value(); 95 | } 96 | 97 | // [Yihui] Highlight the search keyword on current page 98 | $highlighted = $('.page-inner') 99 | .unhighlight(hiOpts).highlight(q, hiOpts).find('span.search-highlight'); 100 | scrollToHighlighted(0); 101 | 102 | return results; 103 | } 104 | 105 | // [Yihui] Scroll the chapter body to the i-th highlighted string 106 | function scrollToHighlighted(d) { 107 | var n = $highlighted.length; 108 | hi = hi === undefined ? 0 : hi + d; 109 | // navignate to the previous/next page in the search results if reached the top/bottom 110 | var b = hi < 0; 111 | if (d !== 0 && (b || hi >= n)) { 112 | var path = currentPath(), n2 = toc_visible.length; 113 | if (n2 === 0) return; 114 | for (var i = b ? 0 : n2; (b && i < n2) || (!b && i >= 0); i += b ? 1 : -1) { 115 | if (toc_visible.eq(i).data('path') === path) break; 116 | } 117 | i += b ? -1 : 1; 118 | if (i < 0) i = n2 - 1; 119 | if (i >= n2) i = 0; 120 | var lnk = toc_visible.eq(i).find('a[href$=".html"]'); 121 | if (lnk.length) lnk[0].click(); 122 | return; 123 | } 124 | if (n === 0) return; 125 | var $p = $highlighted.eq(hi); 126 | $p[0].scrollIntoView(); 127 | $highlighted.css('background-color', ''); 128 | // an orange background color on the current item and removed later 129 | $p.css('background-color', 'orange'); 130 | setTimeout(function() { 131 | $p.css('background-color', ''); 132 | }, 2000); 133 | } 134 | 135 | function currentPath() { 136 | var href = window.location.pathname; 137 | href = href.substr(href.lastIndexOf('/') + 1); 138 | return href === '' ? 'index.html' : href; 139 | } 140 | 141 | // Create search form 142 | function createForm(value) { 143 | if ($searchForm) $searchForm.remove(); 144 | if ($searchLabel) $searchLabel.remove(); 145 | if ($searchInput) $searchInput.remove(); 146 | 147 | $searchForm = $('
    ', { 148 | 'class': 'book-search', 149 | 'role': 'search' 150 | }); 151 | 152 | $searchLabel = $('Creative Commons Attribution 4.0 International, so instructors can feel free to borrow and alter materials to structure their own courses. If you notice any errors or would otherwise like to contribute, feel free to file an issue on GitHub. 19 | 20 | ## About the Authors {-} 21 | 22 | Mairead Shaw is a graduate student in the Quantitative Psychology and Modelling area at McGill University. Her research interests center around effect sizes in multilevel models and measurement considerations for multi-group and replication research. 23 | 24 | Dr. Jessica Flake is an Assistant Professor of Quantitative Psychology and Modelling at McGill University. She received an MA in quantitative psychology from James Madison University and a a PhD in Measurement, Evaluation, and Assessment from the University of Connecticut. Her work focuses on technical and applied aspects of psychological measurement including scale development, psychometric modelling, and scale use and replicability. 25 | 26 | ## Funding {-} 27 | 28 | These materials were made possible by funding from the APS Fund for Teaching and Public Understanding of Psychological Science. You can read more about the fund here. 29 | -------------------------------------------------------------------------------- /open_mlm_materials.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Website 16 | -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/graph-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/graph-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-102-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-102-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-110-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-110-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-113-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-113-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-114-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-114-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-116-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-116-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-116-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-116-2.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-116-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-116-3.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-116-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-116-4.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-116-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-116-5.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-120-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-120-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-121-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-121-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-123-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-123-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-124-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-124-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-127-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-127-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-129-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-129-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-130-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-130-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-131-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-131-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-134-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-134-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-136-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-136-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-137-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-137-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-138-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-138-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-138-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-138-2.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-139-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-139-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-139-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-139-2.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-142-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-142-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-143-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-143-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-144-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-144-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-145-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-145-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-146-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-146-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-16-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-16-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-17-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-17-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-26-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-26-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-43-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-43-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-47-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-47-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-54-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-54-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-93-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-93-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-94-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-94-1.png -------------------------------------------------------------------------------- /open_mlm_materials_files/figure-html/unnamed-chunk-95-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/open_mlm_materials_files/figure-html/unnamed-chunk-95-1.png -------------------------------------------------------------------------------- /packages.bib: -------------------------------------------------------------------------------- 1 | @Manual{R-base, 2 | title = {R: A Language and Environment for Statistical Computing}, 3 | author = {{R Core Team}}, 4 | organization = {R Foundation for Statistical Computing}, 5 | address = {Vienna, Austria}, 6 | year = {2022}, 7 | url = {https://www.R-project.org/}, 8 | } 9 | 10 | @Manual{R-bookdown, 11 | title = {bookdown: Authoring Books and Technical Documents with R Markdown}, 12 | author = {Yihui Xie}, 13 | year = {2022}, 14 | note = {R package version 0.26}, 15 | url = {https://CRAN.R-project.org/package=bookdown}, 16 | } 17 | 18 | @Manual{R-dplyr, 19 | title = {dplyr: A Grammar of Data Manipulation}, 20 | author = {Hadley Wickham and Romain François and Lionel Henry and Kirill Müller}, 21 | year = {2022}, 22 | note = {R package version 1.0.8}, 23 | url = {https://CRAN.R-project.org/package=dplyr}, 24 | } 25 | 26 | @Manual{R-forcats, 27 | title = {forcats: Tools for Working with Categorical Variables (Factors)}, 28 | author = {Hadley Wickham}, 29 | year = {2021}, 30 | note = {R package version 0.5.1}, 31 | url = {https://CRAN.R-project.org/package=forcats}, 32 | } 33 | 34 | @Manual{R-ggplot2, 35 | title = {ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics}, 36 | author = {Hadley Wickham and Winston Chang and Lionel Henry and Thomas Lin Pedersen and Kohske Takahashi and Claus Wilke and Kara Woo and Hiroaki Yutani and Dewey Dunnington}, 37 | year = {2021}, 38 | note = {R package version 3.3.5}, 39 | url = {https://CRAN.R-project.org/package=ggplot2}, 40 | } 41 | 42 | @Manual{R-htmltools, 43 | title = {htmltools: Tools for HTML}, 44 | author = {Joe Cheng and Carson Sievert and Barret Schloerke and Winston Chang and Yihui Xie and Jeff Allen}, 45 | year = {2021}, 46 | note = {R package version 0.5.2}, 47 | url = {https://github.com/rstudio/htmltools}, 48 | } 49 | 50 | @Manual{R-kableExtra, 51 | title = {kableExtra: Construct Complex Table with kable and Pipe Syntax}, 52 | author = {Hao Zhu}, 53 | year = {2021}, 54 | note = {R package version 1.3.4}, 55 | url = {https://CRAN.R-project.org/package=kableExtra}, 56 | } 57 | 58 | @Manual{R-knitr, 59 | title = {knitr: A General-Purpose Package for Dynamic Report Generation in R}, 60 | author = {Yihui Xie}, 61 | year = {2022}, 62 | note = {R package version 1.39}, 63 | url = {https://yihui.org/knitr/}, 64 | } 65 | 66 | @Manual{R-lme4, 67 | title = {lme4: Linear Mixed-Effects Models using Eigen and S4}, 68 | author = {Douglas Bates and Martin Maechler and Ben Bolker and Steven Walker}, 69 | year = {2022}, 70 | note = {R package version 1.1-29}, 71 | url = {https://github.com/lme4/lme4/}, 72 | } 73 | 74 | @Manual{R-lmerTest, 75 | title = {lmerTest: Tests in Linear Mixed Effects Models}, 76 | author = {Alexandra Kuznetsova and Per {Bruun Brockhoff} and Rune {Haubo Bojesen Christensen}}, 77 | year = {2020}, 78 | note = {R package version 3.1-3}, 79 | url = {https://github.com/runehaubo/lmerTestR}, 80 | } 81 | 82 | @Manual{R-lmtest, 83 | title = {lmtest: Testing Linear Regression Models}, 84 | author = {Torsten Hothorn and Achim Zeileis and Richard W. Farebrother and Clint Cummins}, 85 | year = {2022}, 86 | note = {R package version 0.9-40}, 87 | url = {https://CRAN.R-project.org/package=lmtest}, 88 | } 89 | 90 | @Manual{R-magrittr, 91 | title = {magrittr: A Forward-Pipe Operator for R}, 92 | author = {Stefan Milton Bache and Hadley Wickham}, 93 | year = {2022}, 94 | note = {R package version 2.0.3}, 95 | url = {https://CRAN.R-project.org/package=magrittr}, 96 | } 97 | 98 | @Manual{R-Matrix, 99 | title = {Matrix: Sparse and Dense Matrix Classes and Methods}, 100 | author = {Douglas Bates and Martin Maechler}, 101 | year = {2021}, 102 | note = {R package version 1.4-0}, 103 | url = {https://CRAN.R-project.org/package=Matrix}, 104 | } 105 | 106 | @Manual{R-patchwork, 107 | title = {patchwork: The Composer of Plots}, 108 | author = {Thomas Lin Pedersen}, 109 | year = {2020}, 110 | note = {R package version 1.1.1}, 111 | url = {https://CRAN.R-project.org/package=patchwork}, 112 | } 113 | 114 | @Manual{R-performance, 115 | title = {performance: Assessment of Regression Models Performance}, 116 | author = {Daniel Lüdecke and Dominique Makowski and Mattan S. Ben-Shachar and Indrajeet Patil and Philip Waggoner and Brenton M. Wiernik}, 117 | year = {2022}, 118 | note = {R package version 0.9.0}, 119 | url = {https://easystats.github.io/performance/}, 120 | } 121 | 122 | @Manual{R-purrr, 123 | title = {purrr: Functional Programming Tools}, 124 | author = {Lionel Henry and Hadley Wickham}, 125 | year = {2020}, 126 | note = {R package version 0.3.4}, 127 | url = {https://CRAN.R-project.org/package=purrr}, 128 | } 129 | 130 | @Manual{R-readr, 131 | title = {readr: Read Rectangular Text Data}, 132 | author = {Hadley Wickham and Jim Hester and Jennifer Bryan}, 133 | year = {2022}, 134 | note = {R package version 2.1.2}, 135 | url = {https://CRAN.R-project.org/package=readr}, 136 | } 137 | 138 | @Manual{R-rmarkdown, 139 | title = {rmarkdown: Dynamic Documents for R}, 140 | author = {JJ Allaire and Yihui Xie and Jonathan McPherson and Javier Luraschi and Kevin Ushey and Aron Atkins and Hadley Wickham and Joe Cheng and Winston Chang and Richard Iannone}, 141 | year = {2022}, 142 | note = {R package version 2.14}, 143 | url = {https://CRAN.R-project.org/package=rmarkdown}, 144 | } 145 | 146 | @Manual{R-sandwich, 147 | title = {sandwich: Robust Covariance Matrix Estimators}, 148 | author = {Achim Zeileis and Thomas Lumley}, 149 | year = {2021}, 150 | note = {R package version 3.0-1}, 151 | url = {https://sandwich.R-Forge.R-project.org/}, 152 | } 153 | 154 | @Manual{R-stringr, 155 | title = {stringr: Simple, Consistent Wrappers for Common String Operations}, 156 | author = {Hadley Wickham}, 157 | year = {2019}, 158 | note = {R package version 1.4.0}, 159 | url = {https://CRAN.R-project.org/package=stringr}, 160 | } 161 | 162 | @Manual{R-tibble, 163 | title = {tibble: Simple Data Frames}, 164 | author = {Kirill Müller and Hadley Wickham}, 165 | year = {2021}, 166 | note = {R package version 3.1.6}, 167 | url = {https://CRAN.R-project.org/package=tibble}, 168 | } 169 | 170 | @Manual{R-tidyr, 171 | title = {tidyr: Tidy Messy Data}, 172 | author = {Hadley Wickham and Maximilian Girlich}, 173 | year = {2022}, 174 | note = {R package version 1.2.0}, 175 | url = {https://CRAN.R-project.org/package=tidyr}, 176 | } 177 | 178 | @Manual{R-tidyverse, 179 | title = {tidyverse: Easily Install and Load the Tidyverse}, 180 | author = {Hadley Wickham}, 181 | year = {2021}, 182 | note = {R package version 1.3.1}, 183 | url = {https://CRAN.R-project.org/package=tidyverse}, 184 | } 185 | 186 | @Manual{R-zoo, 187 | title = {zoo: S3 Infrastructure for Regular and Irregular Time Series (Z's 188 | Ordered Observations)}, 189 | author = {Achim Zeileis and Gabor Grothendieck and Jeffrey A. Ryan}, 190 | year = {2022}, 191 | note = {R package version 1.8-10}, 192 | url = {https://zoo.R-Forge.R-project.org/}, 193 | } 194 | 195 | @Book{bookdown2016, 196 | title = {bookdown: Authoring Books and Technical Documents with {R} Markdown}, 197 | author = {Yihui Xie}, 198 | publisher = {Chapman and Hall/CRC}, 199 | address = {Boca Raton, Florida}, 200 | year = {2016}, 201 | note = {ISBN 978-1138700109}, 202 | url = {https://bookdown.org/yihui/bookdown}, 203 | } 204 | 205 | @Book{ggplot22016, 206 | author = {Hadley Wickham}, 207 | title = {ggplot2: Elegant Graphics for Data Analysis}, 208 | publisher = {Springer-Verlag New York}, 209 | year = {2016}, 210 | isbn = {978-3-319-24277-4}, 211 | url = {https://ggplot2.tidyverse.org}, 212 | } 213 | 214 | @Book{knitr2015, 215 | title = {Dynamic Documents with {R} and knitr}, 216 | author = {Yihui Xie}, 217 | publisher = {Chapman and Hall/CRC}, 218 | address = {Boca Raton, Florida}, 219 | year = {2015}, 220 | edition = {2nd}, 221 | note = {ISBN 978-1498716963}, 222 | url = {https://yihui.org/knitr/}, 223 | } 224 | 225 | @InCollection{knitr2014, 226 | booktitle = {Implementing Reproducible Computational Research}, 227 | editor = {Victoria Stodden and Friedrich Leisch and Roger D. Peng}, 228 | title = {knitr: A Comprehensive Tool for Reproducible Research in {R}}, 229 | author = {Yihui Xie}, 230 | publisher = {Chapman and Hall/CRC}, 231 | year = {2014}, 232 | note = {ISBN 978-1466561595}, 233 | url = {http://www.crcpress.com/product/isbn/9781466561595}, 234 | } 235 | 236 | @Article{lme42015, 237 | title = {Fitting Linear Mixed-Effects Models Using {lme4}}, 238 | author = {Douglas Bates and Martin M{\"a}chler and Ben Bolker and Steve Walker}, 239 | journal = {Journal of Statistical Software}, 240 | year = {2015}, 241 | volume = {67}, 242 | number = {1}, 243 | pages = {1--48}, 244 | doi = {10.18637/jss.v067.i01}, 245 | } 246 | 247 | @Article{lmerTest2017, 248 | title = {{lmerTest} Package: Tests in Linear Mixed Effects Models}, 249 | author = {Alexandra Kuznetsova and Per B. Brockhoff and Rune H. B. Christensen}, 250 | journal = {Journal of Statistical Software}, 251 | year = {2017}, 252 | volume = {82}, 253 | number = {13}, 254 | pages = {1--26}, 255 | doi = {10.18637/jss.v082.i13}, 256 | } 257 | 258 | @Article{lmtest2002, 259 | title = {Diagnostic Checking in Regression Relationships}, 260 | author = {Achim Zeileis and Torsten Hothorn}, 261 | journal = {R News}, 262 | year = {2002}, 263 | volume = {2}, 264 | number = {3}, 265 | pages = {7--10}, 266 | url = {https://CRAN.R-project.org/doc/Rnews/}, 267 | } 268 | 269 | @Article{performance2021, 270 | title = {{performance}: An {R} Package for Assessment, Comparison and Testing of Statistical Models}, 271 | author = {Daniel Lüdecke and Mattan S. Ben-Shachar and Indrajeet Patil and Philip Waggoner and Dominique Makowski}, 272 | year = {2021}, 273 | journal = {Journal of Open Source Software}, 274 | volume = {6}, 275 | number = {60}, 276 | pages = {3139}, 277 | doi = {10.21105/joss.03139}, 278 | } 279 | 280 | @Book{rmarkdown2018, 281 | title = {R Markdown: The Definitive Guide}, 282 | author = {Yihui Xie and J.J. Allaire and Garrett Grolemund}, 283 | publisher = {Chapman and Hall/CRC}, 284 | address = {Boca Raton, Florida}, 285 | year = {2018}, 286 | note = {ISBN 9781138359338}, 287 | url = {https://bookdown.org/yihui/rmarkdown}, 288 | } 289 | 290 | @Book{rmarkdown2020, 291 | title = {R Markdown Cookbook}, 292 | author = {Yihui Xie and Christophe Dervieux and Emily Riederer}, 293 | publisher = {Chapman and Hall/CRC}, 294 | address = {Boca Raton, Florida}, 295 | year = {2020}, 296 | note = {ISBN 9780367563837}, 297 | url = {https://bookdown.org/yihui/rmarkdown-cookbook}, 298 | } 299 | 300 | @Article{sandwich2020, 301 | title = {Various Versatile Variances: An Object-Oriented Implementation of Clustered Covariances in {R}}, 302 | author = {Achim Zeileis and Susanne K\"oll and Nathaniel Graham}, 303 | journal = {Journal of Statistical Software}, 304 | year = {2020}, 305 | volume = {95}, 306 | number = {1}, 307 | pages = {1--36}, 308 | doi = {10.18637/jss.v095.i01}, 309 | } 310 | 311 | @Article{sandwich2004, 312 | title = {Econometric Computing with {HC} and {HAC} Covariance Matrix Estimators}, 313 | author = {Achim Zeileis}, 314 | journal = {Journal of Statistical Software}, 315 | year = {2004}, 316 | volume = {11}, 317 | number = {10}, 318 | pages = {1--17}, 319 | doi = {10.18637/jss.v011.i10}, 320 | } 321 | 322 | @Article{sandwich2006, 323 | title = {Object-Oriented Computation of Sandwich Estimators}, 324 | author = {Achim Zeileis}, 325 | journal = {Journal of Statistical Software}, 326 | year = {2006}, 327 | volume = {16}, 328 | number = {9}, 329 | pages = {1--16}, 330 | doi = {10.18637/jss.v016.i09}, 331 | } 332 | 333 | @Article{tidyverse2019, 334 | title = {Welcome to the {tidyverse}}, 335 | author = {Hadley Wickham and Mara Averick and Jennifer Bryan and Winston Chang and Lucy D'Agostino McGowan and Romain François and Garrett Grolemund and Alex Hayes and Lionel Henry and Jim Hester and Max Kuhn and Thomas Lin Pedersen and Evan Miller and Stephan Milton Bache and Kirill Müller and Jeroen Ooms and David Robinson and Dana Paige Seidel and Vitalie Spinu and Kohske Takahashi and Davis Vaughan and Claus Wilke and Kara Woo and Hiroaki Yutani}, 336 | year = {2019}, 337 | journal = {Journal of Open Source Software}, 338 | volume = {4}, 339 | number = {43}, 340 | pages = {1686}, 341 | doi = {10.21105/joss.01686}, 342 | } 343 | 344 | @Article{zoo2005, 345 | title = {zoo: S3 Infrastructure for Regular and Irregular Time Series}, 346 | author = {Achim Zeileis and Gabor Grothendieck}, 347 | journal = {Journal of Statistical Software}, 348 | year = {2005}, 349 | volume = {14}, 350 | number = {6}, 351 | pages = {1--27}, 352 | doi = {10.18637/jss.v014.i06}, 353 | } 354 | 355 | -------------------------------------------------------------------------------- /preamble.tex: -------------------------------------------------------------------------------- 1 | \usepackage{booktabs} 2 | -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | p.caption { 2 | color: #777; 3 | margin-top: 10px; 4 | } 5 | p code { 6 | white-space: inherit; 7 | } 8 | pre { 9 | word-break: normal; 10 | word-wrap: normal; 11 | } 12 | pre code { 13 | white-space: inherit; 14 | } 15 | -------------------------------------------------------------------------------- /worksheets/module10.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/worksheets/module10.docx -------------------------------------------------------------------------------- /worksheets/module11.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/worksheets/module11.docx -------------------------------------------------------------------------------- /worksheets/module12.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/worksheets/module12.docx -------------------------------------------------------------------------------- /worksheets/module2.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/worksheets/module2.docx -------------------------------------------------------------------------------- /worksheets/module3.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/worksheets/module3.docx -------------------------------------------------------------------------------- /worksheets/module4.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/worksheets/module4.docx -------------------------------------------------------------------------------- /worksheets/module5.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/worksheets/module5.docx -------------------------------------------------------------------------------- /worksheets/module6.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/worksheets/module6.docx -------------------------------------------------------------------------------- /worksheets/module7.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/worksheets/module7.docx -------------------------------------------------------------------------------- /worksheets/module8.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/worksheets/module8.docx -------------------------------------------------------------------------------- /worksheets/module9.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkshaw/learn-mlms/4d81d95b41bc52533027339772c92d48aa0686ef/worksheets/module9.docx --------------------------------------------------------------------------------