Skip to content

Commit 6841af6

Browse files
authored
provide a breadcrumb when spline interpolation fails during profiling (#857)
1 parent 04d96b4 commit 6841af6

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

issues/794/Project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[deps]
2+
BSplineKit = "093aae92-e908-43d7-9660-e50ee39d5a0a"
3+
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
4+
MixedModels = "ff71e718-51f3-5ec2-a782-8ffcbfa3c316"
5+
MixedModelsDatasets = "7e9fb7ac-9f67-43bf-b2c8-96ba0796cbb6"

issues/794/main.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using CSV
2+
using MixedModels
3+
using MixedModelsDatasets: dataset
4+
x = CSV.read(download("https://gist.githubusercontent.com/yjunechoe/af4a8dd3e2b0343fe3818e93dba8c81d/raw/x.csv"), Table);
5+
m = fit(MixedModel, @formula(y ~ x1 * x2 + (1 | g)), x)
6+
7+
profile(m; threshold=4) # works
8+
9+
profile(m; threshold=3)
10+
11+
s = lmm(@formula(reaction ~ 1 + days + (1 + days| subj)), dataset(:sleepstudy))
12+
13+
profile(s; threshold=3)

src/profile/sigmapr.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ end
3333
profileσ(m::LinearMixedModel, tc::TableColumns; threshold=4)
3434
3535
Return a Table of the profile of `σ` for model `m`. The profile extends to where the magnitude of ζ exceeds `threshold`.
36+
3637
!!! note
3738
This method is called by `profile` and currently considered internal.
3839
As such, it may change or disappear in a future release without being considered breaking.
@@ -69,7 +70,13 @@ function profileσ(m::LinearMixedModel{T}, tc::TableColumns{T}; threshold=4) whe
6970
updateL!(setθ!(m, θ))
7071
σv = [r.σ for r in tbl]
7172
ζv = [r.ζ for r in tbl]
72-
fwd = Dict( => interpolate(σv, ζv, BSplineOrder(4), Natural()))
73-
rev = Dict( => interpolate(ζv, σv, BSplineOrder(4), Natural()))
73+
local fwd, rev
74+
try
75+
fwd = Dict( => interpolate(σv, ζv, BSplineOrder(4), Natural()))
76+
rev = Dict( => interpolate(ζv, σv, BSplineOrder(4), Natural()))
77+
catch
78+
@error "An error occurred while fitting the profile splines for σ. Try adjusting the threshold."
79+
rethrow()
80+
end
7481
return (; m, tbl, fwd, rev)
7582
end

src/profile/vcpr.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,14 @@ function profileσs!(val::NamedTuple, tc::TableColumns{T}; nzlb=1.0e-8) where {T
7878
append!(val.tbl, tbl)
7979
ζcol = getproperty().(tbl)
8080
symcol = gpsym.(tbl)
81-
val.fwd[sym] = interpolate(symcol, ζcol, BSplineOrder(4), Natural())
82-
issorted(ζcol) &&
83-
(val.rev[sym] = interpolate(ζcol, symcol, BSplineOrder(4), Natural()))
81+
try
82+
val.fwd[sym] = interpolate(symcol, ζcol, BSplineOrder(4), Natural())
83+
issorted(ζcol) &&
84+
(val.rev[sym] = interpolate(ζcol, symcol, BSplineOrder(4), Natural()))
85+
catch
86+
@error "An error occurred while fitting the profile splines for the variance components. Try adjusting the threshold."
87+
rethrow()
88+
end
8489
end
8590
end
8691
copyto!(final, initial)

0 commit comments

Comments
 (0)