Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mcmc_areas() fixes #169

Merged
merged 8 commits into from
Oct 23, 2018
Merged

mcmc_areas() fixes #169

merged 8 commits into from
Oct 23, 2018

Conversation

tjmahr
Copy link
Collaborator

@tjmahr tjmahr commented Oct 19, 2018

From the NEWS.md

  • mcmc_areas()
    gains an argument area_method which controls how to draw the density
    curves. The default "equal area" constrains the heights so that the curves
    have the same area. As a result, a narrow interval will appear as a spike
    of density, while a wide, uncertain interval is spread thin over the x axis.
    Alternatively "equal height" will set the maximum height on each curve to
    the same value. This works well when the intervals are about the same width.
    Otherwise, that wide, uncertain interval will dominate the visual space
    compared to a narrow, less uncertain interval. A compromise between the two is
    "scaled height" which scales the curves from "equal height" using
    height * sqrt(height). (support for equal-height curves mcmc_areas() #163, mcmc_areas() fixes #169)

  • mcmc_areas() correctly plots density curves where the point estimate
    does not include the highest point of the density curve.
    (Point estimate plotted weirdly in mcmc_areas() #168, mcmc_areas() fixes #169, @jtimonen)

  • mcmc_areas_ridges() draws the vertical line at x = 0 over the curves so
    that it is always visible.

  • mcmc_intervals() and mcmc_areas() raise a warning if prob_outer is ever
    less than prob. It sorts these two values into the correct order. (prob_outer ignored in mcmc_areas_ridges() #138)

Not in NEWS.md

  • Updated all reference images in the visual unit tests.

Here are examples of the three plotting styles.

library(bayesplot)
library(tidyverse)

set.seed(123)

K <- 4
N <- 1000
X <- array(0,c(N,1,K))
for(k in 1:K) {
  x <- rgamma(N, c(1, 2, 4, 5)[k], c(3, 5, 5, 6)[k])
  X[,1,k] <- x
}
X[,1,4] <- runif(1000, min = min(X), max = max(X))
dimnames(X)[[3]] <- as.list(paste("x", 1:K, sep="_"))
x <- X

p1 <- mcmc_areas(X, area_method = "equal area") + ggtitle("equal area")
p2 <- mcmc_areas(X, area_method = "equal height") + ggtitle("equal height")
p3 <- mcmc_areas(X, area_method = "scaled height") + ggtitle("scaled height")

library(patchwork)
p1 + p2 + p3 + plot_layout(ncol = 1)

image

@tjmahr
Copy link
Collaborator Author

tjmahr commented Oct 19, 2018

Closes #163. Closes #168. Closes #138.

@jgabry jgabry self-requested a review October 23, 2018 18:03
Copy link
Member

@jgabry jgabry left a comment

Choose a reason for hiding this comment

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

@tjmahr These changes are great! And I love the examples you added to the mcmc_areas doc where the titles/subtitles of the plots in the examples clearly explain the difference between the area_method options. Thanks!

@jgabry jgabry merged commit 7bb24d3 into master Oct 23, 2018
@jgabry jgabry deleted the issue-168 branch October 23, 2018 18:08
@jgabry
Copy link
Member

jgabry commented Oct 23, 2018

@avehtari I know you were interested in this, so just tagging you so you know it's merged now. thanks to @tjmahr the master branch of bayesplot should now have mcmc_areas with an argument area_method.

@avehtari
Copy link
Contributor

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants