Skip to content

Commit

Permalink
Remove Model and rewrite turing_model (#45)
Browse files Browse the repository at this point in the history
* Remove `Model` and rewrite `turing_model`

* Apply suggestions from code review

Co-authored-by: Jose Storopoli <[email protected]>

Co-authored-by: Jose Storopoli <[email protected]>
  • Loading branch information
devmotion and Jose Storopoli authored Mar 1, 2022
1 parent ae06605 commit 5731396
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 452 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TuringGLM"
uuid = "0004c1f4-53c5-4d43-a221-a1dac6cf6b74"
authors = ["Jose Storopoli <[email protected]>, Rik Huijzer <[email protected]>, and contributors"]
version = "1.0.0"
version = "2.0.0"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
12 changes: 6 additions & 6 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ The most popular ones are `DataFrame`s and `NamedTuple`s.
TuringGLM supports non-hiearchical and hierarchical models.
For hierarchical models, only single random-intercept hierarchical models are supported.

For likelihoods, `TuringGLM.jl` supports:
Currently, for likelihoods `TuringGLM.jl` supports:

* `Gaussian()` (the default if not specified): linear regression
* `Student()`: robust linear regression
* `Logistic()`: logistic regression
* `Pois()`: Poisson count data regression
* `NegBin()`: negative binomial robust count data regression
* `Normal` (the default if not specified): linear regression
* `TDist`: robust linear regression
* `Bernoulli`: logistic regression
* `Poisson`: Poisson count data regression
* `NegativeBinomial`: negative binomial robust count data regression

## Tutorials

Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/custom_priors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ priors = CustomPrior(Normal(0, 2.5), Normal(10, 20), nothing);

# ╔═╡ 56498ac7-3476-42eb-9c12-078562fff51d
md"""
We instantiate our model with `turing_model` without specifying any model, thus the default model will be used: `Gaussian()`.
We instantiate our model with `turing_model` without specifying any model, thus the default model will be used (`model=Normal`).
Notice that we are specifying the `priors` keyword argument:
"""

Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/hierarchical_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fm = @formula(y ~ (1 | cheese) + background)

# ╔═╡ 934b7ec9-d4b3-435c-876f-49215dca8809
md"""
We instantiate our model with `turing_model` without specifying any model, thus the default model will be used: `Gaussian()`
We instantiate our model with `turing_model` without specifying any model, thus the default model will be used (`model=Normal`):
"""

# ╔═╡ 5fc736a2-068e-4deb-9a77-bd21d93f6f32
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/linear_regression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fm = @formula(kid_score ~ mom_hs * mom_iq)

# ╔═╡ 43d63761-adf5-4a52-b996-4ad3adfb35d0
md"""
Next, we instantiate our model with `turing_model` without specifying any model, thus the default model will be used: `Gaussian()`:
Next, we instantiate our model with `turing_model` without specifying any model, thus the default model will be used (`model=Normal`):
"""

# ╔═╡ 55b91963-001e-4753-93a6-2fa64190f353
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/logistic_regression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ fm = @formula(switch ~ dist + arsenic + assoc + educ)

# ╔═╡ 2ebfa422-f8a5-44d3-8f2c-a34d7832d3f2
md"""
Now we instantiate our model with `turing_model` passing a third argument `Logistic()` to indicate that the model is a logistic regression:
Now we instantiate our model with `turing_model` passing a keyword argument `model=Bernoulli` to indicate that the model is a logistic regression:
"""

# ╔═╡ 1f1158ce-73f0-49fd-a48a-af3b36376030
model = turing_model(fm, wells, Logistic());
model = turing_model(fm, wells; model=Bernoulli);

# ╔═╡ ebe074cb-7bad-4b52-9c9d-b9752af4bedd
chn = sample(model, NUTS(), 2_000);
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/negative_binomial_regression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ fm = @formula(y ~ roach1 + treatment + senior)

# ╔═╡ 124aeb01-7661-4402-a2fa-77d2771b686c
md"""
We instantiate our model with `turing_model` passing a third argument `NegBin()` to indicate that the model is a negative binomial regression:
We instantiate our model with `turing_model` passing a keyword argument `model=NegativeBinomial` to indicate that the model is a negative binomial regression:
"""

# ╔═╡ 7ea3a50d-3b0d-4cfd-b311-806d6ae59c1a
model = turing_model(fm, roaches, NegBin());
model = turing_model(fm, roaches; model=NegativeBinomial);

# ╔═╡ 597ce5d7-df3e-44e3-a154-e06e64894854
chn = sample(model, NUTS(), 2_000);
Expand Down
5 changes: 2 additions & 3 deletions docs/src/tutorials/poisson_regression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ fm = @formula(y ~ roach1 + treatment + senior)

# ╔═╡ 65f4f379-e9a5-4571-bc80-77c024f3f560
md"""
We instantiate our model with `turing_model` passing a third argument `Pois()` to
indicate that the model is a Poisson Regression
We instantiate our model with `turing_model` passing a keyword argument `model=Poisson` to indicate that the model is a Poisson Regression:
"""

# ╔═╡ 9147ed9e-a047-42ca-aa36-f522fad8388b
model = turing_model(fm, roaches, Pois());
model = turing_model(fm, roaches; model=Poisson);

# ╔═╡ aeeac527-2c32-407f-84a1-912cc74f51b7
md"""
Expand Down
5 changes: 2 additions & 3 deletions docs/src/tutorials/robust_regression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ fm = @formula(kid_score ~ mom_hs * mom_iq)

# ╔═╡ 4f9ff3fd-3f04-49a5-924e-aa23702e75a0
md"""
We instantiate our model with `turing_model` passing a third argument `Student()` to
indicate that the model is a robust regression with the Student's t-distribution:
We instantiate our model with `turing_model` passing a keyword argument `model=TDist` to indicate that the model is a robust regression with the Student's t-distribution:
"""

# ╔═╡ 3f4241d4-1c76-4d7c-99c1-aaa2111385f9
model = turing_model(fm, kidiq, Student());
model = turing_model(fm, kidiq; model=TDist);

# ╔═╡ 7bbe4fe4-bcaf-4699-88e4-0dff92250d30
chn = sample(model, NUTS(), 2_000);
Expand Down
2 changes: 0 additions & 2 deletions src/TuringGLM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ end
include("utils.jl")
include("data_constructors.jl")
include("priors.jl")
include("model.jl")
include("turing_model.jl")

export turing_model
export CustomPrior, DefaultPrior
export Gaussian, Student, Logistic, Pois, NegBin

end # module
11 changes: 0 additions & 11 deletions src/model.jl

This file was deleted.

Loading

3 comments on commit 5731396

@rikhuijzer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devmotion register?

@devmotion
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/55741

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.0.0 -m "<description of version>" 5731396204fe9a6c0cf4d61bdfe70af5d2ecfac9
git push origin v2.0.0

Please sign in to comment.