Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 0a08834

Browse files
authored
3d shrinkage example (#43)
1 parent 61af245 commit 0a08834

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

shrink3d/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
settings.json
2+
.vscode

shrink3d/Project.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[deps]
2+
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
3+
MixedModels = "ff71e718-51f3-5ec2-a782-8ffcbfa3c316"
4+
MixedModelsMakie = "b12ae82c-6730-437f-aff9-d2c38332a376"

shrink3d/shrink3d.jl

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using GLMakie
2+
using MixedModels
3+
using MixedModels: dataset
4+
using MixedModelsMakie
5+
6+
# we scale weirdly here so that we have nice scaling in the 3d plot
7+
m = fit(MixedModel,
8+
@formula(rt_trunc / 100 ~ 1 + spkr*prec*load + (1|subj) + (1+spkr+prec|item)),
9+
dataset(:kb07);
10+
contrasts=Dict(:load => HelmertCoding(),
11+
:spkr => HelmertCoding(),
12+
:prec => HelmertCoding()))
13+
14+
shrinkageplot(m, :item)
15+
16+
let gf = :item, θref = 10000*m.optsum.initial
17+
reind = findfirst(==(gf), fnames(m)) # convert the symbol gf to an index
18+
if isnothing(reind)
19+
throw(ArgumentError("gf=$gf is not one of the grouping factor names, $(fnames(m))"))
20+
end
21+
reest = ranef(m)[reind] # random effects conditional means at estimated θ
22+
reref = ranef(updateL!(setθ!(m, θref)))[reind] # same at θref
23+
updateL!(setθ!(m, m.optsum.final)) # restore parameter estimates and update m
24+
25+
tails = [Point3f(reref[:, j]) for j in 1:size(reref,2)]
26+
lengths = [Vec3f(reest[:, j] .- reref[:, j]) for j in 1:size(reref,2)]
27+
f = Figure()
28+
ax3 = Axis3(f[1,1])
29+
arrows!(ax3, tails, lengths)
30+
ax3.xlabel = "Intercept"
31+
ax3.ylabel = "spkr"
32+
ax3.zlabel = "prec"
33+
f
34+
end

0 commit comments

Comments
 (0)