Multilevel Analysis/Hierarchical Linear Modeling
Edpsych/Psych/Stat 587
C.J. Anderson
Fall 2017
Last revised: Decmeber 12, 2017
General Information
Announcements
Course Resources (computing mostly)
Lecture notes
Computer Lab
Homework
Examples of Papers that Use Multilevel Models
Example analyses
Handy program and links
Questions or problems regarding this site should be sent to
cja@illinois.edu.
General Information :
Announcements:
 Dec 12:
 All answer keys are posted
 Nov 16:
 Last homework (#6) is posted
 Nov 16:
 Next lab will be Tuesday November 28. This will cover graphics.
 A new example with time varying coviariates added under lecture on longitudinal data. It uses SAS and
if I get a chance will add it to the notes and some R code for it. Regardless we will go over this in
class.
 Notes on longitudinal data analysis and logistic regression are updated, but I may still make some minor
changes.
 Nov 7:
 Due date for homework 5 extended to Tuesday Nov 14
 Updated project description is below.
 Final exam and data are posted. You get to pick among 4 possible data sets.
 Nov 2:
 SAS example created during lab 3 is now posted. I added comments the help to explain what is done in
by different sections of code.
 R: I have made progress in making the functions robust and hlmRsq easier to use and more stable...I might
not finish this until after the semester if over, but check back if you need them in the future.
 Oct 31:
 Revised compute lab instructions for R is linked below.
 R code that does most of part 18 of the lab instructions is linked below.
 Link to robust function fixed under computer lab 3 for R.
 SAS example created during lab 3 will be posted tomorrow.
 Links to homework 5 on the course website were corrected.
 Oct 30:
 Next computer lab is Tuesday October 31. R Materials and homework 5 are posted below.
 Oct 24:
 Next computer lab is Tuesday October 31. SAS Materials and homework 5 are posted below...I'm still working on the R ones.
 Oct 23:
 R code for lectures on random effects are now posted, which includes plotting them and simulation study.
 Updated notes and R for lecture on random effects
 Oct 12:
 Because exact numerical results differ between SAS and R, separate answer keys for SAS and R for homework 3 are now posted, as well as corrections to two AICs.
 Oct 11:
 R homework assignment posted with correction to coding of hours TV.
 Oct 10:
 SAS and R code from lab 2 last week are posted below
 Oct 3:
 Lab instructionsfor Thrusday Oct 5 are posted. SAS is at 9am and R is at 10:30am.
 Homework 4 is posted and due Thursday October 19th. Note that the assignment for SAS and R are different.
 Answer key for homework 3 is posted along with R and SAS code.
 New version of lecture notes on inference for fixed effects is posted
 Sept 28:
 More stable solution for SAS is at https://www.sas.com/en_us/software/universityedition.html. You can download SAS for free for educational purposes. It does not include a full suite of products, but has everything you need for class. A desciption of what is included is here
 Computer Lab 2 will be Thursday October 5th: 910:30 for the SAS group and 10:3011:50 for the R group. Bring a laptop ready to analyze data. Wes Crues will be our guest lab instructor, and Paige (course TA) will be there as well. Lab materials will be posted in the near future.
 Homework 3 is due today.
 Sept 26:
 Answer key to Homework 2 posted below
 Sept 19:
 SAS code created in lab is now posted below under computer lab 1.
 If you are struggling with R, the R code for random intercept notes might be helpful. This does everything that was in the lecture notes.
 Sept 14:
 R code that works for the newest version of R (9.4.1) and works in Rstudio is posted under computer lab 1.
 Sept 12:
 Homework 2 is posted below and is due Thursday Sept 14 in lab
 Computer Lab 1 will be Thurday Setp 14. If you are using SAS the lab is 9:00am10:30am and if you are using R the lab is 10:3012. Be sure to bring a laptop!
 Computer Lab instructions, data (for R), and associated homework are posted below.
 An R function, icc (file call R_icc.txt) is posted under computer lab 1.
 Aug 31:
 Homework 1 is posted below and is due Tuesday Sept 5 in lecture.
 Paige Sturley's office hours will be on Wednesday 11:00am1:00pm in rm 236C Education Bldg.
 Aug 29:
 Optional introduction to SAS will be Tuesday, Sept 5, 9:0010:00am in rm 22 Education. Bring laptop.
 Introducation lectues note online now have the graphs.
Course Resources (mostly Computer Software Notes) :
 Access to SAS: For those who want to use SAS (Statistical Analysis System), accounts on a university server that has SAS have been created for students enrolled in the course. Here is a
link to wiki with in instructions on how to logon to webstore server.
When you run the RDP (remote desktop program) application and it will run remote desktop application and set up configurations such that you will be able to directly open and save files from the remote server to your computer (and visa versa).
If you don't want to do these things, just use your remote desktop program and enter "remote2.webstore.illinois.edu".
There are 2 things that you need before you can do this:
 Your computer must be hooked up to the internet. If you access the internet via campus wireless, home, hotel, Espresso Royal, or elsewhere), you will need to use VPN (Virtual Private Networking) to securely connect to the campus internet.
 You must be registered for the class. If you recently registered, you may not yet have permission to login (let me know).
 To move files between the server and your laptop:
 For PC users, just "copy" and "paste" file to/from laptop and server.
 For MAC users, instructions are here and
