# Ed Psych 587

Edpsych/Psych/Stat 587

C.J. Anderson

Spring 2018

*Last revised: November 7, 2018*

**Site under re-construction**

**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.

**Announcements:**

- Nov 7: I have started to re-construct this site. Work will be complete by the end of Spring semester.
- Software options and resources:
**SAS:**- You can obtain a free educational versions from SAS.com. Look for "SAS Software for Learning". There is a University Edition and an OnDemand version. The latter requires an internet connection but it also includes more procedures (e.g., GRAPH, ETS and OR). Alternatively, you can purchase a license from webstore.
- Introduction to SAS
- Introduction to SAS notes..
- hsb1.sas. Creates SAS data set of level 1 data for the High School and Beyond data.
- Using SAS assist for graphics.
- Slick online SAS training from SAS.com

**Resources for R users:**- Introduction to Multilevel Modeling in R by Grover, Guillermono and Hudson (2015). This document uses the high school and beyond data set to illustrate a lot about how to do data management, HLM models and analyses, and graphics. If you are using R, I highly recommend this.
- Doing scatter-plots with lattice.
- A Brief Introduction to R, the multilevel package and the nlme package by Paul Bliese (2016). This includes some introductory material on R and how to do multilevel modeling.
- Lecture notes by Kyle Roberts. I included these because there is a nice R code section

**Resources for STATA users:**- Slides on Bayesian estimation of multilevel models by Chuck Huber.
- do file.

**Draft chapters on GLM, GLMM, and LLM (i.e., HLM).**

**Lectures Notes: (I up-date these throughout the semester)**

**Introduction**- SAS:
- R:
- Will go here

**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:- SAS
- NELS data for 10 schools. Run this program before the next one.
- Generates statistics, fits models & produces graphics.

- R

- SAS
**Optional: Optional Introduction to SAS will be held rm 22 Education 9-10am on****tba**- Introduction to SAS notes..
- hsb1.sas. Creates SAS data set of level 1 data for the High School and Beyond data.
- Using SAS assist for graphics.
- Slick online SAS training from SAS.com

**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:
.**SAS and R for HLM**

These will be described and used in lecture:- SAS:
- HSB1 data. (level 1 data -- students)
- HSB2 data (level 2 data -- schools)
- SAS code to be discussed in lecture.
- Using SAS assist for graphics.

- This is from the introduction to SAS session:
- R:
- HSB1data.txt. Student level data
- HSB2data.txt. School level data
- The R code in the notes.

- SAS:
**Random Intercept and Slopes Models**.- SAS
- text file of data. NELS88 data for N=23 school.
- school23.sas. SAS program that creates SAS data set for NEL88 data for N=23 school.
- NELS23.sas. SAS program that fits various random intercept and slope models to the NEL88 data for N=23 school.
- Centering & NELS data. Illustrates effects of different kinds of centering -- NEL88 data for N=23 school.
- SAS examples discussed in lecture.

- R
- NELS23 data in txt format.
- R code for NELS for 23 schools. Including among other things, code for data manipulation, creating variables, doing some graphics, model fitting using lmer.
- Student level HSB data in txt format.
- School level HSB data in txt format.
- R code for HSB. Code for data manipulation, creating variables, doing some graphics, model fitting using lmer. Not all the graphics code is here, but the R code for Nels (23 schools) has examples of similar graphics.

**Estimation of Marginal Model**.- SAS: How to simulate HLM (in SAS).
- SAS: Simulation study on MLE vs REML and different N.
- SAS: For those who might want to use Bayesian estimation, I worked up a small example for the empty model, random intercept with one predictor, and a random intercept and slope model. I also included SAS PROC MIXED code if you want to compare results. You can change the seed to "-1" and run the mcmc code a few times and compare results.

