Skip to content

Commit

Permalink
fix make rank plots use normalized densities at all times
Browse files Browse the repository at this point in the history
  • Loading branch information
Red-Portal committed Nov 28, 2023
1 parent 9b6488b commit 9f25f8a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "MCMCTesting"
uuid = "9963b6a1-5d46-439c-8efc-3a487843c7fa"
version = "0.2.1"
version = "0.3.0"

[deps]
HypothesisTests = "09f84164-cd44-5f33-b23f-e6b0d136a0d5"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ nothing
```
Then, we can simulate the ranks and then plot them using `Plots`.
```@example started
test = ExactRankTest(1000, 30, 10)
test = ExactRankTest(10000, 30, 10)
rank_correct = simulate_ranks(test, TestSubject(model, Gibbs()); show_progress=false)
rank_wrong = simulate_ranks(test, TestSubject(model, GibbsWrongVar()); show_progress=false)
Expand Down
25 changes: 16 additions & 9 deletions src/rankplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
Plot the simulated ranks using `simulate_ranks`.
If the test subjects are correct, the ranks should visually resemble samples from a uniform distribution.
The black horizontal line shows the average counts of a uniform distribution, while the colored bands are the 1σ, 2σ, 3σ deviations from the mean.
The black horizontal line shows the density of a uniform distribution, while the colored bands are the 1σ, 2σ, 3σ deviations.
!!! info
The deviation bands assume uniform bin sizes.
!!! info
`Plots` must be imported to use this plot recipe.
Expand All @@ -26,18 +29,21 @@ The black horizontal line shows the average counts of a uniform distribution, wh

n_max_rank = test.n_mcmc_steps
n_samples = test.n_samples
binprob = 1/n_max_rank
binstd = sqrt((1 - binprob)*(binprob)*n_samples)

xguide --> "Rank"
yguide --> "Count"
xlims --> [1,n_max_rank]
bins --> 1:1:n_max_rank
ylims --> [0, Inf]
bins --> 0:1:n_max_rank
fillalpha --> 0.2

binprob = 1/n_max_rank
binstd = sqrt((1 - binprob)*(binprob))/n_max_rank

# default two-column layout
n_params = size(ranks,1)
size --> (300, 200*n_params)
layout --> (n_params,1)
size --> (300, 200*n_params)
layout --> (n_params,1)

for (idx, ranks_param) in enumerate(eachrow(ranks))
stat_name = if stat_names isa Symbol && stat_names == :auto
Expand All @@ -55,6 +61,7 @@ The black horizontal line shows the average counts of a uniform distribution, wh
fillcolor := :match
linecolor := :match
linealpha := 1.0
normalize := true
seriestype := :stephist
ranks_param
end
Expand All @@ -67,7 +74,7 @@ The black horizontal line shows the average counts of a uniform distribution, wh
fillalpha := 0.1
color := :black
ribbon --> [binstd,binstd]
[n_samples/n_max_rank]
[1/n_max_rank]
end
# 2σ confidence interval
@series begin
Expand All @@ -78,7 +85,7 @@ The black horizontal line shows the average counts of a uniform distribution, wh
fillalpha := 0.05
color := :black
ribbon --> [2*binstd,2*binstd]
[n_samples/n_max_rank]
[1/n_max_rank]
end
# 2σ confidence interval
@series begin
Expand All @@ -89,7 +96,7 @@ The black horizontal line shows the average counts of a uniform distribution, wh
fillalpha := 0.025
color := :black
ribbon --> [3*binstd,3*binstd]
[n_samples/n_max_rank]
[1/n_max_rank]
end
end
end

1 comment on commit 9f25f8a

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/96104

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.0 -m "<description of version>" 9f25f8aaf44358db1321e911a9491c88440bec27
git push origin v0.3.0

Please sign in to comment.