AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / user-23179690

NEA's questions

Martin Hope
NEA
Asked: 2025-04-08 04:41:33 +0800 CST

O elemento de tema "tbl_summary-arg:type" no gtsummary não funciona

  • 5

O elemento de tema "tbl_summary-arg:type" no gtsummary não funciona, embora o argumento de tipo funcione bem com o mesmo código

library(gtsummary)
packageVersion("gtsummary")
#> [1] '2.1.0.9010'

# Reset theme to defaults first
reset_gtsummary_theme()
tbl_summary(trial) |> 
  # Converting to a flextable object because gtsummary 
  # objects aren't rendered properly on Stack Overflow
  as_flex_table()


# Apply my theme
set_gtsummary_theme(list("tbl_summary-arg:type" =
                           list(all_dichotomous() ~ "categorical")))
# check if it works
trial |>
  tbl_summary() |> 
  as_flex_table()
#Not working Patient Died   is still presented as dichotomous

#Checking type argument
reset_gtsummary_theme()
trial |>
  tbl_summary(type = all_dichotomous() ~ "categorical") |> 
  as_flex_table()
#works well

Criado em 2025-04-07 com reprex v2.1.1

Estou esquecendo de algo que está fazendo com que não funcione?

  • 2 respostas
  • 22 Views
Martin Hope
NEA
Asked: 2024-10-08 04:42:02 +0800 CST

Encontrar pontos de corte ótimos para dividir uma variável em grupos iguais considerando empates nos quais os quantis não funcionam

  • 6

Tenho uma variável xe quero dividi-la em três grupos com observações iguais. No entanto, usar quantis não resultou nos grupos mais iguais devido aos empates, pois os pontos de corte dos quantis podem resultar em empates sendo alocados em mais de um grupo. Estou procurando uma função ou algoritmo que possa encontrar os melhores pontos de corte, garantindo que os empates não sejam divididos entre vários grupos.

