diff --git a/src/pk_utilities.jl b/src/pk_utilities.jl index 15c8b0f..07ac03c 100644 --- a/src/pk_utilities.jl +++ b/src/pk_utilities.jl @@ -1,5 +1,3 @@ -using StatsPlots - function pk_qualify(pk::Vector{Float64}) pk_good = sum(pk .<= 0.5) pk_ok = length(pk[pk .<= 0.7]) - pk_good @@ -7,15 +5,5 @@ function pk_qualify(pk::Vector{Float64}) (good=pk_good, ok=pk_ok, bad=pk_bad, very_bad=sum(pk .> 1)) end -function pk_plot(pk::Vector{Float64}; title="PSIS diagnostic plot.", - leg=:topleft, kwargs...) - scatter(pk, xlab="Datapoint", ylab="Pareto shape k", - marker=2.5, lab="Pk points", leg=leg) - hline!([0.5], lab="pk = 0.5");hline!([0.7], lab="pk = 0.7") - hline!([1], lab="pk = 1.0") - title!(title) -end - export - pk_qualify, - pk_plot \ No newline at end of file + pk_qualify diff --git a/src/waic.jl b/src/waic.jl index d51a24a..ce357e1 100644 --- a/src/waic.jl +++ b/src/waic.jl @@ -1,6 +1,22 @@ +""" + waic(ll::AbstractArray{<:Real}; pointwise=false, log_lik="log_lik, kwargs...) -var2(x) = mean(x.^2) .- mean(x)^2 +Compute the Widely Applicable Information Criterion (WAIC). +# Arguments +* `loglik::AbstractArray` : A vector of posterior log likelihoods +* `pointwise::Bool` : Compute WAIC pointwise, return a vector + + +# Returns +* `res::NamedTuple`: (WAIC=waics, lppd=lpd, penalty=pD, std_err=se) where + + WAIC : Sum of pointwise waic values (or pointwise vector) + lppd : Log pointwise predictive density + penalty : Penalty term ("overfitting penalty") + std_err : Standard error of pointwise waic values + +""" function waic( ll::AbstractArray; pointwise=false , log_lik="log_lik" , kwargs... ) n_samples, n_obs = size(ll) @@ -31,6 +47,8 @@ function waic( ll::AbstractArray; pointwise=false , log_lik="log_lik" , kwargs.. (WAIC=waics, lppd=lpd, penalty=pD, std_err=se) end +var2(x) = var(x; corrected=false) + export var2, waic