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

Add argument to force continuous or discrete Mode #240

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bwiernik
Copy link
Contributor

This PR adds an argument to Mode() to allow users to force computation of the discrete mode or continuous MAP, for cases where the default is_integerish() check makes the incorrect call. Some examples include Poisson or other variables with many distinct discrete values (#236) or dosage data with a small number of discrete decimal values.

Closes #236

data.frame(x = datasets::AirPassengers) |>
  ggplot2::ggplot(ggplot2::aes(x = x)) +
  ggdist::stat_slab(ggplot2::aes(height = max(ggplot2::after_stat(pdf)))) +
  ggdist::stat_spike(
    ggplot2::aes(height = max(ggplot2::after_stat(pdf))),
    at = \(x) ggdist::Mode(x, type = "continuous")
  )

@bwiernik
Copy link
Contributor Author

bwiernik commented Jul 18, 2024

library(tidyverse)
library(ggdist)

dat <- data.frame(x = as.numeric(datasets::AirPassengers))


data.frame(x = datasets::AirPassengers) |>
  ggplot2::ggplot(ggplot2::aes(x = x)) +
  ggdist::stat_slab(ggplot2::aes(height = max(ggplot2::after_stat(pdf)))) +
  ggdist::stat_spike(
    ggplot2::aes(height = max(ggplot2::after_stat(pdf))),
    at = Mode
  )
#> Don't know how to automatically pick scale for object of type <ts>. Defaulting
#> to continuous.

data.frame(x = datasets::AirPassengers) |>
  ggplot2::ggplot(ggplot2::aes(x = x)) +
  ggdist::stat_slab(ggplot2::aes(height = max(ggplot2::after_stat(pdf)))) +
  ggdist::stat_spike(
    ggplot2::aes(height = max(ggplot2::after_stat(pdf))),
    at = \(x) Mode(x, type = "continuous")
  )
#> Don't know how to automatically pick scale for object of type <ts>. Defaulting
#> to continuous.

Created on 2024-07-18 with reprex v2.0.2

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.

Mode calculated incorrectly
1 participant