Code Monkey home page Code Monkey logo

modelsummary's People

Contributors

elbersb avatar etiennebacher avatar florence-laflamme avatar gadenbuie avatar grantmcdermott avatar huftis avatar indrajeetpatil avatar joachim-gassen avatar kbroman avatar larmarange avatar lboller avatar lukaswallrich avatar moritzpschwarz avatar nickch-k avatar ramorel avatar rsbivand avatar turbanisch avatar vincentarelbundock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

modelsummary's Issues

gof_map omit column

When omit==TRUE, remove the gof.

What if nrow(gof)==0

At least this is explicit, and users can do:

gm <- gtsummary::gof_map
gm$omit <- FALSE
gtsummary(models, gof_map = gm)

Duplicated `amsmath`?

I'm using the latest github version of gt and gtsummary.
When compiling a rmd file including gtsummary to latex, it returns an error:

"! Package mathspec Error: amsmath' must be loaded earlier than mathspec'."

It appears that calling gtsummary adding amsmath at the end of the setting codes when producing the .tex file that caused the problem. When I manually removed \usepackage{amsmath}, the file is compilable. Actually, for bookdown, it already includes amsmath in the default template. Given this case, it may be helpful if there could be an option for gtsummary or knit_latex to customize the engaged packages---at least amsmath.

Here's some example codes:

---
title: "example"
output:
  bookdown::pdf_document2:
    fig_caption: yes
    keep_tex: yes
    toc: FALSE
    latex_engine: xelatex
---

```{r}
library(gtsummary)

lm(mpg ~ wt, data = mtcars) %>% gtsummary
```

tidy() warnings?

Thanks for the package! I'm getting annoying warnings:

library(lme4)
#> Loading required package: Matrix
data(sleepstudy)
fit <- lmer(Reaction ~ 1|Subject, data=sleepstudy)
modelsummary::msummary(fit)
#> Warning in bind_rows_(x, .id): binding factor and character vector,
#> coercing into character vector
#> Warning in bind_rows_(x, .id): binding character and factor vector,
#> coercing into character vector
#> Warning: `prepend()` is deprecated as of rlang 0.4.0.
#> 
#> Vector tools are now out of scope for rlang to make it a more
#> focused package.
#> This warning is displayed once per session.

with traceback;

