Skip to content

Conversation

@teunbrand
Copy link
Collaborator

This PR aims to fix #5641.

Briefly, the way bounded densities were estimated may result in discontinuities due to incomplete estimation of the tails.
As densities are 'mirrored' across finite bounds, in this PR we ensure that the 'mirror image' is the same size as the original by multiplying the to/from range in density estimation. We also increase n to not lose any detail in the bounded density.

The reprex from #5641 with this PR now shows a flatter line in the uniform density:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

x <- ppoints(100)
p <- ggplot(data.frame(x), aes(x)) + 
  geom_density(bounds = c(0,1))
p

p + coord_cartesian(ylim = c(.99, 1.01))

Created on 2024-01-15 with reprex v2.0.2

@teunbrand
Copy link
Collaborator Author

@mjskay Could I ask you if you think this implementation is correct?

@mjskay
Copy link
Contributor

mjskay commented Jan 16, 2024

Yeah this looks right to me!

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

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

LGTM

@teunbrand teunbrand merged commit e22cff2 into tidyverse:main May 20, 2024
@teunbrand teunbrand deleted the density_discontinuity branch May 20, 2024 09:57
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.

Bounded densities have discontinuities due to incomplete estimation of tails in the reflection method

3 participants