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

ash1() never sees m and kopt #87

Open
fkohrt opened this issue Apr 3, 2024 · 0 comments · May be fixed by #88
Open

ash1() never sees m and kopt #87

fkohrt opened this issue Apr 3, 2024 · 0 comments · May be fixed by #88

Comments

@fkohrt
Copy link

fkohrt commented Apr 3, 2024

The following code should produce (nearly¹) overlapping histograms:

faithful |>
  ggplot2::ggplot(ggplot2::aes(x = eruptions)) +
  ggplot2::stat_bin(
    closed = "right",
    breaks = breaks,
    mapping = ggplot2::aes(y = ggplot2::after_stat(density)),
    fill = NA,
    color = "blue"
  ) +
  ggalt::stat_ash(
    nbin = 18,
    ab = range(breaks),
    m = 1,
    geom = "bar",
    fill = NA,
    color = "red"
  )

...but it doesn't:

The reason is that ash::ash1() is never provided with m (or kopt), but is rather always called with the default m = 5:

ggalt/R/geom_ash.r

Lines 115 to 127 in 30dc0da

compute_group = function(data, scales, ab = NULL,
nbin = 50, m = 5, kopt = c(2, 2)) {
if (is.null(ab)) ab <- nicerange(data$x)
bin_res <- ash::bin1(data$x, ab, nbin)
ash_msg <- capture.output(ash_res <- ash1(bin_res))
if (ash_res$ier == 1) message("Estimate nonzero outside interval ab.")
data.frame(x=ash_res$x, density=ash_res$y)
}


¹ In theory, the histograms should align perfectly. In practice, ash::bin1() differs from graphics::hist(), e.g. compare ash::bin1(faithful$eruptions, ab = c(1.6, 5.2), nbin = 18)$nc and hist(faithful$eruptions, breaks = 18, right = TRUE, plot = FALSE)$counts.

@fkohrt fkohrt linked a pull request Apr 3, 2024 that will close this issue
@fkohrt fkohrt changed the title stat_ash() does not consider m and kopt stat_ash() never sees m and kopt Apr 3, 2024
@fkohrt fkohrt changed the title stat_ash() never sees m and kopt ash1() never sees m and kopt Apr 3, 2024
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 a pull request may close this issue.

1 participant