add_p.tbl_svysummary: Adds p-values to svysummary tables

Description Usage Arguments Value Example Output Author(s) See Also Examples

View source: R/add_p.R

Description

\lifecycle

experimental Adds p-values to tables created by tbl_svysummary by comparing values across groups.

Usage

1
2
3
4
5
6
7
8
9
## S3 method for class 'tbl_svysummary'
add_p(
  x,
  test = NULL,
  pvalue_fun = NULL,
  include = everything(),
  test.args = NULL,
  ...
)

Arguments

x

Object with class tbl_svysummary from the tbl_svysummary function

test

List of formulas specifying statistical tests to perform, e.g. list(all_continuous() ~ "svy.t.test", all_categorical() ~ "svy.wald.test"). Options include

  • "svy.t.test" for a t-test adapted to complex survey samples (cf. survey::svyttest),

  • "svy.wilcox.test" for a Wilcoxon rank-sum test for complex survey samples (cf. survey::svyranktest),

  • "svy.kruskal.test" for a Kruskal-Wallis rank-sum test for complex survey samples (cf. survey::svyranktest),

  • "svy.vanderwaerden.test" for a van der Waerden's normal-scores test for complex survey samples (cf. survey::svyranktest),

  • "svy.median.test" for a Mood's test for the median for complex survey samples (cf. survey::svyranktest),

  • "svy.chisq.test" for a Chi-squared test with Rao & Scott's second-order correction (cf. survey::svychisq),

  • "svy.adj.chisq.test" for a Chi-squared test adjusted by a design effect estimate (cf. survey::svychisq),

  • "svy.wald.test" for a Wald test of independence for complex survey samples (cf. survey::svychisq),

  • "svy.adj.wald.test" for an adjusted Wald test of independence for complex survey samples (cf. survey::svychisq),

  • "svy.lincom.test" for a test of independence using the exact asymptotic distribution for complex survey samples (cf. survey::svychisq),

  • "svy.saddlepoint.test" for a test of independence using a saddlepoint approximation for complex survey samples (cf. survey::svychisq),

Tests default to "svy.wilcox.test" for continuous variables and "svy.chisq.test" for categorical variables.

pvalue_fun

Function to round and format p-values. Default is style_pvalue. The function must have a numeric vector input (the numeric, exact p-value), and return a string that is the rounded/formatted p-value (e.g. pvalue_fun = function(x) style_pvalue(x, digits = 2) or equivalently, purrr::partial(style_pvalue, digits = 2)).

include

Variables to include in output. Input may be a vector of quoted variable names, unquoted variable names, or tidyselect select helper functions. Default is everything().

test.args

List of formulas containing additional arguments to pass to tests that accept arguments. For example, add an argument for all t-tests, use test.args = all_tests("t.test") ~ list(var.equal = TRUE)

...

Not used

Value

A tbl_svysummary object

Example Output

Example 1

Example 2

Example 3

Author(s)

Joseph Larmarange

See Also

Other tbl_svysummary tools: add_n.tbl_summary(), add_overall(), add_q(), add_stat_label(), modify, tbl_merge(), tbl_stack(), tbl_svysummary()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Example 1 ----------------------------------
# A simple weighted dataset
add_p_svysummary_ex1 <-
  survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) %>%
  tbl_svysummary(by = Survived) %>%
  add_p()

# A dataset with a complex design
data(api, package = "survey")
d_clust <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc)

# Example 2 ----------------------------------
add_p_svysummary_ex2 <-
  tbl_svysummary(d_clust, by = both, include = c(cname, api00, api99, both)) %>%
  add_p()

# Example 3 ----------------------------------
# change tests to svy t-test and Wald test
add_p_svysummary_ex3 <-
  tbl_svysummary(d_clust, by = both, include = c(cname, api00, api99, both)) %>%
  add_p(
    test = list(all_continuous() ~ "svy.t.test",
                all_categorical() ~ "svy.wald.test")
  )

ddsjoberg/gtsummary documentation built on April 8, 2021, 5:48 a.m.