Extension of PosteriorStats

The following methods of PosteriorStats.jl are extended by this package.

PosteriorStats.hdiMethod
hdi(data::InferenceData; kwargs...) -> Dataset
hdi(data::Dataset; kwargs...) -> Dataset

Calculate the highest density interval (HDI) for each parameter in the data.

For more details and a description of the kwargs, see PosteriorStats.hdi.

source
PosteriorStats.looMethod
loo(data::Dataset; [var_name::Symbol,] kwargs...) -> PSISLOOResult{<:NamedTuple,<:Dataset}
loo(data::InferenceData; [var_name::Symbol,] kwargs...) -> PSISLOOResult{<:NamedTuple,<:Dataset}

Compute PSIS-LOO from log-likelihood values in data.

If more than one log-likelihood variable is present, then var_name must be provided.

For more details and a description of the kwargs, see PosteriorStats.loo.

Examples

Calculate PSIS-LOO of a model:

julia> using ArviZExampleData, PosteriorStats

julia> idata = load_example_data("centered_eight");

julia> loo(idata)
PSISLOOResult with estimates
 elpd  elpd_mcse    p  p_mcse
  -31        1.4  0.9    0.34

and PSISResult with 500 draws, 4 chains, and 8 parameters
Pareto shape (k) diagnostic values:
                    Count      Min. ESS
 (-Inf, 0.5]  good  6 (75.0%)  135
  (0.5, 0.7]  okay  2 (25.0%)  421
source
PosteriorStats.loo_pitMethod
loo_pit(idata::InferenceData, log_weights; kwargs...) -> DimArray

Compute LOO-PIT values using existing normalized log LOO importance weights.

Keywords

  • y_name: Name of observed data variable in idata.observed_data. If not provided, then the only observed data variable is used.
  • y_pred_name: Name of posterior predictive variable in idata.posterior_predictive. If not provided, then y_name is used.
  • kwargs: Remaining keywords are forwarded to the base method PosteriorStats.loo_pit.

See PosteriorStats.loo_pit for more details.

Examples

Calculate LOO-PIT values using already computed log weights.

julia> using ArviZExampleData, PosteriorStats

julia> idata = load_example_data("centered_eight");

julia> loo_result = loo(idata; var_name=:obs);

