Week 16. Workbook introduction to multilevel data

Written by Rob Davies

Week 16 Multilevel data workbook overview

Welcome to your overview of the work we will do together in Week 16.

We are going to learn about a method or approach that is essential in modern data analysis: multilevel modeling.

We are going to invest the next few weeks in working on this approach.

We are going to do this because multilevel modeling is a very powerful and very flexible technique, and because you will learn best if you take the time to build up and deepen your understanding step-by-step.

Targets

Our learning objectives include the development of key concepts and skills.

  1. concepts – how data can have multilevel structures and what this requires in models
  2. skills – where skills comprise the capacity to:
  • use visualization to examine observations within groups
  • run linear models over all data and within each class
  • use the lmer() function to fit models of multilevel data

We are just getting started this week. Our plan will be to build depth and breadth in understanding as we progress over the next few weeks.

Learning resources

You will see, next, the lectures we share to explain the concepts you will learn about, and the practical data analysis skills you will develop. Then you will see information about the practical materials you can use to build and practise your skills.

Every week, you will learn best if you first watch the lectures then do the practical exercises.

Linked resources

To help your learning, you can read about the ideas and the practical coding required for analyses in the chapters I wrote for this course.

The chapter: Conceptual introduction to multilevel data

Lectures

The lecture materials for this week are presented in three short parts.

Click on a link and your browser should open a tab showing the Panopto video for the lecture part.

  1. Part 1 (17 minutes) Multilevel data: What do we mean when we talk about multilevel structured data and why it matters.
  1. Part 2 (13 minutes): Getting started in learning, working with an example from education, children clustered in classes, analyzing data using linear models, seeing the differences between different classes.
  1. Part 3 (13 minutes): Doing multilevel models in practice, coding models using lmer(), a first look at analysis results.

Lecture slides

Download the lecture slides

The slides presented in the videos can be downloaded here:

The high resolution version is the version delivered for the lecture recordings. Because the images are produced to be high resolution, the file size is quite big (4 MB) so, to make the slides easier to download, I produced low resolution versions: 1pp and 6pp. These should be easier to download and print out if that is what you want to do.

Practical materials: data and R-Studio

We will be working with data taken from a study on education outcomes in Brazilian children, reported by Golino & Gomes (2014).

You can read more about these data in Conceptual introduction to multilevel data.

Important

Get the data: get the data file and the .R script you can use to do the exercises that will support your learning.

  • You can download the files folder for this chapter by clicking on the link 01-multilevel.zip.

The practical materials folder includes:

  • BAFACALO_DATASET.RData
  • 402-01-multilevel-workbook.R the workbook you can use to do the practical exercises.

The data file is in the .RData format: .RData is R’s own file format so the code you use to load and access the data for analysis is a bit simpler than you are used to, as we will see.

Important

You can access the sign-in page for R-Studio Server here

Practical materials guide

Here, our learning targets are:

  • concepts: multilevel data and multilevel modeling
  • skills: visualization – examine overall and within-class trends
  • skills: run linear models over all data – and within each class
  • skills: use the lmer() function to fit models of multilevel data

The aims of the practical work are to:

  • Get practice running the code so that you can reproduce the figures and results from the lecture and in the book chapter.
  • Exercise skills by varying code – changing variables, changing options – so that you can see how the code works.
  • Use the opportunity to reflect on and evaluate results – so that we can support growth in development of understanding of main ideas.

The practical exercises

Now you will progress through a series of tasks, and challenges, to aid your learning.

Warning

We will work with the data file:

  • AFACALO_DATASET.RData

We again split the steps into into parts, tasks and questions.

We are going to work through the following workflow steps: each step is labelled as a practical part.

  1. Set-up
  2. Load the data
  3. Inspect the data
  4. Visualize relationships
  5. Analyze relationships using linear models
  6. Visualize relationships for each class
  7. Mixed-effects analysis
  8. Optional exercises: extensions

In the following, we will guide you through the tasks and questions step by step.

Important

An answers version of the workbook will be revealed after the practical class.

Practical Part 1: Set-up

To begin, we set up our environment in R.

Practical Task 1 – Run code to load relevant libraries

Use the library() function to make the functions we need available to you.

library(broom)
library(gridExtra)
library(lme4)
Loading required package: Matrix
Warning: package 'Matrix' was built under R version 4.1.1
library(tidyverse)
Warning: package 'tidyr' was built under R version 4.1.1
Warning: package 'purrr' was built under R version 4.1.1
Warning: package 'stringr' was built under R version 4.1.1
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ purrr     1.0.1     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::combine() masks gridExtra::combine()
✖ tidyr::expand()  masks Matrix::expand()
✖ dplyr::filter()  masks stats::filter()
✖ dplyr::lag()     masks stats::lag()
✖ tidyr::pack()    masks Matrix::pack()
✖ tidyr::unpack()  masks Matrix::unpack()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

Practical Part 2: Load the data

Practical Task 2 – Read in the data file we will be using

The data file is called:

  • BAFACALO_DATASET.RData

Use the load() function to read the data files into R:

load("BAFACALO_DATASET.RData")

Get summary statistics to inspect what you have got.

