# Ed Psych 587

Edpsych/Psych/Stat 587

C.J. Anderson

Spring 2019

*Last revised: April 11, 2019*

**General Information**

**Announcements**

**Course Resources (computing mostly)**

**Lecture notes**

**Computer Lab**To R users, there is a correction to computer lab 2 and information about convergence posted below.

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

- April 5:
- Computer Lab 4 will be continued on Tuesday where
- SAS group 10:00-10:55am
- R group 10:55-11:50am

- SAS and R created in Lab 4 on Thursday at posted here and below:
- New due date for homework 6: Tuesday April 16
- Newer version of R computer lab 4 instructions posted (the same as what was distributed in lab on Thursday
- Link to data for R lab fixed....same as lab 3 data

- Computer Lab 4 will be continued on Tuesday where
- March 29:
- All lectures notes are posted (2 on longitudinal data and one on logistic regression
- R,SAS and answer keys for Homework 5 have been posted
- Materials for Lab 4 are posted.
- Lab 4 will be held Thursday April 4 and homework will be due 1 week later (Thursday April 11th).
- After turning in Homework 6, you should be working on your projects/finals if you have not already started them

- March 25: First set of notes on longitudinal data are posted.
- March 13: I have posted a description what you should report if you are doing a project. I have also posted a final "exam" and data, which is basically just a project but with data and questions that I provide. For the final, I have provide 4 options: Choose just one.
- March 12: The following are now posted:
- Answer keys for homework 4 are posted, as well as SAS and R scripts for lab 2.
- SAS and R scripts from today's lab are posted under "Computer Lab 3"
- SAS macro hlmRsq.sas works on my office and laptop computer, but only for random intercept & slope models. It is not working for random intercept models, but these are easy to compute.

- Feb 19: The following are now posted:
- Answer keys for homework 3. (For R there is a separate document with an up-dated summary table.)
- SAS and R to estimate the models from computer Lab 1.
- SAS and R developed in Lab2.

- Feb 14: Addendum to R Computer lab 2 and Homework 4.
- Feb 11: Computer lab 2 materials are posted along with homework #4.
- Feb 7: Change of due data for homework 3: Tue Feb 12.
- Jan 29: SAS and R done in lab are posted below (under computer lab 1).
- Jan 18: Homework assignment is posted below and is due Tuesday Jan 29.
- Jan 18: Last year's instructions on graphics are posted under computer lab 4.
- Nov 16: When we have computer labs, SAS will run 9:00 to 10:30am and R will run from 10:30=1:50am
- Nov 7: I have started to re-construct this site. Work will be complete by the end of Spring semester.
**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 obtain a lisence from webstore, which when I last checked (Jan 2, 2019) was $0.00, yes no cost. You can either borrow, download or purchase the program (media) from webstore. With the 2nd option, you should get more procedures and packages.
- 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:**- You can download (for free) R and Rstudio from the internet.
- 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).****Introduction****Models for clustered data: Fixed and random effects ANOVA and multiple regression.**- SAS
- NELS data for 10 schools. Run this program before the next one.
- Generates statistics, fits models & produces graphics.

- R

- SAS
**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.**Little R function that computes the ICC**.

- SAS
. These will be described and used in lecture:**SAS and R for HLM**- 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 (won't be covered):
- 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.

- 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:
- Graphs showling likeihood of normal distribution.
- 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
- R for simulating HLM data. New Spring 2019
- The brms package to fit multilevel model (i.e., Bayesian estimation) New Spring 2019 This example uses the nels23 data, which you can find on this web-site (e.g., under model building). In terms of specify the basic model, the model syntax is very similar to lmer.

- SAS:
**Statistical Inference: Marginal Model**.- 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.

- R:
- 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 betwee/within numerator degrees of freedom options (the residual df are fine, but between/within ones for cross-random effects are a bit "off" relative to SAS/MIXED).
- 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).

- SAS:
**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:
- 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 on the distribution of EB estimates.
- Using SAS/ASSIST to produce graphics. (Alternatives given in next lecture).

- R:
- 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.**- SAS programs:
- <
li>NELS data for N=23 schools (from Kreft & de Leeuw).
- SAS data set 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)

- R:
- 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.

- 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.- SAS:
- R:

**Serial Correlation.**.- Multilevel Logistic Regression.
- 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:
- Computer Lab Session 1: (bring laptop)
- Computer Lab Session 2: (bring laptop) Thursday Feb 14
- SAS:
- R:

- Computer Lab Session 3: bring laptop.
- 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.
- What we did in lab The sas macro hlmrsq.sas worked after lab but only for random intercept AND slope models (did not for models with only random intercept...all work on my office computer so mystery not totally solved).

- R:
- Computer Lab instructions.
- lab3 template. This reads in data, sets up variables, and run all models from labs 1 and 2.
- Data for computer lab 3
- 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. The between/within df for cross-level interactions may not (the residual df are fine).
- hlmRsq. This R code is a function that takes results from lmer and computes R1sq and R2sq as described in Snijders and 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.
- What we did in lab code is a function does contrasts.

- SAS:
- Computer Lab Session 4:
- SAS:
- sas program created in lecture..
- 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)

- R:
- R created in lab.
- R instructions for computer lab 4 with some example graphs.
- Data for computer lab 4 (same as lab 3)
- R code to get started.

- SAS:

**Computing and Other Resources**:

**Lecture Notes**: (Up-dated throughout the semester)

**Computer Lab Sessions: Bring laptop**

**Homework**

- Homework 1:
- Homework assignment 1 Due Tuesday, January 29, 2019.

- Homework 2:
- Homework 2 Due Thursday January 31, 2019
- Answer key.

- Homework 3:
- Homework 3 Due February 7, 2019
- SAS:
- R

- Homework 4:
- Homework 5:
- Homework 6: New due data: Tuesday April 16
- SAS:
- R:
(e.g., turn in Monday, 10 point deduction; turn in Tuesday 20 point, etc).**Final Exam and Projects**: Hardcopy is due**4:30 pm Friday May 3, 2019 (offices in Education are 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

--> (e.g., turn in Monday, 10 point deduction; turn in Tuesday 20 point, etc).**Final Exam and Projects**: Hardcopy is due**4:30 pm Friday May 3, 2019 (offices in Education are 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.