Skip to content

Commit d64441e

Browse files
authored
Fix deprecation of keyword argument in mad (#67)
* Fix deprecations of `mad` keyword argument * Bump version * Fix format
1 parent a61d8a7 commit d64441e

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TuringGLM"
22
uuid = "0004c1f4-53c5-4d43-a221-a1dac6cf6b74"
33
authors = ["Jose Storopoli <[email protected]>, Rik Huijzer <[email protected]>, and contributors"]
4-
version = "2.1.0"
4+
version = "2.1.1"
55

66
[deps]
77
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"

src/turing_model.jl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,14 @@ end
137137
# Default priors
138138
_prior(prior::Prior, y, ::Type{<:UnivariateDistribution}) = prior
139139
function _prior(::DefaultPrior, y, ::Type{Normal})
140-
return CustomPrior(TDist(3), median(y) + mad(y) * TDist(3), nothing)
140+
m = median(y)
141+
return CustomPrior(TDist(3), m + mad(y; center=m, normalize=true) * TDist(3), nothing)
141142
end
142143
function _prior(::DefaultPrior, y, ::Type{TDist})
143-
return CustomPrior(TDist(3), median(y) + mad(y) * TDist(3), Gamma(2, 0.1))
144+
m = median(y)
145+
return CustomPrior(
146+
TDist(3), m + mad(y; center=m, normalize=true) * TDist(3), Gamma(2, 0.1)
147+
)
144148
end
145149
function _prior(::DefaultPrior, y, ::Type{Bernoulli})
146150
return CustomPrior(TDist(3), 2.5 * TDist(3), nothing)
@@ -174,13 +178,14 @@ function _model(μ_X, σ_X, prior, intercept_ranef, idx, ::Type{Normal})
174178
σ_X=σ_X,
175179
prior=prior,
176180
residual=1 / std(y),
181+
mad_y=mad(y; normalize=true),
177182
)
178183
α ~ prior.intercept
179184
β ~ filldist(prior.predictors, predictors)
180185
σ ~ Exponential(residual)
181186
μ = α .+ X * β
182187
if !isempty(intercept_ranef)
183-
τ ~ mad(y) * truncated(TDist(3); lower=0)
188+
τ ~ mad_y * truncated(TDist(3); lower=0)
184189
zⱼ ~ filldist(Normal(), n_gr)
185190
αⱼ = zⱼ .* τ
186191
μ .+= αⱼ[idxs]
@@ -215,14 +220,15 @@ function _model(μ_X, σ_X, prior, intercept_ranef, idx, ::Type{TDist})
215220
σ_X=σ_X,
216221
prior=prior,
217222
residual=1 / std(y),
223+
mad_y=mad(y; normalize=true),
218224
)
219225
α ~ prior.intercept
220226
β ~ filldist(prior.predictors, predictors)
221227
σ ~ Exponential(residual)
222228
ν ~ prior.auxiliary
223229
μ = α .+ X * β
224230
if !isempty(intercept_ranef)
225-
τ ~ 0 + mad(y) * truncated(TDist(3); lower=0)
231+
τ ~ mad_y * truncated(TDist(3); lower=0)
226232
zⱼ ~ filldist(Normal(), n_gr)
227233
αⱼ = zⱼ .* τ
228234
μ .+= αⱼ[idxs]
@@ -257,12 +263,13 @@ function _model(μ_X, σ_X, prior, intercept_ranef, idx, ::Type{Bernoulli})
257263
μ_X=μ_X,
258264
σ_X=σ_X,
259265
prior=prior,
266+
mad_y=mad(y; normalize=true),
260267
)
261268
α ~ prior.intercept
262269
β ~ filldist(prior.predictors, predictors)
263270
μ = α .+ X * β
264271
if !isempty(intercept_ranef)
265-
τ ~ mad(y) * truncated(TDist(3); lower=0)
272+
τ ~ mad_y * truncated(TDist(3); lower=0)
266273
zⱼ ~ filldist(Normal(), n_gr)
267274
αⱼ = zⱼ .* τ
268275
μ .+= αⱼ[idxs]
@@ -295,12 +302,13 @@ function _model(μ_X, σ_X, prior, intercept_ranef, idx, ::Type{Poisson})
295302
μ_X=μ_X,
296303
σ_X=σ_X,
297304
prior=prior,
305+
mad_y=mad(y; normalize=true),
298306
)
299307
α ~ prior.intercept
300308
β ~ filldist(prior.predictors, predictors)
301309
μ = α .+ X * β
302310
if !isempty(intercept_ranef)
303-
τ ~ mad(y) * truncated(TDist(3); lower=0)
311+
τ ~ mad_y * truncated(TDist(3); lower=0)
304312
zⱼ ~ filldist(Normal(), n_gr)
305313
αⱼ = zⱼ .* τ
306314
μ .+= αⱼ[idxs]
@@ -333,14 +341,15 @@ function _model(μ_X, σ_X, prior, intercept_ranef, idx, ::Type{NegativeBinomial
333341
μ_X=μ_X,
334342
σ_X=σ_X,
335343
prior=prior,
344+
mad_y=mad(y; normalize=true),
336345
)
337346
α ~ prior.intercept
338347
β ~ filldist(prior.predictors, predictors)
339348
ϕ⁻ ~ prior.auxiliary
340349
ϕ = 1 / ϕ⁻
341350
μ = α .+ X * β
342351
if !isempty(intercept_ranef)
343-
τ ~ mad(y) * truncated(TDist(3); lower=0)
352+
τ ~ mad_y * truncated(TDist(3); lower=0)
344353
zⱼ ~ filldist(Normal(), n_gr)
345354
αⱼ = zⱼ .* τ
346355
μ .+= αⱼ[idxs]

0 commit comments

Comments
 (0)