summary(BAFACALO_DATASET)
 participant_id   scholarity_father scholarity_mother household_income
 Min.   :  1.00   Min.   :0.000     Min.   :0.000     Min.   :1.000   
 1st Qu.: 73.75   1st Qu.:1.000     1st Qu.:1.000     1st Qu.:1.000   
 Median :146.50   Median :2.000     Median :2.000     Median :2.000   
 Mean   :146.50   Mean   :1.838     Mean   :1.879     Mean   :1.663   
 3rd Qu.:219.25   3rd Qu.:2.000     3rd Qu.:3.000     3rd Qu.:2.000   
 Max.   :292.00   Max.   :3.000     Max.   :3.000     Max.   :3.000   
                  NA's   :20        NA's   :19        NA's   :19      
  class_number previous_school_type      sex              age       
 M11    : 21   Min.   :2            Min.   :0.0000   Min.   :14.00  
 M15    : 20   1st Qu.:2            1st Qu.:0.0000   1st Qu.:15.00  
 M14    : 19   Median :2            Median :1.0000   Median :16.00  
 M36    : 19   Mean   :2            Mean   :0.5348   Mean   :15.71  
 M18    : 18   3rd Qu.:2            3rd Qu.:1.0000   3rd Qu.:16.00  
 (Other):133   Max.   :2            Max.   :1.0000   Max.   :20.00  
 NA's   : 62   NA's   :62           NA's   :62       NA's   :83     
     VZi01            VZi02            VZi03            VZi04       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.9308   Mean   :0.9062   Mean   :0.8252   Mean   :0.9158  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :3        NA's   :4        NA's   :6        NA's   :7       
     VZi05            VZi06            VZi07            VZi08       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.8576   Mean   :0.9094   Mean   :0.5445   Mean   :0.8362  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :4        NA's   :5        NA's   :11       NA's   :5       
     VZi09            VZi10            VZi11            VZi12       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.8403   Mean   :0.9303   Mean   :0.8433   Mean   :0.9041  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :4        NA's   :5        NA's   :24       NA's   :21      
     VZi13            VZi14            VZi15            VZi16       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:1.0000   1st Qu.:1.0000  
 Median :0.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.4749   Mean   :0.5039   Mean   :0.8593   Mean   :0.9032  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :33       NA's   :38       NA's   :29       NA's   :44      
     VZi17            VZi18           VZi19            VZi20       
 Min.   :0.0000   Min.   :0.000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.0000   1st Qu.:1.000   1st Qu.:1.0000   1st Qu.:0.0000  
 Median :1.0000   Median :1.000   Median :1.0000   Median :1.0000  
 Mean   :0.7207   Mean   :0.902   Mean   :0.9422   Mean   :0.6911  
 3rd Qu.:1.0000   3rd Qu.:1.000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.000   Max.   :1.0000   Max.   :1.0000  
 NA's   :45       NA's   :47      NA's   :50       NA's   :46      
     VZi21            VZi22            VZi23            VZi24       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.7811   Mean   :0.9412   Mean   :0.7788   Mean   :0.9021  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :59       NA's   :54       NA's   :66       NA's   :57      
     VZi25            VZi26            VZi27            VZi28       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.9788   Mean   :0.8426   Mean   :0.7944   Mean   :0.9673  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :56       NA's   :76       NA's   :78       NA's   :78      
     VZi29            VZi30            CFi01            CFi02       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.8841   Mean   :0.8889   Mean   :0.8694   Mean   :0.9021  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :85       NA's   :76       NA's   :1        NA's   :6       
     CFi03            CFi04            CFi05            CFi06      
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:0.000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.000  
 Mean   :0.8905   Mean   :0.8298   Mean   :0.6629   Mean   :0.747  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.000  
 NA's   :9        NA's   :10       NA's   :28       NA's   :39     
     CFi07            CFi08            CFi09            CFi10       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.0000   1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.7234   Mean   :0.7696   Mean   :0.9072   Mean   :0.8397  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :57       NA's   :62       NA's   :1        NA's   :5       
     CFi11            CFi12            CFi13            CFi14       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.9537   Mean   :0.5933   Mean   :0.6877   Mean   :0.9733  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :11       NA's   :24       NA's   :23       NA's   :30      
     CFi15            CFi16            CFi17            CFi18       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.0000   1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.7406   Mean   :0.8455   Mean   :0.6926   Mean   :0.9683  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :53       NA's   :59       NA's   :9        NA's   :8       
     CFi19            CFi20            CFi21            CFi22       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:1.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.7782   Mean   :0.5927   Mean   :0.7546   Mean   :0.7683  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :17       NA's   :17       NA's   :23       NA's   :46      
     CFi23            CFi24            CFi25            CFi26       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:1.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.7956   Mean   :0.6453   Mean   :0.8662   Mean   :0.8794  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :67       NA's   :58       NA's   :8        NA's   :10      
     CFi27            CFi28            CFi29            CFi30      
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.000  
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:1.000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.000  
 Mean   :0.7319   Mean   :0.6444   Mean   :0.6279   Mean   :0.753  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.000  
 NA's   :16       NA's   :22       NA's   :34       NA's   :45     
     CFi31            CFi32            V1i01          V1i02       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.00   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:0.75   1st Qu.:0.0000  
 Median :1.0000   Median :1.0000   Median :1.00   Median :1.0000  
 Mean   :0.7902   Mean   :0.7061   Mean   :0.75   Mean   :0.6667  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.00   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.00   Max.   :1.0000  
 NA's   :68       NA's   :64                      NA's   :40      
     V1i03            V1i04            V1i05            V1i06       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:1.0000   1st Qu.:0.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.6329   Mean   :0.5548   Mean   :0.9821   Mean   :0.6667  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :85       NA's   :146      NA's   :13       NA's   :175     
     V1i07            V1i08            V1i09            V1i10      
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.000  
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.000  
 Median :1.0000   Median :0.0000   Median :0.0000   Median :1.000  
 Mean   :0.6371   Mean   :0.4663   Mean   :0.4351   Mean   :0.668  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.000  
 NA's   :168      NA's   :84       NA's   :138      NA's   :51     
     V1i11            V1i12            V1i13            V1i14      
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.000  
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:1.000  
 Median :0.0000   Median :0.0000   Median :0.0000   Median :1.000  
 Mean   :0.4675   Mean   :0.4074   Mean   :0.3582   Mean   :0.964  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.000  
 NA's   :138      NA's   :130      NA's   :225      NA's   :14     
     V1i15            V1i16            V1i17           V1i18      
 Min.   :0.0000   Min.   :0.0000   Min.   :0.000   Min.   :0.000  
 1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:1.000   1st Qu.:0.000  
 Median :1.0000   Median :0.0000   Median :1.000   Median :1.000  
 Mean   :0.9819   Mean   :0.3636   Mean   :0.799   Mean   :0.659  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.000   3rd Qu.:1.000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.000   Max.   :1.000  
 NA's   :15       NA's   :215      NA's   :88      NA's   :75     
     V1i19            V1i20            V1i21           V1i22       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:0.000   1st Qu.:0.0000  
 Median :1.0000   Median :0.0000   Median :0.000   Median :0.0000  
 Mean   :0.8473   Mean   :0.4466   Mean   :0.181   Mean   :0.0885  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:0.000   3rd Qu.:0.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.000   Max.   :1.0000  
 NA's   :17       NA's   :189      NA's   :187     NA's   :66      
     V1i23            V1i24           V2i01            V2i02       
 Min.   :0.0000   Min.   :0.000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.0000   1st Qu.:0.000   1st Qu.:0.0000   1st Qu.:0.0000  
 Median :1.0000   Median :1.000   Median :0.0000   Median :1.0000  
 Mean   :0.7012   Mean   :0.587   Mean   :0.4536   Mean   :0.7056  
 3rd Qu.:1.0000   3rd Qu.:1.000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.000   Max.   :1.0000   Max.   :1.0000  
 NA's   :118      NA's   :200     NA's   :109      NA's   :95      
     V2i03            V2i04            V2i05            V2i06      
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.000  
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.000  
 Median :1.0000   Median :0.0000   Median :0.0000   Median :0.000  
 Mean   :0.6078   Mean   :0.4796   Mean   :0.3387   Mean   :0.336  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.000  
 NA's   :60       NA's   :194      NA's   :230      NA's   :167    
     V2i07            V2i08            V2i09            V2i10       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.0000   1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:0.0000  
 Median :0.0000   Median :1.0000   Median :1.0000   Median :0.0000  
 Mean   :0.3333   Mean   :0.7644   Mean   :0.8122   Mean   :0.3735  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :166      NA's   :101      NA's   :63       NA's   :209     
     V2i11            V2i12            V2i13            V2i14       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000  
 Median :1.0000   Median :0.0000   Median :1.0000   Median :1.0000  
 Mean   :0.6455   Mean   :0.3617   Mean   :0.5645   Mean   :0.6035  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :103      NA's   :104      NA's   :168      NA's   :65      
     V2i15            V2i16            V2i17            V2i18       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:1.0000  
 Median :0.0000   Median :0.0000   Median :0.0000   Median :1.0000  
 Mean   :0.2807   Mean   :0.4789   Mean   :0.2206   Mean   :0.7716  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:0.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :178      NA's   :221      NA's   :224      NA's   :130     
     V3i01            V3i02            V3i03            V3i04       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.7717   Mean   :0.8007   Mean   :0.6917   Mean   :0.8783  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :16       NA's   :6        NA's   :39       NA's   :29      
     V3i05            V3i06            V3i07            V3i08       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000  
 Median :1.0000   Median :1.0000   Median :0.0000   Median :0.0000  
 Mean   :0.6637   Mean   :0.7143   Mean   :0.4083   Mean   :0.3417  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :69       NA's   :110      NA's   :172      NA's   :172     
     V3i09            V3i10            V3i11            V3i12       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:1.0000  
 Median :0.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.1497   Mean   :0.5728   Mean   :0.6528   Mean   :0.8421  
 3rd Qu.:0.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :145      NA's   :189      NA's   :76       NA's   :64      
     V3i13            V3i14            V3i15            V3i16       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.0000   1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:0.0000  
 Median :0.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.2333   Mean   :0.8537   Mean   :0.6475   Mean   :0.5361  
 3rd Qu.:0.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :172      NA's   :169      NA's   :153      NA's   :29      
     V3i17            V3i18            MA1i01          MA1i02      
 Min.   :0.0000   Min.   :0.0000   Min.   :0.000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:1.000   1st Qu.:0.0000  
 Median :1.0000   Median :1.0000   Median :1.000   Median :1.0000  
 Mean   :0.8112   Mean   :0.5151   Mean   :0.766   Mean   :0.7143  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.000   Max.   :1.0000  
 NA's   :43       NA's   :94       NA's   :104     NA's   :117     
     MA1i03           MA1i04           MA1i05           MA1i06      
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.0000   1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:0.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.7299   Mean   :0.7989   Mean   :0.7333   Mean   :0.6835  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :118      NA's   :103      NA's   :142      NA's   :134     
     MA1i07           MA1i08           MA1i09         MA1i10      
 Min.   :0.0000   Min.   :0.0000   Min.   :0.00   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.00   1st Qu.:0.0000  
 Median :1.0000   Median :1.0000   Median :1.00   Median :1.0000  
 Mean   :0.8133   Mean   :0.8589   Mean   :0.85   Mean   :0.6835  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.00   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.00   Max.   :1.0000  
 NA's   :142      NA's   :51       NA's   :92     NA's   :153     
     MA1i11          MA1i12           MA1i13           MA1i14      
 Min.   :0.000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.000   1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:0.0000  
 Median :1.000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.698   Mean   :0.9123   Mean   :0.8664   Mean   :0.7321  
 3rd Qu.:1.000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :143     NA's   :64       NA's   :60       NA's   :124     
     MA1i15           MA2i01           MA2i02          MA2i03    
 Min.   :0.0000   Min.   :0.0000   Min.   :0.000   Min.   :0.00  
 1st Qu.:0.0000   1st Qu.:1.0000   1st Qu.:1.000   1st Qu.:1.00  
 Median :1.0000   Median :1.0000   Median :1.000   Median :1.00  
 Mean   :0.7429   Mean   :0.8374   Mean   :0.934   Mean   :0.88  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.000   3rd Qu.:1.00  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.000   Max.   :1.00  
 NA's   :117      NA's   :126      NA's   :80      NA's   :167   
     MA2i04           MA2i05           MA2i06           MA2i07      
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.9118   Mean   :0.8705   Mean   :0.8919   Mean   :0.9264  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :122      NA's   :153      NA's   :144      NA's   :129     
     MA2i08           MA2i09           MA2i10          MVi01       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :1.000   Median :1.0000  
 Mean   :0.9522   Mean   :0.8676   Mean   :0.872   Mean   :0.9084  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.000   Max.   :1.0000  
 NA's   :83       NA's   :141      NA's   :128     NA's   :19      
     MViO2            MViO3            MVi02            MViO4      
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.000  
 Mean   :0.8851   Mean   :0.9137   Mean   :0.8881   Mean   :0.876  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.000  
 NA's   :31       NA's   :14       NA's   :24       NA's   :34     
     MViO5            MVi03            MViO6            MViO7      
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.000  
 Mean   :0.9504   Mean   :0.8606   Mean   :0.9825   Mean   :0.875  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.000  
 NA's   :10       NA's   :41       NA's   :6        NA's   :20     
     MVi04            MViO8            MViO9            RGi01       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.8705   Mean   :0.8476   Mean   :0.8835   Mean   :0.7845  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :14       NA's   :23       NA's   :26       NA's   :9       
     RGi02            RGi03            RGi04            RGi05       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:0.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.8143   Mean   :0.8185   Mean   :0.6392   Mean   :0.6875  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :12       NA's   :11       NA's   :37       NA's   :68      
     RGi06            RGi07           RGi08            RGi09       
 Min.   :0.0000   Min.   :0.000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:0.000   1st Qu.:1.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.000   Median :1.0000   Median :1.0000  
 Mean   :0.7579   Mean   :0.628   Mean   :0.8389   Mean   :0.8544  
 3rd Qu.:1.0000   3rd Qu.:1.000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.000   Max.   :1.0000   Max.   :1.0000  
 NA's   :69       NA's   :85      NA's   :81       NA's   :86      
     RGi10           RGi11            RGi12            RGi13       
 Min.   :0.000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.500   1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:0.0000  
 Median :1.000   Median :1.0000   Median :1.0000   Median :0.0000  
 Mean   :0.748   Mean   :0.8261   Mean   :0.7027   Mean   :0.4324  
 3rd Qu.:1.000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :169     NA's   :154      NA's   :181      NA's   :255     
     RGi14            RGi15         RLi01            RLi02       
 Min.   :0.0000   Min.   :0.0   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:1.0   1st Qu.:1.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0   Median :1.0000   Median :1.0000  
 Mean   :0.9474   Mean   :0.8   Mean   :0.8897   Mean   :0.8828  
 3rd Qu.:1.0000   3rd Qu.:1.0   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0   Max.   :1.0000   Max.   :1.0000  
 NA's   :197      NA's   :222   NA's   :2        NA's   :2       
     RLi03            RLi04            RLi05            RLi06       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :0.0000   Median :1.0000  
 Mean   :0.8625   Mean   :0.6862   Mean   :0.4688   Mean   :0.8815  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :1        NA's   :2        NA's   :4        NA's   :5       
     RLi07            RLi08            RLi09            RLi10       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:1.0000   1st Qu.:0.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.7042   Mean   :0.7163   Mean   :0.8505   Mean   :0.6725  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :8        NA's   :10       NA's   :11       NA's   :8       
     RLi11            RLi12            RLi13            RLi14       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000  
 Median :1.0000   Median :0.0000   Median :1.0000   Median :0.0000  
 Mean   :0.6559   Mean   :0.4562   Mean   :0.6277   Mean   :0.2321  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:0.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :13       NA's   :18       NA's   :10       NA's   :12      
     RLi15            RLi16            RLi17            RLi18       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.0000   1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :0.0000   Median :1.0000  
 Mean   :0.6431   Mean   :0.9381   Mean   :0.2962   Mean   :0.8676  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :9        NA's   :1        NA's   :5        NA's   :5       
     RLi19           RLi20           RLi21            RLi22       
 Min.   :0.000   Min.   :0.000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:0.000   1st Qu.:0.000   1st Qu.:0.0000   1st Qu.:0.0000  
 Median :1.000   Median :0.000   Median :1.0000   Median :0.0000  
 Mean   :0.617   Mean   :0.259   Mean   :0.7367   Mean   :0.4488  
 3rd Qu.:1.000   3rd Qu.:1.000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.000   Max.   :1.000   Max.   :1.0000   Max.   :1.0000  
 NA's   :10      NA's   :14      NA's   :11       NA's   :9       
     RLi23            RLi24            RLi25            RLi26       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000  
 Median :1.0000   Median :1.0000   Median :0.0000   Median :0.0000  
 Mean   :0.8269   Mean   :0.5632   Mean   :0.3885   Mean   :0.3971  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :9        NA's   :15       NA's   :14       NA's   :15      
     RLi27            RLi28            RLi29            RLi30       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.8885   Mean   :0.7201   Mean   :0.7426   Mean   :0.6527  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :14       NA's   :24       NA's   :20       NA's   :30      
      Ii01             Ii02             Ii03             Ii04       
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.9618   Mean   :0.8635   Mean   :0.7658   Mean   :0.8561  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :4        NA's   :43       NA's   :23       NA's   :21      
      Ii05             Ii06             Ii07             Ii08      
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.000  
 1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:1.0000   1st Qu.:0.000  
 Median :1.0000   Median :1.0000   Median :1.0000   Median :1.000  
 Mean   :0.7961   Mean   :0.8352   Mean   :0.9299   Mean   :0.737  
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.000  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.000  
 NA's   :37       NA's   :31       NA's   :21       NA's   :41     
      Ii09            Ii10             Ii11             Ii12       
 Min.   :0.000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000  
 1st Qu.:1.000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000  
 Median :1.000   Median :1.0000   Median :1.0000   Median :1.0000  
 Mean   :0.786   Mean   :0.6161   Mean   :0.6284   Mean   :0.5353  
 3rd Qu.:1.000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000  
 Max.   :1.000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000  
 NA's   :35      NA's   :68       NA's   :74       NA's   :122     
      Ii13             Ii14             Ii15              N        
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :13.00  
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:27.00  
 Median :0.0000   Median :0.0000   Median :0.0000   Median :32.00  
 Mean   :0.2229   Mean   :0.4938   Mean   :0.4724   Mean   :31.59  
 3rd Qu.:0.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:36.00  
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :58.00  
 NA's   :126      NA's   :130      NA's   :165      NA's   :62     
       P1             P2              P3           FI1             FI2        
 Min.   : 6.0   Min.   : 3.00   48     : 14   Min.   : 0.00   Min.   : 1.000  
 1st Qu.:22.0   1st Qu.:17.00   42     : 12   1st Qu.: 9.00   1st Qu.: 7.000  
 Median :26.5   Median :19.00   32     : 11   Median :12.00   Median : 9.000  
 Mean   :27.6   Mean   :19.36   40     : 10   Mean   :12.85   Mean   : 9.461  
 3rd Qu.:33.0   3rd Qu.:22.00   39     :  9   3rd Qu.:15.00   3rd Qu.:12.000  
 Max.   :50.0   Max.   :32.00   (Other):174   Max.   :38.00   Max.   :22.000  
 NA's   :62     NA's   :62      NA's   : 62   NA's   :62      NA's   :62      
       FF           portuguese     english         math        biology   
 Min.   : 2.000   60     : 10   100    : 17   60     : 13   80     : 15  
 1st Qu.: 6.000   76     :  9   79     : 11   69     :  9   60     : 13  
 Median : 8.000   65     :  8   96     :  8   70     :  9   70     : 10  
 Mean   : 9.061   73     :  8   81     :  7   62     :  8   68.5   :  4  
 3rd Qu.:11.750   74     :  7   89     :  7   71     :  7   75     :  4  
 Max.   :20.000   (Other):188   (Other):180   (Other):184   (Other):184  
 NA's   :62       NA's   : 62   NA's   : 62   NA's   : 62   NA's   : 62  
    physics      chimestry     geography      history   
 60     : 16   79.9   :  3   60     :  7   87     :  5  
 60.1   :  5   84.1   :  3   63.5   :  5   88.5   :  4  
 0      :  4   85     :  3   66     :  5   71     :  3  
 61.8   :  4   85.6   :  3   0      :  3   75.5   :  3  
 66     :  4   89     :  3   64     :  3   79.5   :  3  
 (Other):197   (Other):215   (Other): 98   (Other): 91  
 NA's   : 62   NA's   : 62   NA's   :171   NA's   :183  

