Skip to content
Merged
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "InferenceObjects"
uuid = "b5cf5a8d-e756-4ee3-b014-01d49d192c00"
authors = ["Seth Axen <seth.axen@gmail.com> and contributors"]
version = "0.4.14"
version = "0.4.15"

[deps]
ANSIColoredPrinters = "a4c015fc-c6ff-483c-b24f-f7ea428134e9"
Expand All @@ -23,7 +23,7 @@ InferenceObjectsPosteriorStatsExt = ["PosteriorStats", "StatsBase"]

[compat]
ANSIColoredPrinters = "0.0.1"
ArviZExampleData = "0.1.10"
ArviZExampleData = "0.3"
Dates = "1"
DimensionalData = "0.27, 0.28, 0.29"
EvoTrees = "0.16"
Expand Down
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
InferenceObjects = {path = ".."}

[compat]
ArviZExampleData = "0.3"
Documenter = "1"
DocumenterInterLinks = "1"
6 changes: 3 additions & 3 deletions ext/InferenceObjectsPosteriorStatsExt/r2_score.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@doc """
r2_score(idata::InferenceData; y_name, y_pred_name, kwargs...) -> (; r2, <ci>)
r2_score(idata::InferenceData; y_name, y_pred_name, kwargs...) -> (; r2, <ci_fun>)

Compute ``R²`` from `idata`, automatically formatting the predictions to the correct shape.

Expand All @@ -17,10 +17,10 @@ Compute ``R²`` from `idata`, automatically formatting the predictions to the co
```jldoctest
julia> using ArviZExampleData, PosteriorStats

julia> idata = load_example_data("regression10d");
julia> idata = load_example_data("anes");

julia> r2_score(idata)
(r2 = 0.998384805658226, eti = 0.9982167674001565 .. 0.9985401916739318)
(r2 = 0.4944850210319484, eti = 0.46184359652436546 .. 0.528018251711097)
```
"""
function PosteriorStats.r2_score(
Expand Down
27 changes: 13 additions & 14 deletions test/posteriorstats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,17 @@ _as_array(x::AbstractArray) = x
end

@testset "r2_score" begin
@testset for name in ("regression1d", "regression10d")
idata = load_example_data(name)
r2_val = @inferred(r2_score(idata))
@test r2_val == r2_score(
idata.observed_data.y,
PermutedDimsArray(idata.posterior_predictive.y, (:draw, :chain, :y_dim_0)),
)
@test r2_val == r2_score(idata; y_name=:y)
@test r2_val == r2_score(idata; y_pred_name=:y)
@test r2_val == r2_score(idata; y_name=:y, y_pred_name=:y)
@test_throws Exception r2_score(idata; y_name=:z)
@test_throws Exception r2_score(idata; y_pred_name=:z)
end
idata = load_example_data("anes")
r2_val = @inferred(r2_score(idata))
@test r2_val == r2_score(
idata.observed_data.vote,
PermutedDimsArray(idata.posterior_predictive.vote, (:draw, :chain, :__obs__)),
)
@test r2_val == r2_score(idata; y_name=:vote)
@test r2_val == r2_score(idata; y_pred_name=:vote)
@test r2_val == r2_score(idata; y_name=:vote, y_pred_name=:vote)
@test_throws Exception r2_score(idata; y_name=:z)
@test_throws Exception r2_score(idata; y_pred_name=:z)
end

isdefined(PosteriorStats, :waic) && @testset "waic" begin
Expand Down Expand Up @@ -199,7 +197,8 @@ _as_array(x::AbstractArray) = x
)
idata2 = InferenceData(; log_likelihood=Dataset((; y=ll_perm)))
waic_result2 = waic(idata2)
@test waic_result2.estimates.elpd ≈ waic_result1.estimates.elpd atol = atol_perm
@test waic_result2.estimates.elpd ≈ waic_result1.estimates.elpd atol =
atol_perm
@test isapprox(
waic_result2.estimates.se_elpd,
waic_result1.estimates.se_elpd;
Expand Down
Loading