Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change identifer of stderr to se #368

Merged
merged 3 commits into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/statmodels.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ nulldeviance
r2
rss
score
stderr
stderror
vcov
weights(::StatisticalModel)
```
Expand Down
2 changes: 1 addition & 1 deletion src/StatsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ module StatsBase
nullloglikelihood,
rss,
score,
stderr,
stderror,
vcov,
predict,
predict!,
Expand Down
10 changes: 9 additions & 1 deletion src/deprecates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ import Base.varm, Base.stdm
@deprecate AICc(obj::StatisticalModel) aicc(obj)
@deprecate BIC(obj::StatisticalModel) bic(obj)

if !isdefined(Base, :stderr)
@deprecate stderr(obj::StatisticalModel) stderror(obj)
else
function (io::typeof(stderr))(obj::StatisticalModel)
Copy link
Contributor

Choose a reason for hiding this comment

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

The problem with this is that typeof(stderr) can change at runtime if redirect_stderr is called.

So this should just be ::IO to catch all usages. I don't think it is a problem to have a fairly general method here as a temporary deprecation since it continues to throw a MethodError for non-stderr objects. (People are unlikely to pass StatisticalModel objects to random IO objects by accident anyway.)

Copy link
Member

Choose a reason for hiding this comment

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

I changed ::IO because it doesn't work on 0.7. I'm not sure we should care about supporting that deprecation after calling redirect_stderr... Anyway I don't have any solution to suggest.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why doesn't IO work? On 0.7 (unless something has changed very recently), typeof(stderr) is TTY, which is a subtype of IO.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we should care about supporting that deprecation after calling redirect_stderr

This would mean that the deprecation wouldn't work in IJulia, for example.

Copy link
Member

Choose a reason for hiding this comment

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

Because of JuliaLang/julia#14919:

julia> (io::IO)() = 1
ERROR: cannot add methods to an abstract type

Copy link
Contributor

Choose a reason for hiding this comment

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

I see… yes, I can't think of a way to make it work for IJulia (without adding an IJulia dependency), since IJulia redirects to its own IO type.

Base.depwarn("stderr(obj::StatisticalModel) is deprecated, use stderror(obj) instead", :stderr)
io === stderr ? stderror(obj) : throw(MethodErrror(io, (obj,)))
end
end

@deprecate R2(obj::StatisticalModel, variant::Symbol) r2(obj, variant)
@deprecate R²(obj::StatisticalModel, variant::Symbol) r²(obj, variant)
@deprecate adjR2(obj::StatisticalModel, variant::Symbol) adjr2(obj, variant)
Expand All @@ -38,7 +47,6 @@ function findat!(r::IntegerArray, a::AbstractArray{T}, b::AbstractArray{T}) wher
return r
end


"""
findat(a, b)

Expand Down
4 changes: 2 additions & 2 deletions src/statmodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ informationmatrix(model::StatisticalModel; expected::Bool = true) =
error("informationmatrix is not defined for $(typeof(obj)).")

"""
stderr(obj::StatisticalModel)
stderror(obj::StatisticalModel)
Return the standard errors for the coefficients of the model.
"""
stderr(obj::StatisticalModel) = sqrt.(diag(vcov(obj)))
stderror(obj::StatisticalModel) = sqrt.(diag(vcov(obj)))

"""
vcov(obj::StatisticalModel)
Expand Down
4 changes: 2 additions & 2 deletions test/statmodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ x2 0.368314 Great -90 <1e-4
x3 0.344454 Bad -80 <1e-4
"""

@test sprint(show, CoefTable(m, ["Estimate", "Stderr", "df", "p"],
@test sprint(show, CoefTable(m, ["Estimate", "Stderror", "df", "p"],
["x1", "x2", "x3"], 4)) == """
Estimate Stderr df p
Estimate Stderror df p
x1 0.819778 0.844007 0.923676 0.1717
x2 0.669931 0.67919 0.066098 0.4204
x3 0.453058 0.72525 0.999172 0.5567
Expand Down