Giter Club home page Giter Club logo

Comments (8)

larmarange avatar larmarange commented on June 9, 2024

Because the default (t.test) is not implemented for tbl_svysummary(). You should use "smd", cf. https://www.danieldsjoberg.com/gtsummary/reference/tests.html#tbl-svysummary-add-difference-

Currently, add_difference() does not change the default tests when applied to a tbl_svysummary()

from gtsummary.

ddsjoberg avatar ddsjoberg commented on June 9, 2024

I was thinking more about the tbl_svysummary() table itself. The unobserved columns appear in the table, even if we make the underlying column character.

library(gtsummary)
library(PNSIBGE)

pns <- get_pns(year = 2019, labels = TRUE)
pns.2 <- subset(pns, C009  %in% c("Branca", "Preta")) 
pns.2$variables$C009 <- as.character(pns.2$variables$C009)

pns.2 |> 
  gtsummary::tbl_svysummary(by = C009, include = c(C006)) |> 
  gtsummary::as_kable()
Characteristic Amarela, N = 0 Branca, N = 91,037,722 Ignorado, N = 0 Indígena, N = 0 Parda, N = 0 Preta, N = 21,786,515
C006
Homem 0 (NA%) 42,682,905 (47%) 0 (NA%) 0 (NA%) 0 (NA%) 10,691,164 (49%)
Mulher 0 (NA%) 48,354,817 (53%) 0 (NA%) 0 (NA%) 0 (NA%) 11,095,351 (51%)

But I just tried to tabulate directly with the survey package, and it still shows all levels, even when the column has previously been converted to a character.

image

So what they are dealing with is a non-standard situation, and they'd just need to write their own method in add_stat() for this, and hide the unobserved columns themselves.

from gtsummary.

larmarange avatar larmarange commented on June 9, 2024

Probably because somewhere the levels are still declared. pns.2$variables$C009 <- as.character(pns.2$variables$C009) did not change metadata stored within the survey object.

It is much safier to use fct_drop() through srvyr::mutate()

from gtsummary.

larmarange avatar larmarange commented on June 9, 2024

But a question remains open: if this is a tbl_svysummary table, should we apply, by default, a relevant test?

from gtsummary.

ddsjoberg avatar ddsjoberg commented on June 9, 2024

Even dropping the levels with srvry, the unobserved levels appear from the survey function.

pns.2 <- 
  srvyr::as_survey_design(pns) |> 
  srvyr::filter(C009 %in% c("Branca", "Preta")) |> 
  srvyr::mutate(C009 = as.character(C009))

survey::svytable(~C009,pns.2)
#> C009
#>  Amarela   Branca Ignorado Indígena    Parda    Preta 
#>        0 91037722        0        0        0 21786515 

from gtsummary.

ddsjoberg avatar ddsjoberg commented on June 9, 2024

But, yes, I better default is warrented!

from gtsummary.

larmarange avatar larmarange commented on June 9, 2024

If I remember, as.character keeps the levels attributes, while forcats::fct_drop() remove unobserved levels.

from gtsummary.

ddsjoberg avatar ddsjoberg commented on June 9, 2024

Same issue with forcats::fct_drop() unfortunately

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.