Skip to content

Commit

Permalink
update crosstable functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sbalci committed Jul 2, 2023
1 parent 87af7e8 commit 3e54797
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 60 deletions.
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: ClinicoPathDescriptives
Title: Descriptives Functions for Clinicopathological Research
Version: 0.0.2.06
Date: 2023-06-01
Version: 0.0.2.07
Date: 2023-07-02
Authors@R:
person(given = "Serdar",
family = "Balci",
Expand Down Expand Up @@ -47,10 +47,10 @@ Imports:
DiagrammeR,
DiagrammeRsvg,
rsvg,
shiny
shiny,
gtsummary
Remotes:
nbarrowman/vtree@ffa53d4ea5050fa9b26918f4bb30595e91a0f489,
ddsjoberg/gtsummary@f43332fde6264ff95d092da644284dac739c4e17
nbarrowman/vtree@ffa53d4ea5050fa9b26918f4bb30595e91a0f489
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
Expand Down
6 changes: 3 additions & 3 deletions R/alluvial.h.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ alluvialOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
initialize = function(
vars = NULL,
condensationvar = NULL,
excl = TRUE,
excl = FALSE,
marg = FALSE,
fill = "first_variable",
bin = "default",
Expand All @@ -31,7 +31,7 @@ alluvialOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
private$..excl <- jmvcore::OptionBool$new(
"excl",
excl,
default=TRUE)
default=FALSE)
private$..marg <- jmvcore::OptionBool$new(
"marg",
marg,
Expand Down Expand Up @@ -205,7 +205,7 @@ alluvial <- function(
data,
vars,
condensationvar,
excl = TRUE,
excl = FALSE,
marg = FALSE,
fill = "first_variable",
bin = "default",
Expand Down
79 changes: 53 additions & 26 deletions R/crosstable.b.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ crosstableClass <- if (requireNamespace('jmvcore')) R6::R6Class(
sty <- self$options$sty




if (is.null(self$options$vars) || is.null(self$options$group)) {

# ToDo Message ----
Expand All @@ -39,27 +37,32 @@ crosstableClass <- if (requireNamespace('jmvcore')) R6::R6Class(
todo <- ""
html <- self$results$todo
html$setContent(todo)
}


if (sty == "finalfit") {


todo <- glue::glue("
todo2 <- glue::glue("
<br>
<b>finalfit</b> uses
<em>aov (analysis of variance) or t.test for Welch two sample t-test. Note continuous non-parametric test is always Kruskal Wallis (kruskal.test) which in two-group setting is equivalent to Mann-Whitney U /Wilcoxon rank sum test</em>. See full documentation <a href= 'https://finalfit.org/reference/summary_factorlist.html'>here</a>.
"
)

}

html <- self$results$todo
html$setContent(todo)

if (sty != "finalfit") {

todo2 <- glue::glue("")
}

html <- self$results$todo2
html$setContent(todo2)

# Error Message ----

if (nrow(self$data) == 0) stop("Data contains no (complete) rows")
if (nrow(self$data) == 0) stop("Data contains no (complete) rows")

# Prepare Data ----

Expand Down Expand Up @@ -149,41 +152,48 @@ crosstableClass <- if (requireNamespace('jmvcore')) R6::R6Class(
na_include = FALSE,
na_to_p = FALSE,
cont = self$options$cont,
cont_nonpara = NULL,
cont_cut = 5,
cont_range = TRUE,


p_cont_para = "aov",
p_cat = self$options$pcat,








cont_nonpara = NULL,
cont_cut = 5,
dependent_label_prefix = "Dependent: ",
dependent_label_suffix = "",
row_totals_colname = "Total N",
row_missing_colname = "Missing N",




column = TRUE,

orderbytotal = FALSE,
digits = c(1, 1, 3, 1),
digits = c(1, 1, 3, 1, 0),


na_include_dependent = FALSE,
na_complete_cases = FALSE,
fit_id = FALSE,
add_col_totals = FALSE,

na_to_prop = TRUE,


add_col_totals = TRUE,
include_col_totals_percent = TRUE,
col_totals_rowname = NULL,
col_totals_prefix = "",
add_row_totals = FALSE,
include_row_missing_col = TRUE
include_row_totals_percent = TRUE,
include_row_missing_col = TRUE,

catTest = NULL,
weights = NULL







) -> tablefinalfit

Expand Down Expand Up @@ -213,10 +223,22 @@ crosstableClass <- if (requireNamespace('jmvcore')) R6::R6Class(

tablegtsummary <-
gtsummary::tbl_summary(data = mydata,
by = self$options$group) %>%
gtsummary::modify_header(stat_by =
gt::md("**{level}** N = {n} ({style_percent(p)}%)")) %>%
by = self$options$group,
statistic = list(
gtsummary::all_continuous() ~ "{mean} ({sd})",
gtsummary::all_categorical() ~ "{n} / {N} ({p}%)"
),
digits = gtsummary::all_continuous() ~ 2,
missing_text = "(Missing)"

) %>%
gtsummary::modify_header(
update = gtsummary::all_stat_cols() ~ structure("**{level}** N = {n} ({style_percent(p)}%)", class = "from_markdown")
# stat_by =
# gt::md("**{level}** N = {n} ({style_percent(p)}%)")
) %>%
gtsummary::add_n(x = .) %>%
gtsummary::add_overall() %>%
gtsummary::bold_labels(x = .) %>%
gtsummary::add_p(x = .,
pvalue_fun =
Expand All @@ -225,6 +247,11 @@ crosstableClass <- if (requireNamespace('jmvcore')) R6::R6Class(
digits = 2)
) %>%
gtsummary::add_q()
# %>%
# gtsummary::bold_labels() %>%
# gtsummary::bold_levels() %>%
# gtsummary::bold_p()


tablegtsummary <-
gtsummary::as_kable_extra(tablegtsummary)
Expand Down Expand Up @@ -284,5 +311,5 @@ crosstableClass <- if (requireNamespace('jmvcore')) R6::R6Class(
# tab3 <- CreateTableOne(vars = myVars, strata = "trt" , data = pbc, factorVars = catVars)

}
})
)
)
33 changes: 25 additions & 8 deletions R/crosstable.h.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crosstableOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
vars = NULL,
group = NULL,
sty = "nejm",
excl = TRUE,
excl = FALSE,
cont = "mean",
pcat = "chisq", ...) {

Expand Down Expand Up @@ -44,7 +44,7 @@ crosstableOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
private$..excl <- jmvcore::OptionBool$new(
"excl",
excl,
default=TRUE)
default=FALSE)
private$..cont <- jmvcore::OptionList$new(
"cont",
cont,
Expand Down Expand Up @@ -88,6 +88,7 @@ crosstableResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
inherit = jmvcore::Group,
active = list(
todo = function() private$.items[["todo"]],
todo2 = function() private$.items[["todo2"]],
tablestyle1 = function() private$.items[["tablestyle1"]],
tablestyle2 = function() private$.items[["tablestyle2"]],
tablestyle3 = function() private$.items[["tablestyle3"]],
Expand All @@ -109,14 +110,26 @@ crosstableResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"vars",
"group",
"cont",
"pcat")))
"pcat",
"sty")))
self$add(jmvcore::Html$new(
options=options,
name="todo2",
title="To Do",
clearWith=list(
"vars",
"group",
"cont",
"pcat",
"sty")))
self$add(jmvcore::Html$new(
options=options,
name="tablestyle1",
title="`Cross Table - ${group}`",
clearWith=list(
"vars",
"group"),
"group",
"sty"),
visible="(sty:arsenal)",
refs="arsenal"))
self$add(jmvcore::Html$new(
Expand All @@ -127,7 +140,8 @@ crosstableResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"vars",
"group",
"cont",
"pcat"),
"pcat",
"sty"),
visible="(sty:finalfit)",
refs="finalfit"))
self$add(jmvcore::Html$new(
Expand All @@ -136,7 +150,8 @@ crosstableResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
title="`Cross Table - ${group}`",
clearWith=list(
"vars",
"group"),
"group",
"sty"),
visible="(sty:gtsummary)",
refs="gtsummary"))
self$add(jmvcore::Html$new(
Expand All @@ -145,7 +160,8 @@ crosstableResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
title="`Cross Table - ${group}`",
clearWith=list(
"vars",
"group"),
"group",
"sty"),
visible="(sty:nejm || sty:lancet || sty:hmisc)",
refs="tangram"))}))

