From e4f28ef029e30d5469a2af3ac368ec70cf8df4c3 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 28 Aug 2025 11:02:32 +0200 Subject: [PATCH 01/10] minor updates to GLMM file --- glmm.qmd | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/glmm.qmd b/glmm.qmd index 10f3629..dac8418 100644 --- a/glmm.qmd +++ b/glmm.qmd @@ -1,6 +1,9 @@ --- title: "Generalized linear mixed models" engine: julia +author: + - Douglas Bates + - Phillip Alday julia: exeflags: ["--project", "--threads=auto"] --- @@ -227,7 +230,7 @@ draw( color=:livch, ) * smooth(); - figure=(; resolution=(800, 450)), + figure=(; size=(800, 450)), ) ``` From 066643c8d075fe9f788a0a72e2f1bd1e5c546daf Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 28 Aug 2025 13:31:45 +0200 Subject: [PATCH 02/10] wip --- sesssions/2025-08-28-thursday-pm.jl | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 sesssions/2025-08-28-thursday-pm.jl diff --git a/sesssions/2025-08-28-thursday-pm.jl b/sesssions/2025-08-28-thursday-pm.jl new file mode 100644 index 0000000..e69de29 From c740d47510c995cfca208b05b840cdb34f54bcd7 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 28 Aug 2025 13:38:14 +0200 Subject: [PATCH 03/10] wip --- sesssions/2025-08-28-thursday-pm.jl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sesssions/2025-08-28-thursday-pm.jl b/sesssions/2025-08-28-thursday-pm.jl index e69de29..3d065ca 100644 --- a/sesssions/2025-08-28-thursday-pm.jl +++ b/sesssions/2025-08-28-thursday-pm.jl @@ -0,0 +1,9 @@ +# pkg> status --outdated + +using MixedModels +using MixedModelsDatasets: dataset + +fm1 = lmm(@formula(rt_trunc ~ spkr * prec * load + + (1 + spkr * prec * load|item) + + (1 + spkr * prec * load|subj)), + dataset(:kb07)) From 44396e6a1a640fabff984731a0351718dcf64055 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 28 Aug 2025 13:42:25 +0200 Subject: [PATCH 04/10] restoreoptsum! --- sesssions/2025-08-28-thursday-pm.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sesssions/2025-08-28-thursday-pm.jl b/sesssions/2025-08-28-thursday-pm.jl index 3d065ca..4f2070b 100644 --- a/sesssions/2025-08-28-thursday-pm.jl +++ b/sesssions/2025-08-28-thursday-pm.jl @@ -7,3 +7,13 @@ fm1 = lmm(@formula(rt_trunc ~ spkr * prec * load + (1 + spkr * prec * load|item) + (1 + spkr * prec * load|subj)), dataset(:kb07)) + +saveoptsum("big_mod.json", fm1) + +# just construct, don't fit +reloaded = LinearMixedModel(@formula(rt_trunc ~ spkr * prec * load + + (1 + spkr * prec * load|item) + + (1 + spkr * prec * load|subj)), + dataset(:kb07)) + +restoreoptsum!(reloaded, "big_mod.json") From c9d027d6e7881e1481ab6b3c41752e52d704e222 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 28 Aug 2025 13:55:24 +0200 Subject: [PATCH 05/10] wip --- sesssions/2025-08-28-thursday-pm.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sesssions/2025-08-28-thursday-pm.jl b/sesssions/2025-08-28-thursday-pm.jl index 4f2070b..5e71cfd 100644 --- a/sesssions/2025-08-28-thursday-pm.jl +++ b/sesssions/2025-08-28-thursday-pm.jl @@ -17,3 +17,11 @@ reloaded = LinearMixedModel(@formula(rt_trunc ~ spkr * prec * load + dataset(:kb07)) restoreoptsum!(reloaded, "big_mod.json") + +slp = lmm(@formula(reaction ~ 1 + days + (1+days|subj)), dataset(:sleepstudy)) + +using StandardizedPredictors + +lmm(@formula(reaction ~ 1 + days + (1+days|subj)), + dataset(:sleepstudy); + contrasts=Dict(:days => Center())) From 70db1ef771dd5b78f9fe936325633ffc766df92c Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 28 Aug 2025 13:58:20 +0200 Subject: [PATCH 06/10] standardizedpredictors --- sesssions/2025-08-28-thursday-pm.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sesssions/2025-08-28-thursday-pm.jl b/sesssions/2025-08-28-thursday-pm.jl index 5e71cfd..a08f128 100644 --- a/sesssions/2025-08-28-thursday-pm.jl +++ b/sesssions/2025-08-28-thursday-pm.jl @@ -25,3 +25,20 @@ using StandardizedPredictors lmm(@formula(reaction ~ 1 + days + (1+days|subj)), dataset(:sleepstudy); contrasts=Dict(:days => Center())) + +# we can use a precomputed value +lmm(@formula(reaction ~ 1 + days + (1+days|subj)), + dataset(:sleepstudy); + contrasts=Dict(:days => Center(2))) + +# we can also use a function +using StatsBase +lmm(@formula(reaction ~ 1 + days + (1+days|subj)), + dataset(:sleepstudy); + contrasts=Dict(:days => Center(minimum))) + +# there's also zscore +# (doesn't make sense for days, but whatever...) +lmm(@formula(reaction ~ 1 + days + (1+days|subj)), + dataset(:sleepstudy); + contrasts=Dict(:days => ZScore())) From fb8c3be1ce8fa2ddeb43ea4df5688fa4f35cf981 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 28 Aug 2025 14:04:41 +0200 Subject: [PATCH 07/10] caterpillar options --- sesssions/2025-08-28-thursday-pm.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sesssions/2025-08-28-thursday-pm.jl b/sesssions/2025-08-28-thursday-pm.jl index a08f128..737aa2c 100644 --- a/sesssions/2025-08-28-thursday-pm.jl +++ b/sesssions/2025-08-28-thursday-pm.jl @@ -42,3 +42,11 @@ lmm(@formula(reaction ~ 1 + days + (1+days|subj)), lmm(@formula(reaction ~ 1 + days + (1+days|subj)), dataset(:sleepstudy); contrasts=Dict(:days => ZScore())) + +using CairoMakie, MixedModelsMakie +caterpillar(slp) +caterpillar(slp; + vline_at_zero=true, + # dotcolor=(:cyan, 1.0), + # barcolor=:yellow, + orderby=2) From 2f875f21fd77ca1533dc78db4d802db3f530787e Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 28 Aug 2025 14:06:47 +0200 Subject: [PATCH 08/10] qqcaterpillar --- sesssions/2025-08-28-thursday-pm.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sesssions/2025-08-28-thursday-pm.jl b/sesssions/2025-08-28-thursday-pm.jl index 737aa2c..757d07b 100644 --- a/sesssions/2025-08-28-thursday-pm.jl +++ b/sesssions/2025-08-28-thursday-pm.jl @@ -50,3 +50,6 @@ caterpillar(slp; # dotcolor=(:cyan, 1.0), # barcolor=:yellow, orderby=2) + +qqcaterpillar(slp) +qqcaterpillar(fm1, cols=["(Intercept)"]) From 6c73938531e3af3775384fa30db375bf8071bd2f Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 28 Aug 2025 16:09:48 +0200 Subject: [PATCH 09/10] wip --- sesssions/2025-08-28-thursday-pm.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sesssions/2025-08-28-thursday-pm.jl b/sesssions/2025-08-28-thursday-pm.jl index 757d07b..4f6a4ce 100644 --- a/sesssions/2025-08-28-thursday-pm.jl +++ b/sesssions/2025-08-28-thursday-pm.jl @@ -53,3 +53,18 @@ caterpillar(slp; qqcaterpillar(slp) qqcaterpillar(fm1, cols=["(Intercept)"]) + +# saving bootstrap results +using StableRNGs + +pb_slp = parametricbootstrap(StableRNG(12321), 1000, slp) + +# how many fits were singular? +count(issingular(pb_slp)) +savereplicates("bootstrap.arrow", pb_slp) +# like restoreoptsum, restorereplicates requires a model +# but this model does not have to be fitted + +slp2 = LinearMixedModel(@formula(reaction ~ 1 + days + (1+days|subj)), dataset(:sleepstudy)) + +savereplicates("bootstrap.arrow", slp2) From 23a3da4fed74c2c86d6a07f1a4a78ceed22564cf Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 28 Aug 2025 16:11:33 +0200 Subject: [PATCH 10/10] woops --- sesssions/2025-08-28-thursday-pm.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sesssions/2025-08-28-thursday-pm.jl b/sesssions/2025-08-28-thursday-pm.jl index 4f6a4ce..eae3c46 100644 --- a/sesssions/2025-08-28-thursday-pm.jl +++ b/sesssions/2025-08-28-thursday-pm.jl @@ -67,4 +67,4 @@ savereplicates("bootstrap.arrow", pb_slp) slp2 = LinearMixedModel(@formula(reaction ~ 1 + days + (1+days|subj)), dataset(:sleepstudy)) -savereplicates("bootstrap.arrow", slp2) +restorereplicates("bootstrap.arrow", slp2)