school_data: Simulated school achievement dataset

school_dataR Documentation

Simulated school achievement dataset

Description

A simulated two-level dataset with students nested within schools, designed to illustrate multilevel moderation analysis. The true data-generating model includes a cross-level interaction between student socioeconomic status and school climate.

Usage

school_data

Format

A data frame with 3,000 rows and 6 variables:

school

A factor indicating the school identifier (1–100).

student

An integer indicating the student identifier (1–3000).

math

A numeric mathematics achievement score.

ses

A numeric student socioeconomic status variable (standardized).

climate

A numeric school climate rating (standardized level-2 variable).

gender

A factor indicating student gender with levels "female" and "male".

Details

The data were generated from the model

math_{ij} = 50 + 1.5\,ses_{ij} + 0.8\,climate_j + 0.5\,ses_{ij} climate_j + u_{0j} + u_{1j} ses_{ij} + e_{ij}.

The level-2 random effects were generated as u_{0j} \sim N(0, 9) and u_{1j} \sim N(0, 0.25), and the level-1 residuals were generated as e_{ij} \sim N(0, 25).

Examples

data(school_data)
head(school_data)
str(school_data)


library(lme4)
mod <- lmer(math ~ ses * climate + gender + (1 + ses | school),
            data = school_data)
mlm_probe(mod, pred = "ses", modx = "climate")


mlmoderator documentation built on April 4, 2026, 1:07 a.m.