x = c(26, 34, 27, 26, 38, 40, 34, 28, 27, 36, 29, 30, 29, 44, 30, 
      34, 32, 30, 26, 29, 34, 32, 38, 27, 35, 29, 28, 34, 26, 27, 27, 
      30, 27, 28, 27, 28, 28, 27, 29, 29, 28, 29, 29, 28, 29, 29, 28, 
      27, 29, 27, 36, 34, 34, 39, 34, 31, 31, 33, 35, 31, 31, 32, 37, 
      38, 32, 31, 28, 33, 33, 28, 27, 27, 30, 31, 32, 28, 27, 31, 36, 
      27, 33, 31, 34, 31, 35, 38, 37, 36, 39, 33, 33, 28, 41, 34, 35, 
      37, 37, 41, 32, 37, 30, 34, 38, 30, 40, 35, 31, 30, 30, 29, 29, 
      30, 29, 35, 28, 27, 27, 27, 29, 27, 28, 27, 27, 27, 26, 28, 28, 
      27, 29, 29, 27, 27, 27, 27, 29, 27, 28, 27, 28, 34, 29, 28, 28, 
      28, 29, 38, 33, 39, 28, 27, 28, 27, 29, 34, 29, 32, 70, 26, 29, 
      43, 48, 30, 30, 27, 26, 29, 27, 27, 27, 27, 28, 28, 27, 28, 28, 
      27, 28, 28, 38, 52, 26, 31, 56, 29, 29, 36, 28, 35, 32, 34, 35, 
      28, 27, 37, 26, 26, 32, 26, 27, 30, 28, 28, 30, 29, 30, 29, 29, 
      28, 26, 33, 39, 26, 31, 27, 28, 30, 30, 28, 28, 29, 26, 27, 26, 
      29, 28, 28, 27, 27, 27, 28, 27, 28, 28, 28, 28, 28, 27, 27, 29, 
      27, 26, 28, 28, 27, 27, 28, 27, 28, 28, 30, 27, 30, 28, 32, 34, 
      28, 27, 28, 28, 27, 28, 27, 27, 27, 28, 27, 28, 27, 27, 28, 27, 
      27, 27, 27, 27, 28, 27, 27, 27, 26, 27, 27, 30, 28, 27, 30, 30, 
      42, 26, 27, 40, 33, 29, 29, 29, 52, 58, 44, 32, 43, 30, 27, 38, 
      30, 27, 30, 27, 31, 39, 35, 32, 32, 34, 45, 31, 44, 42, 29, 29, 
      30, 30, 50, 30, 33, 31, 35, 27, 28, 27, 28, 55, 28, 28, 28, 27, 
      27, 28, 29, 27, 28, 27, 28, 28, 28, 28, 27, 28, 29, 34, 45, 27, 
      29, 61, 38, 62, 29, 36, 36, 30, 31, 45, 27, 30, 28, 29, 44, 45, 
      42, 52, 50, 52, 42, 38, 42, 32, 27, 37, 40, 52, 27, 36, 38, 39, 
      34, 30, 29, 34, 29, 26, 35, 43, 33, 40, 35, 33, 41, 61, 45, 35, 
      52, 50, 38, 43, 29, 35, 38, 39, 31, 28, 28, 29, 34, 27, 30, 32, 
      28, 26, 28, 27, 26, 29, 27, 26, 29, 29, 27, 29, 27, 27, 29, 27, 
      30, 29, 25, 30, 27, 29, 29, 30, 30, 27, 30, 28, 28, 27, 29, 29, 
      30, 29, 27, 28, 28, 28, 29, 28, 28, 27, 28, 29, 28, 29, 27, 28, 
      28, 28, 30, 27, 27, 28, 26, 28, 27, 27, 28, 28, 28, 28, 27, 27, 
      28, 27, 28, 27, 35, 27, 27, 28, 29, 27, 27, 28, 26, 27, 28, 28, 
      28, 27, 27, 27, 28, 32, 27, 28, 28, 29, 28, 28, 27, 28, 28, 30, 
      29, 28, 25, 27, 28, 30, 28, 30, 30, 28, 30, 30, 28, 29, 30, 28, 
      28, 26, 27, 28, 45, 36, 40, 28, 50, 45, 30, 45, 40, 30, 45, 45, 
      29, 45, 35, 40, 40, 30, 30, 30, 45, 40, 40, 40, 40, 40, 40, 35, 
      34, 49, 40, 30, 61, 35, 40, 30, 36, 35, 29, 27, 48, 28, 27, 27, 
      26, 27, 29, 27, 26, 27, 31, 27, 27, 28, 29, 28, 27, 28, 29, 38, 
      30, 26, 36, 40, 58, 57, 30, 33, 56, 35, 39, 37, 38, 46, 37, 39, 
      39, 45, 35, 46, 58, 65, 60, 45, 32, 36, 43, 32, 68, 39, 28, 31, 
      27, 28, 27, 37, 38, 30, 30, 28, 36, 45, 28, 26, 28, 28, 28, 27, 
      26, 28, 27, 26, 26, 27, 28, 31, 32, 37, 35, 29, 33, 35, 29, 41, 
      32, 36, 29, 28, 28, 28, 37, 36, 37, 35, 31, 32, 30, 27, 31, 32, 
      31, 33, 28, 33, 29, 27, 28, 31, 28, 31, 28, 34, 27, 27, 28, 27, 
      27, 27, 27, 26, 26, 26, 27, 27, 28, 26, 31, 26, 29, 31, 29, 29, 
      30, 29, 30, 31, 32, 29, 30, 27, 32, 27, 26, 31, 31, 31, 27, 27, 
      33, 27, 28, 28, 28, 26, 27, 27, 28, 30, 27, 27, 30, 29, 26, 27, 
      28, 27, 26, 26, 28, 27, 26, 28, 28, 26, 28, 27, 29, 27, 28, 28, 
      26, 26, 29, 28, 27, 27, 27, 28, 26, 25, 27, 29, 30, 36, 40, 28, 
      38, 26, 27, 27, 50, 27, 45, 27, 28, 26, 25, 35, 35, 44, 30, 27, 
      31, 27, 28, 27, 27, 28, 28, 28, 35, 33, 30, 28, 28, 29, 29, 36, 
      32, 36, 34, 32, 28, 28, 29, 28, 28, 32, 30, 35, 33, 36, 32, 30, 
      32, 36, 34)

quantile(x, probs = c(0.333, 0.666))
#> 33.3% 66.6% 
#>    28    31