Practical Part 3: Tidy the data

Practical Task 3 – Tidy the data

Tidying the data involves a number of tasks, some essential and some things we do for our convenience.

We start by selecting the variables we want:

  • class_number, participant_id, portuguese, english, math, physics
  • We use the {dplyr} function select() to pick just the variables needed.
  • We create a new data-set (call it what you like), from the original, to hold just the selection of variables we want to use in the analysis steps, following.
brazil <- BAFACALO_DATASET %>%
                              select(
                              class_number, participant_id,
                              portuguese, english, math, physics
                              )

Pract.Q.1. Do you know what you are doing with select()? Can you select a different set of variables?

Pract.A.1. You can exercise your skill by checking that you can view the BAFACALO_DATASET and select any variable you like. Be careful and make sure you go back to select the variables shown in the given code chunk: we will need them later.

Practical Task 4 – Take missing values out of the brazil data

There are several rows in the data-set with missing values. You need to remove these from the data before you get started with any calculations.

brazil <- na.omit(brazil)

What have you got?

You should always check the results of a tidying operation, to make sure that what you have got matches what you expected to get.

summary(brazil)
  class_number participant_id    portuguese     english         math    
 M11    : 21   Min.   :  3.0   60     : 10   100    : 17   60     : 13  
 M15    : 20   1st Qu.: 77.5   76     :  9   79     : 11   69     :  9  
 M14    : 19   Median :144.5   65     :  8   96     :  8   70     :  9  
 M36    : 19   Mean   :146.6   73     :  8   81     :  7   62     :  8  
 M18    : 18   3rd Qu.:222.8   74     :  7   89     :  7   71     :  7  
 M21    : 17   Max.   :291.0   82     :  7   86     :  6   66     :  6  
 (Other):116                   (Other):181   (Other):174   (Other):178  
    physics   
 60     : 16  
 60.1   :  5  
 0      :  4  
 61.8   :  4  
 66     :  4  
 74.2   :  4  
 (Other):193  

