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

# S3 method for tbl_svysummary
add_p(x, test = NULL, pvalue_fun = NULL, include = everything(), ...)

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().

...

Not used

Value

A tbl_svysummary object

Example Output

Example 1

Example 2

Example 3

See also

Author

Joseph Larmarange

Examples

# 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") )