l = cut(x, breaks = c(-Inf, 28, 31, Inf))
table(l)
#> l
#> (-Inf,28]   (28,31] (31, Inf] 
#>       387       185       246

#using different cut-off points yielded more equal groups
l = cut(x, breaks = c(-Inf, 28, 32, Inf))
table(l)
#> l
#> (-Inf,28]   (28,32] (32, Inf] 
#>       387       214       217

#again using different cut-off points which yielded more equal groups
l = cut(x, breaks = c(-Inf, 27, 32, Inf))
table(l)
#> l
#> (-Inf,27]   (27,32] (32, Inf] 
#>       222       379       217

Criado em 2024-10-07 com reprex v2.1.1

Editar: Acho que a palavra "igual" não está clara, então acho que posso dizer que busco a alocação mais adequada que forneça a menor diferença entre os números de observação do grupo mais alto e mais baixo, agrupando apenas números consecutivos sem empates em mais de um grupo

  • 2 respostas
  • 65 Views
Martin Hope
NEA
Asked: 2024-09-13 01:00:45 +0800 CST

Erro em tbl_continuous() no gtsummary ao usar temas

  • 7

Eu estava fazendo um novo tema no gtsummarypacote, mas parece que ele afeta a tbl_continuousfunção, embora eu não tenha feito nenhum argumento sobre isso tbl_continuousno meu tema. Além disso, não consigo encontrar na documentação nenhum elemento de tema específico para tbl_continuous.

Aqui está meu código:

    > my_theme = list(
    +   "pkgwide-str:theme_name" = "JO JO",
    +   "pkgwide-fn:pvalue_fun" = function(x) style_pvalue(x, digits = 2),
    +   "pkgwide-fun:pre_conversion" = function(x) bold_labels(x),
    +   "pkgwide-str:ci.sep" = "-",
    +   #$ tbl_regression $#
    +   "tbl_regression-str:ref_row_text" = "1(r)",
    +   #$ tbl_summary $#
    +   "tbl_summary-fn:percent_fun" = function(x) style_percent(x, symbol = T, digits = 1),
    +   "tbl_summary-arg:statistic" = list(all_continuous() ~"{mean} ({sd})",
    +                                      all_categorical() ~ "{n} ({p})"))
    > check_gtsummary_theme(my_theme)
    ✔ Looks good!
    > set_gtsummary_theme(my_theme)
    Setting theme "JO JO"
    > tbl_continuous(
    +   data = trial,
    +   variable = age,
    +   by = trt,
    +   include = grade
    + )
    Error in `tbl_continuous()`:
    ! Problem with the `statistic` argument.
    Error converting string "p" to a function.
    ℹ Is the name spelled correctly and available?
    Run `rlang::last_trace()` to see where the error occurred.
    > rlang::last_trace()
    <error/rlang_error>
    Error in `tbl_continuous()`:
    ! Problem with the `statistic` argument.
    Error converting string "p" to a function.
    ℹ Is the name spelled correctly and available?
    ---
    Backtrace:
        ▆
     1. └─gtsummary::tbl_continuous(data = trial, variable = age, by = trt, include = grade)
    Run rlang::last_trace(drop = FALSE) to see 27 hidden frames.
    > rlang::last_trace(drop = FALSE)
    <error/rlang_error>
    Error in `tbl_continuous()`:
    ! Problem with the `statistic` argument.
    Error converting string "p" to a function.
    ℹ Is the name spelled correctly and available?
    ---
    Backtrace:
         ▆
      1. └─gtsummary::tbl_continuous(data = trial, variable = age, by = trt, include = grade)
      2.   ├─dplyr::bind_rows(...)
      3.   │ └─rlang::list2(...)
      4.   └─gtsummary:::map(...)
      5.     └─base::lapply(.x, .f, ...)
      6.       └─gtsummary (local) FUN(X[[i]], ...)
      7.         ├─cards::bind_ard(...)
      8.         │ └─dplyr::bind_rows(...)
      9.         │   └─rlang::list2(...)
     10.         ├─cards::ard_continuous(...)
     11.         ├─cards:::ard_continuous.data.frame(...)
     12.         │ ├─cards::process_formula_selectors(...)
     13.         │ └─cards:::process_formula_selectors.data.frame(...)
     14.         │   └─rlang::dots_list(...)
     15.         ├─rlang::set_names(...)
     16.         └─gtsummary:::.continuous_statistics_chr_to_fun(statistic)
     17.           └─base::lapply(...)
     18.             └─gtsummary (local) FUN(X[[i]], ...)
     19.               ├─rlang::set_names(...)
     20.               └─gtsummary:::map2(...)
     21.                 └─base::mapply(.f, .x, .y, MoreArgs = list(...), SIMPLIFY = FALSE)
     22.                   └─gtsummary (local) `<fn>`(dots[[1L]][[2L]], dots[[2L]][[2L]])
     23.                     └─base::tryCatch(...)
     24.                       └─base (local) tryCatchList(expr, classes, parentenv, handlers)
     25.                         └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
     26.                           └─value[[3L]](cond)
     27.                             └─cli::cli_abort(...)
     28.                               └─rlang::abort(...)
    > reset_gtsummary_theme()
    > tbl_continuous(
    +   data = trial,
    +   variable = age,
    +   by = trt,
    +   include = grade
    + )

