diff --git a/.nojekyll b/.nojekyll index befa032..233c9d0 100644 --- a/.nojekyll +++ b/.nojekyll @@ -1 +1 @@ -7fe3b56d \ No newline at end of file +671831f7 \ No newline at end of file diff --git a/AoGPlots.html b/AoGPlots.html new file mode 100644 index 0000000..f130cd8 --- /dev/null +++ b/AoGPlots.html @@ -0,0 +1,1072 @@ + + + + + + + + + + + +SMLP2023: Advanced Frequentist Track - Creating multi-panel plots + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +
+ + + +
+ +
+
+

Creating multi-panel plots

+
+ + + +
+ +
+
Author
+
+

Phillip Alday, Douglas Bates, and Reinhold Kliegl

+
+
+ +
+
Published
+
+

2023-08-21

+
+
+ + +
+ + +
+ +

This notebook shows creating a multi-panel plot similar to Figure 2 of Fühner et al. (2021).

+

The data are available from the SMLP2023 example datasets.

+
+
+Code +
using Arrow
+using AlgebraOfGraphics
+using CairoMakie   # for displaying static plots
+using DataFrames
+using Statistics
+using StatsBase
+using SMLP2023: dataset
+
+CairoMakie.activate!(; type="svg") # use SVG (other options include PNG)
+
+
+
+
tbl = dataset("fggk21")
+
+
Arrow.Table with 525126 rows, 7 columns, and schema:
+ :Cohort  String
+ :School  String
+ :Child   String
+ :Sex     String
+ :age     Float64
+ :Test    String
+ :score   Float64
+
+
+
+
typeof(tbl)
+
+
Arrow.Table
+
+
+
+
df = DataFrame(tbl)
+typeof(df)
+
+
DataFrame
+
+
+
+

1 Creating a summary data frame

+

The response to be plotted is the mean score by Test and Sex and age, rounded to the nearest 0.1 years.

+

The first task is to round the age to 1 digit after the decimal place, which can be done with select applied to a DataFrame. In some ways this is the most complicated expression in creating the plot so we will break it down. select is applied to DataFrame(dat), which is the conversion of the Arrow.Table, dat, to a DataFrame. This is necessary because an Arrow.Table is immutable but a DataFrame can be modified.

+

The arguments after the DataFrame describe how to modify the contents. The first : indicates that all the existing columns should be included. The other expression can be pairs (created with the => operator) of the form :col => function or of the form :col => function => :newname. (See the documentation of the DataFrames package for details.)

+

In this case the function is an anonymous function of the form round.(x, digits=1) where “dot-broadcasting” is used to apply to the entire column (see this documentation for details).

+
+
transform!(df, :age, :age => (x -> x .- 8.5) => :a1) # centered age (linear)
+select!(groupby(df, :Test), :, :score => zscore => :zScore) # z-score
+tlabels = [     # establish order and labels of tbl.Test
+  "Run" => "Endurance",
+  "Star_r" => "Coordination",
+  "S20_r" => "Speed",
+  "SLJ" => "PowerLOW",
+  "BPT" => "PowerUP",
+];
+
+

The next stage is a group-apply-combine operation to group the rows by Sex, Test and rnd_age then apply mean to the zScore and also apply length to zScore to record the number in each group.

+
+
df2 = combine(
+  groupby(
+    select(df, :, :age => ByRow(x -> round(x; digits=1)) => :age),
+    [:Sex, :Test, :age],
+  ),
+  :zScore => mean => :zScore,
+  :zScore => length => :n,
+)
+
+
120×5 DataFrame
95 rows omitted
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RowSexTestagezScoren
StringStringFloat64Float64Int64
1maleS20_r8.0-0.02651381223
2maleBPT8.00.0269731227
3maleSLJ8.00.1216091227
4maleStar_r8.0-0.05717261186
5maleRun8.00.2926951210
6femaleS20_r8.0-0.351641411
7femaleBPT8.0-0.6103551417
8femaleSLJ8.0-0.2798721418
9femaleStar_r8.0-0.2682211381
10femaleRun8.0-0.2455731387
11maleS20_r8.10.06083973042
12maleBPT8.10.09554133069
13maleSLJ8.10.1230993069
109maleStar_r9.00.2549734049
110maleRun9.00.2580824034
111femaleS20_r9.1-0.02861721154
112femaleBPT9.1-0.07523011186
113femaleSLJ9.1-0.0945871174
114femaleStar_r9.10.002762521162
115femaleRun9.1-0.2355911150
116maleS20_r9.10.3257451303
117maleBPT9.10.6164161320
118maleSLJ9.10.2675771310
119maleStar_r9.10.2543421297
120maleRun9.10.2510451294
+
+
+
+
+
+

2 Creating the plot

+

The AlgebraOfGraphics package applies operators to the results of functions such as data (specify the data table to be used), mapping (designate the roles of columns), and visual (type of visual presentation).

+
+
let
+  design = mapping(:age, :zScore; color=:Sex, col=:Test)
+  lines = design * linear()
+  means = design * visual(Scatter; markersize=5)
+  draw(data(df2) * means + data(df) * lines)
+end
+
+

