Comments (6)
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.
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.
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.
Good to me
from gtsummary.
Sounds great! Thanks for the quick response. I’ll file a bug with survey and keep you posted once they respond.
from gtsummary.
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)
- Question / Feature request: type "dichotomous" option in tbl_summary not displaying both levels HOT 3
- v2.0 `modify_footnote()` updates HOT 1
- v2.0 README
- Wording in `tbl_uregression()` documentation: univariable instead of univariate? HOT 2
- Compatibility with VGAM HOT 3
- Improve `style_number()` speed?
- Feature request: Informative caption when using `tbl_regression()` with `mice::mira` HOT 2
- v2.0 Add arguments `style_*(prefix, suffix)` ?
- Feature request: Automated suppression of small counts HOT 1
- v2.0 `tbl_stack()`, `tbl_merge()`, `tbl_strata()`, etc.
- `show_header_names()` updates HOT 1
- Feature request: Extend `tbl_merge` to all `gt` tables HOT 2
- Review `tbl_custom_summary()`
- Bug Report: Factor level with `NA` label causes "Column stat_n doesn't exist" error (e.g. created by forcats). HOT 3
- Improve `tbl_summary()` error message for continuous2 type
- v2.0 Add unit test HOT 1
- tbl_strata coding issues HOT 1
- Bug Report: tbl_strata does not treat the values in a small stratum (i.e. with only 7 values) as continuous (despite specification that it should), treats them as categorical HOT 1
- v2.0 Create `card_continuous()`
- Questions about `card_*()` functions.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gtsummary.