Multilevel Models 3 Sociology 229A, Class 10 Copyright © 2008 by Evan Schofer Do not copy or distribute without permission.

Slides:



Advertisements
Similar presentations
Introduction Describe what panel data is and the reasons for using it in this format Assess the importance of fixed and random effects Examine the Hausman.
Advertisements

AMMBR - final stuff xtmixed (and xtreg) (checking for normality, random slopes)
AMMBR from xtreg to xtmixed (+checking for normality, random slopes)
Toolkit + “show your skills” AMMBR from xtreg to xtmixed (+checking for normality, and random slopes, and cross-classified models, and then we are almost.
Random Assignment Experiments
SC968: Panel Data Methods for Sociologists Random coefficients models.
Xtreg and xtmixed: recap We have the standard regression model (here with only one x): but think that the data are clustered, and that the intercept (c.
1 FE Panel Data assumptions. 2 Assumption #1: E(u it |X i1,…,X iT,  i ) = 0.
Lecture 4 (Chapter 4). Linear Models for Correlated Data We aim to develop a general linear model framework for longitudinal data, in which the inference.
Repeated Measures, Part 3 May, 2009 Charles E. McCulloch, Division of Biostatistics, Dept of Epidemiology and Biostatistics, UCSF.
1 BINARY CHOICE MODELS: LOGIT ANALYSIS The linear probability model may make the nonsense predictions that an event will occur with probability greater.
Multilevel Models 4 Sociology 8811, Class 26 Copyright © 2007 by Evan Schofer Do not copy or distribute without permission.
Lecture 4 Linear random coefficients models. Rats example 30 young rats, weights measured weekly for five weeks Dependent variable (Y ij ) is weight for.
AMMBR from xtreg to xtmixed (+checking for normality, and random slopes, and cross-classified models, and then we are done in terms of theory)
Multinomial Logit Sociology 8811 Lecture 11 Copyright © 2007 by Evan Schofer Do not copy or distribute without permission.
Sociology 601 Class 19: November 3, 2008 Review of correlation and standardized coefficients Statistical inference for the slope (9.5) Violations of Model.
Some Terms Y =  o +  1 X Regression of Y on X Regress Y on X X called independent variable or predictor variable or covariate or factor Which factors.
School of Veterinary Medicine and Science Multilevel modelling Chris Hudson.
Sociology 601 Class 21: November 10, 2009 Review –formulas for b and se(b) –stata regression commands & output Violations of Model Assumptions, and their.
Shall we take Solow seriously?? Empirics of growth Ania Nicińska Agnieszka Postępska Paweł Zaboklicki.

Chapter 12 Simple Regression
Multilevel Models 1 Sociology 229: Advanced Regression
Multilevel Models 2 Sociology 8811, Class 24
Multilevel Models 2 Sociology 229A, Class 18
Event History Analysis 7
Multilevel Models 1 Sociology 229A Copyright © 2008 by Evan Schofer Do not copy or distribute without permission.
Clustered or Multilevel Data
1 Review of Correlation A correlation coefficient measures the strength of a linear relation between two measurement variables. The measure is based on.
So far, we have considered regression models with dummy variables of independent variables. In this lecture, we will study regression models whose dependent.
1 Simple Linear Regression Chapter Introduction In this chapter we examine the relationship among interval variables via a mathematical equation.
Multilevel Models 3 Sociology 8811, Class 25 Copyright © 2007 by Evan Schofer Do not copy or distribute without permission.
Topic 3: Regression.
Event History Models Sociology 229: Advanced Regression Class 5
Multiple Regression 2 Sociology 5811 Lecture 23 Copyright © 2005 by Evan Schofer Do not copy or distribute without permission.
Foster Care Reunification: The use of hierarchical modeling to account for sibling and county correlation Emily Putnam-Hornstein, MSW Center for Social.
BINARY CHOICE MODELS: LOGIT ANALYSIS
Linear Regression 2 Sociology 5811 Lecture 21 Copyright © 2005 by Evan Schofer Do not copy or distribute without permission.
Simple Linear Regression. Introduction In Chapters 17 to 19, we examine the relationship between interval variables via a mathematical equation. The motivation.
Generalized Linear Models
Unit 3b: From Fixed to Random Intercepts © Andrew Ho, Harvard Graduate School of EducationUnit 3b – Slide 1
Statistics for Managers Using Microsoft Excel, 4e © 2004 Prentice-Hall, Inc. Chap 12-1 Chapter 12 Simple Linear Regression Statistics for Managers Using.
Hypothesis Testing in Linear Regression Analysis
Methods Workshop (3/10/07) Topic: Event Count Models.
2-1 MGMG 522 : Session #2 Learning to Use Regression Analysis & The Classical Model (Ch. 3 & 4)
How do Lawyers Set fees?. Learning Objectives 1.Model i.e. “Story” or question 2.Multiple regression review 3.Omitted variables (our first failure of.
Multiple Regression 1 Sociology 5811 Lecture 22 Copyright © 2005 by Evan Schofer Do not copy or distribute without permission.
Multilevel Analysis Kate Pickett Senior Lecturer in Epidemiology.
MULTILEVEL ANALYSIS Kate Pickett Senior Lecturer in Epidemiology SUMBER: www-users.york.ac.uk/.../Multilevel%20Analysis.ppt‎University of York.
Repeated Measures, Part 2 May, 2009 Charles E. McCulloch, Division of Biostatistics, Dept of Epidemiology and Biostatistics, UCSF.
Linear Functions 2 Sociology 5811 Lecture 18 Copyright © 2004 by Evan Schofer Do not copy or distribute without permission.
Scientific question: Does the lunch intervention impact cognitive ability? The data consists of 4 measures of cognitive ability including:Raven’s score.
EHA: More On Plots and Interpreting Hazards Sociology 229A: Event History Analysis Class 9 Copyright © 2008 by Evan Schofer Do not copy or distribute without.
© 2001 Prentice-Hall, Inc. Statistics for Business and Economics Simple Linear Regression Chapter 10.
Introduction to Linear Regression
Multiple Regression 3 Sociology 5811 Lecture 24 Copyright © 2005 by Evan Schofer Do not copy or distribute without permission.
Count Models 1 Sociology 8811 Lecture 12
Introduction to Multilevel Modeling Stephen R. Porter Associate Professor Dept. of Educational Leadership and Policy Studies Iowa State University Lagomarcino.
Lecture 3 Linear random intercept models. Example: Weight of Guinea Pigs Body weights of 48 pigs in 9 successive weeks of follow-up (Table 3.1 DLZ) The.
HLM Models. General Analysis Strategy Baseline Model - No Predictors Model 1- Level 1 Predictors Model 2 – Level 2 Predictors of Group Mean Model 3 –
Panel Data. Assembling the Data insheet using marriage-data.csv, c d u "background-data", clear d u "experience-data", clear u "wage-data", clear d reshape.
1 BINARY CHOICE MODELS: LOGIT ANALYSIS The linear probability model may make the nonsense predictions that an event will occur with probability greater.
Linear Regression 1 Sociology 5811 Lecture 19 Copyright © 2005 by Evan Schofer Do not copy or distribute without permission.
Lecture 18 Matched Case Control Studies
Event History Analysis 3
HLM with Educational Large-Scale Assessment Data: Restrictions on Inferences due to Limited Sample Sizes Sabine Meinck International Association.
Advanced quantitative methods for social scientists (2017–2018) LC & PVK Session 2 Multilevel analysis in Stata (with a focus on random slope models for.
Simple Linear Regression
Count Models 2 Sociology 8811 Lecture 13
Presentation transcript:

Multilevel Models 3 Sociology 229A, Class 10 Copyright © 2008 by Evan Schofer Do not copy or distribute without permission

Announcements Final class! Papers due today Topics: Presentations Multilevel models EHA: Shared Frailty EHA: Heterogeneous Diffusion Models.

Multilevel Data Simple example: 2-level data Which can be shown as: Class 1 S1S1 S2S2 S3S3 Class 2 S1S1 S2S2 S3S3 Class 3 S1S1 S2S2 S3S3 Level 2 Level 1

Review: Multilevel Strategies Problems of multilevel models Non-independence; correlated error Standard errors = underestimated Solutions: –Each has benefits, disadvantages… 1. OLS regression 2. Aggregation (between effects model) 3. Robust Standard Errors 4. Robust Cluster Standard Errors 5. Dummy variables (Fixed Effects Model) 6. Random effects models –Intercept only; slopes; cross-level interactions

Review: Fixed Effects Model (FEM) Fixed effects model: For i cases within j groups Therefore  j is a separate intercept for each group It is equivalent to solely at within-group variation: X-bar-sub-j is mean of X for group j, etc Model is “within group” because all variables are centered around mean of each group.

Review: Random Effects Issue: The dummy variable approach (ANOVA, FEM) treats group differences as a fixed effect Alternatively, we can treat it as a random effect Don’t estimate values for each case, but model it –Like “e” in a regression equation This requires making assumptions –e.g., that group differences are normally distributed with a standard deviation that can be estimated from data BUT, ignoring slope variability is also an assumption…

Review: Random Effects A simple random intercept model –Notation from Rabe-Hesketh & Skrondal 2005, p. 4-5 Random Intercept Model Where  is the main intercept Zeta (  ) is a random effect for each group –Allowing each of j groups to have its own intercept –Assumed to be independent & normally distributed Error (e) is the error term for each case –Also assumed to be independent & normally distributed Note: Other texts refer to random intercepts as u j or j.

Linear Random Intercepts Model. xtreg supportenv age male dmar demp educ incomerel ses, i(country) re Random-effects GLS regression Number of obs = Group variable (i): country Number of groups = 26 R-sq: within = Obs per group: min = 511 between = avg = overall = max = 2154 Random effects u_i ~ Gaussian Wald chi2(7) = corr(u_i, X) = 0 (assumed) Prob > chi2 = supportenv | Coef. Std. Err. z P>|z| [95% Conf. Interval] age | male | dmar | demp | educ | incomerel | ses | _cons | sigma_u | sigma_e | rho | (fraction of variance due to u_i) Assumes normal u j, uncorrelated with X vars SD of u (intercepts); SD of e; intra-class correlation

Review: Choosing Models Which model is best? Fixed effects are most consistent under a wide range of circumstances –But, can be a problem if your interest is between-group variation Random Effects = more efficient –But, runs into problems if specification is poor –Esp. X variables correlated with random error Hausman Specification Test: A tool to help evaluate fit of fixed vs. random effects Logic: Both fixed & random effects models are consistent if models are properly specified In short: Models should give the same results… If not, random effects may be biased.

Within & Between Effects Issue: What is the relationship between within-group effects and between-group effects? FEM models within-group variation BEM models between group variation (aggregate) –Usually they are similar Ex: Student skills & test performance Within any classroom, skilled students do best on tests Between classrooms, classes with more skilled students have higher mean test scores –BUT…

Within & Between Effects But: Between and within effects can differ! Ex: Effects of wealth on attitudes toward welfare At the country level (between groups): –Wealthier countries (high aggregate mean) tend to have pro- welfare attitudes (ex: Scandinavia) At the individual level (within group) –Wealthier people are conservative, don’t support welfare Result: Wealth has opposite between vs within effects! –Watch out for ecological fallacy!!! –Issue: Such dynamics often result from omitted level-1 variables (omitted variable bias) Ex: If we control for individual “political conservatism”, effects may be consistent at both levels…

Within & Between Effects / Centering Multilevel models & “centering” variables Grand mean centering: computing variables as deviations from overall mean Often done to X variables Has effect that baseline constant in model reflects mean of all cases –Useful for interpretation Group mean centering: computing variables as deviation from group mean Useful for decomposing within vs. between effects Often in conjunction with aggregate group mean vars.

Within & Between Effects You can estimate BOTH within- and between- group effects in a single model Strategy: Split a variable (e.g., SES) into two new variables… –1. Group mean SES –2. Within-group deviation from mean SES »Often called “group mean centering” Then, put both variables into a random effects model Model will estimate separate coefficients for between vs. within effects –Ex: egen meanvar1 = mean(var1), by(groupid) egen withinvar1 = var1 – meanvar1 Include mean (aggregate) & within variable in model.

Within & Between Effects. xtreg supportenv meanage withinage male dmar demp educ incomerel ses, i(country) mle Random-effects ML regression Number of obs = Group variable (i): country Number of groups = 26 Random effects u_i ~ Gaussian Obs per group: min = 511 avg = max = 2154 LR chi2(8) = Log likelihood = Prob > chi2 = supportenv | Coef. Std. Err. z P>|z| [95% Conf. Interval] meanage | withinage | male | dmar | demp | educ | incomerel | ses | _cons | Between & within effects are opposite. Older countries are MORE environmental, but older people are LESS. Omitted variables? Wealthy European countries with strong green parties have older populations! Example: Pro-environmental attitudes

Generalizing: Random Coefficients Linear random intercept model allows random variation in intercept (mean) for groups But, the same idea can be applied to other coefficients That is, slope coefficients can ALSO be random! Random Coefficient Model Which can be written as: Where zeta-1 is a random intercept component Zeta-2 is a random slope component.

Linear Random Coefficient Model Rabe-Hesketh & Skrondal 2004, p. 63 Both intercepts and slopes vary randomly across j groups

Random Coefficients Summary Some things to remember: Dummy variables allow fixed estimates of intercepts across groups Interactions allow fixed estimates of slopes across groups –Random coefficients allow intercepts and/or slopes to have random variability The model does not directly estimate those effects –Just as we don’t estimate coefficients of “e” for each case… BUT, random components can be predicted after you run a model –Just as you can compute residuals – random error –This allows you to examine some assumptions (normality).

STATA Notes: xtreg, xtmixed xtreg – allows estimation of between, within (fixed), and random intercept models xtreg y x1 x2 x3, i(groupid) fe - fixed (within) model xtreg y x1 x2 x3, i(groupid) be - between model xtreg y x1 x2 x3, i(groupid) re - random intercept (GLS) xtreg y x1 x2 x3, i(groupid) mle - random intercept (MLE) xtmixed – allows random slopes & coefs “Mixed” models refer to models that have both fixed and random components xtmixed [depvar] [fixed equation] || [random eq], options Ex: xtmixed y x1 x2 x3 || groupid: x2 –Random intercept is assumed. Random coef for X2 specified.

STATA Notes: xtreg, xtmixed Random intercepts xtreg y x1 x2 x3, i(groupid) mle –Is equivalent to xtmixed y x1 x2 x3 || groupid:, mle xtmixed assumes random intercept – even if no other random effects are specified after “groupid” –But, we can add random coefficients for all Xs: xtmixed y x1 x2 x3 || groupid: x1 x2 x3, mle cov(unstr) –Useful to add: “cov(unstructured)” Stata default treats random terms (intercept, slope) as totally uncorrelated… not always reasonable “cov(unstr) relaxes constraints regarding covariance among random effects (See Rabe-Hesketh & Skrondal).

STATA Notes: GLLAMM Note: xtmixed can do a lot… but GLLAMM can do even more! “General linear & latent mixed models” Must be downloaded into stata. Type “search gllamm” and follow instructions to install… –GLLAMM can do a wide range of mixed & latent- variable models Multilevel models; Some kinds of latent class models; Confirmatory factor analysis; Some kinds of Structural Equation Models with latent variables… and others… Documentation available via Stata help –And, in the Rabe-Hesketh & Skrondal text.

Random intercepts: xtmixed. xtmixed supportenv age male dmar demp educ incomerel ses || country:, mle Mixed-effects ML regression Number of obs = Group variable: country Number of groups = 26 Obs per group: min = 511 avg = max = 2154 Wald chi2(7) = Log likelihood = Prob > chi2 = supportenv | Coef. Std. Err. z P>|z| [95% Conf. Interval] age | male | dmar | demp | educ | incomerel | ses | _cons | [remainder of output cut off] Note: xtmixed yields identical results to xtreg, mle Example: Pro-environmental attitudes

Random intercepts: xtmixed supportenv | Coef. Std. Err. z P>|z| [95% Conf. Interval] age | male | dmar | demp | educ | incomerel | ses | _cons | Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] country: Identity | sd(_cons) | sd(Residual) | LR test vs. linear regression: chibar2(01) = Prob >= chibar2 = xtmixed output puts all random effects below main coefficients. Here, they are “cons” (constant) for groups defined by “country”, plus residual (e) Ex: Pro-environmental attitudes (cont’d) Non-zero SD indicates that intercepts vary

Random Coefficients: xtmixed. xtmixed supportenv age male dmar demp educ incomerel ses || country: educ, mle [output omitted] supportenv | Coef. Std. Err. z P>|z| [95% Conf. Interval] age | male | dmar | demp | educ | incomerel | ses | _cons | Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] country: Independent | sd(educ) | sd(_cons) | sd(Residual) | LR test vs. linear regression: chi2(2) = Prob > chi2 = Ex: Pro-environmental attitudes (cont’d) Here, we have allowed the slope of educ to vary randomly across countries Educ (slope) varies, too!

Random Coefficients: xtmixed What if the random intercept or slope coefficients aren’t significantly different from zero? Answer: that means there isn’t much random variability in the slope/intercept Conclusion: You don’t need to specify that random parameter –Also: Models include a LRtest to compare with a simple OLS model (no random effects) If models don’t differ (Chi-square is not significant) stick with a simpler model.

Random Coefficients: xtmixed What are random coefficients doing? Let’s look at results from a simplified model –Only random slope & intercept for education Model fits a different slope & intercept for each group!

Random Coefficients Why bother with random coefficients? –1. A solution for clustering (non-independence) –Usually people just use random intercepts, but slopes may be an issue also –2. You can create a better-fitting model –If slopes & intercepts vary, a random coefficient model may fit better –Assuming distributional assumptions are met –Model fit compared to OLS can be tested…. –3. Better predictions –Attention to group-specific random effects can yield better predictions (e.g., slopes) for each group »Rather than just looking at “average” slope for all groups.

Random Coefficients 4. Multilevel models explicitly put attention on levels of causality Higher level / “contextual” effects versus individual / unit-level effects A technology for separating out between/within NOTE: this can be done w/out random effects –But it goes hand-in-hand with clustered data… Note: Be sure you have enough level-2 units! –Ex: Models of individual environmental attitudes Adding level-2 effects: Democracy, GDP, etc. –Ex: Classrooms Is it student SES, or “contextual” class/school SES?

Multilevel Model Notation So far, we have expressed random effects in a single equation: Random Coefficient Model However, it is common to separate levels: Gamma = constant u = random effect Here, we specify a random component for level-1 constant & slope Intercept equation Slope Equation Level 1 equation

Multilevel Model Notation The “separate equation” formulation is no different from what we did before… But it is a vivid & clear way to present your models All random components are obvious because they are stated in separate equations NOTE: Some software (e.g., HLM) requires this –Rules: 1. Specify an OLS model, just like normal 2. Consider which OLS coefficients should have a random component –These could be the intercept or any X (slope) coefficient 3. Specify an additional formula for each random coefficient… adding random components when desired

Cross-Level Interactions Does context (i.e., level-2) influence the effect of level-1 variables? –Example: Effect of poverty on homelessness Does it interact with welfare state variables? –Ex: Effect of gender on math test scores Is it different in coed vs. single-sex schools? –Can you think of others?

Cross-level interactions Idea: specify a level-2 variable that affects a level-1 slope Intercept equation Level 1 equation Slope equation with interaction Cross-level interaction: Level-2 variable Z affects slope (B2) of a level-1 X variable Coefficient  3 reflects size of interaction (effect on B2 per unit change in Z)

Cross-level Interactions Cross-level interaction in single-equation form: Random Coefficient Model with cross-level interaction –Stata strategy: manually compute cross-level interaction variables Ex: Poverty*WelfareState, Gender*SingleSexSchool Then, put interaction variable in the “fixed” model –Interpretation: B3 coefficient indicates the impact of each unit change in Z on slope B2 If B3 is positive, increase in Z results in larger B2 slope.

Cross-level Interactions. xtmixed supportenv age male dmar demp educ income_dev inc_meanXeduc ses || country: income_mean, mle cov(unstr) Mixed-effects ML regression Number of obs = Group variable: country Number of groups = 26 supportenv | Coef. Std. Err. z P>|z| [95% Conf. Interval] age | male | dmar | demp | educ | income_dev | inc_meanXeduc| ses | _cons | Pro-environmental attitudes Interaction: inc_meanXeduc has a positive effect… The education slope is bigger in wealthy countries Note: main effects change. “educ” indicates slope when inc_mean = 0 Interaction between country mean income and individual-level education

Cross-level Interactions. xtmixed supportenv age male dmar demp educ income_dev inc_meanXeduc ses || country: income_mean, mle cov(unstr) Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] country: Unstructured | sd(income~n) | sd(_cons) | corr(income~n,_cons) | sd(Residual) | LR test vs. linear regression: chi2(3) = Prob > chi2 = Random part of output (cont’d from last slide) Random components: Income_mean slope allowed to have random variation Interceps (“cons”) allowed to have random variation “cov(unstr)” allows for the possibility of correlation between random slopes & intercepts… generally a good idea.

Beyond 2-level models Sometimes data has 3 levels or more Ex: School, classroom, individual Ex: Family, individual, time (repeated measures) Can be dealt with in xtmixed, GLLAMM, HLM Note: stata manual doesn’t count lowest level –What we call 3-level is described as “2-level” in stata manuals –xtmixed syntax: specify “fixed” equation and then random effects starting with “top” level xtmixed var1 var2 var3 || schoolid: var2 || classid:var3 –Again, specify unstructured covariance: cov(unstr)

Beyond Linear Models Stata can specify multilevel models for dichotomous & count variables –Random intercept models xtlogit – logistic regression – dichotomous xtpois – poisson regression – counts xtnbreg – negative binomial – counts xtgee – any family, link… w/random intercept –Random intercept & coefficient models –Plus, allows more than 2 levels… xtmelogit – mixed logit model xtmepoisson – mixed poisson model

Panel Data Panel data is a multilevel structure Cases measured repeatedly over time Measurements are ‘nested’ within cases Person 1 T2T2 T1T1 T4T4 T3T3 T5T5 Person 2 T2T2 T1T1 T4T4 T3T3 T5T5 Person 3 T2T2 T1T1 T4T4 T3T3 T5T5 Person 4 T2T2 T1T1 T4T4 T3T3 T5T5 –Obviously, error is clustered within cases… but… –Error may also be clustered by time Historical time events or life-course events may mean that cases aren’t independent –Ex: All T1s and all T5s Ex: Models of economic growth… certain periods (e.g., Oil shocks of 1970s) affect all countries.

Panel Data Issue: panel data may involve clustering across cases & time Good news: Stata’s “xt” commands were made for this Allow specification of both ID and TIME clusters… Ex: xtreg var1 var2 var3, mle i(countryid) t(year) –Note: You can also “mix and match” fixed and random effects Ex: You can use dummies (manually) to deal with time-cultuering with a random effect for case ids

Panel Data: serial correlation Panel data may have another problem: Sequential cases may have correlated error –Ex: Adjacent years (1950 & 1951 or 2007 & 2008) may be very similar. Correlation denoted by “rho” (  ) Called “autocorrelation” or “serial correlation” “Time-series” models are needed xtregar – xtreg, for cases in which the error-term is “first-order autoregressive” First order means the prior time influences the current –Only adjacent time-points… assumes no effect of those prior Can be used to estimate FEM, BEM, or GLS model Use option “lbi” to test for autocorrelation (rho = 0?).

Panel Data: Choosing a Model If clustering is mainly a nuisance: Adjust SEs: vce(cluster caseid) Or simple fixed or random effects –Choice between fixed & random Fixed is “safer” – reviewers are less likely to complain –If hausman test works, random = OK, too But, if cross-sectional variation is of interest, fixed can be a problem… –In that case, use random effects… and hope the reviewers don’t give you grief.

Panel Data: Choosing a Model If you have substantive interests in cross-level dynamics, mixed models are probably the way to go… Plus, you can create a better-fitting model –Allows you to relax the assumption that slopes are the same across groups.