Skip to contents

Generates the built-in HSB-style example dataset used by the mlmr Shiny app. The data include student-level predictors, school-level predictors, categorical predictors, grouping factors, and outcomes suitable for mixed-effects model demonstrations.

Usage

example_hsb(n_schools = 24, min_students = 18, max_students = 34,
  seed = 20260423)

Arguments

n_schools

Number of schools to simulate.

min_students, max_students

Minimum and maximum number of students per school.

seed

Random seed used to make the generated data reproducible.

Value

A data frame containing simulated student, school, district, and teacher variables.

Examples

dat <- example_hsb(n_schools = 4, min_students = 5, max_students = 6)
str(dat)
#> 'data.frame':	22 obs. of  16 variables:
#>  $ studentid   : chr  "ST0001" "ST0002" "ST0003" "ST0004" ...
#>  $ schoolid    : Factor w/ 4 levels "S01","S02","S03",..: 1 1 1 1 1 1 2 2 2 2 ...
#>  $ districtid  : Factor w/ 4 levels "D01","D02","D03",..: 1 1 1 1 1 1 2 2 2 2 ...
#>  $ teacherid   : Factor w/ 9 levels "T01","T02","T03",..: 8 2 2 8 9 6 4 5 5 5 ...
#>  $ mathscore   : num  71.9 57.5 70.8 71.3 76.9 ...
#>  $ ses         : num  -0.28 -0.923 -1.051 -0.179 0.226 ...
#>  $ priorachieve: num  41.9 54.8 42.1 43 50.8 ...
#>  $ homework    : num  6.5 4.8 5.4 6.5 5.8 5.4 5 6.7 1.8 5 ...
#>  $ meanses     : num  0.125 0.125 0.125 0.125 0.125 0.125 0.516 0.516 0.516 0.516 ...
#>  $ climate     : num  -0.167 -0.167 -0.167 -0.167 -0.167 -0.167 0.35 0.35 0.35 0.35 ...
#>  $ schoolsize  : num  789 789 789 789 789 789 872 872 872 872 ...
#>  $ passmath    : Factor w/ 2 levels "No","Yes": 2 1 1 2 2 2 2 2 2 1 ...
#>  $ absences    : int  3 5 4 0 3 1 1 0 2 2 ...
#>  $ sector      : Factor w/ 2 levels "Catholic","Public": 1 1 1 1 1 1 1 1 1 1 ...
#>  $ female      : Factor w/ 2 levels "Male","Female": 2 2 1 2 2 1 2 2 2 2 ...
#>  $ minority    : Factor w/ 2 levels "No","Yes": 1 1 2 1 2 1 1 1 2 1 ...