Pract.Q.2. Do you see the difference between the summary of the brazil data shown before and after you run na.omit()? What is it?

Pract.A.2. You should see that NAs are listed in some columns in the data before but not after you run na.omit().

Practical Task 5 – Get R to treat a variable as a type object of the kind required – using the as.numeric() or as.factor() functions
brazil$portuguese <- as.numeric(brazil$portuguese)
brazil$english <- as.numeric(brazil$english)
brazil$math <- as.numeric(brazil$math)
brazil$physics <- as.numeric(brazil$physics)

brazil$class_number <- as.factor(brazil$class_number)
brazil$participant_id <- as.factor(brazil$participant_id)

What have you got?

summary(brazil)
  class_number participant_id   portuguese       english           math       
 M11    : 21   3      :  1    Min.   : 1.00   Min.   : 1.00   Min.   :  1.00  
 M15    : 20   4      :  1    1st Qu.:26.25   1st Qu.:29.00   1st Qu.: 39.00  
 M14    : 19   5      :  1    Median :42.00   Median :55.00   Median : 58.00  
 M36    : 19   6      :  1    Mean   :43.55   Mean   :50.25   Mean   : 58.17  
 M18    : 18   7      :  1    3rd Qu.:58.75   3rd Qu.:73.00   3rd Qu.: 79.75  
 M21    : 17   9      :  1    Max.   :83.00   Max.   :93.00   Max.   :104.00  
 (Other):116   (Other):224                                                    
    physics      
 Min.   :  1.00  
 1st Qu.: 34.00  
 Median : 71.50  
 Mean   : 71.57  
 3rd Qu.:107.75  
 Max.   :148.00  
                 

