use simulated_multilevel_data.dta
4 Cross Sectional Multilevel Models
4.1 The Equation
Recall the general model of Equation 1.1, and the syntax outlined in Section 1.3. Below in Equation 4.1, we consider a more substantive example.
\[\text{outcome}_{ij}= \beta_0 + \beta_1 \text{warmth}_{ij} + \tag{4.1}\]
\[\beta_2 \text{physical punishment}_{ij} +\]
\[\beta_3 \text{identity}_{ij} + \beta_4 \text{intervention}_{ij} + \beta_5 \text{HDI}_{ij} +\]
\[u_{0j} + u_{1j} \times \text{warmth}_{ij} + e_{ij}\]
4.3 Run Models
4.3.0.1 Get The Data
4.3.0.2 Run The Model
identity i.intervention HDI || country: warmth mixed outcome warmth physical_punishment i.
Performing EM optimization ...
Performing gradient-based optimization:
Iteration 0: Log likelihood = -9626.6279
Iteration 1: Log likelihood = -9626.607
Iteration 2: Log likelihood = -9626.607
Computing standard errors ...
Mixed-effects ML regression Number of obs = 3,000
Group variable: country Number of groups = 30
Obs per group:
min = 100
avg = 100.0
max = 100
Wald chi2(5) = 334.14
Log likelihood = -9626.607 Prob > chi2 = 0.0000
-------------------------------------------------------------------------------------
outcome | Coefficient Std. err. z P>|z| [95% conf. interval]
--------------------+----------------------------------------------------------------
warmth | .8345368 .0637213 13.10 0.000 .7096453 .9594282
physical_punishment | -.9916657 .0797906 -12.43 0.000 -1.148052 -.8352791
2.identity | -.3004767 .2170295 -1.38 0.166 -.7258466 .1248933
1.intervention | .6396427 .2174519 2.94 0.003 .2134448 1.065841
HDI | -.003228 .0199257 -0.16 0.871 -.0422817 .0358256
_cons | 51.99991 1.371257 37.92 0.000 49.3123 54.68753
-------------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects parameters | Estimate Std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
country: Independent |
var(warmth) | .0227504 .0257784 .0024689 .2096436
var(_cons) | 2.963975 .9737647 1.556777 5.643163
-----------------------------+------------------------------------------------
var(Residual) | 34.97499 .9097109 33.23668 36.80422
------------------------------------------------------------------------------
LR test vs. linear model: chi2(2) = 205.74 Prob > chi2 = 0.0000
Note: LR test is conservative and provided only for reference.
4.3.0.3 Get The Data
library(haven)
<- read_dta("simulated_multilevel_data.dta") df
4.3.0.4 Run The Model
lme4
does not directly provide p values in results, because of some disagreement over exactly how these p values should be calculated. Therefore, in this Appendix, I also call library lmerTest
to provide p values for lme4
results.
R prefers to use scientific notation when possible. I find that the use of scientific notation can be confusing in reading results. I turn off scientific notation by setting a penalty for its use: options(scipen = 999)
.
library(lme4)
library(lmerTest)
options(scipen = 999)
<- lmer(outcome ~ warmth + physical_punishment +
fit1 + intervention + HDI +
identity 1 + warmth || country),
(data = df)
summary(fit1)
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: outcome ~ warmth + physical_punishment + identity + intervention +
HDI + (1 + warmth || country)
Data: df
REML criterion at convergence: 19268.8
Scaled residuals:
Min 1Q Median 3Q Max
-3.9774 -0.6563 0.0187 0.6645 3.6730
Random effects:
Groups Name Variance Std.Dev.
country (Intercept) 3.19056 1.786
country.1 warmth 0.02465 0.157
Residual 35.01782 5.918
Number of obs: 3000, groups: country, 30
Fixed effects:
Estimate Std. Error df t value
(Intercept) 52.311714 1.446735 33.113738 36.158
warmth 0.834562 0.064252 41.896966 12.989
physical_punishment -0.991892 0.079845 2968.010901 -12.423
identity -0.300350 0.217179 2970.106304 -1.383
intervention 0.639059 0.217603 2971.185215 2.937
HDI -0.003395 0.020596 27.598517 -0.165
Pr(>|t|)
(Intercept) < 0.0000000000000002 ***
warmth 0.000000000000000277 ***
physical_punishment < 0.0000000000000002 ***
identity 0.16678
intervention 0.00334 **
HDI 0.87027
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Correlation of Fixed Effects:
(Intr) warmth physc_ idntty intrvn
warmth -0.119
physcl_pnsh -0.145 -0.003
identity -0.220 -0.012 -0.003
interventin -0.077 0.034 0.022 -0.018
HDI -0.922 -0.006 0.009 -0.001 0.000
4.3.0.5 Get The Data
using Tables, MixedModels, StatFiles, DataFrames, CategoricalArrays, DataFramesMeta
= DataFrame(load("simulated_multilevel_data.dta")) df
4.3.0.6 Change Country To Categorical
@transform!(df, :country = categorical(:country))
4.3.0.7 Run The Model
= fit(MixedModel, @formula(outcome ~ warmth + physical_punishment +
m1 + intervention + HDI +
identity 1 | country) +
(0 + warmth | country)), df) (
Linear mixed model fit by maximum likelihood
outcome ~ 1 + warmth + physical_punishment + identity + intervention + HDI + (1 | country) + (0 + warmth | country)
logLik -2 logLik AIC AICc BIC
-9626.6070 19253.2140 19271.2140 19271.2742 19325.2713
Variance components:
Column Variance Std.Dev. Corr.
country (Intercept) 2.963849 1.721583
warmth 0.022756 0.150852 .
Residual 34.974984 5.913965
Number of obs: 3000; levels of grouping factors: 30
Fixed-effects parameters:
─────────────────────────────────────────────────────────────
Coef. Std. Error z Pr(>|z|)
─────────────────────────────────────────────────────────────
(Intercept) 52.3004 1.40406 37.25 <1e-99
warmth 0.834537 0.0637228 13.10 <1e-38
physical_punishment -0.991665 0.0797906 -12.43 <1e-34
identity -0.300475 0.217029 -1.38 0.1662
intervention 0.639641 0.217452 2.94 0.0033
HDI -0.0032286 0.0199255 -0.16 0.8713
─────────────────────────────────────────────────────────────
4.4 Interpretation
Models suggest that parental warmth is associated with increases in the beneficial outcome, while physical punishment is associated with decreases in the beneficial outcome. Membership in the group represented by identity
is not associated with the outcome. The intervention is associated with increases in the outcome. The Human Development Index is not associated with the outcome.