Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Feature request/suggestion - point estimate with interval labels to aid in plotting

Abierto
#223 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
r

Línea de trabajo

Revisa el comportamiento solicitado de las estimaciones puntuales y las etiquetas de intervalos, incluido el ejemplo de R proporcionado y sus combinaciones compatibles de media, mediana, moda, HDI y ETI. Determina el punto de entrada y la API adecuados de bayesplot, y luego define pruebas o ejemplos que verifiquen el formato y dejen claro cuándo la funcionalidad está completa.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

feature

I've found it very useful to have easy access to a 'label' providing a chosen point estimate and density interval, which can be added for example to graphs as a means of providing extra, concise information about a parameter or effect that is depicted. E.g., adding label with the median and 95% HDI from the posterior, or whatever other point estimate/interval you choose, in the form: 5.67 [4.33 - 6.01].

The following R code takes a posterior distribution in the form of a vector and returns a summary. You can ignore most of the probably very inelegant coding, but the function inside of this function called 'point.uncertainty' could be a useful place to begin if you think this feature may be useful.

This requires dplyr and hdinterval packages to run.

summarise.me <- function(posterior, name = "summary", interval = .95, p.e = "median", u.e = "hdi") {
  
  hdi.bounds <- hdi(posterior, credMass = interval)
  hdi.lower <- hdi.bounds["lower"]
  hdi.upper <- hdi.bounds["upper"]
  
  eti.upper <- quantile(posterior, probs = interval + ((1 - interval) / 2) )
  eti.lower <- quantile(posterior, probs = (1 - interval) / 2)
    
  mean <- mean(posterior)
  median <- median(posterior)
  mode <- (density(as.numeric(posterior))
           $x[which.max(density(as.numeric(posterior))$y)])
  
  hdi.width <- hdi.upper - hdi.lower
  eti.width <- eti.upper - eti.lower
  
  posterior.summary <- 
    tibble(name = name,
           mean = mean,
           median = median,
           mode = mode,
           hdi.lower = hdi.lower,
           hdi.upper = hdi.upper,
           hdi.width = hdi.width,
           eti.lower = eti.lower,
           eti.upper = eti.upper,
           eti.width = eti.width,
           interval = interval)
  
  point.uncertainty <- function(summary, point.estimate = "mean", uncertainty = "hdi") {
    if (point.estimate == "mean" & uncertainty == "hdi")
    {
      paste(sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$mean)), 
            " [", 
            sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$hdi.lower)), 
            "-", 
            sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$hdi.upper)), 
            "]" , 
            sep = "")
    } else if (point.estimate == "mode" & uncertainty == "hdi")
    {
      paste(sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$mode)), 
            " [", 
            sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$hdi.lower)), 
            "-", 
            sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$hdi.upper)), 
            "]" , 
            sep = "")
    } else if (point.estimate == "median" & uncertainty == "hdi")
    {
      paste(sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$median)), 
            " [", 
            sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$hdi.lower)), 
            "-", 
            sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$hdi.upper)), 
            "]" , 
            sep = "")
    } else if (point.estimate == "mean" & uncertainty == "eti")
    {
      paste(sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$mean)), 
            " [", 
            sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$eti.lower)), 
            "-", 
            sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$eti.upper)), 
            "]" , 
            sep = "")
    } else if (point.estimate == "mode" & uncertainty == "eti")
    {
      paste(sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$mode)), 
            " [", 
            sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$eti.lower)), 
            "-", 
            sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$eti.upper)), 
            "]" , 
            sep = "")
    }else if (point.estimate == "median" & uncertainty == "eti")
  {
    paste(sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$median)), 
          " [", 
          sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$eti.lower)), 
          "-", 
          sub("^(-?)0.", "\\1.", sprintf("%.2f", summary$eti.upper)), 
          "]" , 
          sep = "")
  }

  }
  posterior.summary <- posterior.summary %>%
    mutate(label = point.uncertainty(posterior.summary, point.estimate = p.e, uncertainty = u.e))
  
  return(posterior.summary)
}
Lenguaje dominante
R
Estrellas
442
Forks
93
Merge medio
3 h 17 min
PR fusionados (30 d)
2

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de stan-dev/bayesplot

Todos los issues de stan-dev/bayesplot

Issues similares

Más issues de R

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.