Expand Down Expand Up @@ -188,6 +204,7 @@ crosstableBase <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
#' @return A results object containing:
#' \tabular{llllll}{
#' \code{results$todo} \tab \tab \tab \tab \tab a html \cr
#' \code{results$todo2} \tab \tab \tab \tab \tab a html \cr
#' \code{results$tablestyle1} \tab \tab \tab \tab \tab a html \cr
#' \code{results$tablestyle2} \tab \tab \tab \tab \tab a html \cr
#' \code{results$tablestyle3} \tab \tab \tab \tab \tab a html \cr
Expand All @@ -200,7 +217,7 @@ crosstable <- function(
vars,
group,
sty = "nejm",
excl = TRUE,
excl = FALSE,
cont = "mean",
pcat = "chisq") {

Expand Down
6 changes: 3 additions & 3 deletions R/tableone.h.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tableoneOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
initialize = function(
vars = NULL,
sty = "t1",
excl = TRUE, ...) {
excl = FALSE, ...) {

super$initialize(
package="ClinicoPathDescriptives",
Expand All @@ -31,7 +31,7 @@ tableoneOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
private$..excl <- jmvcore::OptionBool$new(
"excl",
excl,
default=TRUE)
default=FALSE)

self$.addOption(private$..vars)
self$.addOption(private$..sty)
Expand Down Expand Up @@ -160,7 +160,7 @@ tableone <- function(
data,
vars,
sty = "t1",
excl = TRUE) {
excl = FALSE) {

if ( ! requireNamespace("jmvcore", quietly=TRUE))
stop("tableone requires jmvcore to be installed (restart may be required)")
Expand Down
6 changes: 3 additions & 3 deletions R/vartree.h.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ vartreeOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
follow = NULL,
followLevel1 = NULL,
followLevel2 = NULL,
excl = TRUE,
excl = FALSE,
vp = TRUE,
horizontal = FALSE,
sline = TRUE,
Expand Down Expand Up @@ -105,7 +105,7 @@ vartreeOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
private$..excl <- jmvcore::OptionBool$new(
"excl",
excl,
default=TRUE)
default=FALSE)
private$..vp <- jmvcore::OptionBool$new(
"vp",
vp,
Expand Down Expand Up @@ -360,7 +360,7 @@ vartree <- function(
follow,
followLevel1,
followLevel2,
excl = TRUE,
excl = FALSE,
vp = TRUE,
horizontal = FALSE,
sline = TRUE,
Expand Down
4 changes: 2 additions & 2 deletions jamovi/0000.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: Descriptives Functions for Clinicopathological Research
name: ClinicoPathDescriptives
version: 0.0.2.06
version: 0.0.2.07
jms: '1.0'
authors:
- Serdar Balci
maintainer: Serdar Balci <[email protected]>
date: '2023-06-01'
date: '2023-07-02'
type: R
description: >-
Descriptives Functions for Clinicopathological Research Descriptive functions
Expand Down
2 changes: 1 addition & 1 deletion jamovi/alluvial.a.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ options:
- name: excl
title: Exclude missing (NA)
type: Bool
default: true
default: false

- name: marg
title: Marginal plots
Expand Down
2 changes: 1 addition & 1 deletion jamovi/crosstable.a.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ options:
- name: excl
title: Exclude Missing (NA)
type: Bool
default: true
default: false


- name: cont
Expand Down
Loading

0 comments on commit 3e54797

Please sign in to comment.