Pract.Q.3. Do you see the difference between the summary of the brazil data shown before and after you run as.numeric() or as.factor() function lines? What is it?

Pract.A.3. You should see that numeric variables like portuguese are listed with summary statistics like the mean after but not before you coerce the variables.

Practical Task 6 – Exercise – experiment with coercion
  1. Test out variable type using the is...() function for some of the variables
  2. Test out coercion – and its results – using the as...() function for some of the variables
  3. Look at the results using summary()

Practical Part 4: Visualize the relationship

Here, we are interested in the relationship between school grades, for the sample of Brazilian children for whom we have data.

  • What is the relationship between portuguese and english grades?
Practical Task 7 – Visualize the relationship between portuguese and english grades using a scatterplot

This should be a revision exercise for you.

  • Do you notice any changes in the way in which the plotting code is laid out?
brazil %>%
  ggplot(aes(x = portuguese, y = english)) +
  geom_point(colour = "black", size = 2.5, alpha = .5) +
  geom_smooth(method = "lm", size = 1.5, se = FALSE, colour = "red") +
  xlab("Portuguese") + ylab("English") + theme_bw() 
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
`geom_smooth()` using formula = 'y ~ x'

Practical Task 8 – Exercise – edit plots
  1. Change the x and y variables to math and physics
  2. Change the theme from theme_bw() to something different
  3. Change the appearance of the points, try different colour, shape, size

