Skip to content

Commit

Permalink
fix doctests and add missing docstrings (#192)
Browse files Browse the repository at this point in the history
* first round of doctest(; fix=true): coeftables, hypotheiscoding

* use Documenter 0.25 series; docstrings for response/modelmatrix

* include hypothesis_matrix in contrasts doc page

* DataFrames.DataFrame -> DataFrame

* build docs on 1.5

* bump patch version

* specify rng in internals

* add StableRNGs to project

* stablerng everywhere there's a rand

* don't need rand here

* don't seed RNG in setdocmeta

* run doctest(; fix=true)

* missed some fixes...

* use julia-repl for the ugly hypmat text and add some explanatory txt

* bump patch version

* fix a few more stray small exponents

* Revert "fix a few more stray small exponents"

This reverts commit c458cdf.
  • Loading branch information
kleinschmidt authored Dec 29, 2020
1 parent a496205 commit e6b5f23
Show file tree
Hide file tree
Showing 12 changed files with 316 additions and 231 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "StatsModels"
uuid = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
version = "0.6.16"
version = "0.6.17"

[deps]
DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
Expand Down
3 changes: 2 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
GLM = "38e38edf-8417-5370-95a0-9cbb8c7f171a"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StatsModels = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
Documenter = "~0.24"
Documenter = "0.25"
6 changes: 5 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Documenter, StatsModels

DocMeta.setdocmeta!(StatsModels, :DocTestSetup, :(using StatsModels, StatsBase); recursive=true)


using Pkg
Pkg.precompile()

Expand All @@ -12,7 +15,8 @@ makedocs(
"Contrast coding categorical variables" => "contrasts.md",
"Temporal variables and Time Series Terms" => "temporal_terms.md",
"API documentation" => "api.md"
]
],
modules = [StatsModels]
)

