Multilevel Analysis/Hierarchical Linear Modeling
Edpsych/Psych/Stat 587
C.J. Anderson
Fall 2016
Last revised: September 22, 2016
General Information
Announcements
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 (MSword format):
Announcements:
 Sept 22: Next lab will the Thurday Sept 29th. R at 9:0010:30 and SAS at 10:3012:00.
 Sept 20: Wes's office hours for rest of semester: Wed 1:303:30, i224B Col. Wolf School, 403 East Healey (at corner of 4th & Healey) or if you would like a map http://ada.fs.illinois.edu/0167.html
 Sept 18: Homework #3 is due on THURSDAY Sept 22.
 Sept 12: updated notes on inference for marginal model.
 Sept 8: R script and SAS code posted below.
 Lab 1 materials for both SAS and R are posted below. IF you are using SAS, make sure that your can access it. If you are using R, make sure that it is installed on your computer (you may want to get the package lmerTest beforehand).
 Sept 1:
 Homework #2 is due in class on Tuesday, September 6. If you want to see me in office hours before
turning in the homework, may turn it in by 5pm to my mailbox on the 3rd floor of Education. Harcopy
is much prefered (email gets lost in my mailbox
 The first computer lab on random intercept models will be Thursday September 8th. Those using R should
attend the 9:0010:30 session and those using SAS should attend the 10:3012 session. Be sure to
bring you (charged) laptop and it is useful to down load materials ahead of time. These will be
posted in the near future.
 The wiki that was online has been fixed thanks to our trusty IT staff.
 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.
 Aug 30: Homework is due at the beginning of lecture. If you are sick then give it to a friend or email it to both
Wes and Carolyn.
 Aug 30: If you come to the lab session at 9am for an introduction to SAS, bring your laptop and put data file on
your remote desktop account (if using).
 Aug 25:
 Introduction to SAS will be Tuesday Sept 1, 910am in room 22 Education. Bring you laptop.
 The lab sessions when we have them will be 910:30 for R and 10:3012 for SAS and mostly likely
be on Thursdays.
 Aug 25: See below for the first homework assignement, which is due Tuesday August 30.
 Aug 24: Those who came to class but weren't registered and signed the attendence sheet can all register.
You have to send me your UIN and netid so that I can put in a request for an override.
 Draft chapters on GLM, GLMM, and LLM (i.e., HLM).
 Resources for R users:
 Computing: We will be running statistical software (SAS) using remote desktop to a university server. Here are the instructions:
remote desktop connection. Here is the file referred to in the instructions as an RDP file. 
Use "Save link as" when you download the RDP file and save it to a convient location (e.g., desktop).
When you run the RDP 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 eed
to use VPN (Virtual Private Networking) to securely connect to the campus internet.
 You must be registered for the class. If you reccently registered, you may not yet have permission to login yet.
Lectures Notes: (I am updating throughout the semester)
 Introduction ( updated Fall 2016).
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. updated Fall 2016
SAS and R code that reproduces the statistics, graphs, etc. in the lecture notes:
 Optional: Introduction to SAS to be held....Tuesday Aug 30, 9am in room 22 Education.
 Random Intercept Models. updated Fall 2016
 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: (New 2016)
 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 package lmer, lattice and lmerTest.
 SAS for HLM and a little R. Updated Fall 2016
These will be used in lecture (they can also be used to reproduce the models for HSB data in
the lecture notes on random intercept models):
 SAS:
 This is from the introduction to SAS session:
 R: See R code under Notes on Random Intercept Models
 Random Intercept and Slopes Models . (updated Fall 2016)
 Estimation of Marginal Model. (updated fall 2016)
 Statistical Inference: Marginal Model. (updated Fall 2016)
 SAS:
 R: (new fall 2016)
 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.
 HSB1.txt Needed for example at end of function.
 HSB2.txt Needed for example at end of function.
 hsb.sas This SAS code can used to compare results of R and SAS.
 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 work (I think) for both random intercept and random intercept and slope models. Be sure to read comments at the top before use.
 Illustrates some of things done in lecture (i.e., computing roubst se, computing R squares, and finding mixture pvalues).
 Random Effects.
 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: ( comming soon fall 2016)
 R code to go with this lecture
 Model Building.
 Longitudinal Data Analysis
 Multilevel Logistic Regression.
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 8, 2016
 Computer Lab Session 2: (bring laptop)
 Computer Lab Session 3: bring laptop.
 Computer Lab Session 4: bring laptop.
Homework
 Homwork 1:
 Homwork 2:
 Homwork 3:
 Homwork 4:
 Final Exam and Projects: Hardcopy is due 3:45pm Friday December 9th (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 Monday, 10 point deduction; turn in Tuesday 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.
 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.