Use the ggplot reference documentation to help you make choices:

You should be using webpages like the reference page often in your work.

Practical Part 5: Visualize the relationship

We move next to analyzing the relationship between variation in grades in different subjects, across the children in our sample.

Practical Task 9 – Analyze the relationship between english and portuguese grades in the brazil data

You should be able to reproduce the results shown in the slides and the book chapter.

summary(lm(english ~ portuguese, data = brazil))

Call:
lm(formula = english ~ portuguese, data = brazil)

Residuals:
    Min      1Q  Median      3Q     Max 
-64.909 -17.573   2.782  20.042  53.292 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 29.77780    3.81426   7.807 2.11e-13 ***
portuguese   0.47001    0.07897   5.952 9.91e-09 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 25.02 on 228 degrees of freedom
Multiple R-squared:  0.1345,    Adjusted R-squared:  0.1307 
F-statistic: 35.43 on 1 and 228 DF,  p-value: 9.906e-09
Practical Task 10 – Exercise – adapt the lm() code to do a different analysis

Change the outcome and predictor variables to math and physics.

summary(lm(physics ~ math, data = brazil))

Call:
lm(formula = physics ~ math, data = brazil)

Residuals:
    Min      1Q  Median      3Q     Max 
-70.360 -14.265   0.437  14.797  78.784 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -1.83703    3.71858  -0.494    0.622    
math         1.26202    0.05795  21.777   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 23.81 on 228 degrees of freedom
Multiple R-squared:  0.6753,    Adjusted R-squared:  0.6739 
F-statistic: 474.2 on 1 and 228 DF,  p-value: < 2.2e-16

Pract.Q.4. What is the estimated coefficient of the “effect” of math ability (grade) on physics grade?

Pract.A.4. The summary shows that physics grades are on average 1.3 higher for unit increase in math grade.

Pract.Q.5. Draw a scatterplot showing the relationship between math and physics grades. Does the trend you see in the plot reflect the coefficient you see in the linear model summary?

Pract.A.5. The plot shows the positive association between math and physics grade also indicated by the estimated coefficient of the math effect.