a screen shot is here.
 Resources for R users:
 Resources for STATA users:
 Draft chapters on GLM, GLMM, and LLM (i.e., HLM).
Lectures Notes: (I update these throughout the semester)
 Introduction
SAS that generated (most of) the statistics and graphs in the lecture notes:
 Models for clustered data: Fixed and random effects ANOVA and multiple regression.
SAS and R code that reproduces the statistics, graphs, etc. in the lecture notes:
 Optional: Optional Introduction to SAS will be held rm 22 Education 910am on tba
 Random Intercept Models.
 SAS:
 ANCOVA.sas.
Fits ANCOVA model to NELS88, N=10 data (includes centering a variable, model
fitting using GLM, and SAS/GRAPH of model).
 hsb1.sas.
Creates SAS data set of level 1 data for the High School and Beyond data.
 hsb2.sas.
Creates SAS data set of level 2 data for the High School and Beyond data.
 hsball.sas.
Merges level 1 and level 2 high school and beyond sas datasets.
 betwithin.sas.
SAS/GRAPHS for looking between and within variability of SES in the high
school and beyond data.
 randomintercepts.sas.
SAS PROC MIXED and fitting random intercept models (includes centering SES)...and some graphics.
 R:
 For the NELS example, use R from note on previous lecture on models for clustered data.
 HSB1data.txt. Student level data
 HSB2data.txt. School level data
 R_hsb_rand_intercept.txt. R code that reproduces everything in lecture notes. You will need to change the "setwd" to where you put the data, and install packages lmer, lattice and lmerTest.
 SAS and R for HLM.
These will be described and used in lecture:
 SAS:
 This is from the introduction to SAS session:
 R:
 Random Intercept and Slopes Models .
 Estimation of Marginal Model.
 Statistical Inference: Marginal Model. (updated Fall 2017)
 SAS:
 R: (revised fall 2017)
 HSB1.txt Can use to try out functions.
 HSB2.txt Can use to try out functions.
 hsb.sas This SAS code can used to compare results of R and SAS.
 robust. This R code is a function that computes robust ("sandwiche") standard errors for fixed effects. Be sure to read comments at the top regarding use. I am still working on this function to make it easier to use and adding numerator degrees of freedom options (the residual df are fine, need to do more checking of between/within ones).
 hlmRsq. This R code is a function that takes results from lmer and computes R1sq and R2sq as described in Snijders, TAB, Bosker, RJ (1994). Modeled variance in twolevel models." Sociological Methods & Research, 22, 342363. This works for both random intercept and random intercept and slope models. Be sure to read comments at the top before use.
 contrast.txt This R code is a function does contrasts. It takes as input model and a vector/matrix of contrasts and computes both F and Wald test statistics.
 Illustrates some of things done in lecture (i.e., computing roubst se, computing R squares, and finding mixture pvalues).....Need to update with newer version(s) of functions
 Random Effects. (updated Fall 2017)
 Power and sample size:
 Xiaofeng Steven Liu (2014). Statistical Power Analysis for the Social and Behavioral Sciences: Basic and Advanced Techinques.
Routledge: NY. This book contains explanation of procedures and code for R, SAS and SPSS. If you search google scholar
 Optimal Design Software Program and documenation from Raudenbush group. (PC only)
 PINT Program and documentation from Snijders. (PC only)
 Google "Xiaofeng Liu power hlm", you will find some of his papers on power and HLM (I think he was a student of Raudenbush).
 SAS:
 R: (new fall 2017)
 Model Building.
 New SAS programs:
 R: (new fall 2016)