R: R code for graphs illustrating MLE. (new fall 2016) **Statistical Inference: Marginal Model**.**(up-dated Fall 2017)**- SAS:
- SAS commands for ddfm (Simulation to show what different choices for df yield).
- HSB1 data. (level 1 data -- students)
- HSB2 data (level 2 data -- schools)
- hlmrsq.sas SAS macro that computes R_1^2 and R_2^2.
- Recchia JSS paper describing the hlmrsq.sas macro and how to use it.
- SAS for fixed effects & Rsq. Illustrates various things.
- Example: computing p-value of mixture of chi-squares (i.e., test of variance).

- 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 two-level models." Sociological Methods & Research, 22, 342-363. 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 p-values).....
**Need to up-date with newer version(s) of functions**

**Random Effects.**(up-dated 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:
- HSB1 data. (level 1 data -- students)
- HSB2 data (level 2 data -- schools)
- SAS program and EB estimates of U's.
- SAS commands for mini-study on micro sample size on U's.
- SAS commands for mini-study on macro sample size on estimates.
- SAS commands for mini-study on effects of non-normality onf the distribution of EB estimates.
- Using SAS/ASSIST to produce graphics. (Alternatives given in next lecture).

- R: (new fall 2017)
- High School and Beyond data. (level 1 and level 2 in one file).
- R that goes with lecture
- Function to simulate simple HLM with mixture of 2 normals for Uoj with examples. This also includes easier ways to plot histograms and qqplots of estimated random effects. The function can be modified to fit more complex models.

**Model Building.**- New SAS programs:
- NELS data for N=23 schools (from Kreft & de Leeuw).
- SAS Exploratory data analysis: Fixed Effects
- SAS Exploratory data analysis: Random Effects
- Modeling the data & diagnostics.
- Assessing homogeneity variance assumption (and modeling level 1 variance as random ).
You will need the high school and beyond data for this:
- HSB1 data. (level 1 data -- students)
- HSB2 data (level 2 data -- schools)

- Old SAS programs:
- eda.sas SAS program including commands for exploratory data analyses (SAS/GRAPH, R^2meta, R^2_j, means structure, etc).
- Simulations.sas. SAS program running first simulation and exploration of random structure.
- Simulation_long.sas. SAS program running second simulation and exploration of random structure. This has a different sigma^2's and tau's.
- New Variance EDA.sas. Exploratory data analyses of random structure for example given in class.
- SAS v9.1 experimental diagnostics..

- R: (new fall 2016)
- R code for graphics and more, including some tests, and some graphics not covered in lecture (described in lme4 mannual).
- nels data used by R code.

- New SAS programs:

**Longitudinal Data and HLM.**Note that data in this lecture and next is from data from Hedeker web-site and web-site for Hedeker & Gibbons book on longitudinal data analysis.

**Serial Correlation.**.

- SAS:
- Multilevel Logistic Regression. (up-dated 2017)
- SAS:
- Longitudinal study on depression. (data from Agresti, 2002)
- Longitudinal study on respiratory infections. (data from Skrondal & Rabe-Hesketh,2004)
- Simmulation study & demonstration.
- I will not be posting the Rodkin et al. data set or SAS code.
- Rasch and 2pl model fit to LSAT6.
- Rasch and 2pl model fit to General Social Suvery Vocabulary items with covariate.
- SAS for plotting item response curves for GSS data.

- R: (revised 2017)

- HSB1 data sas file (level 1 data -- students)
- Introduction to SAS notes..
- Using SAS assist for graphics.
- Slick online SAS training from SAS.com

- SAS:
- R:

- SAS:
- SAS program and data for Lab 2.
- Computer Lab instructions & description of data.
- Short program created during session .
- SAS program that does it all. (available after homework 4 turned in).

- R:
- lab2.txt. (data file, plain text)
- R lab2 template.txt.
- Computer Lab instructions & description of data. Typos fixed.
- Short R code created during session.
- R code that does it all. (txt file).

- SAS:
- Computer Lab instructions.
- We will use data and your programs from previous labs. If you don't have it handy, use SAS program that does it all.
- hlmrsq.sas SAS macro that computes R_1^2 and R_2^2.
- lab3 example SAS code created in lab to show how to do various procedures.
- SAS program for homework does everything in computer lab 3 instructions and homework5.

- 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 two-level models." Sociological Methods & Research, 22, 342-363. 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.

- SAS:
- Instructions that include some example graphs.
- SAS program needed for computer lab 4.
- Some SAS code for exploring preliminary random effects structure (if you want this, but it is NOT required for lab or homework)
- SAS created in lab. Posted Nov 10
- SAS code to get answers.

- R:
- R instructions for computer lab 4 with some example graphs.
- Data for computer lab 4, which is the same as what we used for lab 3.
- R code to get started.
- R code to get answers.

**Homework**

- -->
- Homwork 1:
- Homework 1 (Due Sept 5, 2017)
- Some example answers and other useful information.

- Homework 2:
- Homework 2 (Due Sept 14, 2017)
- Answer key.

- Homework 3:
- Homework 3 (Due Sept 28, 2107)
- SAS
- R

- Homework 4:
**(due in lecture Thursday October 19, 2017)**- SAS:
- R:

- Homework 5:
**(due in lecture Thursday Nov 14, 2017)**- SAS:
- Homework 5 for those using SAS. Thursday November 3, 2017
- Answer key for SAS users will go here.
- SAS code to get answers.

- R:
- Homework 5 for those using R. Thursday November 3, 2017
- Answer key for R users will go here.
- R code to get answers.

- SAS:
- Homework 6:
**(Due in lectures Thursday Dec 7, 2017)**- SAS:
- Homework 17 for those using SAS.
- Answer key for SAS users will go here. Note this is full answer key from 2016, including questions that you were not asked to answers.
- SAS code to get answers.

- R:
- Homework 6 for those using R. Due Thursday November 17, 2017.
- Answer key for R users will go here. Note this is full answer key from 2016, including questions that you were not asked to answers.
- R code to get answers.

- SAS:
(e.g., turn in Friday, 10 point deduction; turn in Monday 20 point, etc).**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.- Final Exam and data
- with SAS code to create data set:
- as plain txt file for R or other programs:

- What to include in a Final Project.

- Final Exam and data

-->

**Examples of Papers that Use Multilevel Models**

- Payne, B.R., Gao, X., Noh, S.R., Anderson, C.J., Stine-Morrow, 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 cell-mediated immunity: The role
of positive affect. Psychological Science, 21, 448-455.

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). Council-Based approaches to intimate partner violence: Evidence for distal change in system response. American Journal of Community
Psychology, 52, 1-12.

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, 1403-1415.

Example of an accelerated longitudinal design. - Steen-Baker, A.A., Ng, Shukhan, Payne, B.R., Anderson, C.J., Federmeier, K.D., & Stine-Morrow, 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, 460-472.

Example cross-random effects in an study using eye-tracking data. Data were skewed so first log-transformed and then used HLM (i.e., a log-normal model). - Examples from Tom Snijders course web-page 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 2-level analyses from Chapter 4 (random intercept models).**Ch5_examples.sas**. Example 2-level 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:****Centre for Multilevel Modelling.**This site includes trainting materials, publications, reviews of multilevel software, data sets, a BBC audio program featuring Harvey Goldstein, and more..**Tom Snijders' multilevel web-site.**This has data & various material that's used in Snijders & Bosker*An Introduction to Basic and Advanced Multilevel Modeling*as well as other multilevel stuff.**Scientific software international**home page. Student version of HLM program can be downloaded from this site.**NELS88 data**: various data sets used in Kreft & de Leeuw (Introducing heirarchical linear modeling)**Using SAS PROC MIXED to fit multilevel, heirarchical models, and individual growth models.**Downloadable paper by Judith Singer. Other papers also downloadable.