brazil %>%
  ggplot(aes(x = math, y = physics)) +
  geom_point(colour = "black", size = 2.5, alpha = .5) +
  geom_smooth(method = "lm", size = 1.5, se = FALSE, colour = "red") +
  theme_bw() 
`geom_smooth()` using formula = 'y ~ x'

Pract.Q.6. How does the strength of the math-physics relationship compare with the english-portuguese relationship?

Pract.A.6. Both the linear model and the plots indicate that the math-physics relationship is much stronger.

Practical Part 6: Visualize the relationship for each class

Practical Task 11 – Plot the relationship between english and portuguese grades separately for each class using facet_wrap()
ggplot(data = brazil, aes(x = portuguese, y = english)) +
  geom_point(colour = "darkgrey") + 
  geom_smooth(method = "lm", se = FALSE, colour = "black") +
  xlab("Portuguese") + ylab("English") + theme_bw() +
  scale_x_continuous(breaks=c(25,50,75)) + scale_y_continuous(breaks=c(0,50,100)) +
  facet_wrap(~ class_number) 
`geom_smooth()` using formula = 'y ~ x'

Practical Task 12 – Exercises to practice your facet_wrap() skills
  1. Change the x and y variables to math and physics and draw a facetted scatterplot again
  2. Experiment with showing the differences between classes in a different way: instead of using facet_wrap(), in aes() add colour = class_number, and remove colour from geom_point and geom_smooth
ggplot(data = brazil, aes(x = math, y = physics)) +
  geom_point(colour = "darkgrey") + 
  geom_smooth(method = "lm", se = FALSE, colour = "black") +
  facet_wrap(~ class_number) 
`geom_smooth()` using formula = 'y ~ x'

ggplot(data = brazil, aes(x = math, y = physics, colour = class_number)) +
  geom_point() + geom_smooth(method = "lm", se = FALSE)
`geom_smooth()` using formula = 'y ~ x'

Pract.Q.8. Evaluate the consistency between classes of the relationship between math and physics grades: what do the plots show? how does this compare with what you see of the relationship between english and portuguese grades?

Pract.A.8. The plots show that the relationship between math and physics is very consistent between classes, and more consistent than the relationship between english and portuguese grades appears to be.

Practical Part 7: Mixed-effects analysis

Practical Task 13 – Run a linear mixed-effects analysis of the relationship between english and portuguese grades using lmer()

You should be able to replicate the results shown in the slides and the book chapter.

porto.lmer1 <- lmer(english ~ portuguese +
                      (portuguese + 1|class_number),
                      data = brazil)
summary(porto.lmer1)
Linear mixed model fit by REML ['lmerMod']
Formula: english ~ portuguese + (portuguese + 1 | class_number)
   Data: brazil

REML criterion at convergence: 2104.3

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-2.81321 -0.59584  0.04359  0.60018  2.23722 

Random effects:
 Groups       Name        Variance Std.Dev. Corr 
 class_number (Intercept) 341.4803 18.479        
              portuguese    0.3295  0.574   -0.98
 Residual                 493.1009 22.206        
Number of obs: 230, groups:  class_number, 18

Fixed effects:
            Estimate Std. Error t value
(Intercept)  25.2837     6.2669   4.034
portuguese    0.6590     0.1729   3.811

Correlation of Fixed Effects:
           (Intr)
portuguese -0.943
Practical Task 14 - Exercise mixed-effects model coding
  1. Vary the random effects part of the model, while keeping this bit the same: lmer(english ~ portuguese + ...)
  2. Change the random effect from (portuguese + 1 | class_number) to (1 | class_number): what you are doing is asking R to ignore the differences in the slope of the effect of Portuguese grades.
  3. Change the random effect from (portuguese + 1 | class_number) to (portuguese + 0 | class_number): what you are doing is asking R to ignore the differences in the intercept
porto.lmer1 <- lmer(english ~ portuguese +
                      (portuguese + 1|class_number),
                    data = brazil)
summary(porto.lmer1)
Linear mixed model fit by REML ['lmerMod']
Formula: english ~ portuguese + (portuguese + 1 | class_number)
   Data: brazil

REML criterion at convergence: 2104.3

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-2.81321 -0.59584  0.04359  0.60018  2.23722 

Random effects:
 Groups       Name        Variance Std.Dev. Corr 
 class_number (Intercept) 341.4803 18.479        
              portuguese    0.3295  0.574   -0.98
 Residual                 493.1009 22.206        
Number of obs: 230, groups:  class_number, 18

Fixed effects:
            Estimate Std. Error t value
(Intercept)  25.2837     6.2669   4.034
portuguese    0.6590     0.1729   3.811

Correlation of Fixed Effects:
           (Intr)
portuguese -0.943
#

porto.lmer2 <- lmer(english ~ portuguese +
                      (1|class_number),
                    data = brazil)
summary(porto.lmer2)
Linear mixed model fit by REML ['lmerMod']
Formula: english ~ portuguese + (1 | class_number)
   Data: brazil

REML criterion at convergence: 2129.2

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-2.55966 -0.68483  0.08471  0.77210  2.51034 

Random effects:
 Groups       Name        Variance Std.Dev.
 class_number (Intercept)  47.59    6.899  
 Residual                 588.91   24.267  
Number of obs: 230, groups:  class_number, 18

Fixed effects:
            Estimate Std. Error t value
(Intercept) 26.02493    4.60799   5.648
portuguese   0.55060    0.08995   6.121

Correlation of Fixed Effects:
           (Intr)
portuguese -0.856
#