+
+
+
    +
  • TBD: Relabel factor levels (Boys, Girls; fitness components for Test)
  • +
  • TBD: Relevel factors; why not levels from Tables?
  • +
  • TBD: Set range (7.8 to 9.2 and tick marks (8, 8.5, 9) of axes.
  • +
  • TBD: Move legend in plot?
  • +
+
+
+Fühner, T., Granacher, U., Golle, K., & Kliegl, R. (2021). Age and sex effects in physical fitness components of 108,295 third graders including 515 primary schools and 9 cohorts. Scientific Reports, 11(1). https://doi.org/10.1038/s41598-021-97000-4 +
+
+ + +
+ + Back to top
+ + +
+ + + + \ No newline at end of file diff --git a/AoGPlots_files/figure-html/cell-8-output-1.svg b/AoGPlots_files/figure-html/cell-8-output-1.svg new file mode 100644 index 0000000..2c47d39 --- /dev/null +++ b/AoGPlots_files/figure-html/cell-8-output-1.svg @@ -0,0 +1,826 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/about.html b/about.html index 53cbc68..882344d 100644 --- a/about.html +++ b/about.html @@ -2,14 +2,14 @@ - + - + -SMLP2023 - About +SMLP2023: Advanced Frequentist Track - About + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +
+ + + +
+ +
+
+

Transformed and original metrics in Emotikon

+
+ + + +
+ +
+
Author
+
+

Phillip Alday, Douglas Bates, and Reinhold Kliegl

+
+
+ +
+
Published
+
+

2023-08-21

+
+
+ + +
+ + +
+ +

In Fühner et al. (2021) the original metric of two tasks (Star, S20) is time, but they were transformed to speed scores in the publication prior to computing z-scores. The critical result is the absence of evidence for the age x Sex x Test interaction. Is this interaction significant if we analyse all tasks in their original metric?

+

Fitting the LMM of the publication takes time, roughly 1 hour. However, if you save the model parameters (and other relevant information), you can restore the fitted model object very quickly. The notebook also illustrates this procedure.

+
+

1 Getting the packages and data

+
+
+Code +
using AlgebraOfGraphics
+using Arrow
+using CairoMakie
+using DataFrames
+using DataFrameMacros
+using MixedModels
+using MixedModelsMakie
+using RCall
+using Serialization
+using StatsBase
+
+CairoMakie.activate!(; type="svg")
+datadir = joinpath(@__DIR__, "data");
+
+
+
+

1.1 Data and figure in publication

+
+
dat = DataFrame(Arrow.Table(joinpath(datadir, "fggk21.arrow")))
+@transform!(dat, :a1 = :age - 8.5);
+select!(groupby(dat, :Test), :, :score => zscore => :zScore);
+describe(dat)
+
+
9×7 DataFrame
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Rowvariablemeanminmedianmaxnmissingeltype
SymbolUnion…AnyUnion…AnyInt64DataType
1TestBPTStar_r0String
2Cohort201120190String
3SchoolS100043S8002000String
4ChildC002352C1179660String
5Sexfemalemale0String
6age8.560737.994528.558529.106090Float64
7score226.1411.141524.651161530.00Float64
8a10.0607297-0.5054760.05852160.6060920Float64
9zScore-3.91914e-13-3.15420.000310883.550780Float64
+
+
+
+
+
+

1.2 Data and figure with z-scores based on original metric

+
+
# dat_om = rcopy(R"readRDS('./data/fggk21_om.rds')");  #Don't know what the _om is
+# @transform!(dat_om, :a1 = :age - 8.5);
+# select!(groupby(dat_om, :Test), :, :score => zscore => :zScore);
+# describe(dat_om)
+
+
+
+
+

2 LMMs

+
+

2.1 Contrasts

+
+
contrasts = Dict(
+  :Test => SeqDiffCoding(),
+  :Sex => HelmertCoding(),
+  :School => Grouping(),
+  :Child => Grouping(),
+  :Cohort => Grouping(),
+);
+
+
+
+

2.2 Formula

+
+
f1 = @formula zScore ~
+  1 +
+  Test * a1 * Sex +
+  (1 + Test + a1 + Sex | School) +
+  (1 + Test | Child) +
+  zerocorr(1 + Test | Cohort);
+
+
+
+

2.3 Restore LMM m1 from publication

+
    +
  • Command for fitting LMM m1 = fit(MixedModel, f1, dat, contrasts=contr)
  • +
  • Fit statistics for LMM m1: Minimizing 5179 Time: 0 Time: 1:00:38 ( 0.70 s/it)
  • +
+
+
m1x = LinearMixedModel(f1, dat; contrasts)
+restoreoptsum!(m1x, "./fits/fggk21_m1_optsum.json")
+
+ ++++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Est.SEzpσ_Childσ_Schoolσ_Cohort
(Intercept)-0.03830.0108-3.560.00040.59390.20240.0157
Test: Run-0.02280.0274-0.830.40520.83840.35880.0651
Test: S20_r-0.01470.0405-0.360.71710.58250.35960.1107
Test: SLJ0.03280.03300.990.31980.41270.30270.0896
Test: Star_r0.00060.01970.030.97630.55740.36200.0313
a10.27130.008631.63<1e-990.0966
Sex: male0.20640.002486.55<1e-990.0245
Test: Run & a1-0.44640.0131-34.05<1e-99
Test: S20_r & a10.14730.011412.97<1e-37
Test: SLJ & a1-0.00680.0103-0.660.5116
Test: Star_r & a10.07610.01116.84<1e-11
Test: Run & Sex: male-0.09000.0037-24.10<1e-99
Test: S20_r & Sex: male-0.09120.0032-28.23<1e-99
Test: SLJ & Sex: male0.03300.002911.24<1e-28
Test: Star_r & Sex: male-0.07200.0032-22.65<1e-99
a1 & Sex: male0.00100.00690.140.8876
Test: Run & a1 & Sex: male-0.01540.0126-1.220.2233
Test: S20_r & a1 & Sex: male0.01290.01091.180.2380
Test: SLJ & a1 & Sex: male-0.00980.0100-0.980.3256
Test: Star_r & a1 & Sex: male0.01660.01081.540.1241
Residual0.5880
+
+
+
+
VarCorr(m1x)
+
+ ++++++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ColumnVarianceStd.DevCorr.
Child(Intercept)0.35272940.5939103
Test: Run0.70290030.8383915+0.11
Test: S20_r0.33933560.5825252+0.19-0.53
Test: SLJ0.17029000.4126621+0.05-0.14-0.29
Test: Star_r0.31072270.5574251-0.10+0.01-0.13-0.42
School(Intercept)0.04096400.2023957
Test: Run0.12876900.3588440+0.26
Test: S20_r0.12933510.3596319+0.01-0.57
Test: SLJ0.09165220.3027411-0.13+0.01-0.53
Test: Star_r0.13105750.3620187+0.26+0.09-0.06-0.28
a10.00934120.0966499+0.48+0.25-0.15-0.01+0.12
Sex: male0.00059990.0244934+0.09+0.13-0.01+0.05-0.19+0.25
Cohort(Intercept)0.00024520.0156587
Test: Run0.00423890.0651068.
Test: S20_r0.01225350.1106954..
Test: SLJ0.00802100.0895599...
Test: Star_r0.00098280.0313498....
Residual0.34568720.5879517
+
+
+
+
+

2.4 Restore new LMM m1_om Star and S20 in original metric

+
    +
  • Command for fitting LMM m1_om = fit(MixedModel, f1, dat_om, contrasts=contr)
  • +
  • Minimizing 10502 Time: 0 Time: 2:09:40 ( 0.74 s/it)
  • +
  • Store with: julia> saveoptsum(“./fits/fggk21_m1_om_optsum.json”, m1_om)
  • +
  • Only for short-term and when desparate: julia> serialize(“./fits/m1_om.jls”, m1_om);
  • +
+
+

2.4.1 … restoreoptsum!()

+
+
m1_om = LinearMixedModel(f1, dat; contrasts=contr);
+restoreoptsum!(m1_om, "./fits/fggk21_m1_om_optsum.json");
+
+
+
+

2.4.2 … deserialize()

+
+
m1x_om = deserialize("./fits/m1_om.jls")
+
+
+
VarCorr(m1x_om)
+
+
+
+
+

2.5 Residual diagnostics for LMM m1

+

Residual plots for published LMM

+
+
#scatter(fitted(m1x), residuals(m1x)
+
+
+
#qqnorm(m1x)
+
+
+
+

2.6 Residual diagnostics for LMM m1_om

+

Residual plots for LMM with Star and Speed in original metric.

+
+
#scatter(fitted(m1_om_v2), residuals(m1_om_v2)
+
+
+
#qqnorm(m1_om_v2)
+
+
+
+Fühner, T., Granacher, U., Golle, K., & Kliegl, R. (2021). Age and sex effects in physical fitness components of 108,295 third graders including 515 primary schools and 9 cohorts. Scientific Reports, 11(1). https://doi.org/10.1038/s41598-021-97000-4 +
+
+ + +
+
+ + Back to top
+ +
+ + + + \ No newline at end of file diff --git a/contrasts_fggk21.html b/contrasts_fggk21.html index 2228752..6299543 100644 --- a/contrasts_fggk21.html +++ b/contrasts_fggk21.html @@ -2,14 +2,14 @@ - + - - + + -SMLP2023 - Mixed Models Tutorial: Contrast Coding +SMLP2023: Advanced Frequentist Track - Mixed Models Tutorial: Contrast Coding + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +
+ + + +
+ +
+
+

Basics with Emotikon Project

+
+ + + +
+ +
+
Author
+
+

Phillip Alday, Douglas Bates, and Reinhold Kliegl

+
+
+ +
+
Published
+
+

2023-08-21

+
+
+ + +
+ + +
+ +

This script uses a subset of data reported in Fühner et al. (2021). To circumvent delays associated with model fitting we work with models that are less complex than those in the reference publication. All the data to reproduce the models in the publication are used here, too; the script requires only a few changes to specify the more complex models in the article.

+

The script is structured in four main sections:

+
    +
  1. Setup with reading and examing the data, plotting the main results, and specifying the contrasts for the fixed factor Test
  2. +
  3. a demonstration of model complexification to determine a parsimonious random-effect structure appropriate for and supported by the data, including also a quite elaborate demonstration of principle component analyses (PCAs) of levels (scores) and effects,
  4. +
  5. specification of nested fixed effects or interactions in the levels of another, superordinate factors,
  6. +
  7. a Glossary of MixedModels.jl commands to inspect the information generated for a fitted model object.
  8. +
+
+

1 Packages and functions

+
+
+Code +
using AlgebraOfGraphics
+using AlgebraOfGraphics: linear
+using Arrow
+using CairoMakie
+using CategoricalArrays
+using Chain
+using DataFrameMacros
+using DataFrames
+using MixedModels
+using MixedModelsMakie
+using MixedModelsMakie: simplelinreg
+using ProgressMeter
+using Random
+using Statistics
+using StatsBase
+using SMLP2023: dataset
+
+ProgressMeter.ijulia_behavior(:clear)
+CairoMakie.activate!(; type="svg")
+
+
+
+
+

2 Readme

+

Number of scores: 525126 in dataset(:fggk21)

+
    +
  1. Cohort: 9 levels; 2011-2019

  2. +
  3. School: 515 levels

  4. +
  5. Child: 108295 levels; all children are between 8.0 and 8.99 years old

  6. +
  7. Sex: “Girls” (n=55,086), “Boys” (n= 53,209)

  8. +
  9. age: testdate - middle of month of birthdate

  10. +
  11. Test: 5 levels

    +
      +
    • Endurance (Run): 6 minute endurance run [m]; to nearest 9m in 9x18m field
    • +
    • Coordination (Star_r): star coordination run [m/s]; 9x9m field, 4 x diagonal = 50.912 m
    • +
    • Speed(S20_r): 20-meters sprint [m/s]
    • +
    • Muscle power low (SLJ): standing long jump [cm]
    • +
    • Muscle power up (BPT): 1-kg medicine ball push test [m]
    • +
  12. +
  13. score - see units

  14. +
+
+
+

3 Preprocessing

+
+

3.1 Read data

+
+
df = DataFrame(dataset(:fggk21))
+transform!(df,
+    :age => (x -> x .- 8.5) => :a1,
+    :Sex => categorical => :Sex,
+    :Test => categorical => :Test,
+  )
+levels!(df.Sex, ["male", "female"])
+recode!(df.Sex, "male" => "Boys", "female" => "Girls")
+levels!(df.Test, ["Run", "Star_r", "S20_r", "SLJ", "BPT"])
+recode!(
+  df.Test,
+  "Run" => "Endurance",
+  "Star_r" => "Coordination",
+  "S20_r" => "Speed",
+  "SLJ" => "PowerLOW",
+  "BPT" => "PowerUP",
+)
+describe(df)
+
+
8×7 DataFrame
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Rowvariablemeanminmedianmaxnmissingeltype
SymbolUnion…AnyUnion…AnyInt64DataType
1Cohort201120190String
2SchoolS100043S8002000String
3ChildC002352C1179660String
4SexBoysGirls0CategoricalValue{String, UInt32}
5age8.560737.994528.558529.106090Float64
6TestEndurancePowerUP0CategoricalValue{String, UInt32}
7score226.1411.141524.651161530.00Float64
8a10.0607297-0.5054760.05852160.6060920Float64
+
+
+
+
+

3.1.1 Transformations

+

We center age at 8.5 years and compute z-scores for each Test. With these variables the data frame df contains all variables used for the final model in the original publication.

+
+
select!(groupby(df, :Test),  Not(:score), :score => zscore => :zScore)
+
+
525126×8 DataFrame
525101 rows omitted
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RowTestCohortSchoolChildSexagea1zScore
Cat…StringStringStringCat…Float64Float64Float64
1Speed2013S100067C002352Boys7.99452-0.5054761.7913
2PowerUP2013S100067C002352Boys7.99452-0.505476-0.0622317
3PowerLOW2013S100067C002352Boys7.99452-0.505476-0.0336567
4Coordination2013S100067C002352Boys7.99452-0.5054761.46874
5Endurance2013S100067C002352Boys7.99452-0.5054760.331058
6Speed2013S100067C002353Boys7.99452-0.5054761.15471
7PowerUP2013S100067C002353Boys7.99452-0.5054760.498354
8PowerLOW2013S100067C002353Boys7.99452-0.505476-0.498822
9Coordination2013S100067C002353Boys7.99452-0.505476-0.9773
10Endurance2013S100067C002353Boys7.99452-0.5054760.574056
11Speed2013S100067C002354Boys7.99452-0.5054760.0551481
12PowerUP2013S100067C002354Boys7.99452-0.5054760.218061
13PowerLOW2013S100067C002354Boys7.99452-0.505476-0.757248
525115Coordination2018S401470C117964Boys9.106090.606092-1.43175
525116Endurance2018S401470C117964Boys9.106090.606092-0.944681
525117Speed2018S401470C117965Girls9.106090.6060920.31086
525118PowerUP2018S401470C117965Girls9.106090.6060920.0779146
525119PowerLOW2018S401470C117965Girls9.106090.606092-0.137027
525120Coordination2018S401470C117965Girls9.106090.606092-1.8077
525121Endurance2018S401470C117965Girls9.106090.6060920.513306
525122Speed2018S800200C117966Boys9.106090.6060920.0551481
525123PowerUP2018S800200C117966Boys9.106090.6060920.0779146
525124PowerLOW2018S800200C117966Boys9.106090.606092-1.32578
525125Coordination2018S800200C117966Boys9.106090.6060920.473217
525126Endurance2018S800200C117966Boys9.106090.606092-0.0941883
+
+
+
+
+
+
+

3.2 Extract a stratified subsample

+

For the prupose of the tutorial, we extract a random sample of 1000 boys and 1000 girls. Child, School, and Cohort are grouping variables. Traditionally, they are called random factors because the units (levels) of the factor are assumed to be a random sample from the population of their units (levels).

+

Cohort has only nine “groups” and could have been included as a set of polynomical fixed-effect contrasts rather than a random factor. This choice warrants a short excursion: The secular trends are very different for different tests and require the inclusion of interaction terms with Test contrasts (see Figure 4 in (Fühner et al., 2021). The authors opted to absorb these effects in cohort-related variance components for the Test contrasts and plan to address the details of secular changes in a separate analysis.

+

For complex designs, when they are in the theoretical focus of an article, factors and covariates should be specified as part of the fixed effects. If they are not in the theoretical focus, but serve as statistical control variables, they could be put in the RES - if supported by the data.

+

Stratified sampling: We generate a Child table with information about children. MersenneTwister(42) specifies 42 as the seed for the random number generator to ensure reproducibility of the stratification. For a different pattern of results choose, for example, 84. We randomly sample 1000 boys and 1000 girls from this table; they are stored in samp. Then, we extract the corresponding subset of these children’s test scores from df and store them dat.

+
+
Child = unique(select(df, :Cohort, :School, :Child, :Sex, :age))
+sample = let
+  rng = MersenneTwister(42)
+  combine(
+    groupby(Child, :Sex), x -> x[rand(rng, 1:nrow(x), 1000), :]
+  )
+end
+insamp(x) = x  sample.Child
+dat = @subset(df, insamp(:Child))
+
+
9663×8 DataFrame
9638 rows omitted
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RowTestCohortSchoolChildSexagea1zScore
Cat…StringStringStringCat…Float64Float64Float64
1Speed2013S101540C002482Girls7.99452-0.5054760.0551481
2PowerUP2013S101540C002482Girls7.99452-0.505476-0.342524
3PowerLOW2013S101540C002482Girls7.99452-0.5054760.74162
4Coordination2013S101540C002482Girls7.99452-0.505476-0.209186
5Endurance2013S101540C002482Girls7.99452-0.505476-0.127938
6Speed2013S102090C002513Girls7.99452-0.505476-0.422921
7PowerUP2013S102090C002513Girls7.99452-0.505476-0.762963
8PowerLOW2013S102090C002513Girls7.99452-0.505476-0.188712
9Coordination2013S102090C002513Girls7.99452-0.5054760.81382
10Endurance2013S102090C002513Girls7.99452-0.5054760.452557
11Speed2013S103299C002621Girls7.99452-0.5054760.859704
12PowerUP2013S103299C002621Girls7.99452-0.5054760.218061
13PowerLOW2013S103299C002621Girls7.99452-0.5054760.74162
9652Coordination2018S111508C117805Girls9.106090.606092-0.95589
9653Endurance2018S111508C117805Girls9.106090.606092-1.67367
9654Speed2018S111648C117827Boys9.106090.6060920.859704
9655PowerUP2018S111648C117827Boys9.106090.6060920.6385
9656PowerLOW2018S111648C117827Boys9.106090.6060920.483194
9657Coordination2018S111648C117827Boys9.106090.6060920.708474
9658Endurance2018S111648C117827Boys9.106090.606092-0.337186
9659Speed2018S112197C117868Boys9.106090.6060920.578748
9660PowerUP2018S112197C117868Boys9.106090.6060920.498354
9661PowerLOW2018S112197C117868Boys9.106090.606092-0.550508
9662Coordination2018S112197C117868Boys9.106090.6060920.538978
9663Endurance2018S112197C117868Boys9.106090.6060920.938553
+
+
+
+

Due to missing scores for some tests we have about 2% less than 10,000 observtions.

+
+
+

3.3 No evidence for age x Sex x Test interaction

+

The main results are captured in the figure constructed in this section. We build it both for the full data and the stratified subset.

+
+
df2 = combine(
+  groupby(
+    select(df, :, :age => ByRow(x -> round(x; digits=1)) => :age),
+    [:Sex, :Test, :age],
+  ),
+  :zScore => mean => :zScore,
+  :zScore => length => :n,
+)
+
+
120×5 DataFrame
95 rows omitted
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RowSexTestagezScoren
Cat…Cat…Float64Float64Int64
1BoysSpeed8.0-0.02651381223
2BoysPowerUP8.00.0269731227
3BoysPowerLOW8.00.1216091227
4BoysCoordination8.0-0.05717261186
5BoysEndurance8.00.2926951210
6GirlsSpeed8.0-0.351641411
7GirlsPowerUP8.0-0.6103551417
8GirlsPowerLOW8.0-0.2798721418
9GirlsCoordination8.0-0.2682211381
10GirlsEndurance8.0-0.2455731387
11BoysSpeed8.10.06083973042
12BoysPowerUP8.10.09554133069
13BoysPowerLOW8.10.1230993069
109BoysCoordination9.00.2549734049
110BoysEndurance9.00.2580824034
111GirlsSpeed9.1-0.02861721154
112GirlsPowerUP9.1-0.07523011186
113GirlsPowerLOW9.1-0.0945871174
114GirlsCoordination9.10.002762521162
115GirlsEndurance9.1-0.2355911150
116BoysSpeed9.10.3257451303
117BoysPowerUP9.10.6164161320
118BoysPowerLOW9.10.2675771310
119BoysCoordination9.10.2543421297
120BoysEndurance9.10.2510451294
+
+
+
+
+

3.3.1 Figure(s) of interaction

+

The core results of the article are reported in Figure 2 of Fühner et al. (2021). In summary:

+
    +
  • Main effects of age and Sex: There are developmental gains in the ninth year of life; boys outperform girls. There is no main effect of Test because of z-scoring.
  • +
  • Interactions of Test and age: Tests differ in how much children improve during the year (i.e., the magnitude of developmental gain), that is slopes depend on Test.
  • +
  • Interactions of Test and Sex: The sex difference is test dependent, that is the difference between the slopes depends on Test.
  • +
  • The most distinctive result is the absence of evidence for an age x Sex x Test interaction, that is the slopes for boys and girls are statistically parallel for each of the five tests.
  • +
+
+
+Code +
let
+  design1 = mapping(:age, :zScore; color=:Sex, col=:Test)
+  lines1 = design1 * linear()
+  means1 = design1 * visual(Scatter; markersize=5)
+  draw(data(df2) * means1 + data(df) * lines1;)
+end
+
+
+
+
+

+
Figure 1: Age trends by sex for each Test for the full data set
+
+
+
+
+

Figure 1 shows performance differences for the full set of data between 8.0 and 9.2 years by sex in the five physical fitness tests presented as z-transformed data computed separately for each test.

+
    +
  • Endurance = cardiorespiratory endurance (i.e., 6-min-run test),
  • +
  • Coordination = star-run test,
  • +
  • Speed = 20-m linear sprint test,
  • +
  • PowerLOW = power of lower limbs (i.e., standing long jump test),
  • +
  • PowerUP = power of upper limbs (i.e., ball push test),
  • +
  • SD = standard deviation. Points are binned observed child means; lines are simple regression fits to the observations.
  • +
+

What do the results look like for the stratified subsample? Here the parallelism is much less clear. In the final LMM we test whether the two regression lines in each of the five panels are statistically parallel for this subset of data. That is, we test the interaction of Sex and age as nested within the levels of Test. Most people want to know the signficance of these five Sex x age interactions.

+

The theoretical focus of the article, however, is on comparisons between tests displayed next to each other. We ask whether the degree of parallelism is statistically the same for Endurance and Coordination (H1), Coordination and Speed (H2), Speed and PowerLOW (H3), and PowerLow and PowerUP (H4). Hypotheses H1 to H4 require Sequential Difference contrasts c1 to c4 for Test; they are tested as fixed effects for`H1 x age x Sex, H2 x age x Sex, H3 x age x Sex, and H4 x age x Sex.

+
+
+Code +
dat2 = combine(
+  groupby(
+    select(dat, :, :age => ByRow(x -> round(x; digits=1)) => :age),
+    [:Sex, :Test, :age],
+  ),
+  :zScore => mean => :zScore,
+  :zScore => length => :n,
+)
+
+
+
120×5 DataFrame
95 rows omitted
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RowSexTestagezScoren
Cat…Cat…Float64Float64Int64
1GirlsSpeed8.0-0.32311428
2GirlsPowerUP8.0-0.59047626
3GirlsPowerLOW8.00.067799227
4GirlsCoordination8.00.027331825
5GirlsEndurance8.0-0.1733726
6BoysSpeed8.00.39463419
7BoysPowerUP8.00.32870319
8BoysPowerLOW8.00.10507719
9BoysCoordination8.0-0.17001819
10BoysEndurance8.00.40708419
11GirlsSpeed8.1-0.20593454
12GirlsPowerUP8.1-0.65396154
13GirlsPowerLOW8.1-0.15712754
109GirlsCoordination9.0-0.00018884268
110GirlsEndurance9.0-0.23444868
111GirlsSpeed9.1-0.28504725
112GirlsPowerUP9.1-0.11268425
113GirlsPowerLOW9.1-0.11764524
114GirlsCoordination9.1-0.12784425
115GirlsEndurance9.1-0.58749624
116BoysSpeed9.10.37980817
117BoysPowerUP9.10.52308517
118BoysPowerLOW9.10.29469617
119BoysCoordination9.10.20930916
120BoysEndurance9.10.26651216
+
+
+
+
+
+Code +
let
+  design2 = mapping(:age, :zScore; color=:Sex, col=:Test)
+  lines2 = design2 * linear()
+  means2 = design2 * visual(Scatter; markersize=5)
+  draw(data(dat2) * means2 + data(dat) * lines2;)
+end
+
+
+
+
+

+
Figure 2: Age trends by sex for each Test for the stratified sample
+
+
+
+
+

Figure 2 Performance differences for subset of data between 8.0 and 9.2 years by sex in the five physical fitness tests presented as z-transformed data computed separately for each test.

+
    +
  • Endurance = cardiorespiratory endurance (i.e., 6-min-run test),
  • +
  • Coordination = star-run test,
  • +
  • Speed = 20-m linear sprint test,
  • +
  • PowerLOW = power of lower limbs (i.e., standing long jump test),
  • +
  • PowerUP = power of upper limbs (i.e., ball push test),
  • +
  • SD = standard deviation. Points are binned observed child means; lines are simple regression fits to the observations.
  • +
+
+
+

3.3.2 Regression on age by Sex for each Test

+

Another set of relevant statistics are the slopes for the regression of performance on age for boys and girls in each of the five tests. The lines in Figures 1 and 2, however, are computed directly from the raw data with the linear() command.

+
+
combine(
+  groupby(df, [:Sex, :Test]),
+  [:age, :zScore] => simplelinreg => :coef,
+)
+
+
10×3 DataFrame
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RowSexTestcoef
Cat…Cat…Tuple…
1BoysEndurance(0.00256718, 0.0291899)
2BoysCoordination(-2.47279, 0.302819)
3BoysSpeed(-2.12689, 0.267153)
4BoysPowerLOW(-1.4307, 0.189659)
5BoysPowerUP(-4.35864, 0.549005)
6GirlsEndurance(-0.692022, 0.0523217)
7GirlsCoordination(-2.50524, 0.279119)
8GirlsSpeed(-2.34431, 0.255687)
9GirlsPowerLOW(-1.87241, 0.196917)
10GirlsPowerUP(-4.82271, 0.524799)
+
+
+
+
+
combine(
+  groupby(dat, [:Sex, :Test]),
+  [:age, :zScore] => simplelinreg => :coef,
+)
+
+
10×3 DataFrame
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RowSexTestcoef
Cat…Cat…Tuple…
1BoysEndurance(0.39203, -0.0150694)
2BoysCoordination(-3.33518, 0.401051)
3BoysSpeed(-1.75685, 0.228662)
4BoysPowerLOW(-1.06646, 0.151546)
5BoysPowerUP(-4.15536, 0.5245)
6GirlsEndurance(0.941712, -0.141158)
7GirlsCoordination(-0.681898, 0.0714891)
8GirlsSpeed(-0.786382, 0.0725931)
9GirlsPowerLOW(-0.208472, 0.00150731)
10GirlsPowerUP(-5.23593, 0.570806)
+
+
+
+
+
+
+

3.4 SeqDiffCoding of Test

+

SeqDiffCoding was used in the publication. This specification tests pairwise differences between the five neighboring levels of Test, that is:

+
    +
  • H1: Star_r - Run (2-1)
  • +
  • H2: S20_r - Star_r (3-2)
  • +
  • H3: SLJ - S20_r (4-3)
  • +
  • H4: BPT - SLJ (5-4)
  • +
+

The levels were sorted such that these contrasts map onto four a priori hypotheses; in other words, they are theoretically motivated pairwise comparisons. The motivation also encompasses theoretically motivated interactions with Sex. The order of levels can also be explicitly specified during contrast construction. This is very useful if levels are in a different order in the dataframe.

+

Note that random factors Child, School, and Cohort are declared as Grouping variables. Technically, this specification is required for variables with a very large number of levels (e.g., 100K+ children). We recommend the explicit specification for all random factors as a general coding style.

+

The first command recodes names indicating the physical fitness components used in the above figures and tables back to the shorter actual test names. This reduces clutter in LMM outputs.

+
+
recode!(
+  dat.Test,
+  "Endurance" => "Run",
+  "Coordination" => "Star_r",
+  "Speed" => "S20_r",
+  "PowerLOW" => "SLJ",
+  "PowerUP" => "BMT",
+)
+contrasts = merge(
+  Dict(nm => SeqDiffCoding() for nm in (:Test, :Sex)),
+  Dict(nm => Grouping() for nm in (:Child, :School, :Cohort)),
+);
+
+

The statistical disadvantage of SeqDiffCoding is that the contrasts are not orthogonal, that is the contrasts are correlated. This is obvious from the fact that levels 2, 3, and 4 are all used in two contrasts. One consequence of this is that correlation parameters estimated between neighboring contrasts (e.g., 2-1 and 3-2) are difficult to interpret. Usually, they will be negative because assuming some practical limitations on the overall range (e.g., between levels 1 and 3), a small “2-1” effect “correlates” negatively with a larger “3-2” effect for mathematical reasons.

+

Obviously, the tradeoff between theoretical motivation and statistical purity is something that must be considered carefully when planning the analysis.

+

Various options for contrast coding are the topic of the MixedModelsTutorial_contrasts_emotikon.jl and MixedModelsTutorial_contrasts_kwdyz.jl notebooks.

+
+
+
+

4 Model complexification

+

We fit and compare three LMMs with the same fixed-effect structure but increasing complexity of the random-effect structure for School. We ignore the other two random factors Child and Cohort to avoid undue delays when fitting the models.

+
    +
  1. LMM m_ovi: allowing only varying intercepts (“Grand Means”);
  2. +
  3. LMM m_zcp: adding variance components (VCs) for the four Test contrasts, Sex, and age to LMM m_ovi, yielding the zero-correlation parameters LMM;
  4. +
  5. LMM m_cpx: adding correlation parameters (CPs) to LMM m_zcp; yielding a complex LMM.
  6. +
+

In a final part illustrate how to check whether the complex model is supported by the data, rather than leading to a singular fit and, if supported by the data, whether there is an increase in goodness of fit associated with the model complexification.

+
+

4.1 LMM m_ovi

+

In its random-effect structure (RES) we only vary intercepts (i.e., Grand Means) for School (LMM m_ovi), that is we allow that the schools differ in the average fitness of its children, average over the five tests.

+

It is well known that such a simple RES is likely to be anti-conservative with respect to fixed-effect test statistics.

+
+
m_ovi = let
+  f = @formula zScore ~ 1 + Test * Sex * a1 + (1 | School)
+  fit(MixedModel, f, dat; contrasts)
+end
+
+ ++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Est.SEzpσ_School
(Intercept)-0.01740.0198-0.880.37870.3417
Test: Star_r-0.00260.0303-0.090.9304
Test: S20_r0.00970.03020.320.7469
Test: SLJ0.00330.03000.110.9119
Test: BMT-0.05390.0299-1.800.0711
Sex: Girls-0.43720.0205-21.35<1e-99
a10.17610.03544.97<1e-06
Test: Star_r & Sex: Girls0.38020.06056.28<1e-09
Test: S20_r & Sex: Girls-0.20380.0604-3.380.0007
Test: SLJ & Sex: Girls-0.06690.0600-1.110.2651
Test: BMT & Sex: Girls-0.27300.0598-4.57<1e-05
Test: Star_r & a10.31460.10383.030.0024
Test: S20_r & a1-0.07670.1034-0.740.4584
Test: SLJ & a1-0.07450.1027-0.730.4683
Test: BMT & a10.47240.10254.61<1e-05
Sex: Girls & a1-0.10440.0709-1.470.1405
Test: Star_r & Sex: Girls & a1-0.19120.2076-0.920.3570
Test: S20_r & Sex: Girls & a10.17420.20680.840.3997
Test: SLJ & Sex: Girls & a10.00840.20540.040.9672
Test: BMT & Sex: Girls & a10.19230.20500.940.3482
Residual0.9152
+
+
+

Is the model singular (overparameterized, degenerate)? In other words: Is the model not supported by the data?

+
+
issingular(m_ovi)
+
+
false
+
+
+

Models varying only in intercepts are almost always supported by the data.

+
+
+

4.2 LMM m_zcp

+

In this LMM we allow that schools differ not only in GM, but also in the size of the four contrasts defined for Test, in the difference between boys and girls (Sex) and the developmental gain children achieve within the third grade (age).

+

We assume that there is covariance associated with these CPs beyond residual noise, that is we assume that there is no detectable evidence in the data that the CPs are different from zero.

+
+
m_zcp = let
+  f = @formula(
+    zScore ~
+      1 + Test * Sex * a1 + zerocorr(1 + Test + Sex + a1 | School)
+  )
+  fit(MixedModel, f, dat; contrasts)
+end
+
+
Minimizing 148   Time: 0:00:00 ( 1.87 ms/it)
+  objective:  25923.460469750346
+
+
+ ++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Est.SEzpσ_School
(Intercept)-0.02470.0198-1.240.21360.3257
Test: Star_r0.00290.03110.090.92540.2208
Test: S20_r0.01020.02860.360.72090.0503
Test: SLJ0.00490.02830.170.86340.0000
Test: BMT-0.04600.0309-1.490.13680.2286
Sex: Girls-0.43990.0322-13.64<1e-410.4503
a10.18400.05733.210.00130.7780
Test: Star_r & Sex: Girls0.37840.05776.55<1e-10
Test: S20_r & Sex: Girls-0.20190.0570-3.540.0004
Test: SLJ & Sex: Girls-0.06660.0566-1.180.2392
Test: BMT & Sex: Girls-0.27800.0570-4.87<1e-05
Test: Star_r & a10.31010.09923.130.0018
Test: S20_r & a1-0.07280.0976-0.750.4558
Test: SLJ & a1-0.07840.0968-0.810.4180
Test: BMT & a10.47410.09794.84<1e-05
Sex: Girls & a1-0.14530.0791-1.840.0662
Test: Star_r & Sex: Girls & a1-0.15700.1982-0.790.4284
Test: S20_r & Sex: Girls & a10.17990.19520.920.3566
Test: SLJ & Sex: Girls & a10.00610.19360.030.9749
Test: BMT & Sex: Girls & a10.16570.19580.850.3974
Residual0.8623
+
+
+

Depending on sampling, this model estimating variance components for School may or may not be supported by the data.

+
+
issingular(m_zcp)
+
+
true
+
+
+
+
+

4.3 LMM m_cpx

+

In the complex LMM investigated in this sequence we give up the assumption of zero-correlation between VCs.

+
+
m_cpx = let
+  f = @formula(
+    zScore ~ 1 + Test * Sex * a1 + (1 + Test + Sex + a1 | School)
+  )
+  fit(MixedModel, f, dat; contrasts)
+end
+
+
Minimizing 2515      Time: 0:00:02 ( 0.85 ms/it)
+  objective:  25864.389680661036
+
+
+ ++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Est.SEzpσ_School
(Intercept)-0.02680.0198-1.350.17570.3264
Test: Star_r0.00560.03100.180.85750.2203
Test: S20_r0.01040.03010.350.72940.1757
Test: SLJ0.00240.02940.080.93570.1477
Test: BMT-0.04010.0305-1.320.18830.2245
Sex: Girls-0.43560.0320-13.61<1e-410.4482
a10.18770.05663.310.00090.7688
Test: Star_r & Sex: Girls0.37590.05756.53<1e-10
Test: S20_r & Sex: Girls-0.19690.0572-3.440.0006
Test: SLJ & Sex: Girls-0.06730.0567-1.190.2350
Test: BMT & Sex: Girls-0.27170.0566-4.80<1e-05
Test: Star_r & a10.31120.09883.150.0016
Test: S20_r & a1-0.07070.0981-0.720.4711
Test: SLJ & a1-0.06420.0971-0.660.5085
Test: BMT & a10.46780.09714.82<1e-05
Sex: Girls & a1-0.14050.0783-1.790.0728
Test: Star_r & Sex: Girls & a1-0.16320.1974-0.830.4085
Test: S20_r & Sex: Girls & a10.18620.19610.950.3424
Test: SLJ & Sex: Girls & a10.00110.19410.010.9954
Test: BMT & Sex: Girls & a10.16380.19420.840.3989
Residual0.8598
+
+
+

We also need to see the VCs and CPs of the random-effect structure (RES).

+
+
VarCorr(m_cpx)
+
+ ++++++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ColumnVarianceStd.DevCorr.
School(Intercept)0.1065430.326409
Test: Star_r0.0485160.220263+0.10
Test: S20_r0.0308590.175666-0.19-0.22
Test: SLJ0.0218280.147744-0.10+0.07-0.83
Test: BMT0.0504090.224519-0.75+0.43-0.13+0.16
Sex: Girls0.2009240.448245-0.04+0.25+0.20-0.26-0.10
a10.5910160.768776+0.02-0.13+0.03-0.49+0.17-0.06
Residual0.7392660.859806
+
+
+
+
issingular(m_cpx)
+
+
true
+
+
+

The complex model may or may not be supported by the data.

+
+
+

4.4 Model comparisons

+

The checks of model singularity indicate that the three models are supported by the data. Does model complexification also increase the goodness of fit or are we only fitting noise?

+
+

4.4.1 LRT and goodness-of-fit statistics

+

As the thee models are strictly hierarchically nested, we compare them with a likelihood-ratio tests (LRT) and AIC and BIC goodness-of-fit statistics derived from them.

+
+
MixedModels.likelihoodratiotest(m_ovi, m_zcp, m_cpx)
+
+ ++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
model-dofdevianceχ²χ²-dofP(>χ²)
zScore ~ 1 + Test + Sex + a1 + Test & Sex + Test & a1 + Sex & a1 + Test & Sex & a1 + (1 | School)2226273
zScore ~ 1 + Test + Sex + a1 + Test & Sex + Test & a1 + Sex & a1 + Test & Sex & a1 + zerocorr(1 + Test + Sex + a1 | School)28259233496<1e-71
zScore ~ 1 + Test + Sex + a1 + Test & Sex + Test & a1 + Sex & a1 + Test & Sex & a1 + (1 + Test + Sex + a1 | School)49258645921<1e-04
+
+
+
+
+Code +
gof_summary = let
+  nms = [:m_ovi, :m_zcp, :m_cpx]
+  mods = eval.(nms)
+  DataFrame(;
+    name=nms,
+    dof=dof.(mods),
+    deviance=deviance.(mods),
+    AIC=aic.(mods),
+    AICc=aicc.(mods),
+    BIC=bic.(mods),
+  )
+end
+
+
+
3×6 DataFrame
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RownamedofdevianceAICAICcBIC
SymbolInt64Float64Float64Float64Float64
1m_ovi2226272.926316.926317.026474.8
2m_zcp2825923.525979.525979.626180.4
3m_cpx4925864.425962.425962.926314.0
+
+
+
+

These statistics will depend on sampling. In general, smaller deviance, AIC, and BIC indicate an improvement in goodness of fit. Usually, χ² should be larger than the associated degrees of freedom; for AIC and BIC the decrease should amount to more than 5, according to some literature. Severity of meeting these criteria increases from deviance to AIC to BIC. Therefore, it is not always the case that the criteria are unanimous in their verdict. Basicly, the more confirmatory the analysis, the more one may go with deviance and AIC; for exploratory analyses the BIC is probably a better guide. There are grey zones here.

+
+
+

4.4.2 Comparing fixed effects of m_ovi, m_zcp, and m_cpx

+

We check whether enriching the RES changed the significance of fixed effects in the final model.

+
+
+Code +
m_ovi_fe = DataFrame(coeftable(m_ovi));
+m_zcp_fe = DataFrame(coeftable(m_zcp));
+m_cpx_fe = DataFrame(coeftable(m_cpx));
+m_all = hcat(
+  m_ovi_fe[:, [1, 2, 4]],
+  leftjoin(
+    m_zcp_fe[:, [1, 2, 4]],
+    m_cpx_fe[:, [1, 2, 4]];
+    on=:Name,
+    makeunique=true,
+  );
+  makeunique=true,
+)
+rename!(
+  m_all,
+  "Coef." => "b_ovi",
+  "Coef._2" => "b_zcp",
+  "Coef._1" => "b_cpx",
+  "z" => "z_ovi",
+  "z_2" => "z_zcp",
+  "z_1" => "z_cpx",
+)
+m_all2 =
+  round.(
+    m_all[:, [:b_ovi, :b_zcp, :b_cpx, :z_ovi, :z_zcp, :z_cpx]],
+    digits=2,
+  )
+m_all3 = hcat(m_all.Name, m_all2)
+
+
+
20×7 DataFrame
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Rowx1b_ovib_zcpb_cpxz_oviz_zcpz_cpx
StringFloat64Float64Float64Float64Float64Float64
1(Intercept)-0.02-0.02-0.03-0.88-1.24-1.35
2Test: Star_r-0.00.00.01-0.090.090.18
3Test: S20_r0.010.010.010.320.360.35
4Test: SLJ0.00.00.00.110.170.08
5Test: BMT-0.05-0.05-0.04-1.8-1.49-1.32
6Sex: Girls-0.44-0.44-0.44-21.35-13.64-13.61
7a10.180.180.194.973.213.31
8Test: Star_r & Sex: Girls0.380.380.386.286.556.53
9Test: S20_r & Sex: Girls-0.2-0.2-0.2-3.38-3.54-3.44
10Test: SLJ & Sex: Girls-0.07-0.07-0.07-1.11-1.18-1.19
11Test: BMT & Sex: Girls-0.27-0.28-0.27-4.57-4.87-4.8
12Test: Star_r & a10.310.310.313.033.133.15
13Test: S20_r & a1-0.08-0.07-0.07-0.74-0.75-0.72
14Test: SLJ & a1-0.07-0.08-0.06-0.73-0.81-0.66
15Test: BMT & a10.470.470.474.614.844.82
16Sex: Girls & a1-0.1-0.15-0.14-1.47-1.84-1.79
17Test: Star_r & Sex: Girls & a1-0.19-0.16-0.16-0.92-0.79-0.83
18Test: S20_r & Sex: Girls & a10.170.180.190.840.920.95
19Test: SLJ & Sex: Girls & a10.010.010.00.040.030.01
20Test: BMT & Sex: Girls & a10.190.170.160.940.850.84
+
+
+
+

The three models usually do not differ in fixed-effect estimates. For main effects of age and Sex, z-values decrease strongly with the complexity of the model (i.e., standard errors are larger). For other coefficients, the changes are not very large and not consistent.

+

In general, dropping significant variance components and/or correlation parameters may lead to anti-conservative estimates of fixed effects (e.g., Schielzeth & Forstmeier, 2008). Basically, some of the variance allocated to age and Sex in LMM m_ovi could also be due to differences between schools. This ambiguity increased the uncertainty of the respective fixed effects in the other two LMMs.

+
+
+
+

4.5 Fitting an overparameterized LMM

+

The complex LMM was not overparameterized with respect to School, because there are over 400 schools in the data. When the number of units (levels) of a grouping factor is small relative to the number of parameters we are trying to estimate, we often end up with an overparameterized / degenerate random-effect structure.

+

As an illustration, we fit a full CP matrix for the Cohort. As there are only nine cohorts in the data, we may be asking too much to estimate 5*6/2 = 15 VC/CP parameters.

+
+
m_cpxCohort = let
+  f = @formula zScore ~ 1 + Test * a1 * Sex + (1 + Test | Cohort)
+  fit(MixedModel, f, dat; contrasts)
+end
+
+ ++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Est.SEzpσ_Cohort
(Intercept)-0.00090.0161-0.060.95480.0378
Test: Star_r-0.00730.0380-0.190.84820.0614
Test: S20_r0.00560.03830.150.88450.0636
Test: SLJ0.01010.04510.220.82260.0959
Test: BMT-0.05560.0335-1.660.09680.0330
a10.20550.03495.90<1e-08
Sex: Girls-0.42380.0201-21.07<1e-97
Test: Star_r & a10.28490.11012.590.0097
Test: S20_r & a1-0.11720.1096-1.070.2851
Test: SLJ & a1-0.02700.1094-0.250.8049
Test: BMT & a10.45550.10844.20<1e-04
Test: Star_r & Sex: Girls0.37000.06405.78<1e-08
Test: S20_r & Sex: Girls-0.21160.0638-3.320.0009
Test: SLJ & Sex: Girls-0.05520.0634-0.870.3844
Test: BMT & Sex: Girls-0.27180.0632-4.30<1e-04
a1 & Sex: Girls-0.13680.0690-1.980.0473
Test: Star_r & a1 & Sex: Girls-0.20990.2194-0.960.3387
Test: S20_r & a1 & Sex: Girls0.16090.21860.740.4616
Test: SLJ & a1 & Sex: Girls0.02250.21720.100.9174
Test: BMT & a1 & Sex: Girls0.19010.21660.880.3801
Residual0.9671
+
+
+
+
VarCorr(m_cpxCohort)
+
+ ++++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ColumnVarianceStd.DevCorr.
Cohort(Intercept)0.00142730.0377794
Test: Star_r0.00376510.0613601-0.90
Test: S20_r0.00404490.0635995-1.00+0.87
Test: SLJ0.00918850.0958567+0.98-0.97-0.97
Test: BMT0.00108820.0329872-1.00+0.91+0.99-0.99
Residual0.93531390.9671163
+
+
+
+
issingular(m_cpxCohort)
+
+
true
+
+
+

The model is overparameterized with several CPs estimated between |.98| and |1.00|. How about the zero-correlation parameter (zcp) version of this LMM?

+
+
m_zcpCohort = let
+  f = @formula(
+    zScore ~ 1 + Test * a1 * Sex + zerocorr(1 + Test | Cohort)
+  )
+  fit(MixedModel, f, dat; contrasts)
+end
+
+ ++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Est.SEzpσ_Cohort
(Intercept)-0.00220.0152-0.150.88370.0341
Test: Star_r-0.00420.0339-0.120.90230.0331
Test: S20_r0.00880.03190.270.78370.0000
Test: SLJ0.00450.03170.140.88760.0000
Test: BMT-0.05360.0316-1.690.09030.0000
a10.19990.03515.70<1e-07
Sex: Girls-0.42450.0201-21.08<1e-97
Test: Star_r & a10.30780.11012.800.0052
Test: S20_r & a1-0.08490.1093-0.780.4377
Test: SLJ & a1-0.07480.1086-0.690.4911
Test: BMT & a10.47170.10844.35<1e-04
Test: Star_r & Sex: Girls0.37290.06405.82<1e-08
Test: S20_r & Sex: Girls-0.20790.0638-3.260.0011
Test: SLJ & Sex: Girls-0.06110.0634-0.960.3354
Test: BMT & Sex: Girls-0.26970.0632-4.27<1e-04
a1 & Sex: Girls-0.13720.0691-1.990.0470
Test: Star_r & a1 & Sex: Girls-0.20410.2195-0.930.3525
Test: S20_r & a1 & Sex: Girls0.17330.21870.790.4280
Test: SLJ & a1 & Sex: Girls0.00510.21720.020.9811
Test: BMT & a1 & Sex: Girls0.19620.21680.900.3655
Residual0.9680
+
+
+
+
issingular(m_zcpCohort)
+
+
true
+
+
+

This zcpLMM is also singular. Three of the five VCs are estimated as zero. This raises the possibility that LMM m_oviCohort might fit as well as LMM m_zcpCohort.

+
+
m_oviCohort = let
+  f = @formula zScore ~ 1 + Test * a1 * Sex + (1 | Cohort)
+  fit(MixedModel, f, dat; contrasts)
+end
+
+ ++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Est.SEzpσ_Cohort
(Intercept)-0.00220.0152-0.150.88350.0340
Test: Star_r-0.00320.0320-0.100.9196
Test: S20_r0.00870.03190.270.7847
Test: SLJ0.00450.03170.140.8869
Test: BMT-0.05360.0316-1.690.0903
a10.19990.03515.69<1e-07
Sex: Girls-0.42450.0201-21.08<1e-97
Test: Star_r & a10.31350.10972.860.0043
Test: S20_r & a1-0.08480.1093-0.780.4378
Test: SLJ & a1-0.07480.1086-0.690.4910
Test: BMT & a10.47180.10844.35<1e-04
Test: Star_r & Sex: Girls0.37360.06405.84<1e-08
Test: S20_r & Sex: Girls-0.20790.0638-3.260.0011
Test: SLJ & Sex: Girls-0.06110.0634-0.960.3356
Test: BMT & Sex: Girls-0.26970.0632-4.27<1e-04
a1 & Sex: Girls-0.13710.0691-1.990.0471
Test: Star_r & a1 & Sex: Girls-0.20220.2195-0.920.3568
Test: S20_r & a1 & Sex: Girls0.17330.21870.790.4281
Test: SLJ & a1 & Sex: Girls0.00510.21720.020.9811
Test: BMT & a1 & Sex: Girls0.19610.21680.900.3657
Residual0.9681
+
+
+
+
issingular(m_oviCohort)
+
+
false
+
+
+

This solves the problem with singularity, but does LMM m_zcpCohort fit noise relative to the LMM m_oviCohort?

+
+
MixedModels.likelihoodratiotest(m_oviCohort, m_zcpCohort)
+
+ ++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
model-dofdevianceχ²χ²-dofP(>χ²)
zScore ~ 1 + Test + a1 + Sex + Test & a1 + Test & Sex + a1 & Sex + Test & a1 & Sex + (1 | Cohort)2226803
zScore ~ 1 + Test + a1 + Sex + Test & a1 + Test & Sex + a1 & Sex + Test & a1 & Sex + zerocorr(1 + Test | Cohort)2626803040.9968
+
+
+
+
gof_summary2 = let
+  mods = [m_oviCohort, m_zcpCohort, m_cpxCohort]
+  DataFrame(;
+    dof=dof.(mods),
+    deviance=deviance.(mods),
+    AIC=aic.(mods),
+    AICc=aicc.(mods),
+    BIC=bic.(mods),
+  )
+end
+
+
3×5 DataFrame
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RowdofdevianceAICAICcBIC
Int64Float64Float64Float64Float64
12226802.926846.926847.027004.7
22626802.726854.726854.827041.3
33626790.526862.526862.727120.8
+
+
+
+

Indeed, adding VCs is fitting noise. Again, the goodness of fit statistics unanimously favor the selection of the LMM m_oviCohort.

+

Not shown here, but the Cohort-related VCs for the Test contrasts could be estimated reliably for the full data. Thus, the small number of cohorts does not necessarily prevent the determination of reliable differences between tests across cohorts. What if we include VCs and CPs related to random factors Child and School?

+
+
+

4.6 Fitting the published LMM m1 to the reduced data

+
+
+
+ +
+
+Warning +
+
+
+

The following LMMs m1, m2, etc. take a bit longer (e.g., close to 6 minutes in the Pluto notebook, close to 3 minutes in the REPL on a MacBook Pro).

+
+
+

LMM m1 reported in Fühner et al. (2021) included random factors for School, Child, and Cohort. The RES for School was specified like in LMM m_cpx. The RES for Child included VCs and CPs for Test, but not for linear developmental gain in the ninth year of life a1 or Sex; they are between-Child effects.

+

The RES for Cohort included only VCs, no CPs for Test. The parsimony was due to the small number of nine levels for this grouping factor.

+

Here we fit this LMM m1 for the reduced data. For a different subset of similar size on MacBook Pro [13 | 15 | 16] this took [303 | 250 | 244 ] s; for LMM m1a (i.e., dropping 1 school-relate VC for Sex), times are [212 | 165 | 160] s. The corresponding lme4 times for LMM m1 are [397 | 348 | 195].

+

Finally, times for fitting the full set of data –not in this script–, for LMM m1are [60 | 62 | 85] minutes (!); for LMM m1a the times were [46 | 48 | 34] minutes. It was not possible to fit the full set of data with lme4; after about 13 to 18 minutes the program stopped with: Error in eval_f(x, ...) : Downdated VtV is not positive definite.

+
+
m1 = let
+  f = @formula(
+    zScore ~
+      1 +
+      Test * a1 * Sex +
+      (1 + Test + a1 + Sex | School) +
+      (1 + Test | Child) +
+      zerocorr(1 + Test | Cohort)
+  )
+  fit(MixedModel, f, dat; contrasts)
+end
+
+
Minimizing 2162      Time: 0:00:31 (14.80 ms/it)
+  objective:  24651.01322999849
+
+
+ ++++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Est.SEzpσ_Childσ_Schoolσ_Cohort
(Intercept)-0.01330.0192-0.690.48780.59080.21380.0132
Test: Star_r0.00880.03750.240.81350.77050.33290.0637
Test: S20_r0.00920.02930.310.75420.66560.32810.0068
Test: SLJ0.00340.02990.110.91050.57860.32120.0339
Test: BMT-0.03830.0296-1.290.19540.74910.31300.0000
a10.19550.05443.590.00030.2823
Sex: Girls-0.42870.0312-13.75<1e-420.1438
Test: Star_r & a10.28980.08873.270.0011
Test: S20_r & a1-0.07840.0817-0.960.3373
Test: SLJ & a1-0.06310.0769-0.820.4116
Test: BMT & a10.47130.08515.54<1e-07
Test: Star_r & Sex: Girls0.37560.05117.35<1e-12
Test: S20_r & Sex: Girls-0.18670.0475-3.93<1e-04
Test: SLJ & Sex: Girls-0.06950.0445-1.560.1184
Test: BMT & Sex: Girls-0.28120.0495-5.68<1e-07
a1 & Sex: Girls-0.12670.1048-1.210.2269
Test: Star_r & a1 & Sex: Girls-0.13820.1756-0.790.4312
Test: S20_r & a1 & Sex: Girls0.17530.16331.070.2832
Test: SLJ & a1 & Sex: Girls-0.01540.1530-0.100.9196
Test: BMT & a1 & Sex: Girls0.15480.17020.910.3630
Residual0.5136
+
+
+
+
VarCorr(m1)
+
+ ++++++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ColumnVarianceStd.DevCorr.
Child(Intercept)0.349039800.59079590
Test: Star_r0.593642200.77048180+0.14
Test: S20_r0.443043050.66561479+0.00-0.52
Test: SLJ0.334810890.57862846+0.05-0.04-0.37
Test: BMT0.561207730.74913799-0.33+0.13-0.17-0.25
School(Intercept)0.045697340.21376937
Test: Star_r0.110813380.33288644-0.06
Test: S20_r0.107634420.32807686-0.08-0.39
Test: SLJ0.103147450.32116576-0.19+0.21-0.80
Test: BMT0.097962130.31298902-0.33-0.02+0.13-0.38
a10.079714640.28233780+0.62-0.20+0.11-0.61+0.45
Sex: Girls0.020669030.14376729-0.45+0.45+0.31-0.27-0.15-0.37
Cohort(Intercept)0.000173360.01316656
Test: Star_r0.004059750.06371614.
Test: S20_r0.000046310.00680502..
Test: SLJ0.001146310.03385719...
Test: BMT0.000000000.00000000....
Residual0.263772710.51358807
+
+
+
+
issingular(m1)
+
+
true
+
+
+

Depending on the random number for stratified samplign, LMM m1 may or may not be supported by the data.

+

We also fit an alternative parameterization, estimating VCs and CPs for Test scores rather than Test effects by replacing the 1 + ... in the RE terms with 0 + ....

+
+
m2 = let
+  f = @formula(
+    zScore ~
+      1 +
+      Test * a1 * Sex +
+      (0 + Test + a1 + Sex | School) +
+      (0 + Test | Child) +
+      zerocorr(0 + Test | Cohort)
+  )
+  fit(MixedModel, f, dat; contrasts)
+end
+
+
Minimizing 1464      Time: 0:00:21 (14.46 ms/it)
+  objective:  24646.87190533457
+
+
+ ++++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Est.SEzpσ_Childσ_Schoolσ_Cohort
(Intercept)-0.01360.0195-0.700.4844
Test: Star_r0.00930.03650.260.79870.79720.31030.0208
Test: S20_r0.00600.03540.170.86530.76780.33050.0563
Test: SLJ0.00520.03390.150.87870.78060.24780.0157
Test: BMT-0.03880.0300-1.290.19670.69700.19690.0000
a10.19350.05453.550.00040.2833
Sex: Girls-0.42900.0312-13.75<1e-420.1433
Test: Star_r & a10.29320.08873.310.0009
Test: S20_r & a1-0.10070.0826-1.220.2228
Test: SLJ & a1-0.04560.0773-0.590.5549
Test: BMT & a10.46850.08535.50<1e-07
Test: Star_r & Sex: Girls0.37590.05117.36<1e-12
Test: S20_r & Sex: Girls-0.18920.0475-3.98<1e-04
Test: SLJ & Sex: Girls-0.06800.0445-1.530.1262
Test: BMT & Sex: Girls-0.28150.0495-5.68<1e-07
a1 & Sex: Girls-0.12620.1049-1.200.2290
Test: Star_r & a1 & Sex: Girls-0.13710.1756-0.780.4348
Test: S20_r & a1 & Sex: Girls0.17200.16341.050.2926
Test: SLJ & a1 & Sex: Girls-0.01250.1529-0.080.9348
Test: BMT & a1 & Sex: Girls0.15420.17020.910.3648
Test: Run0.75010.37020.0548
Residual0.5118
+
+
+
+
issingular(m2)
+
+
true
+
+
+

Depending on the random number generator seed, the model may or may not be supported in the alternative parameterization of scores. The fixed-effects profile is not affected (see 2.8 below).

+
+
+
+ +
+
+Caution +
+
+
+

RK: The order of RE terms is critical. In formula f2 the zerocorr() term must be placed last as shown. If it is placed first, School-related and Child-related CPs are estimated/reported (?) as zero. This was not the case for formula m1. Thus, it appears to be related to the 0-intercepts in School and Child terms. Need a reprex.

+
+
+
+
VarCorr(m2)
+
+ ++++++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ColumnVarianceStd.DevCorr.
ChildTest: Run0.56263150.7500877
Test: Star_r0.63548710.7971744+0.50
Test: S20_r0.58946300.7677650+0.56+0.64
Test: SLJ0.60932490.7805927+0.55+0.60+0.72
Test: BMT0.48583960.6970219+0.19+0.40+0.37+0.49
SchoolTest: Run0.13703670.3701847
Test: Star_r0.09628420.3102970+0.53
Test: S20_r0.10924590.3305237+0.47+0.48
Test: SLJ0.06139160.2477733+0.47+0.76+0.41
Test: BMT0.03875550.1968641+0.15+0.38+0.18+0.02
a10.08024300.2832720+0.58+0.47+0.56-0.05+0.65
Sex: Girls0.02054880.1433486-0.63-0.27+0.06-0.28-0.58-0.37
CohortTest: Run0.00300670.0548338
Test: Star_r0.00043470.0208494.
Test: S20_r0.00317250.0563249..
Test: SLJ0.00024520.0156604...
Test: BMT0.00000000.0000000....
Residual0.26191460.5117760
+
+
+
+
+

4.7 Principle Component Analysis of Random Effect Structure (rePCA)

+

The ìssingular() command is sort of a shortcut for a quick inspection of the principle components (PCs) of the variance-covariance matrix of the RES. With the MixedModels.PCA() command, we also obtain information about the amount of cumulative variance accounted for as we add PCs.

+

The output also provides PC loadings which may facilitate interpretation of the CP matrices (if estimated). This topic will be picked uo in a separate vignette. See also Fühner et al. (2021) for an application.

+
+
+

4.8 Effects in RES

+

For every random factor, MixedModels.PCA() extracts as many PCs as there are VCs. Therefore, the cumulation of variance across PCs within a random factor will always add up to 100% – at the latest with the last VC, but, in the case of overparameterized LMMs, the ceiling will be reached earlier. The final PCs are usually quite small.

+

PCs are extracted in the order of the amount of unique variance they account for. The first PC accounts for the largest and the final PC for the least amount of variance. The number the PCs with percent variance above a certain threshold indicates the number of weighted composites needed and reflects the dimensionality of the orthogonal space within which (almost) all the variance can be accounted for. The weights for forming composite scores are the listed loadings. For ease of interpretation it is often useful to change the sign of some composite scores.

+

The PCA for LMM m1 shows that each of the five PCs for Child accounts for a non-zero percent of unique variance.

+

For School fewer than seven PCs have unique variance. The exact number depends on sampling. The overparameterization of School might be resolved when the CPs for Sex are dropped from the LMM.

+

Cohort was estimated with CPs forced to zero. Therefore, the VCs were forced to be orthogonal; they already represent the PCA solution. However, depending on sampling, not all PCs may be identified for this random factor either.

+

Importantly, again depending on sampling, a non-singular fit does not imply that unique variance is associated with all PCs (i.e., not for last PC for School). Embrace uncertainty!

+
+
MixedModels.PCA(m1)
+
+
(Child = 
+Principal components based on correlation matrix
+ (Intercept)    1.0     .      .      .      .
+ Test: Star_r   0.14   1.0     .      .      .
+ Test: S20_r    0.0   -0.52   1.0     .      .
+ Test: SLJ      0.05  -0.04  -0.37   1.0     .
+ Test: BMT     -0.33   0.13  -0.17  -0.25   1.0
+
+Normalized cumulative variances:
+[0.3283, 0.6158, 0.8282, 0.9389, 1.0]
+
+Component loadings
+                 PC1    PC2    PC3    PC4    PC5
+ (Intercept)   -0.08   0.54   0.59  -0.59  -0.02
+ Test: Star_r  -0.6   -0.11   0.45   0.42   0.5
+ Test: S20_r    0.71   0.04   0.15   0.06   0.68
+ Test: SLJ     -0.33   0.44  -0.65  -0.22   0.48
+ Test: BMT     -0.14  -0.71  -0.01  -0.65   0.24, School = 
+Principal components based on correlation matrix
+ (Intercept)    1.0     .      .      .      .      .      .
+ Test: Star_r  -0.06   1.0     .      .      .      .      .
+ Test: S20_r   -0.08  -0.39   1.0     .      .      .      .
+ Test: SLJ     -0.19   0.21  -0.8    1.0     .      .      .
+ Test: BMT     -0.33  -0.02   0.13  -0.38   1.0     .      .
+ a1             0.62  -0.2    0.11  -0.61   0.45   1.0     .
+ Sex: Girls    -0.45   0.45   0.31  -0.27  -0.15  -0.37   1.0
+
+Normalized cumulative variances:
+[0.3569, 0.6351, 0.8058, 0.9687, 1.0, 1.0, 1.0]
+
+Component loadings
+                 PC1    PC2    PC3    PC4    PC5    PC6    PC7
+ (Intercept)   -0.25  -0.49  -0.42  -0.37   0.18   0.52   0.29
+ Test: Star_r   0.31   0.12   0.17  -0.75   0.47  -0.25  -0.1
+ Test: S20_r   -0.4    0.44  -0.31   0.2    0.52  -0.29   0.39
+ Test: SLJ      0.55  -0.31   0.11   0.2    0.03  -0.21   0.71
+ Test: BMT     -0.29   0.14   0.79   0.0    0.15   0.41   0.28
+ a1            -0.52  -0.27   0.16  -0.31  -0.41  -0.57   0.2
+ Sex: Girls     0.14   0.6   -0.2   -0.34  -0.53   0.23   0.36, Cohort = 
+Principal components based on correlation matrix
+ (Intercept)   1.0  .    .    .    .
+ Test: Star_r  0.0  1.0  .    .    .
+ Test: S20_r   0.0  0.0  1.0  .    .
+ Test: SLJ     0.0  0.0  0.0  1.0  .
+ Test: BMT     0.0  0.0  0.0  0.0  0.0
+
+Normalized cumulative variances:
+[0.25, 0.5, 0.75, 1.0, 1.0]
+
+Component loadings
+                PC1   PC2   PC3   PC4     PC5
+ (Intercept)   0.0   0.0   1.0   0.0     0.0
+ Test: Star_r  1.0   0.0   0.0   0.0     0.0
+ Test: S20_r   0.0   0.0   0.0   1.0     0.0
+ Test: SLJ     0.0   1.0   0.0   0.0     0.0
+ Test: BMT     0.0   0.0   0.0   0.0   NaN)
+
+
+
+

4.8.1 Scores in RES

+

Now lets looks at the PCA results for the alternative parameterization of LMM m2. It is important to note that the reparameterization to base estimates of VCs and CPs on scores rather than effects applies only to the Test factor (i.e., the first factor in the formula); VCs for Sex and age refer to the associated effects.

+

Depending on sampling, the difference between LMM m1 and LMM m2 may show that overparameterization according to PCs may depend on the specification chosen for the other the random-effect structure.

+
+
+
+ +
+
+Note +
+
+
+

For the complete data, all PCs had unique variance associated with them.

+
+
+
+
MixedModels.PCA(m2)
+
+
(Child = 
+Principal components based on correlation matrix
+ Test: Run     1.0    .     .     .     .
+ Test: Star_r  0.5   1.0    .     .     .
+ Test: S20_r   0.56  0.64  1.0    .     .
+ Test: SLJ     0.55  0.6   0.72  1.0    .
+ Test: BMT     0.19  0.4   0.37  0.49  1.0
+
+Normalized cumulative variances:
+[0.6114, 0.7767, 0.8675, 0.9484, 1.0]
+
+Component loadings
+                 PC1    PC2    PC3    PC4    PC5
+ Test: Run     -0.42   0.53   0.63   0.37   0.08
+ Test: Star_r  -0.47   0.03  -0.65   0.58  -0.16
+ Test: S20_r   -0.49   0.15  -0.24  -0.49   0.66
+ Test: SLJ     -0.5   -0.05   0.09  -0.5   -0.7
+ Test: BMT     -0.34  -0.83   0.33   0.2    0.2, School = 
+Principal components based on correlation matrix
+ Test: Run      1.0     .      .      .      .      .      .
+ Test: Star_r   0.53   1.0     .      .      .      .      .
+ Test: S20_r    0.47   0.48   1.0     .      .      .      .
+ Test: SLJ      0.47   0.76   0.41   1.0     .      .      .
+ Test: BMT      0.15   0.38   0.18   0.02   1.0     .      .
+ a1             0.58   0.47   0.56  -0.05   0.65   1.0     .
+ Sex: Girls    -0.63  -0.27   0.06  -0.28  -0.58  -0.37   1.0
+
+Normalized cumulative variances:
+[0.4822, 0.6938, 0.8508, 0.9553, 1.0, 1.0, 1.0]
+
+Component loadings
+                 PC1    PC2    PC3    PC4    PC5    PC6    PC7
+ Test: Run     -0.44   0.08   0.15  -0.64  -0.16  -0.51   0.29
+ Test: Star_r  -0.44   0.28   0.02   0.41  -0.56   0.32   0.38
+ Test: S20_r   -0.34   0.27  -0.58  -0.1    0.6    0.24   0.21
+ Test: SLJ     -0.32   0.56   0.33   0.25   0.22  -0.23  -0.55
+ Test: BMT     -0.32  -0.53  -0.02   0.55   0.25  -0.47   0.19
+ a1            -0.41  -0.35  -0.42  -0.14  -0.33   0.11  -0.62
+ Sex: Girls     0.34   0.35  -0.59   0.18  -0.29  -0.55  -0.0, Cohort = 
+Principal components based on correlation matrix
+ Test: Run     1.0  .    .    .    .
+ Test: Star_r  0.0  1.0  .    .    .
+ Test: S20_r   0.0  0.0  1.0  .    .
+ Test: SLJ     0.0  0.0  0.0  1.0  .
+ Test: BMT     0.0  0.0  0.0  0.0  0.0
+
+Normalized cumulative variances:
+[0.25, 0.5, 0.75, 1.0, 1.0]
+
+Component loadings
+                PC1   PC2   PC3   PC4     PC5
+ Test: Run     1.0   0.0   0.0   0.0     0.0
+ Test: Star_r  0.0   1.0   0.0   0.0     0.0
+ Test: S20_r   0.0   0.0   1.0   0.0     0.0
+ Test: SLJ     0.0   0.0   0.0   1.0     0.0
+ Test: BMT     0.0   0.0   0.0   0.0   NaN)
+
+
+
+
+
+

4.9 Summary of results for stratified subset of data

+

Returning to the theoretical focus of the article, the significant main effects of age and Sex, the interactions between age and c1 and c4 contrasts and the interactions between Sex and three test contrasts (c1, c2, c4) are replicated. Obviously, the subset of data is much noisier than the full set.

+
+
+
+

5 Age x Sex nested in levels of Test

+

In this final LMM, we test post-hoc five age x Sex interactions by nesting the interaction in the levels of Test. As this LMM m2_nested is a reparameterization of LMM m2.

+
+
m2_nested = let
+  f = @formula(
+    zScore ~
+      1 +
+      Test +
+      Test & (a1 * Sex) +
+      (0 + Test + a1 + Sex | School) +
+      (0 + Test | Child) +
+      zerocorr(0 + Test | Cohort)
+  )
+  fit(MixedModel, f, dat; contrasts)
+end
+
+
Minimizing 1781      Time: 0:00:25 (14.48 ms/it)
+  objective:  24646.871904034535
+
+
+ ++++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Est.SEzpσ_Childσ_Schoolσ_Cohort
(Intercept)-0.01360.0195-0.700.4844
Test: Star_r0.00930.03650.260.79870.79180.31030.0208
Test: S20_r0.00600.03540.170.86530.76210.33050.0563
Test: SLJ0.00520.03390.150.87870.77510.24780.0157
Test: BMT-0.03880.0300-1.290.19670.69080.19680.0000
Test: Run & a1-0.05610.0783-0.720.4735
Test: Star_r & a10.23700.08012.960.0031
Test: S20_r & a10.13640.07861.740.0826
Test: SLJ & a10.09080.07741.170.2409
Test: BMT & a10.55930.07167.81<1e-14
Test: Run & Sex: Girls-0.53270.0448-11.90<1e-31
Test: Star_r & Sex: Girls-0.15680.0461-3.400.0007
Test: S20_r & Sex: Girls-0.34600.0449-7.70<1e-13
Test: SLJ & Sex: Girls-0.41400.0447-9.26<1e-19
Test: BMT & Sex: Girls-0.69550.0414-16.80<1e-62
Test: Run & a1 & Sex: Girls-0.14550.1523-0.950.3396
Test: Star_r & a1 & Sex: Girls-0.28260.1572-1.800.0722
Test: S20_r & a1 & Sex: Girls-0.11060.1530-0.720.4695
Test: SLJ & a1 & Sex: Girls-0.12310.1516-0.810.4167
Test: BMT & a1 & Sex: Girls0.03110.14040.220.8248
a10.2833
Sex: Girls0.1434
Test: Run0.74430.37020.0548
Residual0.5201
+
+
+

The results show that none of the interactions in the panels of Figure 2 is significant. The size and direction of interaction effects correspond with what is shown in Figure 2.

+
+

5.0.1 CONSTRUCTION SITE: More model comparisons

+
+
+Code +
gof_summary3 = let
+  nms = [:m1, :m2, :m2_nested]
+  mods = eval.(nms)
+  DataFrame(;
+    name=nms,
+    dof=dof.(mods),
+    deviance=deviance.(mods),
+    AIC=aic.(mods),
+    AICc=aicc.(mods),
+    BIC=bic.(mods),
+  )
+end
+
+
+
3×6 DataFrame
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RownamedofdevianceAICAICcBIC
SymbolInt64Float64Float64Float64Float64
1m16924651.024789.024790.025284.2
2m26924646.924784.924785.925280.0
3m2_nested6924646.924784.924785.925280.0
+
+
+
+
+
n, p, q, k = size(m1)  # nobs, fe params, VCs+CPs, re terms
+
+
(9663, 20, 13076, 3)
+
+
+

In prinicple, the models should yield the save deviance. When models are not supported by the data, that is for singular models, there may be small differences between deviances for these reparameterizations. During optimization such models search for the absolute minimum in a very shallow surface and may end up in a local minimum instead.

+
+
+

5.0.2 Geometric degrees of freedom

+

From MixedModels documentation: “The sum of the leverage values is the rank of the model matrix and n - sum(leverage(m)) is the degrees of freedom for residuals. The sum of the leverage values is also the trace of the so-called”hat” matrixH.”

+

New term: geometric degrees of freedom.

+
+
m1_geomdf = sum(leverage(m1))  # geom_dof
+
+
5746.176138702353
+
+
+
+
sum(leverage(m2))
+
+
5770.539545559104
+
+
+
+
sum(leverage(m2_nested))
+
+
5642.49781841101
+
+
+
+
n - m1_geomdf
+
+
3916.8238612976475
+
+
+
+
m1.feterm.rank
+
+
20
+
+
+
+
dof(m1)
+
+
69
+
+
+
+
+
+

6 Glossary of MixedModels.jl commands

+

Here we introduce most of the commands available in the MixedModels.jl package that allow the immediated inspection and analysis of results returned in a fitted linear mixed-effect model.

+

Postprocessing related to conditional modes will be dealt with in a different tutorial.

+
+

6.1 Overall summary statistics

+
+ julia> m1.optsum         # MixedModels.OptSummary:  gets all info
++ julia> loglikelihood(m1) # StatsBase.loglikelihood: return loglikelihood
+                             of the model
++ julia> deviance(m1)      # StatsBase.deviance: negative twice the log-likelihood
+                             relative to saturated model
++ julia> objective(m1)     # MixedModels.objective: saturated model not clear:
+                             negative twice the log-likelihood
++ julia> nobs(m1)          # n of observations; they are not independent
++ julia> dof(m1)           # n of degrees of freedom is number of model parameters
++ julia> aic(m1)           # objective(m1) + 2*dof(m1)
++ julia> bic(m1)           # objective(m1) + dof(m1)*log(nobs(m1))
+
+
m1.optsum            # MixedModels.OptSummary:  gets all info
+
+ ++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Initialization
Initial parameter vector[1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
Initial objective value25840.65375540981
Optimizer settings
Optimizer (from NLopt)LN_BOBYQA
Lower bounds[0.0, -Inf, -Inf, -Inf, -Inf, 0.0, -Inf, -Inf, -Inf, 0.0, -Inf, -Inf, 0.0, -Inf, 0.0, 0.0, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, 0.0, -Inf, -Inf, -Inf, -Inf, -Inf, 0.0, -Inf, -Inf, -Inf, -Inf, 0.0, -Inf, -Inf, -Inf, 0.0, -Inf, -Inf, 0.0, -Inf, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
ftol_rel1.0e-12
ftol_abs1.0e-8
xtol_rel0.0
xtol_abs[1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10, 1.0e-10]
initial_step[0.75, 1.0, 1.0, 1.0, 1.0, 0.75, 1.0, 1.0, 1.0, 0.75, 1.0, 1.0, 0.75, 1.0, 0.75, 0.75, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.75, 1.0, 1.0, 1.0, 1.0, 1.0, 0.75, 1.0, 1.0, 1.0, 1.0, 0.75, 1.0, 1.0, 1.0, 0.75, 1.0, 1.0, 0.75, 1.0, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75]
maxfeval-1
maxtime-1.0
Result
Function evaluations2161
Final parameter vector[1.1503, 0.2062, 0.0009, 0.0507, -0.4821, 1.486, -0.6797, -0.0491, 0.2518, 1.1034, -0.5191, -0.1336, 0.9974, -0.4436, 1.2717, 0.4162, -0.0382, -0.0488, -0.1159, -0.2032, 0.3417, -0.1254, 0.647, -0.2549, 0.1256, -0.0254, -0.092, 0.1178, 0.5837, -0.5055, 0.0597, 0.0542, 0.1363, 0.326, -0.4193, -0.4, -0.0256, 0.3874, 0.1186, -0.1718, 0.0037, -0.001, 0.0, 0.0256, 0.1241, 0.0132, 0.0659, 0.0]
Final objective value24651.0132
Return codeFTOL_REACHED
+
+
+
+
loglikelihood(m1) # StatsBase.loglikelihood: return loglikelihood of the model
+
+
-12325.506614999245
+
+
+
+
deviance(m1)      # StatsBase.deviance: negative twice the log-likelihood relative to saturated mode`
+
+
24651.01322999849
+
+
+
+
objective(m1)    # MixedModels.objective: saturated model not clear: negative twice the log-likelihood
+
+
24651.01322999849
+
+
+
+
nobs(m1) # n of observations; they are not independent
+
+
9663
+
+
+
+
n_, p_, q_, k_ = size(m1)
+
+
(9663, 20, 13076, 3)
+
+
+
+
dof(m1)  # n of degrees of freedom is number of model parameters
+
+
69
+
+
+
+
geom_df = sum(leverage(m1)) # trace of hat / rank of model matrix / geom dof
+
+
5746.176138702353
+
+
+
+
resid_df = nobs(m1) - geom_df  # eff. residual degrees of freedom
+
+
3916.8238612976475
+
+
+
+
aic(m1)  # objective(m1) + 2*dof(m1)
+
+
24789.01322999849
+
+
+
+
bic(m1)  # objective(m1) + dof(m1)*log(nobs(m1))
+
+
25284.161331220443
+
+
+
+
+

6.2 Fixed-effect statistics

+
+ julia> coeftable(m1)     # StatsBase.coeftable: fixed-effects statiscs;
+                             default level=0.95
++ julia> Arrow.write("./data/m_cpx_fe.arrow", DataFrame(coeftable(m1)));
++ julia> coef(m1)          # StatsBase.coef - parts of the table
++ julia> fixef(m1)         # MixedModels.fixef: not the same as coef()
+                             for rank-deficient case
++ julia> m1.beta           # alternative extractor
++ julia> fixefnames(m1)    # works also for coefnames(m1)
++ julia> vcov(m1)          # StatsBase.vcov: var-cov matrix of fixed-effects coef.
++ julia> stderror(m1)      # StatsBase.stderror: SE for fixed-effects coefficients
++ julia> propertynames(m1) # names of available extractors
+
+
coeftable(m1) # StatsBase.coeftable: fixed-effects statiscs; default level=0.95
+
+ +++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Coef.Std. ErrorzPr(>
(Intercept)-0.01331710.0191925-0.690.4878
Test: Star_r0.00883950.03746410.240.8135
Test: S20_r0.00915990.0292540.310.7542
Test: SLJ0.00336740.02994380.110.9105
Test: BMT-0.03829070.0295746-1.290.1954
a10.1955450.05444883.590.0003
Sex: Girls-0.4287440.0311858-13.75<1e-42
Test: Star_r & a10.289790.08874813.270.0011
Test: S20_r & a1-0.07839640.0817053-0.960.3373
Test: SLJ & a1-0.06312870.0768871-0.820.4116
Test: BMT & a10.4713170.08514995.54<1e-07
Test: Star_r & Sex: Girls0.3756010.05108447.35<1e-12
Test: S20_r & Sex: Girls-0.1867270.0475087-3.93<1e-04
Test: SLJ & Sex: Girls-0.06951180.0445172-1.560.1184
Test: BMT & Sex: Girls-0.2812330.0495206-5.68<1e-07
a1 & Sex: Girls-0.1266570.104826-1.210.2269
Test: Star_r & a1 & Sex: Girls-0.1382070.175584-0.790.4312
Test: S20_r & a1 & Sex: Girls0.1752980.1633361.070.2832
Test: SLJ & a1 & Sex: Girls-0.01544090.152985-0.100.9196
Test: BMT & a1 & Sex: Girls0.1547820.1701570.910.3630
+
+
+
+
#Arrow.write("./data/m_cpx_fe.arrow", DataFrame(coeftable(m1)));
+
+
+
coef(m1)              # StatsBase.coef; parts of the table
+
+
20-element Vector{Float64}:
+ -0.01331706655216196
+  0.00883950028956812
+  0.009159901903096396
+  0.0033673954396057993
+ -0.03829070122404062
+  0.19554482244322863
+ -0.4287443626724418
+  0.28979031920970977
+ -0.07839639356634587
+ -0.06312871281837554
+  0.47131713732193803
+  0.37560077961217664
+ -0.18672725220576128
+ -0.06951177262870464
+ -0.28123301997348354
+ -0.1266566750821929
+ -0.13820729140481497
+  0.17529825709418737
+ -0.015440927030435017
+  0.15478201529135271
+
+
+
+
fixef(m1)    # MixedModels.fixef: not the same as coef() for rank-deficient case
+
+
20-element Vector{Float64}:
+ -0.01331706655216196
+  0.00883950028956812
+  0.009159901903096396
+  0.0033673954396057993
+ -0.03829070122404062
+  0.19554482244322863
+ -0.4287443626724418
+  0.28979031920970977
+ -0.07839639356634587
+ -0.06312871281837554
+  0.47131713732193803
+  0.37560077961217664
+ -0.18672725220576128
+ -0.06951177262870464
+ -0.28123301997348354
+ -0.1266566750821929
+ -0.13820729140481497
+  0.17529825709418737
+ -0.015440927030435017
+  0.15478201529135271
+
+
+
+
m1.β                  # alternative extractor
+
+
20-element Vector{Float64}:
+ -0.01331706655216196
+  0.00883950028956812
+  0.009159901903096396
+  0.0033673954396057993
+ -0.03829070122404062
+  0.19554482244322863
+ -0.4287443626724418
+  0.28979031920970977
+ -0.07839639356634587
+ -0.06312871281837554
+  0.47131713732193803
+  0.37560077961217664
+ -0.18672725220576128
+ -0.06951177262870464
+ -0.28123301997348354
+ -0.1266566750821929
+ -0.13820729140481497
+  0.17529825709418737
+ -0.015440927030435017
+  0.15478201529135271
+
+
+
+
fixefnames(m1)        # works also for coefnames(m1)
+
+
20-element Vector{String}:
+ "(Intercept)"
+ "Test: Star_r"
+ "Test: S20_r"
+ "Test: SLJ"
+ "Test: BMT"
+ "a1"
+ "Sex: Girls"
+ "Test: Star_r & a1"
+ "Test: S20_r & a1"
+ "Test: SLJ & a1"
+ "Test: BMT & a1"
+ "Test: Star_r & Sex: Girls"
+ "Test: S20_r & Sex: Girls"
+ "Test: SLJ & Sex: Girls"
+ "Test: BMT & Sex: Girls"
+ "a1 & Sex: Girls"
+ "Test: Star_r & a1 & Sex: Girls"
+ "Test: S20_r & a1 & Sex: Girls"
+ "Test: SLJ & a1 & Sex: Girls"
+ "Test: BMT & a1 & Sex: Girls"
+
+
+
+
vcov(m1)   # StatsBase.vcov: var-cov matrix of fixed-effects coefficients
+
+
20×20 Matrix{Float64}:
+  0.000368351   2.45468e-5   -1.72453e-5   …   3.89056e-6    2.86117e-6
+  2.45468e-5    0.00140356   -0.000421444     -9.31972e-7   -1.04343e-7
+ -1.72453e-5   -0.000421444   0.000855795      2.05736e-5   -6.92183e-7
+ -2.68168e-5    5.45073e-5   -0.000468396     -2.44359e-5    1.37239e-6
+ -0.000143239   3.24513e-5   -7.84251e-6       1.42159e-6   -1.19387e-5
+ -4.42745e-5   -7.46407e-5    2.77403e-5   …  -6.02716e-5   -5.09392e-5
+ -4.43171e-5    6.33573e-5    4.36499e-5      -7.38976e-5    0.000282215
+ -2.73546e-5   -0.000442542   0.000212864      8.70091e-6    2.62083e-6
+  3.45871e-6    0.000213247  -0.000395414     -0.000104376   8.17941e-6
+ -2.00311e-5    7.81719e-8    0.000175323      0.000158956  -6.11846e-5
+  7.30133e-5   -2.67094e-5    2.85589e-5   …  -5.7891e-5     8.27717e-5
+  6.89346e-6    8.80541e-7   -2.06783e-6       8.67367e-6   -0.000108136
+  5.13451e-6   -1.96787e-6    7.69769e-6       0.000673738   0.000117904
+ -5.23405e-6   -1.56257e-6   -4.65589e-6      -0.00136392    0.000576753
+ -1.14233e-6    6.34682e-7   -9.06233e-7       0.000577419  -0.00171453
+ -4.58649e-6   -1.20769e-5    3.57658e-7   …   0.000152536  -0.00391907
+ -1.2815e-5    -2.83723e-5    2.85677e-5      -0.000139039   0.00179084
+  4.96066e-7    2.86311e-5   -4.70739e-5      -0.0115807    -0.00195294
+  3.89056e-6   -9.31972e-7    2.05736e-5       0.0234043    -0.00998529
+  2.86117e-6   -1.04343e-7   -6.92183e-7      -0.00998529    0.0289533
+
+
+
+
vcov(m1; corr=true) # StatsBase.vcov: correlation matrix of fixed-effects coefficients
+
+
20×20 Matrix{Float64}:
+  1.0           0.0341389    -0.0307153    …   0.00132505    0.000876119
+  0.0341389     1.0          -0.384539        -0.000162607  -1.63681e-5
+ -0.0307153    -0.384539      1.0              0.00459702   -0.000139055
+ -0.0466626     0.0485884    -0.534714        -0.00533426    0.000269353
+ -0.252355      0.0292886    -0.00906467       0.000314202  -0.0023724
+ -0.0423677    -0.0365909     0.0174156    …  -0.00723564   -0.00549812
+ -0.074043      0.0542282     0.0478456       -0.0154891     0.0531832
+ -0.0160598    -0.133101      0.0819894        0.000640852   0.000173552
+  0.00220563    0.0696654    -0.165431        -0.00835027    0.000588332
+ -0.0135744     2.71383e-5    0.077947         0.0135137    -0.00467669
+  0.0446773    -0.00837267    0.0114649    …  -0.00444405    0.00571279
+  0.00703102    0.000460094  -0.0013837        0.00110986   -0.0124404
+  0.00563112   -0.00110563    0.00553863       0.0926979     0.014585
+ -0.00612604   -0.000936911  -0.00357512      -0.200269      0.0761401
+ -0.00120191    0.000342101  -0.00062556       0.0762178    -0.203474
+ -0.00227972   -0.00307519    0.000116631  …   0.00951161   -0.219717
+ -0.0038028    -0.00431315    0.00556167      -0.0051761     0.0599409
+  0.000158243   0.00467887   -0.00985172      -0.463453     -0.0702678
+  0.00132505   -0.000162607   0.00459702       1.0          -0.383587
+  0.000876119  -1.63681e-5   -0.000139055     -0.383587      1.0
+
+
+
+
stderror(m1)       # StatsBase.stderror: SE for fixed-effects coefficients
+
+
20-element Vector{Float64}:
+ 0.019192465300358272
+ 0.03746407305661245
+ 0.02925397597009649
+ 0.029943795561659332
+ 0.02957456318772991
+ 0.054448757362360926
+ 0.031185791059940196
+ 0.08874814582057454
+ 0.08170531215279139
+ 0.07688713611571989
+ 0.0851499496378772
+ 0.05108438663261352
+ 0.04750873665393441
+ 0.044517155988056785
+ 0.0495206365951175
+ 0.10482604370023066
+ 0.17558419241258222
+ 0.16333633596447028
+ 0.1529846844619703
+ 0.17015682547428446
+
+
+
+
propertynames(m1)  # names of available extractors
+
+
(:formula, :reterms, :Xymat, :feterm, :sqrtwts, :parmap, :dims, :A, :L, :optsum, :θ, :theta, :β, :beta, :βs, :betas, :λ, :lambda, :stderror, :σ, :sigma, :σs, :sigmas, :σρs, :sigmarhos, :b, :u, :lowerbd, :X, :y, :corr, :vcov, :PCA, :rePCA, :objective, :pvalues)
+
+
+
+
+

6.3 Covariance parameter estimates

+

These commands inform us about the model parameters associated with the RES.

+
+ julia> issingular(m1)        # Test singularity for param. vector m1.theta
++ julia> VarCorr(m1)           # MixedModels.VarCorr: est. of RES
++ julia> propertynames(m1)
++ julia> m1.σ                  # residual; or: m1.sigma
++ julia> m1.σs                 # VCs; m1.sigmas
++ julia> m1.θ                  # Parameter vector for RES (w/o residual); m1.theta
++ julia> MixedModels.sdest(m1) #  prsqrt(MixedModels.varest(m1))
++ julia> BlockDescription(m1)  #  Description of blocks of A and L in an LMM
+
+
issingular(m1) # Test if model is singular for paramter vector m1.theta (default)
+
+
true
+
+
+
+
issingular(m2)
+
+
true
+
+
+
+
VarCorr(m1) # MixedModels.VarCorr: estimates of random-effect structure (RES)
+
+ ++++++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ColumnVarianceStd.DevCorr.
Child(Intercept)0.349039800.59079590
Test: Star_r0.593642200.77048180+0.14
Test: S20_r0.443043050.66561479+0.00-0.52
Test: SLJ0.334810890.57862846+0.05-0.04-0.37
Test: BMT0.561207730.74913799-0.33+0.13-0.17-0.25
School(Intercept)0.045697340.21376937
Test: Star_r0.110813380.33288644-0.06
Test: S20_r0.107634420.32807686-0.08-0.39
Test: SLJ0.103147450.32116576-0.19+0.21-0.80
Test: BMT0.097962130.31298902-0.33-0.02+0.13-0.38
a10.079714640.28233780+0.62-0.20+0.11-0.61+0.45
Sex: Girls0.020669030.14376729-0.45+0.45+0.31-0.27-0.15-0.37
Cohort(Intercept)0.000173360.01316656
Test: Star_r0.004059750.06371614.
Test: S20_r0.000046310.00680502..
Test: SLJ0.001146310.03385719...
Test: BMT0.000000000.00000000....
Residual0.263772710.51358807
+
+
+
+
VarCorr(m2)
+
+ ++++++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ColumnVarianceStd.DevCorr.
ChildTest: Run0.56263150.7500877
Test: Star_r0.63548710.7971744+0.50
Test: S20_r0.58946300.7677650+0.56+0.64
Test: SLJ0.60932490.7805927+0.55+0.60+0.72
Test: BMT0.48583960.6970219+0.19+0.40+0.37+0.49
SchoolTest: Run0.13703670.3701847
Test: Star_r0.09628420.3102970+0.53
Test: S20_r0.10924590.3305237+0.47+0.48
Test: SLJ0.06139160.2477733+0.47+0.76+0.41
Test: BMT0.03875550.1968641+0.15+0.38+0.18+0.02
a10.08024300.2832720+0.58+0.47+0.56-0.05+0.65
Sex: Girls0.02054880.1433486-0.63-0.27+0.06-0.28-0.58-0.37
CohortTest: Run0.00300670.0548338
Test: Star_r0.00043470.0208494.
Test: S20_r0.00317250.0563249..
Test: SLJ0.00024520.0156604...
Test: BMT0.00000000.0000000....
Residual0.26191460.5117760
+
+
+
+
m1.σs      # VCs; m1.sigmas
+
+
(Child = (var"(Intercept)" = 0.5907959029225862, var"Test: Star_r" = 0.7704817994480245, var"Test: S20_r" = 0.6656147888960222, var"Test: SLJ" = 0.5786284552355224, var"Test: BMT" = 0.7491379937832613), School = (var"(Intercept)" = 0.2137693688364067, var"Test: Star_r" = 0.33288643566454384, var"Test: S20_r" = 0.3280768567505694, var"Test: SLJ" = 0.3211657642930787, var"Test: BMT" = 0.31298901749687913, a1 = 0.28233780381354795, var"Sex: Girls" = 0.143767290743394), Cohort = (var"(Intercept)" = 0.013166555574091778, var"Test: Star_r" = 0.06371614416899145, var"Test: S20_r" = 0.006805016452716729, var"Test: SLJ" = 0.03385719231820434, var"Test: BMT" = 0.0))
+
+
+
+
m1.θ       # Parameter vector for RES (w/o residual); m1.theta
+
+
48-element Vector{Float64}:
+  1.1503302598343477
+  0.2062190787609727
+  0.0008666159469680149
+  0.050734934180392224
+ -0.48211325954936624
+  1.4859529039387687
+ -0.6797347055373657
+ -0.04906500731877601
+  0.25177147495411384
+  1.103448875092165
+ -0.5190786027370973
+ -0.13364340349638246
+  0.9974426672137859
+  ⋮
+ -0.02563052910620881
+  0.3873988146494795
+  0.118601913906712
+ -0.1718026965130414
+  0.0036579916237788343
+ -0.0010172580519802405
+  0.0
+  0.02563641220215602
+  0.12406079377832567
+  0.013249950288257796
+  0.06592285532786576
+  0.0
+
+
+
+
BlockDescription(m1) #  Description of blocks of A and L in a LinearMixedModel
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
rowsChildSchoolCohortfixed
9930BlkDiag
3101SparseBlkDiag
45DenseDenseBlkDiag/Dense
21DenseDenseDenseDense
+
+
+
+
m2.θ
+
+
48-element Vector{Float64}:
+  1.46565629578844
+  0.7825331498310524
+  0.8427270268123437
+  0.843701714893452
+  0.26423363532022687
+  1.3468316700709517
+  0.6159105518922656
+  0.5685881881743816
+  0.4806008412988357
+  1.0775237645019875
+  0.5454461221597267
+  0.21582202447173554
+  0.9968896467848608
+  ⋮
+ -0.01778801467231765
+  0.31874007820888184
+  0.13868543043388296
+ -0.18628651012633302
+  0.0
+ -0.00019459500089828938
+  0.0
+  0.10714419938783641
+  0.040739228366369604
+  0.11005771477604791
+  0.03060005959856037
+  0.0
+
+
+
+
BlockDescription(m2)
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
rowsChildSchoolCohortfixed
9930BlkDiag
3101SparseBlkDiag
45DenseDenseBlkDiag/Dense
21DenseDenseDenseDense
+
+
+
+
+

6.4 Model “predictions”

+

These commands inform us about extracion of conditional modes/means and (co-)variances, that using the model parameters to improve the predictions for units (levels) of the grouping (random) factors. We need this information, e.g., for partial-effect response profiles (e.g., facet plot) or effect profiles (e.g., caterpillar plot), or visualizing the borrowing-strength effect for correlation parameters (e.g., shrinkage plots). We are using the fit of LMM m2.

+
julia> condVar(m2)
+

Some plotting functions are currently available from the MixedModelsMakie package or via custom functions.

+
+ julia> caterpillar!(m2)
++ julia> shrinkage!(m2)
+
+

6.4.1 Conditional covariances

+
+
condVar(m1)
+
+
3-element Vector{Array{Float64, 3}}:
+ [0.05575383274003557 0.00863915213999665 … 0.0031232443363528556 -0.021138218415038885; 0.00863915213999665 0.29001266660027136 … -0.0070474409935052055 0.022922985962176668; … ; 0.0031232443363528556 -0.0070474409935052055 … 0.20790206584505386 -0.0852354729075977; -0.021138218415038885 0.022922985962176668 … -0.0852354729075977 0.26330097819700116;;; 0.06213230185040765 0.010826308858088864 … 0.003929097771018621 -0.028409878110103502; 0.010826308858088864 0.29938324063036736 … -0.005483186816479629 0.023531240948500384; … ; 0.003929097771018621 -0.005483186816479629 … 0.21199432719260117 -0.08620203115574254; -0.028409878110103502 0.023531240948500384 … -0.08620203115574254 0.2731885630201976;;; 0.05928754515087498 0.009999345149668016 … 0.003214830309751238 -0.02513168722029122; 0.009999345149668016 0.29438206427015273 … -0.006437102215677196 0.022965997644015704; … ; 0.003214830309751238 -0.006437102215677196 … 0.21076926571106885 -0.08552674167274826; -0.02513168722029122 0.022965997644015704 … -0.08552674167274826 0.26861055510165105;;; … ;;; 0.0907210265033368 0.010497457003751263 … -0.0060407174687821434 -0.023131077664248153; 0.010497457003751263 0.2970544531740206 … -0.0069478640031876895 0.024285798673900034; … ; -0.0060407174687821434 -0.0069478640031876895 … 0.2099626452419368 -0.08344670225122619; -0.023131077664248153 0.024285798673900034 … -0.08344670225122619 0.2685457288945719;;; 0.09719108603781947 0.007906212183110295 … -0.001320199364202595 -0.022070542259081175; 0.007906212183110295 0.29347487103474784 … -0.007201306571266091 0.02468292835627069; … ; -0.001320199364202595 -0.007201306571266091 … 0.20924944238722887 -0.08407452186026657; -0.022070542259081175 0.02468292835627069 … -0.08407452186026657 0.2654490089917222;;; 0.08379719940391851 0.007847588198883811 … -0.00028220224056425754 -0.01854945143543425; 0.007847588198883811 0.29055593804014934 … -0.007421355885115292 0.02415358501664865; … ; -0.00028220224056425754 -0.007421355885115292 … 0.20794862679330195 -0.0842550154482498; -0.01854945143543425 0.02415358501664865 … -0.0842550154482498 0.2624831493252433]
+ [0.03738099438108044 -0.001778150236782388 … 0.030005959239663836 -0.012422815955098213; -0.001778150236782388 0.09046590526227734 … -0.012438199387792876 0.017400101424582894; … ; 0.030005959239663836 -0.012438199387792876 … 0.06539708247917235 -0.012780944067289027; -0.012422815955098213 0.017400101424582894 … -0.012780944067289027 0.01833845610541896;;; 0.032174800419166066 0.00021552464206599673 … 0.02631804193514885 -0.010643849286266155; 0.00021552464206599673 0.07636177622427075 … -0.007781645246191157 0.014216263238686322; … ; 0.02631804193514885 -0.007781645246191157 … 0.057233707504033296 -0.010780210452738961; -0.010643849286266155 0.014216263238686322 … -0.010780210452738961 0.015905591438488714;;; 0.029307729689901536 -0.0031500145971753725 … 0.02159243212220725 -0.01044773671375439; -0.0031500145971753725 0.0877447231001567 … -0.01330551483540402 0.018117822615212966; … ; 0.02159243212220725 -0.01330551483540402 … 0.05168567480761258 -0.010391773146284176; -0.01044773671375439 0.018117822615212966 … -0.010391773146284176 0.01678423124230707;;; … ;;; 0.026752237575879263 0.0029124911661105326 … 0.01908410221796392 -0.006843494296351528; 0.0029124911661105326 0.07610913276468977 … -0.005653623936266287 0.012914109119085188; … ; 0.01908410221796392 -0.005653623936266287 … 0.05072498368147368 -0.006134494719465586; -0.006843494296351528 0.012914109119085188 … -0.006134494719465586 0.013714332731263679;;; 0.02722117937531621 0.0035247368383708056 … 0.020363601389567814 -0.0061486862691171144; 0.0035247368383708056 0.07602932922491482 … -0.005124378717151021 0.012614623673192117; … ; 0.020363601389567814 -0.005124378717151021 … 0.05286205808611119 -0.00631660908074008; -0.0061486862691171144 0.012614623673192117 … -0.00631660908074008 0.013738866013923129;;; 0.04333514144377728 -0.0030526201099861485 … 0.0364639269042496 -0.013644784026381104; -0.0030526201099861485 0.09939148209978196 … -0.01520556786587638 0.0191560598024237; … ; 0.0364639269042496 -0.01520556786587638 … 0.07495035348527168 -0.014381992472318614; -0.013644784026381104 0.0191560598024237 … -0.014381992472318614 0.01951413892155994]
+ [0.00016287570134958826 6.856559889853957e-6 … -4.739951921609176e-6 0.0; 6.856559889853957e-6 0.0023548313779246824 … -0.00015351717222254004 0.0; … ; -4.739951921609176e-6 -0.00015351717222254004 … 0.0008614762660391023 0.0; 0.0 0.0 … 0.0 0.0;;; 0.00015950907262546907 8.701350327885633e-6 … -6.024504894509734e-6 0.0; 8.701350327885633e-6 0.0020423106983111475 … -0.0001673374995288987 0.0; … ; -6.024504894509734e-6 -0.0001673374995288987 … 0.0007931845117108109 0.0; 0.0 0.0 … 0.0 0.0;;; 0.00016145306769277504 7.573327674888944e-6 … -5.152636375745283e-6 0.0; 7.573327674888944e-6 0.0022393880860264387 … -0.00015896888705918904 0.0; … ; -5.152636375745283e-6 -0.00015896888705918904 … 0.0008333330451138073 0.0; 0.0 0.0 … 0.0 0.0;;; 0.00016084702419261226 8.35246981386616e-6 … -5.4742810949165876e-6 0.0; 8.35246981386616e-6 0.0021616288990247254 … -0.00016342062464208147 0.0; … ; -5.4742810949165876e-6 -0.00016342062464208147 … 0.0008213033177068655 0.0; 0.0 0.0 … 0.0 0.0;;; 0.00015845270342141037 8.619670728536786e-6 … -6.900073371582094e-6 0.0; 8.619670728536786e-6 0.0019601068318098897 … -0.0001690666309293983 0.0; … ; -6.900073371582094e-6 -0.0001690666309293983 … 0.0007719484491124605 0.0; 0.0 0.0 … 0.0 0.0;;; 0.00015768719984250653 7.385065727666733e-6 … -7.336092614509354e-6 0.0; 7.385065727666733e-6 0.0019316205603731977 … -0.00016776153068661235 0.0; … ; -7.336092614509354e-6 -0.00016776153068661235 … 0.0007548457845576088 0.0; 0.0 0.0 … 0.0 0.0;;; 0.00015975999081971895 7.948268432845527e-6 … -6.413248551251487e-6 0.0; 7.948268432845527e-6 0.002074914216290986 … -0.00016692868092659584 0.0; … ; -6.413248551251487e-6 -0.00016692868092659584 … 0.0007975022546437895 0.0; 0.0 0.0 … 0.0 0.0;;; 0.00015744703326980335 8.402243512073218e-6 … -7.90817159440362e-6 0.0; 8.402243512073218e-6 0.0018868038496581622 … -0.00017276721709532413 0.0; … ; -7.90817159440362e-6 -0.00017276721709532413 … 0.0007513634534431922 0.0; 0.0 0.0 … 0.0 0.0;;; 0.00015564965231731795 9.68631259477342e-6 … -7.697020113052748e-6 0.0; 9.68631259477342e-6 0.0017866573072894876 … -0.0001720968882090284 0.0; … ; -7.697020113052748e-6 -0.0001720968882090284 … 0.0007251764673322595 0.0; 0.0 0.0 … 0.0 0.0]
+
+
+
+
condVar(m2)
+
+
3-element Vector{Array{Float64, 3}}:
+ [0.17116315582859484 0.027498862453680717 … 0.034104094305388286 -0.007244970029438276; 0.027498862453680717 0.17384103461076678 … 0.03748145360126994 0.018816089248565385; … ; 0.034104094305388286 0.03748145360126994 … 0.16031916639849703 0.028749779922481; -0.007244970029438276 0.018816089248565385 … 0.028749779922481 0.1607955523119319;;; 0.18238552619993495 0.03427097227300673 … 0.04141109934983114 -0.009148439621905625; 0.03427097227300673 0.1856359829925568 … 0.04863182300871331 0.021358489400357405; … ; 0.04141109934983114 0.04863182300871331 … 0.17268807116668955 0.031166483369606347; -0.009148439621905625 0.021358489400357405 … 0.031166483369606347 0.16324754394182825;;; 0.17621626015158762 0.031072180113851766 … 0.038125649002372385 -0.007995567564654946; 0.031072180113851766 0.1803469801138963 … 0.04349850263409247 0.020097760108707865; … ; 0.038125649002372385 0.04349850263409247 … 0.16701836305224055 0.030006687972602957; -0.007995567564654946 0.020097760108707865 … 0.030006687972602957 0.16197496984573145;;; … ;;; 0.21740912937655923 0.07090924481039461 … 0.06741379636911818 0.021486080664454548; 0.07090924481039461 0.22153412311552326 … 0.07279946779268884 0.050948373881341553; … ; 0.06741379636911818 0.07279946779268884 … 0.18373137691509117 0.05058489384545355; 0.021486080664454548 0.050948373881341553 … 0.05058489384545355 0.18633185886033954;;; 0.22426025206639164 0.0776902430712113 … 0.07687730598105631 0.03219132055270273; 0.0776902430712113 0.22462307925799707 … 0.07888460223906732 0.05867761080950808; … ; 0.07687730598105631 0.07888460223906732 … 0.19238983868372397 0.060896061536589774; 0.03219132055270273 0.05867761080950808 … 0.060896061536589774 0.19517714451586868;;; 0.2061169154182078 0.061463168353437944 … 0.062212999195302 0.022103225527677538; 0.061463168353437944 0.2073660464425763 … 0.0640017165502183 0.047830931525945246; … ; 0.062212999195302 0.0640017165502183 … 0.1792425246311685 0.05164496814401823; 0.022103225527677538 0.047830931525945246 … 0.05164496814401823 0.18684232972258574]
+ [0.10768178505825274 0.048400872742620095 … 0.04766684633075814 -0.027767663870375308; 0.048400872742620095 0.07949976129667788 … 0.034944549376798424 -0.010301353681294811; … ; 0.04766684633075814 0.034944549376798424 … 0.06575697359151865 -0.012753936623032553; -0.027767663870375308 -0.010301353681294811 … -0.012753936623032553 0.01822072725963938;;; 0.08790095967031233 0.04039487399830374 … 0.04006050669017243 -0.022694796915798992; 0.04039487399830374 0.06914919686791131 … 0.03207348888389284 -0.008419559170898776; … ; 0.04006050669017243 0.03207348888389284 … 0.05750637187929682 -0.010759600050894616; -0.022694796915798992 -0.008419559170898776 … -0.010759600050894616 0.01580107265173481;;; 0.0963598911033401 0.035885072470449086 … 0.038333060297426495 -0.02541792355752846; 0.035885072470449086 0.0630834010975428 … 0.02477182157087897 -0.007236741864081645; … ; 0.038333060297426495 0.02477182157087897 … 0.0519930767818036 -0.010389841513651113; -0.02541792355752846 -0.007236741864081645 … -0.010389841513651113 0.016683879213529238;;; … ;;; 0.07440697397002378 0.030529015222540118 … 0.029374057723458375 -0.017031449145314057; 0.030529015222540118 0.06267553791989461 … 0.023497129411826363 -0.004055529443914723; … ; 0.029374057723458375 0.023497129411826363 … 0.051035223116704755 -0.006132115409660271; -0.017031449145314057 -0.004055529443914723 … -0.006132115409660271 0.013629228762574913;;; 0.07355978268459702 0.03053833755418159 … 0.030108406727685198 -0.01606992180353426; 0.03053833755418159 0.06346698084161012 … 0.024774759577003626 -0.0033909215418409006; … ; 0.030108406727685198 0.024774759577003626 … 0.053155675557087244 -0.006318319173994548; -0.01606992180353426 -0.0033909215418409006 … -0.006318319173994548 0.013652196613227967;;; 0.12472878923414969 0.057966342588725205 … 0.05756315402857382 -0.03100070689366643; 0.057966342588725205 0.09051345642227474 … 0.042031396044692 -0.011772108325862396; … ; 0.05756315402857382 0.042031396044692 … 0.0753703800124635 -0.01436086970585532; -0.03100070689366643 -0.011772108325862396 … -0.01436086970585532 0.019396316425718988]
+ [0.0018739464805060115 3.099298859387236e-5 … 2.2116659335547737e-5 0.0; 3.099298859387236e-5 0.0003982925350932456 … 5.662327674244246e-6 0.0; … ; 2.2116659335547737e-5 5.662327674244246e-6 … 0.0002316450289147418 0.0; 0.0 0.0 … 0.0 0.0;;; 0.0016451178801496406 3.732469788303523e-5 … 2.7075622912847006e-5 0.0; 3.732469788303523e-5 0.00038699606081539056 … 7.752861937193192e-6 0.0; … ; 2.7075622912847006e-5 7.752861937193192e-6 … 0.0002272553166207261 0.0; 0.0 0.0 … 0.0 0.0;;; 0.001788360817926057 3.246216882159844e-5 … 2.409075582915546e-5 0.0; 3.246216882159844e-5 0.0003941993142896808 … 6.47076235799776e-6 0.0; … ; 2.409075582915546e-5 6.47076235799776e-6 … 0.0002298593116535934 0.0; 0.0 0.0 … 0.0 0.0;;; 0.0017314736634095084 3.439352491212058e-5 … 2.510100552477303e-5 0.0; 3.439352491212058e-5 0.00039210347603502567 … 6.686612028470298e-6 0.0; … ; 2.510100552477303e-5 6.686612028470298e-6 … 0.0002292053931970069 0.0; 0.0 0.0 … 0.0 0.0;;; 0.0015869175336522604 3.8916114227008614e-5 … 2.7858034993426766e-5 0.0; 3.8916114227008614e-5 0.00038392382166180716 … 8.107240306589517e-6 0.0; … ; 2.7858034993426766e-5 8.107240306589517e-6 … 0.00022584769979068763 0.0; 0.0 0.0 … 0.0 0.0;;; 0.0015689110909946945 4.003621092371261e-5 … 2.8522941942561645e-5 0.0; 4.003621092371261e-5 0.00038047593288191215 … 8.919058051767636e-6 0.0; … ; 2.8522941942561645e-5 8.919058051767636e-6 … 0.00022463172084040967 0.0; 0.0 0.0 … 0.0 0.0;;; 0.001670592740351977 3.6961837280171235e-5 … 2.6093380656973352e-5 0.0; 3.6961837280171235e-5 0.00038740854803262644 … 7.506517475684638e-6 0.0; … ; 2.6093380656973352e-5 7.506517475684638e-6 … 0.00022749979656451797 0.0; 0.0 0.0 … 0.0 0.0;;; 0.0015337205158612683 4.093131889936314e-5 … 2.9075417115821492e-5 0.0; 4.093131889936314e-5 0.000380334357158905 … 8.821163224637285e-6 0.0; … ; 2.9075417115821492e-5 8.821163224637285e-6 … 0.00022435470926792088 0.0; 0.0 0.0 … 0.0 0.0;;; 0.001453753506796497 4.288550370752128e-5 … 3.0677599882156927e-5 0.0; 4.288550370752128e-5 0.00037427960644329807 … 9.99134452808877e-6 0.0; … ; 3.0677599882156927e-5 9.99134452808877e-6 … 0.00022244049186675522 0.0; 0.0 0.0 … 0.0 0.0]
+
+
+

They are hard to look at. Let’s take pictures.

+
+
+

6.4.2 Caterpillar plots

+
+
+Code +
caterpillar!(
+  Figure(; resolution=(800, 400)), ranefinfo(m1, :Cohort)
+)
+
+
+
+
+

+
Figure 3: Prediction intervals of the random effects for Cohort in model m1
+
+
+
+
+
+
+

6.4.3 Shrinkage plots

+

These are just teasers. We will pick this up in a separate tutorial. Enjoy!

+
+
+Code +
shrinkageplot!(Figure(; resolution=(800, 800)), m1, :Cohort)
+
+
+
+
+

+
Figure 4: Shrinkage plot of the random effects for Cohort in model m1
+
+
+
+
+
+
+Code +
shrinkageplot!(Figure(; resolution=(800, 800)), m2, :Cohort)
+
+
+
+
+

+
Figure 5: Shrinkage plot of the random effects for Cohort in model m2
+
+
+
+
+
+
+Fühner, T., Granacher, U., Golle, K., & Kliegl, R. (2021). Age and sex effects in physical fitness components of 108,295 third graders including 515 primary schools and 9 cohorts. Scientific Reports, 11(1). https://doi.org/10.1038/s41598-021-97000-4 +
+
+Schielzeth, H., & Forstmeier, W. (2008). Conclusions beyond support: Overconfident estimates in mixed models. Behavioral Ecology, 20(2), 416–420. https://doi.org/10.1093/beheco/arn145 +
+
+ + +
+
+
+ + Back to top
+ +
+ + + + \ No newline at end of file diff --git a/fggk21_files/figure-html/fig-agetrends-output-1.svg b/fggk21_files/figure-html/fig-agetrends-output-1.svg new file mode 100644 index 0000000..8aa9927 --- /dev/null +++ b/fggk21_files/figure-html/fig-agetrends-output-1.svg @@ -0,0 +1,961 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fggk21_files/figure-html/fig-agetrendssamp-output-1.svg b/fggk21_files/figure-html/fig-agetrendssamp-output-1.svg new file mode 100644 index 0000000..d956e80 --- /dev/null +++ b/fggk21_files/figure-html/fig-agetrendssamp-output-1.svg @@ -0,0 +1,961 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fggk21_files/figure-html/fig-caterpillarcohort-output-1.svg b/fggk21_files/figure-html/fig-caterpillarcohort-output-1.svg new file mode 100644 index 0000000..081ef80 --- /dev/null +++ b/fggk21_files/figure-html/fig-caterpillarcohort-output-1.svg @@ -0,0 +1,1097 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fggk21_files/figure-html/fig-m1shrinkagecohort-output-1.svg b/fggk21_files/figure-html/fig-m1shrinkagecohort-output-1.svg new file mode 100644 index 0000000..827408f --- /dev/null +++ b/fggk21_files/figure-html/fig-m1shrinkagecohort-output-1.svg @@ -0,0 +1,1507 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fggk21_files/figure-html/fig-m2shrinkagecohort-output-1.svg b/fggk21_files/figure-html/fig-m2shrinkagecohort-output-1.svg new file mode 100644 index 0000000..d16d144 --- /dev/null +++ b/fggk21_files/figure-html/fig-m2shrinkagecohort-output-1.svg @@ -0,0 +1,1671 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/glmm.html b/glmm.html index d4eac1d..f9b410a 100644 --- a/glmm.html +++ b/glmm.html @@ -2,14 +2,14 @@ - + - + -SMLP2023 - Generalized linear mixed models +SMLP2023: Advanced Frequentist Track - Generalized linear mixed models + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +
+ + + +
+ +
+
+

Raw score density

+
+ + + +
+ +
+
Author
+
+

Phillip Alday, Douglas Bates, and Reinhold Kliegl

+
+
+ +
+
Published
+
+

2023-08-21

+
+
+ + +
+ + +
+ +
+
+Code +
using Arrow
+using CairoMakie
+using DataFrames
+CairoMakie.activate!(; type="svg") # use SVG (other options include PNG)
+
+
+
+
tbl = Arrow.Table("./data/fggk21.arrow")
+
+
Arrow.Table with 525126 rows, 7 columns, and schema:
+ :Cohort  String
+ :School  String
+ :Child   String
+ :Sex     String
+ :age     Float64
+ :Test    String
+ :score   Float64
+
+
+
+
df = DataFrame(tbl)
+describe(df)
+
+
7×7 DataFrame
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Rowvariablemeanminmedianmaxnmissingeltype
SymbolUnion…AnyUnion…AnyInt64DataType
1Cohort201120190String
2SchoolS100043S8002000String
3ChildC002352C1179660String
4Sexfemalemale0String
5age8.560737.994528.558529.106090Float64
6TestBPTStar_r0String
7score226.1411.141524.651161530.00Float64
+
+
+
+
+
let
+  fdensity = Figure(; resolution=(1000, 500))
+  axs = Axis(fdensity[1, 1])
+  tdf = filter(:Test => ==(test), df)
+  colors = Makie.cgrad(:PuOr_4, 2; categorical=true, alpha=0.6)
+  if by_sex
+    density!(
+      axs,
+      filter(:Sex => ==("female"), tdf).score;
+      color=colors[1],
+      label="Girls",
+    )
+    density!(
+      axs,
+      filter(:Sex => ==("male"), tdf).score;
+      color=colors[2],
+      label="Boys",
+    )
+    axislegend(axs; position=:lt)
+  else
+    density!(axs, tdf.score)
+  end
+  fdensity
+end
+
+ + + + Back to top
+ +
+ + + + \ No newline at end of file diff --git a/shrinkageplot.html b/shrinkageplot.html index 3d3d8a5..f45a243 100644 --- a/shrinkageplot.html +++ b/shrinkageplot.html @@ -2,14 +2,14 @@ - + - + -SMLP2023 - More on shrinkage plots +SMLP2023: Advanced Frequentist Track - More on shrinkage plots