deploydocs(
Expand Down
1 change: 1 addition & 0 deletions docs/src/contrasts.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ EffectsCoding
HelmertCoding
SeqDiffCoding
HypothesisCoding
hypothesis_matrix
```

### Special internal contrasts
Expand Down
126 changes: 64 additions & 62 deletions docs/src/formula.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
CurrentModule = StatsModels
DocTestSetup = quote
using StatsModels
using Random
Random.seed!(1)
end
```

Expand Down Expand Up @@ -42,6 +40,8 @@ Here is an example of the `@formula` in action:
```jldoctest 1
julia> using StatsModels, DataFrames
julia> using StableRNGs; rng = StableRNG(1);
julia> f = @formula(y ~ 1 + a + b + c + b&c)
FormulaTerm
Response:
Expand All @@ -53,20 +53,20 @@ Predictors:
c(unknown)
b(unknown) & c(unknown)
julia> df = DataFrame(y = rand(9), a = 1:9, b = rand(9), c = repeat(["d","e","f"], 3))
9×4 DataFrames.DataFrame
Row │ y a b │ c │
│ Float64 Int64 Float64 String
─────┼──────────────────────────────────────┤
│ 1 │ 0.236033 │ 1 │ 0.986666 │ d │
│ 2 │ 0.346517 │ 2 │ 0.555751 │ e │
│ 3 │ 0.312707 │ 3 │ 0.437108 │ f │
│ 4 │ 0.00790928 │ 4 │ 0.424718 │ d │
│ 5 │ 0.488613 │ 5 │ 0.773223 │ e │
│ 6 │ 0.210968 │ 6 │ 0.28119 │ f │
│ 7 │ 0.951916 │ 7 │ 0.209472 │ d │
│ 8 │ 0.999905 │ 8 │ 0.251379 │ e │
│ 9 │ 0.251662 │ 9 0.0203749 │ f │
julia> df = DataFrame(y = rand(rng, 9), a = 1:9, b = rand(rng, 9), c = repeat(["d","e","f"], 3))
9×4 DataFrame
Row │ y a b c
│ Float64 Int64 Float64 String
─────┼────────────────────────────────────
1 │ 0.585195 1 0.236782 d
2 │ 0.0773379 2 0.943741 e
3 │ 0.716628 3 0.445671 f
4 │ 0.320357 4 0.763679 d
5 │ 0.653093 5 0.145071 e
6 │ 0.236639 6 0.021124 f
7 │ 0.709684 7 0.152545 d
8 │ 0.557787 8 0.617492 e
9 │ 0.05079 9 0.481531 f
julia> f = apply_schema(f, schema(f, df))
FormulaTerm
Expand All @@ -83,15 +83,15 @@ julia> resp, pred = modelcols(f, df);
julia> pred
9×7 Array{Float64,2}:
1.0 1.0 0.986666 0.0 0.0 0.0 0.0
1.0 2.0 0.555751 1.0 0.0 0.555751 0.0
1.0 3.0 0.437108 0.0 1.0 0.0 0.437108
1.0 4.0 0.424718 0.0 0.0 0.0 0.0
1.0 5.0 0.773223 1.0 0.0 0.773223 0.0
1.0 6.0 0.28119 0.0 1.0 0.0 0.28119
1.0 7.0 0.209472 0.0 0.0 0.0 0.0
1.0 8.0 0.251379 1.0 0.0 0.251379 0.0
1.0 9.0 0.0203749 0.0 1.0 0.0 0.0203749
1.0 1.0 0.236782 0.0 0.0 0.0 0.0
1.0 2.0 0.943741 1.0 0.0 0.943741 0.0
1.0 3.0 0.445671 0.0 1.0 0.0 0.445671
1.0 4.0 0.763679 0.0 0.0 0.0 0.0
1.0 5.0 0.145071 1.0 0.0 0.145071 0.0
1.0 6.0 0.021124 0.0 1.0 0.0 0.021124
1.0 7.0 0.152545 0.0 0.0 0.0 0.0
1.0 8.0 0.617492 1.0 0.0 0.617492 0.0
1.0 9.0 0.481531 0.0 1.0 0.0 0.481531
julia> coefnames(f)
("y", ["(Intercept)", "a", "b", "c: e", "c: f", "b & c: e", "b & c: f"])
Expand Down Expand Up @@ -224,13 +224,13 @@ StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Array{Float64,1}},GLM.De
:(log(y)) ~ 1 + a + b
Coefficients:
──────────────────────────────────────────────────────────────────────────────
Estimate Std. Error t value Pr(>|t|) Lower 95% Upper 95%
──────────────────────────────────────────────────────────────────────────────
(Intercept) -4.16168 2.98788 -1.39285 0.2131 -11.4727 3.14939
a 0.357482 0.342126 1.04489 0.3363 -0.479669 1.19463
b 2.32528 3.13735 0.741159 0.4866 -5.35154 10.0021
──────────────────────────────────────────────────────────────────────────────
──────────────────────────────────────────────────────────────────────────
Coef. Std. Error t Pr(>|t|) Lower 95% Upper 95%
──────────────────────────────────────────────────────────────────────────
(Intercept) 0.0698025 0.928295 0.08 0.9425 -2.20165 2.34126
a -0.105669 0.128107 -0.82 0.4410 -0.419136 0.207797
b -1.63199 1.12678 -1.45 0.1977 -4.38911 1.12513
──────────────────────────────────────────────────────────────────────────
julia> df.log_y = log.(df.y);
Expand All @@ -240,13 +240,13 @@ StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Array{Float64,1}},GLM.De
log_y ~ 1 + a + b
Coefficients:
──────────────────────────────────────────────────────────────────────────────
Estimate Std. Error t value Pr(>|t|) Lower 95% Upper 95%
──────────────────────────────────────────────────────────────────────────────
(Intercept) -4.16168 2.98788 -1.39285 0.2131 -11.4727 3.14939
a 0.357482 0.342126 1.04489 0.3363 -0.479669 1.19463
b 2.32528 3.13735 0.741159 0.4866 -5.35154 10.0021
──────────────────────────────────────────────────────────────────────────────
──────────────────────────────────────────────────────────────────────────
Coef. Std. Error t Pr(>|t|) Lower 95% Upper 95%
──────────────────────────────────────────────────────────────────────────
(Intercept) 0.0698025 0.928295 0.08 0.9425 -2.20165 2.34126
a -0.105669 0.128107 -0.82 0.4410 -0.419136 0.207797
b -1.63199 1.12678 -1.45 0.1977 -4.38911 1.12513
──────────────────────────────────────────────────────────────────────────
```

Expand All @@ -256,15 +256,15 @@ interpretation of `+`, `*`, and `&`:
```jldoctest 1
julia> modelmatrix(@formula(y ~ 1 + b + identity(1+b)), df)
9×3 Array{Float64,2}:
1.0 0.986666 1.98667
1.0 0.555751 1.55575
1.0 0.437108 1.43711
1.0 0.424718 1.42472
1.0 0.773223 1.77322
1.0 0.28119 1.28119
1.0 0.209472 1.20947
1.0 0.251379 1.25138
1.0 0.0203749 1.02037
1.0 0.236782 1.23678
1.0 0.943741 1.94374
1.0 0.445671 1.44567
1.0 0.763679 1.76368
1.0 0.145071 1.14507
1.0 0.021124 1.02112
1.0 0.152545 1.15255
1.0 0.617492 1.61749
1.0 0.481531 1.48153
```

## Constructing a formula programmatically
Expand Down Expand Up @@ -350,13 +350,15 @@ simulated coefficients.
```jldoctest
julia> using GLM, DataFrames, StatsModels
julia> data = DataFrame(a = rand(100), b = repeat(["d", "e", "f", "g"], 25));
julia> using StableRNGs; rng = StableRNG(1);
julia> data = DataFrame(a = rand(rng, 100), b = repeat(["d", "e", "f", "g"], 25));
julia> X = StatsModels.modelmatrix(@formula(y ~ 1 + a*b).rhs, data);
julia> β_true = 1:8;
julia> ϵ = randn(100)*0.1;
julia> ϵ = randn(rng, 100)*0.1;
julia> data.y = X*β_true .+ ϵ;
Expand All @@ -366,18 +368,18 @@ StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Array{Float64,1}},GLM.De
y ~ 1 + a + b + a & b
Coefficients:
──────────────────────────────────────────────────────────────────────────
Estimate Std. Error t value Pr(>|t|) Lower 95% Upper 95%
──────────────────────────────────────────────────────────────────────────
(Intercept) 0.98878 0.0384341 25.7266 <1e-43 0.912447 1.06511
a 2.00843 0.0779388 25.7694 <1e-43 1.85364 2.16323
b: e 3.03726 0.0616371 49.2764 <1e-67 2.91484 3.15967
b: f 4.03909 0.0572857 70.5078 <1e-81 3.92531 4.15286
b: g 5.02948 0.0587224 85.6484 <1e-88 4.91285 5.14611
a & b: e 5.9385 0.10753 55.2264 <1e-71 5.72494 6.15207
a & b: f 6.9073 0.112483 61.4075 <1e-75 6.6839 7.1307
a & b: g 7.93918 0.111285 71.3407 <1e-81 7.71816 8.16021
──────────────────────────────────────────────────────────────────────────
───────────────────────────────────────────────────────────────────────
Coef. Std. Error t Pr(>|t|) Lower 95% Upper 95%
───────────────────────────────────────────────────────────────────────
(Intercept) 1.01518 0.0400546 25.34 <1e-42 0.935626 1.09473
a 1.97476 0.0701427 28.15 <1e-46 1.83545 2.11407
b: e 3.01269 0.0571186 52.74 <1e-69 2.89925 3.12614
b: f 4.01918 0.065827 61.06 <1e-75 3.88844 4.14992
b: g 4.99176 0.0593715 84.08 <1e-88 4.87385 5.10968
a & b: e 5.98288 0.0954641 62.67 <1e-76 5.79328 6.17248
a & b: f 6.98622 0.107871 64.76 <1e-77 6.77197 7.20046
a & b: g 7.92541 0.109873 72.13 <1e-82 7.70719 8.14362
───────────────────────────────────────────────────────────────────────
```

Expand Down
Loading

2 comments on commit e6b5f23

@kleinschmidt
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 register()

@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/27027

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 v0.6.17 -m "<description of version>" e6b5f231c17e5723864c573ef7ef8d4fb0992b0c
git push origin v0.6.17

Please sign in to comment.