porto.lmer3 <- lmer(english ~ portuguese +
                      (portuguese + 0|class_number),
                    data = brazil)
Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.00236563 (tol = 0.002, component 1)
summary(porto.lmer3)
Linear mixed model fit by REML ['lmerMod']
Formula: english ~ portuguese + (portuguese + 0 | class_number)
   Data: brazil

REML criterion at convergence: 2116.1

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-2.74726 -0.65271  0.03263  0.64709  2.71650 

Random effects:
 Groups       Name       Variance Std.Dev.
 class_number portuguese   0.053   0.2302 
 Residual                535.157  23.1335 
Number of obs: 230, groups:  class_number, 18

Fixed effects:
            Estimate Std. Error t value
(Intercept)  22.0168     4.0359   5.455
portuguese    0.6813     0.1087   6.266

Correlation of Fixed Effects:
           (Intr)
portuguese -0.778
optimizer (nloptwrap) convergence code: 0 (OK)
Model failed to converge with max|grad| = 0.00236563 (tol = 0.002, component 1)

Pract.Q.9. Compare the results of the different versions of the model. Can you identify where the results are different?

Pract.A.9. It can be seen that Rhe estimated effect of portuguese varies between the models but the estimate is more similar, around .65, where the random effect is specified as (portuguese + 1|class_number) or (portuguese + 0|class_number). The residual variance term is different between the models. Which random effects variances are shown is also different. There is a convergence warning for:

english ~ portuguese + (portuguese + 0 | class_number)

Practical Task 15 - Exercise mixed-effects model coding

Change the outcome (from english) and the predictor (from portuguese) – this is about changing the fixed effect part of the model.

  • Note that you will need to change the random effect part as well.
porto.lmer1 <- lmer(physics ~ math +
                      (math + 1|class_number),
                    data = brazil)
boundary (singular) fit: see help('isSingular')
summary(porto.lmer1)
Linear mixed model fit by REML ['lmerMod']
Formula: physics ~ math + (math + 1 | class_number)
   Data: brazil

REML criterion at convergence: 2066

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.9688 -0.5956  0.0461  0.6276  3.4865 

Random effects:
 Groups       Name        Variance  Std.Dev. Corr
 class_number (Intercept) 8.827e+01  9.39523     
              math        3.892e-03  0.06238 1.00
 Residual                 4.118e+02 20.29397     
Number of obs: 230, groups:  class_number, 18

Fixed effects:
            Estimate Std. Error t value
(Intercept)  1.46514    4.10294   0.357
math         1.19196    0.05564  21.423

Correlation of Fixed Effects:
     (Intr)
math -0.570
optimizer (nloptwrap) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')

Pract.Q.10. What elements of the model summary stand out for you? It will help to see what you should notice if you compare the math-physics model with the first english-portuguese model.

Pract.A.10. You may notice that:

  • The summary comes with a fit is singular? warning.
  • The variance terms for intercept or the math effect by class number and the residual are very very small: much smaller than for the english-portuguese model.

Practical Part 8: Extension

Practical Task Optional

In the lecture materials, I display a plot showing the estimated intercept and coefficient for each class, estimated using separate models for different classes.

  • Some of you may be interested in how I did that, you can run the following code to see.
  1. Use the {dplyr} %>% syntax to run a model for each class separately, collect together the results into a dataframe.
brazlm <- brazil %>% group_by(class_number) %>% do(tidy(lm(english ~ portuguese, data=.)))
brazlm$term <- as.factor(brazlm$term)
  1. Extract the per-class estimates of the intercepts and the ‘portuguese’ effect coefficient estimates.
brazlmint <- filter(brazlm, term == '(Intercept)')
brazlmport <- filter(brazlm, term == 'portuguese')
  1. Plot the estimates.
pbrazlmint <- ggplot(brazlmint, aes(x = class_number, y = estimate, ymin = estimate - std.error, ymax = estimate + std.error))
pbrazlmint <- pbrazlmint + geom_point(size = 2) + geom_linerange() + theme_bw() 
pbrazlmint <- pbrazlmint + ggtitle("Intercept") + ylab("Estimated coefficient +/- SE") + xlab("Class")
pbrazlmint <- pbrazlmint + theme(axis.title.y = element_text(size = 10), axis.text.x = element_blank(), panel.grid = element_blank())
# pbrazlmint

pbrazlmport <- ggplot(brazlmport, aes(x = class_number, y = estimate, ymin = estimate - std.error, ymax = estimate + std.error))
pbrazlmport <- pbrazlmport + geom_point(size = 2) + geom_linerange() + theme_bw() 
pbrazlmport <- pbrazlmport + ggtitle("Portuguese effect") + ylab("Estimated coefficient +/- SE") + xlab("Class")
pbrazlmport <- pbrazlmport + theme(axis.title.y = element_text(size = 10), axis.text.x = element_blank(), panel.grid = element_blank())
# pbrazlmport

# -- ask R to make a grid:

grid.arrange(pbrazlmint, pbrazlmport,
             ncol = 2)
Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_segment()`).
Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_segment()`).

Challenge: Can you change the code to show the estimates for the relationship between physics and math grades?

The answers

After the practical class, we will reveal the answers that are currently hidden.

The answers version of the webpage will present my answers for questions, and some extra information where that is helpful.

Back to top

References

Golino, H., & Gomes, C. (2014). Psychology data from the BAFACALO project: The Brazilian Intelligence Battery based on two state-of-the-art models Carrolls Model and the CHC model. Journal of Open Psychology Data, 2(1), e6. https://doi.org/10.5334/jopd.af