11: doWithOneRestart(return(expr), restart)
10: withOneRestart(expr, restarts[[1L]])
9: withRestarts({
       .Internal(.signalCondition(simpleWarning(msg, call), msg, 
    ...
8: .signalSimpleWarning("binding factor and character vector, coercing into character vector", 
       base::quote(bind_rows_(x, .id)))
7: bind_rows_(x, .id)
6: bind_rows(ret_list)
5: tidy.merMod(model)
4: generics::tidy(model)
3: extract_estimates(model = models[[i]], fmt = fmt, statistic = statistic, 
       statistic_override = statistic_override[[i]], conf_level = conf_level, 
    ...
2: modelsummary::extract(models, statistic = statistic, statistic_override = statistic_override, 
       conf_level = conf_level, coef_map = coef_map, coef_omit = coef_omit, 
    ...
1: modelsummary::msummary(fit)

Seems like these are tidy()-related (?)

What to do inside or outside?

Should we have arguments for:

  • notes
  • footnotes
  • column spans
  • row groups
  • title subtitle

when those are available in gt? My intuition is it's fine to have redundancy for convenience, but I'm not sure where to stop.

Hardcoded characters in `statistic_override` produces warning

@LukasWallrich , I get this warning when running tests for your new merged code:

test-statistic-override.R:148: warning: list of hardcoded character and possibly numeric values
attributes are not identical across measure variables;
they will be dropped

test-statistic-override.R:148: warning: list of hardcoded character and possibly numeric values
attributes are not identical across measure variables;
they will be dropped

test-statistic-override.R:148: warning: list of hardcoded character and possibly numeric values
attributes are not identical across measure variables;
they will be dropped

test-statistic-override.R:148: warning: list of hardcoded character and possibly numeric values
attributes are not identical across measure variables;
they will be dropped

Any idea where that comes from?

Here's what I'm running:

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.3

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] sandwich_2.5-1          dplyr_0.8.99.9002       MASS_7.3-51.4          
[4] gt_0.2.0.5              modelsummary_0.2.0.9000 testthat_2.3.2         
[7] devtools_2.2.1          usethis_1.5.1          

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4            compiler_3.6.1        pillar_1.4.3          prettyunits_1.1.1    
 [5] remotes_2.1.0         tools_3.6.1           digest_0.6.25         pkgbuild_1.0.6       
 [9] pkgload_1.0.2         gtable_0.3.0          checkmate_2.0.0       lattice_0.20-38      
[13] memoise_1.1.0         lifecycle_0.2.0       tibble_3.0.0          nlme_3.1-140         
[17] pkgconfig_2.0.3       rlang_0.4.5.9000      cli_2.0.2             rstudioapi_0.10      
[21] stringr_1.4.0         withr_2.1.2           sass_0.1.2.1          desc_1.2.0           
[25] generics_0.0.2        fs_1.4.1              vctrs_0.2.99.9010     lmtest_0.9-37        
[29] grid_3.6.1            rprojroot_1.3-2       tidyselect_1.0.0.9000 glue_1.4.0           
[33] R6_2.4.1              processx_3.4.2        fansi_0.4.1           sessioninfo_1.1.1    
[37] ggplot2_3.3.0.9000    tidyr_1.0.2           callr_3.4.3           purrr_0.3.3          
[41] magrittr_1.5          htmltools_0.4.0       scales_1.1.0          backports_1.1.6      
[45] ps_1.3.2              ellipsis_0.3.0        assertthat_0.2.1      colorspace_1.4-1     
[49] stringi_1.4.6         munsell_0.5.0         broom_0.5.2           crayon_1.3.4         
[53] zoo_1.8-6   

Error when gof_matrix has no omit = FALSE

modelsummary:::extract_gof throws a very unclear error when all gof are set to be ommitted. A clear error message might be better, or ideally, it should just return the summary without gof information?

RTF export is broken

Here is a test case

library(MASS)
library(modelsummary)

url <- 'https://vincentarelbundock.github.io/Rdatasets/csv/HistData/Guerry.csv'
dat <- read.csv(url) 
dat$Clergy <- ifelse(dat$Clergy > 40, 1, 0) # binary variable for logit model

models <- list()
models[['OLS 1']] <- lm(Literacy ~ Crime_prop + Infants, dat)
models[['NBin 1']] <- glm.nb(Literacy ~ Crime_prop + Donations, dat)
models[['OLS 2']] <- lm(Desertion ~ Crime_prop + Infants, dat)
models[['NBin 2']] <- glm.nb(Desertion ~ Crime_prop + Donations, dat)
models[['Logit 1']] <- glm(Clergy ~ Crime_prop + Infants, dat, family = binomial())

modelsummary(models)

modelsummary(models, file="test.rtf")

Set `use.fallback = TRUE` in `extract_gof` to get `nobs` for models w/o `nobs` method

First off, great package, really happy to be using it.

I ran into an issue trying to create a regression table for a series of fixed-effects models using the lfe package. There is no nobs method for the models produced by this package, and so I can't get the number of observations in the table.

This can be solved by adding the argument use.fallback = TRUE in the nobs function call in the extract_gof function.

For example:

library(lfe)
#> Loading required package: Matrix

## create covariates
x <- rnorm(1000)
x2 <- rnorm(length(x))

## individual and firm
id <- factor(sample(20,length(x),replace=TRUE))
firm <- factor(sample(13,length(x),replace=TRUE))

## effects for them
id.eff <- rnorm(nlevels(id))
firm.eff <- rnorm(nlevels(firm))

## left hand side
u <- rnorm(length(x))
y <- x + 0.5*x2 + id.eff[id] + firm.eff[firm] + u

## estimate and print result
est <- felm(y ~ x+x2| id + firm)

nobs(est)
#> Error in nobs.default(est): no 'nobs' method is available

nobs(est, use.fallback = TRUE)
#> [1] 1000

Created on 2019-07-26 by the reprex package (v0.3.0)

I will create a pull request modifying the nobs call. I don't think that adding the use.fallback argument will cause any unwanted behavior.

Support bookdown-style table referencing for model summary tables

Hello,

It would be a nice addition to your package if you can support bookdown-style table referencing for model summary tables. Bookdown version of the output formats (e.g., pdf_document2(), word_document2(), etc.) are now becoming the standard and are being preferred over their rmarkdown counterparts. Please check out the last paragraph of this chapter: https://bookdown.org/yihui/bookdown/tables.html for a potential idea.

Thanks!

Support formatting of terms and model names

It would be great if there was a way to support markdown formatting and line breaks in terms and model names. Could that be added as an option? (Or am I missing a feature?)

latex doesn't compile if there is just one gof

---
title: "test_modelsummary"
author: "Vincent Arel-Bundock"
date: '2019-06-14'
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(modelsummary)
library(tidyverse)
```

```{r}
dat <- read.csv('data/titanic.csv')
models <- list()
models[['LPM']] <- lm(survie ~ femme, data = dat)
models[['Logit']] <- glm(survie ~ femme, data = dat, family = binomial(link = 'logit'))
models[['Probit']] <- glm(survie ~ femme, data = dat, family = binomial(link = 'probit'))
```

```{r}
cm <- c('(Intercept)' = 'Constante', 'femme' = 'Femme')
gm <- modelsummary::gof_map
gm$omit <- TRUE
gm$omit[1] <- FALSE
modelsummary(models, coef_map = cm, gof_map = gm) %>% knit_latex()
```

Glance for class `MCMCglmm`

Thank you so much for the amazing package! Right now the gtsummary seems still not supporting glancing MCMCglmm outputs, while broom.mixed::tidy is already able to convert such outputs into tidy tables. If gtsummary could support this class and probably allow adding customized glancing classes, it will be fantastic!

LaTeX not compiling when "Intercept" is surrounded by ()

I'm seeing some strange behavior with current versions of modelsummary and gt. When knitting a document like this with LaTeX…

---
title: "Example"
output:
  pdf_document: 
    keep_tex: yes
---

```{r}
library(gt)
library(MASS)
library(modelsummary)

url <- 'https://vincentarelbundock.github.io/Rdatasets/csv/HistData/Guerry.csv'
dat <- read.csv(url) 
dat$Clergy <- ifelse(dat$Clergy > 40, 1, 0) # binary variable for logit model

models <- list()
models[['OLS 1']] <- lm(Literacy ~ Crime_prop + Infants, dat)
models[['NBin 1']] <- glm.nb(Literacy ~ Crime_prop + Donations, dat)
models[['OLS 2']] <- lm(Desertion ~ Crime_prop + Infants, dat)
models[['NBin 2']] <- glm.nb(Desertion ~ Crime_prop + Donations, dat)
models[['Logit 1']] <- glm(Clergy ~ Crime_prop + Infants, dat, family = binomial())
```

```{r}
msummary(models)
```

…I get this error about something with the (Intercept) line in the table:

! Undefined control sequence.
<argument> ...al \expandafter \let \cmrsideswitch 
                                                  \@tempa \fi \fi 
l.143 (Intercept)
                  & 64.114 & 4.218 & 57.331 & 4.384 & 1.006 \\ 

Error: LaTeX failed to compile bloop.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See bloop.log for more info.
Execution halted

If I edit the generated .tex file and remove the parentheses around (Intercept), though, it compiles just fine:

\midrule
Intercept & 64.114 & 4.218 & 57.331 & 4.384 & 1.006 \\ 
 & (5.247) & (0.144) & (8.315) & (0.233) & (0.710) \\ 

image

tidy.mira no longer called automatically

When running the README example for mice-models, the correct tidy function no longer gets called, resulting in an error.

library(mice)
# Create a new dataset with missing values
url <- 'https://vincentarelbundock.github.io/Rdatasets/csv/HistData/Guerry.csv'
tmp <- read.csv(url)[, c('Clergy', 'Donations', 'Literacy')]
tmp$Clergy[sample(1:nrow(tmp), 3)] <- NA
tmp$Donations[sample(1:nrow(tmp), 3)] <- NA
tmp$Literacy[sample(1:nrow(tmp), 3)] <- NA
# Impute dataset 5 times
tmp <- mice(tmp, m = 5, printFlag = FALSE, seed = 1024)
# Estimate models
mod <- list()
mod[[1]] <- with(tmp, lm(Clergy ~ Donations))
mod[[2]] <- with(tmp, lm(Clergy ~ Donations + Literacy))
generics::tidy(mod[[1]])

Error in seq_len(nrow(x)) :
argument must be coercible to non-negative integer

With the current modelsummary, modelsummary::tidy() does not work either. However, if I install an old version ("1824f065ac037438e0a019d3968ec2f4acf6ff99"), right after you committed my changes to tidy.mira, modelsummary::tidy() works. Any idea what happened there?

SEs to the side

Hey Vincent,

Apologies if I missed it, but is there a way to put the SEs (or whatever statistic you prefer) to the side of the coefficient values, rather than underneath?

Thanks!

new method to generic

What is the correct way to add new methods to a generic from a different package using roxygen2? What I have now seems to work, but I'm not sure it's 100% standard.

Category specification and explanatory note for `table1`

Congratulations on the major update of 0.1.0! The gtsummary produces the best summary table I've ever used (or created by myself)!
Two quick question-suggestions:

  1. Is there a way to change the categories of variables without specifying each of them? Something like mutate_if in dplyr? Also, how does the function distinguish the categorical? Is there a way to customize the rule?
  2. The current ways to present the categorical and binaries is excellent! Clear and transparent! For the continuous, though, will that be helpful to add some inline, something like 3.15 (min: 0, max: 5) or an elaborated endnote of the presenting rule?

gtsummary vs modelsummary?

I'm trying to run the code included in the .README file to install the package:

remotes::install_github('vincentarelbundock/modelsummary')

Shouldn't this instead be remotes::install_github('vincentarelbundock/gtsummary')?

Problems with table title and float in knitr pdf output

Hello,

Thanks for this wonderful package! I started using the package recently and found some problems that I thought I should bring to your attention.

  1. title argument in the msummary() function does not seem to have an effect in the knitr pdf output.
  2. The table does not float and breaks across pages in the final output.

Thanks!

gt has no clean mechanism to add \midrule between gof and coef

Currently, the HTML rule that separates gof and coef is drawn by changing the cell border. This doesn't work in LaTeX. Need a more general mechanism, but probably have to wait until gt's LaTeX support improves.

Groups produced double lines, so that's not a clean solution either.

How to override existing tidy methods?

I want to override tidy.lm to add new columns, thus allowing me to include new statistics.

For instance, I would like to do this:

library(broom)
library(sandwich)

f <- function(x, ...) {
    out <- broom:::tidy.lm(x, ...)
    out$std.error.hc1 <- sqrt(diag(sandwich::vcovHC(x, type = 'HC1')))
    out$std.error.hc3 <- sqrt(diag(sandwich::vcovHC(x, type = 'HC3')))
    out$std.error.hac <- sqrt(diag(sandwich::vcovHAC(x)))
    return(out)
}
setMethod("tidy", "lm", f)

x <- rnorm(10)
y <- rnorm(10)
model <- lm(y ~ x)
tidy(model)

This works when I simply call tidy(model) from the interactive console, that is, the output has new columns for the other types of standard errors.

Unfortunately, the functions in my package which use @importFrom generics tidy continue to return the output of broom::tidy internally, instead of using the newly defined method:

https://github.com/vincentarelbundock/modelsummary/blob/master/R/extract_estimates.R#L31

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.