IndrajeetPatil / ggstatsplot

Enhancing {ggplot2} plots with statistical analysis 📊📣
https://indrajeetpatil.github.io/ggstatsplot/
GNU General Public License v3.0
2.02k stars 186 forks source link

GLM issue ("coefficients" not "estimate" output) and request for ggcoefstats (remove certain estimates from visualization) #460

Closed IsadoraBM closed 4 years ago

IsadoraBM commented 4 years ago

Issue: Using rms::GLM but ggcoefstats(x = model) throws out an error that The tidy dataframe *must* contain column called 'estimate'. Check the tidy output using argument 'output = 'tidy'. Using names(model) <- "estimate" to change the name works on the model output but error persists.

Request: feature to specify which estimates to display from model (e.g remove controls from condensed visualization) similar to coefplot's predictors argument.

IndrajeetPatil commented 4 years ago

Hmm, I actually can't reproduce this error:

set.seed(123)
library(ggstatsplot)
library(rms)

## Dobson (1990) Page 93: Randomized Controlled Trial :
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
f <- glm(counts ~ outcome + treatment, family=poisson())

ggstatsplot::ggcoefstats(f)

Created on 2020-10-09 by the reprex package (v0.3.0)

IndrajeetPatil commented 4 years ago

As for the second issue, I would prefer not to support specifying exactly which predictors to show. This is at any case easier for the user to do. There are two options:

  1. If there are too many effects, maybe only display the significant ones:
Screenshot 2020-10-09 at 09 14 38
  1. Simply select the predictors you want to display and then enter a dataframe with the selected ones:
set.seed(123)
library(tidyverse)
library(rms)

## Dobson (1990) Page 93: Randomized Controlled Trial :
counts <- c(18, 17, 15, 20, 10, 20, 25, 13, 12)
outcome <- gl(3, 1, 9)
treatment <- gl(3, 3)
f <- glm(counts ~ outcome + treatment, family = poisson())

# only showing treatment effects
broomExtra::tidy_parameters(f) %>%
  dplyr::filter(!grepl(pattern = "outcome", x = term, ignore.case = TRUE)) %>%
  ggstatsplot::ggcoefstats(., statistic = "z", exclude.intercept = FALSE)

Created on 2020-10-09 by the reprex package (v0.3.0)

IsadoraBM commented 4 years ago

glm is the base-R function, in rms it is capitalized so rms::Glm() Could you try that?

On Fri, Oct 9, 2020, 03:09 Indrajeet Patil notifications@github.com wrote:

Hmm, I actually can't reproduce this error:

set.seed(123) library(ggstatsplot) library(rms)

Dobson (1990) Page 93: Randomized Controlled Trial :counts <- c(18,17,15,20,10,20,25,13,12)outcome <- gl(3,1,9)treatment <- gl(3,3)f <- glm(counts ~ outcome + treatment, family=poisson())

ggstatsplot::ggcoefstats(f)

https://camo.githubusercontent.com/6dd0077fd4008539d6cde15f3f87feb6a960a424/68747470733a2f2f692e696d6775722e636f6d2f3943695230374b2e706e67

Created on 2020-10-09 by the reprex package https://reprex.tidyverse.org (v0.3.0)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/IndrajeetPatil/ggstatsplot/issues/460#issuecomment-706012455, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGNA6COEGSBUFH2KTVHPPUDSJ2ZKJANCNFSM4SJQCHXQ .

IndrajeetPatil commented 4 years ago

Oops, sorry about that.

I can reproduce this now.

set.seed(123)
library(ggstatsplot)
library(rms)

## Dobson (1990) Page 93: Randomized Controlled Trial :
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
f <- Glm(counts ~ outcome + treatment, family=poisson())

broomExtra::tidy_parameters(f)
#> NULL

Created on 2020-10-09 by the reprex package (v0.3.0)

IndrajeetPatil commented 4 years ago

Closed in favor of https://github.com/easystats/parameters/issues/313