Longitudinal Data and HLM. Note that data in this lecture and next is from data from Hedeker website and website for Hedeker & Gibbons book on longitudinal data analysis.
Serial Correlation..
Computer Lab Sessions: Bring laptop
 Computer Lab Session 0 (optional): Introduction to SAS > Tuesday 9am, Aug 30, 3016
 Computer Lab Session 1: (bring laptop) > Thursday September 14, 2017
 Computer Lab Session 2: (bring laptop) > Thursday October 5, 2017 (SAS at 9am and R at 10:30am)
 Computer Lab Session 3: bring laptop. date: Tuesday October 31, 2017
 SAS:
 R:
 Computer Lab instructions. (revised)
 We will use data and programs from previous labs 1 and 2. For your convience, here is modified version for lab3.
 Data for computer lab 3
 R that does parts 1 through 8 of the lab instructions.
 robust. This R code is a function that computes robust ("sandwiche") standard errors for fixed effects. Be sure to read comments at the top regarding use. I am still working on this function to make it easier to use and adding numerator degrees of freedom options (the residual df are fine, need to do more checking of between/within ones).
 hlmRsq. This R code is a function that takes results from lmer and computes R1sq and R2sq as described in Snijders, TAB, Bosker, RJ (1994). Modeled variance in twolevel models." Sociological Methods & Research, 22, 342363. This works for both random intercept and random intercept and slope models. Be sure to read comments at the top before use.
 contrast.txt This R code is a function does contrasts. It takes as input model and a vector/matrix of contrasts and computes both F and Wald test statistics.
 R code to get answers.
 Computer Lab Session 4: Tuesday November 28, 2017
Homework
 Homwork 1:
 Homework 2:
 Homework 3:
 Homework 4: (due in lecture Thursday October 19, 2017)
 Homework 5: (due in lecture Thursday Nov 14, 2017)
 Homework 6: (Due in lectures Thursday Dec 7, 2017)
 Final Exam and Projects: Hardcopy is due 4:30 pm December 14th (offices are sometimes locked around 4:00pm).
Pentalty for late finals or projects is 10 points (out of 100 points) per weekday.
(e.g., turn in Friday, 10 point deduction; turn in Monday 20 point, etc).
Examples of Papers that Use Multilevel Models
 Payne, B.R., Gao, X., Noh, S.R., Anderson, C.J., StineMorrow, E.A.L. (2011). The effects of print
exposure on sentence processing and memory in older adulats: Evidence for efficiency and reserve. Aging, Neuropsychology, and Cognition.
Some examples of crossed random effects, skewed responses (i.e., reaction times), and discrete response (i.e., Poisson).
 Segerstrom, S.C. & Sephton, S.E. (2010). Optimistic expectanices and cellmediated immunity: The role
of positive affect. Psychological Science, 21, 448455.
Example of where cluster centered level one variable is substantive (theoretical) interest. The response variable is numerical/continuous.
 Allen, N.E., Todd, N.R., Anderson, C.J., Davis, S.M., Javdani, Bruehler, V., & Dorsey, H.
(2013). CouncilBased approaches to intimate partner violence: Evidence for distal change in system response. American Journal of Community
Psychology, 52, 112.
Example of a longitudinal study with creative centering of time. The response variable was a rate (probability).
 Poteat, V.P. & Anderson, C.J. (2012). Developmental changes in sexual prejudice from early to late
adolescence: The effects of gener, race, and ideology on different patterns of change. Developmental Psychology, 48, 14031415.
Example of an accelerated longitudinal design.
 SteenBaker, A.A., Ng, Shukhan, Payne, B.R., Anderson, C.J., Federmeier, K.D., & StineMorrow, E.A.L (2017). The effects of context on processing words during sentence reading among adults varying in age and literacy skills. Psychology and Aging, 32, 460472.
Example crossrandom effects in an study using eyetracking data. Data were skewed so first logtransformed and then used HLM (i.e., a lognormal model).
 Examples from Tom Snijders course webpage where multilevel models have been used. (click on "info course multilevel" on left and go to
bottom of page. These papers cover a range of topics (e.g., political science, sociology, school psychology, criminology, medicine, and others).
Example SAS Programs (ascii/text format):
Examples from Snijders & Bosker using SAS
 MLbook.sas.
Create SAS data for examples in Chapters 4 and 5.
 Ch4_examples.sas.
Example 2level analyses from Chapter 4 (random intercept models).
 Ch5_examples.sas.
Example 2level analyses from Chapter 5 (random intercept and
slopes).
 Ch12_examples.sas.
Examples analyses from Chapter 12 (longitudinal data analysis),
including creating sas dataset.
Examples from Chapter 4 of Kreft & de Leeuw (provided and written
by Carol Nickerson):

School23.sas.
SAS code that creates data set and fits models reported in Kreft &
de Leeuw.

school23.dat.
Raw data file that is used as input to school23.sas.
Handy Programs and Links:

Ones specific to multilevel modeling:

General ones:

CIforP.f:
A FORTRAN program that computes large sample confidence intervals for a
proportion.

pvalue.f:
A FORTRAN program that computes pvalues and (bonferroni) critical values
for the standard normal, chisquared, t, and F distributions (and for correlations).
For users of PC type computers,
pvalue.exe
is an executable (i.e. already compiled) program.