| prop_diff_test | R Documentation | 
The analyze function test_proportion_diff() creates a layout element to test the difference between two
proportions. The primary analysis variable, vars, indicates whether a response has occurred for each record. See
the method parameter for options of methods to use to calculate the p-value. Additionally, a stratification
variable can be supplied via the strata element of the variables argument.
test_proportion_diff(
  lyt,
  vars,
  variables = list(strata = NULL),
  method = c("chisq", "schouten", "fisher", "cmh"),
  var_labels = vars,
  na_str = default_na_str(),
  nested = TRUE,
  show_labels = "hidden",
  table_names = vars,
  section_div = NA_character_,
  ...,
  na_rm = TRUE,
  .stats = c("pval"),
  .stat_names = NULL,
  .formats = c(pval = "x.xxxx | (<0.0001)"),
  .labels = NULL,
  .indent_mods = c(pval = 1L)
)
s_test_proportion_diff(
  df,
  .var,
  .ref_group,
  .in_ref_col,
  variables = list(strata = NULL),
  method = c("chisq", "schouten", "fisher", "cmh"),
  ...
)
a_test_proportion_diff(
  df,
  ...,
  .stats = NULL,
  .stat_names = NULL,
  .formats = NULL,
  .labels = NULL,
  .indent_mods = NULL
)
| lyt | ( | 
| vars | ( | 
| variables | (named  | 
| method | ( | 
| var_labels | ( | 
| na_str | ( | 
| nested | ( | 
| show_labels | ( | 
| table_names | ( | 
| section_div | ( | 
| ... | additional arguments for the lower level functions. | 
| na_rm | ( | 
| .stats | ( Options are:  | 
| .stat_names | ( | 
| .formats | (named  | 
| .labels | (named  | 
| .indent_mods | (named  | 
| df | ( | 
| .var | ( | 
| .ref_group | ( | 
| .in_ref_col | ( | 
test_proportion_diff() returns a layout object suitable for passing to further layouting functions,
or to rtables::build_table(). Adding this function to an rtable layout will add formatted rows containing
the statistics from s_test_proportion_diff() to the table layout.
s_test_proportion_diff() returns a named list with a single item pval with an attribute label
describing the method used. The p-value tests the null hypothesis that proportions in two groups are the same.
a_test_proportion_diff() returns the corresponding list with formatted rtables::CellValue().
test_proportion_diff(): Layout-creating function which can take statistics function arguments
and additional format arguments. This function is a wrapper for rtables::analyze().
s_test_proportion_diff(): Statistics function which tests the difference between two proportions.
a_test_proportion_diff(): Formatted analysis function which is used as afun in test_proportion_diff().
h_prop_diff_test
dta <- data.frame(
  rsp = sample(c(TRUE, FALSE), 100, TRUE),
  grp = factor(rep(c("A", "B"), each = 50)),
  strata = factor(rep(c("V", "W", "X", "Y", "Z"), each = 20))
)
# With `rtables` pipelines.
l <- basic_table() %>%
  split_cols_by(var = "grp", ref_group = "B") %>%
  test_proportion_diff(
    vars = "rsp",
    method = "cmh", variables = list(strata = "strata")
  )
build_table(l, df = dta)
## "Mid" case: 4/4 respond in group A, 1/2 respond in group B.
nex <- 100 # Number of example rows
dta <- data.frame(
  "rsp" = sample(c(TRUE, FALSE), nex, TRUE),
  "grp" = sample(c("A", "B"), nex, TRUE),
  "f1" = sample(c("a1", "a2"), nex, TRUE),
  "f2" = sample(c("x", "y", "z"), nex, TRUE),
  stringsAsFactors = TRUE
)
s_test_proportion_diff(
  df = subset(dta, grp == "A"),
  .var = "rsp",
  .ref_group = subset(dta, grp == "B"),
  .in_ref_col = FALSE,
  variables = NULL,
  method = "chisq"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.