julia> loo_pit(idata, loo_result.psis_result.log_weights; y_name=:obs)
╭────────────────────────────────────────────╮
│ 8-element DimArray{Float64, 1} loo_pit_obs │
├────────────────────────────────────────────┴─────────────────────────── dims ┐
  ↓ school Categorical{String} [Choate, Deerfield, …, St. Paul's, Mt. Hermon] Unordered
└──────────────────────────────────────────────────────────────────────────────┘
 "Choate"            0.943511
 "Deerfield"         0.63797
 "Phillips Andover"  0.316697
 "Phillips Exeter"   0.582252
 "Hotchkiss"         0.295321
 "Lawrenceville"     0.403318
 "St. Paul's"        0.902508
 "Mt. Hermon"        0.655275
source
PosteriorStats.loo_pitMethod
loo_pit(idata::InferenceData; kwargs...) -> DimArray

Compute LOO-PIT from groups in idata using PSIS-LOO.

Keywords

  • y_name: Name of observed data variable in idata.observed_data. If not provided, then the only observed data variable is used.
  • y_pred_name: Name of posterior predictive variable in idata.posterior_predictive. If not provided, then y_name is used.
  • log_likelihood_name: Name of log-likelihood variable in idata.log_likelihood. If not provided, then y_name is used if idata has a log_likelihood group, otherwise the only variable is used.
  • reff::Union{Real,AbstractArray{<:Real}}: The relative effective sample size(s) of the likelihood values. If an array, it must have the same data dimensions as the corresponding log-likelihood variable. If not provided, then this is estimated using ess.
  • kwargs: Remaining keywords are forwarded to PosteriorStats.loo_pit.

See PosteriorStats.loo_pit for more details.

Examples

Calculate LOO-PIT values using as test quantity the observed values themselves.

julia> using ArviZExampleData, PosteriorStats

julia> idata = load_example_data("centered_eight");

julia> loo_pit(idata; y_name=:obs)
╭────────────────────────────────────────────╮
│ 8-element DimArray{Float64, 1} loo_pit_obs │
├────────────────────────────────────────────┴─────────────────────────── dims ┐
  ↓ school Categorical{String} [Choate, Deerfield, …, St. Paul's, Mt. Hermon] Unordered
└──────────────────────────────────────────────────────────────────────────────┘
 "Choate"            0.943511
 "Deerfield"         0.63797
 "Phillips Andover"  0.316697
 "Phillips Exeter"   0.582252
 "Hotchkiss"         0.295321
 "Lawrenceville"     0.403318
 "St. Paul's"        0.902508
 "Mt. Hermon"        0.655275
source
PosteriorStats.r2_scoreMethod
r2_score(idata::InferenceData; y_name, y_pred_name) -> (; r2, r2_std)

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

Keywords

  • y_name: Name of observed data variable in idata.observed_data. If not provided, then the only observed data variable is used.
  • y_pred_name: Name of posterior predictive variable in idata.posterior_predictive. If not provided, then y_name is used.

See PosteriorStats.r2_score for more details.

Examples

julia> using ArviZExampleData, PosteriorStats

julia> idata = load_example_data("regression10d");

julia> r2_score(idata) |> pairs
pairs(::NamedTuple) with 2 entries:
  :r2     => 0.998385
  :r2_std => 0.000100621
source
PosteriorStats.summarizeMethod
summarize(data::InferenceData, group=:posterior, stats_funs...; kwargs...)
summarize(data::Dataset, stats_funs...; kwargs...)

Compute summary statistics for the data using the provided functions.

For verbose variable labels, provide compat_labels=false. For details on stats_funs and kwargs, see PosteriorStats.summarize.

Examples

Compute all default summary statistics for the eight schools model in the centered parameterization:

julia> using ArviZExampleData, PosteriorStats, StatsBase

julia> data = load_example_data("centered_eight");

julia> summarize(data)
SummaryStats
                          mean  std  hdi_3%  hdi_97%  mcse_mean  mcse_std  ess ⋯
 mu                        4.5  3.5  -1.62     10.7        0.23      0.11      ⋯
 theta[Choate]             6.5  5.9  -4.56     17.1        0.30      0.29      ⋯
 theta[Deerfield]          5.0  4.9  -4.31     14.3        0.23      0.17      ⋯
 theta[Phillips Andover]   3.9  5.7  -7.77     13.7        0.23      0.28      ⋯
 theta[Phillips Exeter]    4.9  5.0  -4.49     14.7        0.26      0.17      ⋯
 theta[Hotchkiss]          3.7  5.0  -6.47     11.7        0.25      0.16      ⋯
 theta[Lawrenceville]      4.0  5.2  -7.04     12.2        0.22      0.22      ⋯
 theta[St. Paul's]         6.6  5.1  -3.09     16.3        0.30      0.19      ⋯
 theta[Mt. Hermon]         4.8  5.7  -5.86     16.0        0.26      0.25      ⋯
 tau                       4.1  3.1   0.896     9.67       0.26      0.17      ⋯
                                                               3 columns omitted

Compute the mean, standard deviation, median, and median absolute deviation of the theta parameters:

julia> summarize(data.posterior[(:theta,)], (:mean, :std) => mean_and_std, median, mad)
SummaryStats
                          mean   std  median   mad
 theta[Choate]            6.46  5.87    6.08  4.64
 theta[Deerfield]         5.03  4.88    5.01  4.96
 theta[Phillips Andover]  3.94  5.69    4.23  4.67
 theta[Phillips Exeter]   4.87  5.01    5.02  4.82
 theta[Hotchkiss]         3.67  4.96    3.89  4.70
 theta[Lawrenceville]     3.97  5.19    4.14  4.64
 theta[St. Paul's]        6.58  5.11    6.07  4.47
 theta[Mt. Hermon]        4.77  5.74    4.71  4.95
source
PosteriorStats.waicMethod
waic(data::Dataset; [var_name::Symbol]) -> WAICResult{<:NamedTuple,<:Dataset}
waic(data::InferenceData; [var_name::Symbol]) -> WAICResult{<:NamedTuple,<:Dataset}

Compute WAIC from log-likelihood values in data.

If more than one log-likelihood variable is present, then var_name must be provided.

See PosteriorStats.waic for more details.

Examples

Calculate WAIC of a model:

julia> using ArviZExampleData, PosteriorStats

julia> idata = load_example_data("centered_eight");

julia> waic(idata)
WAICResult with estimates
 elpd  elpd_mcse    p  p_mcse
  -31        1.4  0.9    0.33
source