Git Product home page Git Product logo

Comments (6)

larmarange avatar larmarange commented on June 9, 2024

After exploring it, the issue is not coming from gtsummary but from survey. The survey::svytable() is failing if we ask it to summarize a variable named weights. If you change the variable name, there is no problem.

library(dplyr)
#> 
#> Attachement du package : 'dplyr'
#> Les objets suivants sont masqués depuis 'package:stats':
#> 
#>     filter, lag
#> Les objets suivants sont masqués depuis 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(gtsummary)
library(survey)
#> Le chargement a nécessité le package : grid
#> Le chargement a nécessité le package : Matrix
#> Le chargement a nécessité le package : survival
#> 
#> Attachement du package : 'survey'
#> L'objet suivant est masqué depuis 'package:graphics':
#> 
#>     dotchart
library(WeightIt)

n <- 100000
age <- rnorm(n,60,10)
sex <- rbinom(n,1,0.5)
X <- rbinom(n,1,0.4) * rnorm(n,30,5) + sex * rnorm(n,40,5) + age
X <- round(pnorm(X, mean(X), sd(X)))
Y <- 30*X + age + 40*sex
df <- data.frame(age = age, sex = sex, X = X, Y = Y)
df$w <- weightit(data = df, formula = X ~ age + sex)$weights

svy_tbl <- svydesign(~1, data = df, weights = ~w) %>%
  tbl_svysummary(by = X)
svy_tbl |> 
  as_kable()
Characteristic 0, N = 81,261 1, N = 93,096
age 57 (51, 64) 62 (57, 67)
sex 28,743 (35%) 50,170 (54%)
Y 70 (57, 90) 115 (94, 131)
w 1.5 (1.1, 4.0) 1.6 (1.1, 6.1)

Created on 2023-10-07 with reprex v2.0.2

from gtsummary.

larmarange avatar larmarange commented on June 9, 2024

On survey side, it could be worth to mention the issue to their team, at lest to mention in the documentation that weights is a reserved named. (even if this variable is something else than the survey weights).

On gtsummary side, we could eventually add a check on the names in include and add a specific error message. @ddsjoberg What do you think?

from gtsummary.

ddsjoberg avatar ddsjoberg commented on June 9, 2024

Before we add a message in gtsummary, @zheer-kejlberg can you file a bug report with survey package? Hopefully, they'll just update on their end and we won't need to keep track of this message. Sound good @larmarange ?

from gtsummary.

larmarange avatar larmarange commented on June 9, 2024

Good to me

from gtsummary.

zheer-kejlberg avatar zheer-kejlberg commented on June 9, 2024

Sounds great! Thanks for the quick response. I’ll file a bug with survey and keep you posted once they respond.

from gtsummary.

ddsjoberg avatar ddsjoberg commented on June 9, 2024

Great, thank you! Please update us on the outcome! Even if they don't wish to make the update in survey, i hope more informative messaging could be added.

from gtsummary.

Related Issues (20)

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.