Quando eu reseto o tema, ele emite a tabela sem problemas. Quero saber onde está o problema e também por que não há elementos de tema específicos para tbl_continuous.

Editar: Também tentei usar theme_gtsummary_mean_sd()o built-in gtsummarye o mesmo erro persiste.

    > theme_gtsummary_mean_sd()
    > trial |> 
    +   tbl_continuous(age)
    Error in `tbl_continuous()`:
    ! Problem with the `statistic` argument.
    Error converting string "p" to a function.
    ℹ Is the name spelled correctly and available?
    Run `rlang::last_trace()` to see where the error occurred.
  • 1 respostas
  • 30 Views

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Reformatar números, inserindo separadores em posições fixas

    • 6 respostas
  • Marko Smith

    Por que os conceitos do C++20 causam erros de restrição cíclica, enquanto o SFINAE antigo não?

    • 2 respostas
  • Marko Smith

    Problema com extensão desinstalada automaticamente do VScode (tema Material)

    • 2 respostas
  • Marko Smith

    Vue 3: Erro na criação "Identificador esperado, mas encontrado 'import'" [duplicado]

    • 1 respostas
  • Marko Smith

    Qual é o propósito de `enum class` com um tipo subjacente especificado, mas sem enumeradores?

    • 1 respostas
  • Marko Smith

    Como faço para corrigir um erro MODULE_NOT_FOUND para um módulo que não importei manualmente?

    • 6 respostas
  • Marko Smith

    `(expression, lvalue) = rvalue` é uma atribuição válida em C ou C++? Por que alguns compiladores aceitam/rejeitam isso?

    • 3 respostas
  • Marko Smith

    Um programa vazio que não faz nada em C++ precisa de um heap de 204 KB, mas não em C

    • 1 respostas
  • Marko Smith

    PowerBI atualmente quebrado com BigQuery: problema de driver Simba com atualização do Windows

    • 2 respostas
  • Marko Smith

    AdMob: MobileAds.initialize() - "java.lang.Integer não pode ser convertido em java.lang.String" para alguns dispositivos

    • 1 respostas
  • Martin Hope
    Fantastic Mr Fox Somente o tipo copiável não é aceito na implementação std::vector do MSVC 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant Encontre o próximo dia da semana usando o cronógrafo 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor O inicializador de membro do construtor pode incluir a inicialização de outro membro? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský Por que os conceitos do C++20 causam erros de restrição cíclica, enquanto o SFINAE antigo não? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul O C++20 mudou para permitir a conversão de `type(&)[N]` de matriz de limites conhecidos para `type(&)[]` de matriz de limites desconhecidos? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann Como/por que {2,3,10} e {x,3,10} com x=2 são ordenados de forma diferente? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller O ponto e vírgula agora é opcional em condicionais bash com [[ .. ]] na versão 5.2? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench Por que um traço duplo (--) faz com que esta cláusula MariaDB seja avaliada como verdadeira? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng Por que `dict(id=1, **{'id': 2})` às vezes gera `KeyError: 'id'` em vez de um TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob: MobileAds.initialize() - "java.lang.Integer não pode ser convertido em java.lang.String" para alguns dispositivos 2024-03-20 03:12:31 +0800 CST

Hot tag

python javascript c++ c# java typescript sql reactjs html

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve