Skip to content

Commit

Permalink
Fix line length
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhuijzer committed Sep 1, 2021
1 parent 7daf2c6 commit 5695b1f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
7 changes: 4 additions & 3 deletions src/gelmandiag.jl
Expand Up @@ -54,9 +54,10 @@ end
"""
gelmandiag(chains::AbstractArray{<:Real,3}; alpha::Real=0.95)
Compute the Gelman, Rubin and Brooks diagnostics [^Gelman1992] [^Brooks1998].
Values of the diagnostic’s potential scale reduction factor (PSRF) that are close to one suggest convergence.
As a rule-of-thumb, convergence is rejected if the 97.5 percentile of a PSRF is greater than 1.2.
Compute the Gelman, Rubin and Brooks diagnostics [^Gelman1992] [^Brooks1998]. Values of the
diagnostic’s potential scale reduction factor (PSRF) that are close to one suggest
convergence. As a rule-of-thumb, convergence is rejected if the 97.5 percentile of a PSRF
is greater than 1.2.
[^Gelman1992]: Gelman, A., & Rubin, D. B. (1992). Inference from iterative simulation using multiple sequences. Statistical science, 7(4), 457-472.
Expand Down
15 changes: 9 additions & 6 deletions src/gewekediag.jl
@@ -1,13 +1,16 @@
"""
gewekediag(x::AbstractVector{<:Real}; first::Real=0.1, last::Real=0.5, kwargs...)
Compute the Geweke diagnostic [^Geweke1991] from the `first` and `last` proportion of samples `x`.
Compute the Geweke diagnostic [^Geweke1991] from the `first` and `last` proportion of
samples `x`.
The diagnostic is designed to asses convergence of posterior means estimated with autocorrelated samples.
It computes a normal-based test statistic comparing the sample means in two windows containing proportions of the first and last iterations.
Users should ensure that there is sufficient separation between the two windows to assume that their samples are independent.
A non-significant test p-value indicates convergence.
Significant p-values indicate non-convergence and the possible need to discard initial samples as a burn-in sequence or to simulate additional samples.
The diagnostic is designed to asses convergence of posterior means estimated with
autocorrelated samples. It computes a normal-based test statistic comparing the sample
means in two windows containing proportions of the first and last iterations. Users should
ensure that there is sufficient separation between the two windows to assume that their
samples are independent. A non-significant test p-value indicates convergence. Significant
p-values indicate non-convergence and the possible need to discard initial samples as a
burn-in sequence or to simulate additional samples.
[^Geweke1991]: Geweke, J. F. (1991). Evaluating the accuracy of sampling-based approaches to the calculation of posterior moments (No. 148). Federal Reserve Bank of Minneapolis.
"""
Expand Down
9 changes: 5 additions & 4 deletions src/heideldiag.jl
Expand Up @@ -3,10 +3,11 @@
x::AbstractVector{<:Real}; alpha::Real=0.05, eps::Real=0.1, start::Int=1, kwargs...
)
Compute the Heidelberger and Welch diagnostic [^Heidelberger1983].
This diagnostic tests for non-convergence (non-stationarity) and whether ratios of estimation interval halfwidths to means are within a target ratio.
Stationarity is rejected (0) for significant test p-values.
Halfwidth tests are rejected (0) if observed ratios are greater than the target, as is the case for `s2` and `beta[1]`.
Compute the Heidelberger and Welch diagnostic [^Heidelberger1983]. This diagnostic tests for
non-convergence (non-stationarity) and whether ratios of estimation interval halfwidths to
means are within a target ratio. Stationarity is rejected (0) for significant test p-values.
Halfwidth tests are rejected (0) if observed ratios are greater than the target, as is the
case for `s2` and `beta[1]`.
[^Heidelberger1983]: Heidelberger, P., & Welch, P. D. (1983). Simulation run length control in the presence of an initial transient. Operations Research, 31(6), 1109-1144.
"""
Expand Down
34 changes: 21 additions & 13 deletions src/rafterydiag.jl
@@ -1,23 +1,31 @@
@doc raw"""
rafterydiag(x::AbstractVector{<:Real}; q=0.025, r=0.005, s=0.95, eps=0.001, range=1:length(x))
rafterydiag(
x::AbstractVector{<:Real}; q=0.025, r=0.005, s=0.95, eps=0.001, range=1:length(x))
Compute the Raftery and Lewis diagnostic [^rafterydiag].
This diagnostic is used to determine the number of iterations required to estimate a specified quantile `q` within a desired degree of accuracy.
The diagnostic is designed to determine the number of autocorrelated samples required to estimate a specified quantile $\theta_q$, such that $\Pr(\theta \le \theta_q) = q$, within a desired degree of accuracy.
In particular, if $\hat{\theta}_q$ is the estimand and $\Pr(\theta \le \hat{\theta}_q) = \hat{P}_q$ the estimated cumulative probability, then accuracy is specified in terms of `r` and `s`, where $\Pr(q - r < \hat{P}_q < q + r) = s$.
Thinning may be employed in the calculation of the diagnostic to satisfy its underlying assumptions.
However, users may not want to apply the same (or any) thinning when estimating posterior summary statistics because doing so results in a loss of information.
Accordingly, sample sizes estimated by the diagnostic tend to be conservative (too large).
Compute the Raftery and Lewis diagnostic [^rafterydiag]. This diagnostic is used to
determine the number of iterations required to estimate a specified quantile `q` within a
desired degree of accuracy. The diagnostic is designed to determine the number of
autocorrelated samples required to estimate a specified quantile $\theta_q$, such that
$\Pr(\theta \le \theta_q) = q$, within a desired degree of accuracy. In particular, if
$\hat{\theta}_q$ is the estimand and $\Pr(\theta \le \hat{\theta}_q) = \hat{P}_q$ the
estimated cumulative probability, then accuracy is specified in terms of `r` and `s`, where
$\Pr(q - r < \hat{P}_q < q + r) = s$. Thinning may be employed in the calculation of the
diagnostic to satisfy its underlying assumptions. However, users may not want to apply the
same (or any) thinning when estimating posterior summary statistics because doing so results
in a loss of information. Accordingly, sample sizes estimated by the diagnostic tend to be
conservative (too large).
Furthermore, the argument `r` specifies the margin of error for estimated cumulative probabilities and `s` the probability for the margin of error.
`eps` specifies the tolerance within which the probabilities of transitioning from initial to retained iterations are within the equilibrium probabilities for the chain.
This argument determines the number of samples to discard as a burn-in sequence and is typically left at its default value.
Furthermore, the argument `r` specifies the margin of error for estimated cumulative
probabilities and `s` the probability for the margin of error. `eps` specifies the tolerance
within which the probabilities of transitioning from initial to retained iterations are
within the equilibrium probabilities for the chain. This argument determines the number of
samples to discard as a burn-in sequence and is typically left at its default value.
[^rafterydiag]: A L Raftery and S Lewis. Bayesian Statistics, chapter How Many Iterations in the Gibbs Sampler? Volume 4. Oxford University Press, New York, 1992.
"""
function rafterydiag(
x::AbstractVector{<:Real}; q=0.025, r=0.005, s=0.95, eps=0.001, range=1:length(x)
)
x::AbstractVector{<:Real}; q=0.025, r=0.005, s=0.95, eps=0.001, range=1:length(x))

nx = length(x)
phi = sqrt(2.0) * SpecialFunctions.erfinv(s)
nmin = ceil(Int, q * (1.0 - q) * (phi / r)^2)
Expand Down

0 comments on commit 5695b1f

Please sign in to comment.