Introduction.

This is a worksheet for use with Lecture 10.

You have a video of me narrating these slides. Note that there are potentially minor discrepancies between the current set of slides and the one in the video. The slide numbers refer to the current set. I do not cover every single slide but you can code along!

If you answer correctly the colour of the box will change from red dashed to full blue! (Don't worry about bonus questions, they are very much just that: a bonus!)

Slides

Simpson's paradox / Ecological Fallacy (atomistic fallacy). (Slide 9)

A famous example of Simpson's Paradox comes from admission data to a University: UC

Use your search skills in scholar google to find this information.

Reasons to opt for multilevel models. (Slide 11)

Click the link with 'country' and have a look at the paper.

Read the section on cross-level interactions (p. 416). Complete the following:

The section covers an example with consumption and per capita.

Contrary to the country level data, , a poorer region, consumed more meat on average than Flanders, an affluent region.

Assumptions (Slide 13)

Please complete the following:

  • There were assumptions with OLS regression.

  • The Durbin-Watson test can be used to test the assumption of .

  • The graph below illustrates .

Go back over the slides for regression, week 4.

Multilevel model. (lme4) (Slide 18)

In order to avoid confusion this is now called 'Exam' (data<- stores it elsewhere, but it was still called as the package was loaded).

Summary (Slide 19)

There were pupils from schools.

nlme. (Slide 21)

True or False.

The fixed estimate of the intercept is the same to the 3rd decimal regardless of using 'lme4' or 'nlme'.

Model random intercept + fixed effect. (Slide 23)

Run the code on the slides.

What is the t-value for the fixed effect? (2 decimals)

Model with random slope AND fixed effect. (Slide 34)

Run the code on the slides.

What it the t value for the fixed effect? (3 decimals)

Model. (Slide 36)

Run the code on the slides. You will require the lmerTest package to print p values.

What it the p value for the fixed effect of school average? (3 decimals)

Try it yourself (Slide 37-38)

Use the previous slides, try and complete the questions. Speak to your group members if you run into issues

Some diagnostic checks. (Slide 40)

True or False.

The residuals are normally distributed.

Bootstrap fixed effect. (Slide 47)

Note that the commands have changed between the video and the slides

Results. (Slide 48)

This will look different from the video as I have used print() now. Run the code from the previous slides.

What is the bootstrapped standard deviation for 'standLRT'? (3 decimals)

What is the bootstrapped mean for 'schavg'? (3 decimals)

What is the bootstrapped maximum for 'schavg'? (3 decimals)

Exercise (Slide 52)

Complete the exercise and submit via Blackboard!

Going further.

Session Info.

Thanks to Lisa DeBruine for the webex package. Please see general disclaimer.

sessionInfo()
## R version 4.3.2 (2023-10-31)
## Platform: aarch64-apple-darwin20 (64-bit)
## Running under: macOS Ventura 13.4
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib 
## LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## time zone: Europe/London
## tzcode source: internal
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] webexercises_1.1.0
## 
## loaded via a namespace (and not attached):
##  [1] digest_0.6.35     R6_2.5.1          fastmap_1.1.1     xfun_0.43        
##  [5] cachem_1.0.8      knitr_1.45        htmltools_0.5.8.1 rmarkdown_2.26   
##  [9] lifecycle_1.0.4   cli_3.6.2         sass_0.4.9        jquerylib_0.1.4  
## [13] compiler_4.3.2    highr_0.10        rstudioapi_0.16.0 tools_4.3.2      
## [17] evaluate_0.23     bslib_0.7.0       yaml_2.3.8        jsonlite_1.8.8   
## [21] rlang_1.1.3

The end...