Skip to content

Add argument to force continuous or discrete Mode#240

Open
bwiernik wants to merge 2 commits intomjskay:masterfrom
bwiernik:mode_map
Open

Add argument to force continuous or discrete Mode#240
bwiernik wants to merge 2 commits intomjskay:masterfrom
bwiernik:mode_map

Conversation

@bwiernik
Copy link
Copy Markdown
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
Copy Markdown
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