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

Return NaN for negative ModeResult variance estimates #2471

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
LogDensityProblemsAD = "996a588d-648d-4e1f-a8f0-a84b347e47b1"
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
NamedArrays = "86f7a689-2022-50b4-a561-43c23ac3c673"
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
OptimizationOptimJL = "36348300-93cb-4f02-beb5-3c3902f8871e"
Expand Down Expand Up @@ -71,6 +72,7 @@ LinearAlgebra = "1"
LogDensityProblems = "2"
LogDensityProblemsAD = "1.7.0"
MCMCChains = "5, 6"
NaNMath = "1"
NamedArrays = "0.9, 0.10"
Optim = "1"
Optimization = "3, 4"
Expand Down
3 changes: 3 additions & 0 deletions src/optimisation/Optimisation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using ForwardDiff: ForwardDiff
using StatsAPI: StatsAPI
using Statistics: Statistics
using NaNMath: NaNMath
using LinearAlgebra: LinearAlgebra

export maximum_a_posteriori, maximum_likelihood
# The MAP and MLE exports are only needed for the Optim.jl interface.
Expand Down Expand Up @@ -281,6 +283,7 @@
return NamedArrays.NamedArray(info, (varnames, varnames))
end

StatsAPI.stderror(model::ModeResult) = NaNMath.sqrt.(LinearAlgebra.diag(StatsBase.vcov(model)))

Check warning on line 286 in src/optimisation/Optimisation.jl

View check run for this annotation

Codecov / codecov/patch

src/optimisation/Optimisation.jl#L286

Added line #L286 was not covered by tests
StatsBase.coef(m::ModeResult) = m.values
StatsBase.coefnames(m::ModeResult) = names(m.values)[1]
StatsBase.params(m::ModeResult) = StatsBase.coefnames(m)
Expand Down
Loading